Going Mobile With Magic Xpa 3.x
Going Mobile With Magic Xpa 3.x
Going Mobile With Magic Xpa 3.x
ii
Contents
Introduction................................................................................................................... 1
About Magic xpa ....................................................................................................... 1
About the Seminar ..................................................................................................... 2
Seminar Prerequisites.................................................................................................. 2
Magic Software University .......................................................................................... 2
Setting Up the Mobile Clients .......................................................................................... 3
Mobile Design Mode .................................................................................................. 3
My First Magic Program ............................................................................................. 4
Mobile Preview Pane .................................................................................................. 4
Execution Properties File ............................................................................................. 5
Running the Program on a Mobile Device ..................................................................... 6
How Does It Work? .................................................................................................... 8
Executing a Program Directly from the Studio (Android only) ........................................... 8
Understanding the Client .............................................................................................. 11
About Mobile Devices .............................................................................................. 12
Magic xpa on a Mobile Device ................................................................................. 13
Developing in RIA .................................................................................................... 13
Form Considerations................................................................................................. 14
Window Types ..................................................................................................... 14
Form Size ............................................................................................................ 14
Placement................................................................................................................ 15
Supported Controls................................................................................................... 20
Edit Controls......................................................................................................... 21
Image Controls ..................................................................................................... 21
Two-State Images .................................................................................................. 21
Button Controls ..................................................................................................... 21
Tab Controls......................................................................................................... 21
Application Navigation ............................................................................................ 21
Navigation........................................................................................................... 21
Termination .......................................................................................................... 22
i
Design Considerations .............................................................................................. 22
Status Bar ............................................................................................................ 23
Colors and Fonts ................................................................................................... 23
Colors ................................................................................................................. 23
Fonts ................................................................................................................... 23
Adding a font manually ......................................................................................... 25
Summary ................................................................................................................. 26
Advanced Controls ...................................................................................................... 27
Tables ..................................................................................................................... 28
Landscape Mode .................................................................................................. 28
Mobile Events .......................................................................................................... 29
Selection Lists........................................................................................................... 30
Selection Program ................................................................................................. 30
Selection Controls ................................................................................................. 30
Menus .................................................................................................................... 30
Summary ................................................................................................................. 31
Interacting with the Device ............................................................................................ 33
Mobile File System ................................................................................................... 34
Querying Device Characteristics ................................................................................ 34
Finding the Device Location (GPS) .............................................................................. 35
Camera Support ...................................................................................................... 36
Gallery Support ....................................................................................................... 36
Accessing the Mobile Devices’ Capabilities ................................................................. 37
Summary ................................................................................................................. 38
Offline Implementation ................................................................................................. 39
Concept .................................................................................................................. 40
How Does It Work? .................................................................................................. 41
Summary ................................................................................................................. 42
Customization and Installation ...................................................................................... 43
Execution Properties File – Additional Information ........................................................ 44
Customizing the Application ...................................................................................... 44
Keystore File ......................................................................................................... 46
ii
APK File ............................................................................................................... 46
Installing the Client on the Android Device or Emulator ............................................. 47
Summary ................................................................................................................. 48
Preparing the Testing Environment ................................................................................. 49
Defining a Simulator ................................................................................................. 50
Android ............................................................................................................... 50
Android SDK Manager .......................................................................................... 50
Android Virtual Device Manager ............................................................................ 50
Installation on the Device ....................................................................................... 51
Using the Keyboard on the Device Simulator ............................................................ 52
Troubleshooting ....................................................................................................... 52
Mobile device fails to communicate with the Web server ........................................... 52
Execution properties file defined in the URL dialog is wrong ....................................... 53
Debugging .............................................................................................................. 53
Android ............................................................................................................... 53
iOS ..................................................................................................................... 54
Summary ................................................................................................................. 55
iii
iv
Introduction
Welcome to Magic Software University’s Going Mobile with Magic xpa 3.x self-paced
tutorial. We, at Magic Software University, hope that you will find this guide informative and
that it will assist you in getting started with this exciting product.
Applications developed using Magic xpa typically have fewer coding mistakes, undergo more
thorough prototyping, benefit from greater business-side input and optimization, and can be
more easily adapted to changing business needs.
Magic xpa enables you to focus more on the business logic of the application and less on
what is happening behind the scenes.
Please ensure that your computer meets the hardware requirements listed
on the following page.
During the course you will learn about how Magic xpa works with mobile devices.
By the end of the course you will have created programs that demonstrate the ease of use of
the Magic xpa and mobile integration.
Seminar Prerequisites
Before you start with the seminar there is basic knowledge that you need to have:
Magic xpa allows you to easily develop mobile applications by using a Mobile Design mode.
When the Mobile Design mode is enabled and controls are added to the form, some of the
properties will be set with different default values, which better support the mobile platforms.
You activate this feature by clicking the Mobile Design Mode button from the toolbar or by
opening the Options menu and selecting the Mobile Design Mode option.
The screen size is smaller. This is because it is recommended to design a screen for the
smallest device and use placement to increase the size of the controls for larger devices.
The size of controls is larger.
The color of the table is defined according to the table color and not the column color (in
the Set Table Color property).
The Table control will not show scrollbars.
button from the toolbar or by opening the Form menu and selecting the Mobile Preview
Pane option.
This lets you play around with the placement and size of the controls and see how the controls
will appear on various mobile devices. The form and control properties related to placement
and size are the properties that are supported for this preview pane.
From the floating pane you can select which mobile device you want to preview, such as
iPhone 6. Next to the name of the device, you will see the dimensions of the device.
You can also change the orientation of the device and change the zoom level.
Controls that are not supported for mobile devices, appear as a crossed out rectangle:
.
This is a Rich Client program, so if you execute the program using the F7 key, it will execute in
the RIA environment. So, to execute the program, you need to run the project.
This file can be later be embedded in your client or placed on your server accessed you’re
your client using a URL.
1. Copy the devprops.txt file from the RIAModules\Android folder to a folder on your
server that has an IIS alias so that it will be exposed for use. You can use for example
the Scripts folder under the Magic folder, which is exposed by default.
2. Open the file in a text editor and update the properties as follows:
<properties>
</properties>
The properties file does not need to have the txt extension. You can
use any extension you choose as long as you set the MIME type on
the server so that the mobile devices will be able to open the file.
At this stage, we will use a generic Magic xpa client application available on the Google Play
store and the App Store.
Of course you can create your own client application with your own application name and
1. After you install the client application on your device, start it by double clicking on the
application icon.
When the program is run initially, you will receive the following dialog box, requiring you to
enter the URL of a details file. You will also receive this dialog box if the URL file is not found
or accessible. (This dialog box will not appear for your users in your customized application.)
? If you want to run another program as the start program, how will you
implement this?
In the Program repository, remove the start public name from the Hello World program
and add it to the requested program. Do not forget to select the Expose option. This is a
very simple method.
Add a public name to the requested program, such as orders and in the devprops file,
change the <property key="prgname" val="start"/> to <property key="prgname"
val="orders"/>
Note: It is not always feasible to use this option and you will understand why later in this
course.
When the mobile client application loads it searches for the execution details. The execution
details file is retrieved in one of the following two methods:
Opening a dialog box to receive the URL of the file as you did in this exercise.
Embedding the details with the client in an execution.properties file. You will learn more
about this in the lesson about customization.
The client reads the content of the file to find the address of the server, the name of the
application and the name of the initial program. This is the reason you were instructed to
define the name of the application as demo and the program as start.
The process now behaves like any other Rich Client application.
by first pressing in the Execution on Android toggle button. You can do this from the
Magic xpa toolbar or the Debug menu.
Once the button appears pressed in, you can execute your program or project on an Android
device directly from the Studio:
1. Press F7 to execute a Rich Client program. This will switch the engine to Runtime mode
and launch the application on the mobile device or simulator using the selected
program as the start program.
2. Press Ctrl+F7 to execute the project. This will switch the engine to Runtime mode and
launch the application on the mobile device or simulator using the start program that is
defined in the execution properties file.
To do it, open the file using a text editor and change the value of the PackageName
variable to your package name, as it is defined in the settings.properties file.
If you are using the store client, set the name to com.magicsoftware.richclient.
To check if your PC can access your device, open the command prompt, navigate to the
RIAModules\Utils\ADB folder under the installation folder and execute the following
command: adb devices.
Note: If the server on which Magic xpa is running is not defined in DNS, the Android
mobile client will fail to access the Magic xpa server, since the device cannot
translate the machine name to the IP address and you will get the following
error: "Unable to resolve host name". If you encounter this error, you need to set
the full URL with your machine's IP address in the HTTP Requester environment
setting. For example: http://192.168.0.111/magicscripts/MGrqispi.dll.
Usually, when using the Genymotion simulator, you can define the following
value as the IP address: http://192.168.56.1/magicscripts/MGrqispi.dll
(192.168.56.1 is the default host IP address that the Genymotion VirtualBox
supplies).
Devices differ in screen size, fonts, expected interaction device features (such as a camera
and GPS), security related features and more. This lesson will give you a better understanding
of the client devices.
Form considerations
Design considerations
Application navigation
Supported controls
iOS and Android devices each have different characteristics when it comes to displaying
information and enabling the user to enter information. You will learn more about this during
the seminar.
Screen sizes and orientation – Mobile devices have various resolutions and screen sizes in
both landscape and portrait orientations.
Keyboard devices – Some mobile devices have a full QWERTY keyboard. In addition to a
keyboard, some devices have a dedicated Menu key, an Esc key and a trackpad or
trackball that are equivalent to the desktop keyboard arrow keys. The trackpad also
provides a dedicated Fire action when pressed. Keyboard-only devices have a fixed
screen orientation and cannot be rotated.
Touch devices – Some mobile devices have a touch screen, some in addition to a full
keyboard, and some without a keyboard. Touch devices support screen rotation and
provide an on-screen virtual keyboard when a full keyboard is not available.
Windowing model – Mobile devices support a simple stacked window model. Each
application can open multiple windows, but each new window is stacked on top of the
previous windows and is modal. There is no mouse pointer and therefore the end user has
no control over the window, meaning that it cannot be resized or moved. When an
application is run, its main window (and subsequent stacked windows) occupies the entire
device screen.
Form navigation using touch keyboard – Touch devices use an on-screen virtual keyboard.
Some devices rely on tapping on the controls to navigate between the fields while others
have Tab functionality in the virtual keyboard. The navigation inside an Edit control is
made using a long press on the field content.
Context menu – The context menu is an important and central user interaction tool. Since
the screen size is relatively small, it is common to perform most tasks using the context
menu, instead of wasting screen real-estate on buttons and on-screen menus.
Input modes – The Edit control is always in Insert mode. There is no equivalent Overwrite
mode on the mobile devices.
Running in the background – The mobile devices’ OS is a multi-tasking operating system
meaning that each application can run either in the foreground or in the background. The
end user can see the running applications and switch between them. An application
running in the background is not suspended and continues to run, but does not have
access to the screen.
Web application – A Browser application using the mobile internet browser. There are
advantages to this method in that if you already have a browser application, it can
already be deployed. Your application will not look like a native mobile application. You
will also have limited, if any, access to the mobile’s functionality, such as the camera.
Hybrid – The interface is a mixture of a native application, JS and HTML. As an example,
you may be using a Browser control to display a PDF. In this case, you have local access
to the device.
Native – This is a native mobile interface with full access to the device.
Magic xpa enables you to develop whichever method you select. This seminar will deal with
the native application.
Developing in RIA
Developing a RIA application for a mobile device, you use the same skills that you use for a
regular RIA application. The difference being that you have to take into account a smaller
sized screen and different operating systems.
Each device has its own native look and feel. The preferred way to develop an application for
a mobile device is to design your application with a native look and feel. You can define your
program so that it has a context menu, but that is of little use if your device is an iPhone in
which there is no context menu. Your challenge is not the technology, but the display. You do
not need to worry about Java for Android or Objective C for iOS. You will see this later on in
this course.
Full-screen forms – By default, the form will automatically be full screen, taking up the
entire screen area of the device. All position and size properties of the form are ignored.
This means that when you design for a device such as Android or iOS, which have both a
mobile device and a tablet, the screens will be expanded or decreased accordingly and
will have a different look.
Pop-up forms – The form will be opened as a popup window (not full screen) if the Pop Up
form property is set to True. The location of the pop-up window is defined in the Startup
Position form property as follows:
o The Customized value will open the popup window in the location defined by the X
and Y form properties.
o The Centered to... and OS Default … values will open the popup window as
centered on the device.
Each application must start with a full-screen form that remains open
for the duration of the session. When the initial program is closed, the
application terminates. You can open additional forms, but if the
initial program closes, all programs will terminate.
Form Size
The RIA client supports both form scrolling and placement. However, when developing an
application that needs to run on devices with significantly different screen sizes, such as the
iPhone and iPad, it is best practice to develop two separate forms, since the number of
controls will be different on each device.
Placement should be used for each form so that it can be displayed on different devices.
The Width and Height Dialog unit values of a full screen form with a title bar are:
You may decide that you want different forms for different devices or a specific form for a
mobile phone and a different form for a tablet. The ClientOSEnvGet function enables you to
Placement
Often you design your form and the controls on the form according to a fixed size. You place
all the controls on the form relative to one another in the Form Designer and then you run the
program. In a Windows environment that is often satisfactory.
However what happens when the user increases the size of the form? This is a built-in feature
of the Windows operating system. This can happen when the user drags one of the sides of
the form or even the bottom right corner. The form simply gets increased. The image below
shows an example of what the end user will see when they use the bottom-right corner to
increase the size of the form.
This is not what you would want to happen. The table has a scrollbar and only displays a few
rows. You would expect that the table increase in size and the push button move accordingly.
This feature is handled by a property named Placement.
The examples here will be shown using regular Rich Client programs.
The Placement property determines whether or not controls are resized when a parent form or
parent container control is resized. When a control’s
Placement property equals zero, the relative size of
the control does not change when the size of the
parent container is changed in runtime.
When the Placement property is larger than zero, the
relative size changes proportionally when the size of the parent container changes in runtime.
The X and Y values determine how the control moves itself when the form is resized. The value
is in percentages. When you set the value as zero, you are defining that the control stays in
place. When you set a value of 100, you are saying that the control moves with the form for
its full placement.
You can see this with a simple exercise using a regular Rich Client program in which you will
define that the form’s push button remains relative to the form when it is resized. To do this:
Customer ID
Customer Name
Address
1. Zoom into the Customers program and zoom into the Form Designer.
2. Park on the table.
3. Open the control property sheet.
4. Click on the Placement property and then click the Zoom button.
5. Set the value of 100 in the Width property and the value of 100 in the Height
property.
6. Click OK. The Placement property will show: 0,100,0,100.
7. Execute the program.
If you increase or decrease the form you will see the changes. When you increased the form,
the table also increased. You saw more records in the table. This is in essence what will
happen when you move from Landscape mode to Portrait mode on your mobile device.
What you saw here was:
Increasing one control, the Table control, when the form itself increases.
Have a control, the push button, remain in the same place relative to the bottom of the
form when the form is increased.
The controls will never get smaller than their original size. So if you
are expecting a form to be resized, create each control at the
smallest required size.
The issue of placement gets more complicated when you have more than one control on the
form and you want the controls to increase in width, when the form is increased. This is
important when you have a large control, such as an Edit control, that you cannot initially
display all the information, but when you increase the form you find that you have enough
space to display more information.
When you increase the group container, you would expect that each control would increase
in width. The controls would move and resize in the following way:
To do this:
Customer ID
Customer Name
Address
4. Zoom into the Form Designer and add a Group control onto the form.
5. Park on the Group control and zoom into the Placement property. Set the Width
property to 100 and the Height property to 100.
6. You can name the Group control as Customers.
7. Drop the Customer ID Edit control onto the Group control. Set the Width property to
32. This control remains in place, but it must increase in size. Remember that we have
three controls that need to increase in size, so each control will increase in size by a
third. Zoom into the Placement property. Set the Width property to 33. The setting will
be: 0,33,0,0.
8. Drop the Name Edit control onto the Group control. Set the Width property to 40.
Now comes the fun part. The ID control increased in size by 33%, so the Left or X
offset of this control must move by 33%. It must also increase in size by 33%. Zoom
into the Placement property. Set the X property to 33. Set the Width property to 33.
The setting will be: 33,33,0,0.
9. Drop the Address Edit control onto the Group control. Set the Width property to 24.
The Name control moved 33% and increased in size by 33%, so the Left or X offset of
the Address control must take both into consideration. Therefore it must move by 66%.
It must also increase in size by 33%. Zoom from the Placement property. Set the X
property to 33. Set the Width property to 33. The setting will be: 66,33,0,0.
When you increase the size of the form, the form will now look similar to the image below.
Defining values of X=100 and Y=100 will keep the control in the bottom right position.
This is mostly used for buttons that should remain in that position, regardless of the size of
the form.
Defining values of Width=100 will resize the control horizontally. This is mostly used when
the control size is smaller than its content.
Defining values of X=100 will move the control horizontally. This is mostly used when this
control is displayed after a control that has a Width placement of 100%.
When you resize a control, you need to take into account the starting offset of the
adjacent controls.
In the mobile world you have many different sizes and so you cannot develop, one size fits all.
Therefore placement is very important. Bear in mind when designing your form, that when you
design for a tablet and want the same layout on the mobile, such as developing for an iPad
and viewing on an iPhone, the form may be too small and user-unfriendly.
On mobile devices, the Magic xpa placement mechanism is implemented in a specific way to
accommodate different device resolutions and to handle device rotation. The placement
mechanism is not relevant for pop-up forms. It works as follows:
Resize on open – Before opening the form, the form size as defined by the developer is
compared with the current screen size. The difference between the sizes on each axis is
considered as a window resize, and will activate the placement mechanism on all
controls. This enables forms designed for smaller screen resolutions to “expand” in higher
resolutions.
Resize on rotate – On touch devices, it is possible to rotate the device, effectively changing
the resolution on the fly, such as from 480x360 to 360x480. In such a case, the currently
displayed form will consider the new resolution as a window resize event, and will
activate the placement mechanism on all controls.
Supported Controls
Controls on mobile devices are different than the Windows controls in their appearance,
minimum size and space padding. They are also different on each device. The size of the
control will change according to the device’s DPI (dots per inch). As a result, the size of the
controls defined using the Magic xpa Fit to Size option may not be large enough to display
the entire control text due to the larger padding on the mobile device controls.
The Rich Text, Rich Edit, Tree, List Box and .NET controls are not supported on mobile devices.
Image Controls
Images with the Copied style do not change and use the same amount of pixels as in the
image, so the images will appear in different sizes when used on devices with different DPIs.
It is best practice to use Distorted Scaling or Scaled to Fit styles to attain the desired
appearance.
Two-State Images
You can create two-state images. This means that by clicking on the image on the mobile
device, the image will switch to an alternate image. This is done by setting the Image List File
Name property in the Check Box control's Mobile section.
You can also create multiple two-state images. This is done by setting the Image List File Name
property in the Radio Button control's Mobile section.
Button Controls
The push button is not parkable. The current control will remain the parked control.
Tab Controls
The Tab control appears as a tab bar on Android and iOS devices. The tab bar will appear in
full screen; therefore, when developing an app, it is recommended to stretch the Tab control
across the entire form. In general, the tab bar's functionality is based on the device's default
behavior. You can find more information about this in the Magic xpa Help.
Application Navigation
Navigation
Mobile devices can support a simple stacked window model. Each application can open
multiple windows, but each new window is stacked on top of previous windows and is
inherently modal. Closing the current window and returning to the previous window can be
done either by raising the internal Exit event or using the built-in capabilities of the mobile
devices:
Termination
The application can be closed either by raising the internal Exit System event or using the built-
in capabilities of the mobile devices:
Android – using the ‘Back’ button from the first screen of the application
iOS – using the close button (‘X’) on the window title bar from the first screen of the
application (if the window was defined to open a System menu)
When pressing the mobile device’s home button, the application will remain running in the
background.
When you terminate the application in other ways (such as from the
Note: Task Manager), the context on the server will not be released
automatically. It will be released only after the context timeout period.
Design Considerations
Magic enables you to develop for mobile devices in the same manner that you developed for
Windows with the same look and feel and functionality. However, when developing for
mobile devices you want your application to look like other mobile applications, meaning
native applications.
As an example of designing your screen for a mobile device, consider the virtual keyboard
that was opened when you started editing and ask yourself:
How do you add a new record? The Magic xpa shortcut is F4.
How do you delete a record? The Magic xpa shortcut is F3.
How do you move to the next record, or the previous record (Page Up / Page Down)?
What about query / sort / range, etc.?
When you look at your mobile contacts or mobile emails or other programs, you normally
have a list and when you want to add something you have a button for creating a record. The
same for editing; you generally have a button that opens a different form for editing. You will
practice this in the example in this lesson and the next lesson when you learn about tables,
combo boxes and other controls.
Status Bar
You may have noticed that there is no status bar. Take this into account when displaying
messages.
Colors
Mobile devices use the same Magic xpa color table as other RIA clients. Each color must
specify the exact RGB value for both background and foreground. You do this in the Magic
xpa color table. However, take into account that the mobile devices do not support the
Windows “System” colors.
If a system color is selected, the mobile device will display its own
default color for the form or control. If you want to use a specific
color, you need to implicitly define the foreground and background
colors.
For some controls, to see the border, you must use a color with a non-
system color.
For Combo Box controls, to see the arrow you must use a color with a
system color.
Fonts
The Magic xpa mobile RIA client uses the same font table as other interfaces. Each device has
a set of available fonts that are usually different from the fonts found on a Windows desktop
and different from one another. If the font defined in the font table is not found on the mobile
device, the default font will be used with the size defined in the font table.
When you develop, you need to take into consideration whether you want to use specific fonts
for each device or enable the device to use the defaults.
You may decide that working with the CASE function will better suit
your application.
On Android devices you need to send the font family name and the style of the font you want.
The system will find a matching font for you. For example, to use a Droid Serif font use:
"Android Serif bold,Serif,12,0,0". You can see the font list in the System/Fonts folder in the
device file system.
You cannot select mobile fonts using the Windows fonts dialog box. If you decide to use
separate font entries for each device, you need to edit the fonts table manually using an
external text editor such as Notepad.
1. Open the fnt_rnt.eng file in a text editor. By default, this file is in the support folder of
the installation.
2. Add the following line: Android Edit Labels,sans,8,0,0,Bold
3. Save the file.
4. Close the demo application and reopen it so that the new font list will be reloaded.
5. Zoom into the Hello World program.
6. Zoom into the Form Designer and for the Label control, select the new font. Because
the font is now bold, you need to increase the width.
7. Execute the project.
The attributes are the Font Style and the Effects. The dialog box above will be translated to the
following entry in the Font list:
You learned that you can continue developing your application in the same way that you
developed for desktop applications, but that it is good practice to take into account the
limitations of the mobile device, which are smaller devices and are also not Windows devices.
You learned to take into account the sizes, the colors and the fonts on the mobile device and
you learned how to get information from the device, such as its operating system. You can use
this knowledge to define that certain programs will not run on certain devices.
This lesson can be summarized by saying that when developing for a mobile device, think
native!
As you know when working with Magic xpa, when you design a program, you are not only
using simple controls such as a Button, an Edit, or a Text control, but you also display data in
a table, select data from a list and others. You will learn about this in this lesson.
Tables
Events
Selection Lists
Menus
Advanced Controls 27
Tables
As you learned, developing for a mobile device has limitations but it also provides you with
some advantages. When you use a Table control in Magic xpa, you normally add as many
columns of data as you need. If there is not enough room to display the table, you have a
horizontal scrollbar on the form.
On mobile devices, horizontal scrolling is allowed on the form only. Horizontal scrolling on
the content of the table is not possible.
How many of you have developed a one-to-many form such as an order form in which the
order lines are displayed in a table? To create a new order-line, you instructed the user to click
F4 and you were able to enter a new line. The Create Line event is supported by Magic xpa,
but there is no F4 key on a mobile phone. This is also not the accepted method for the user
display when working with a mobile device. Remember also that when working with an
Android in the one-to-many scenario, you will not have a vertical scrollbar.
Apple wrote a document known as Human Interface Guidelines (HIG) in which they defined a
table as a view that presents data in a single-column list of multiple rows. Look at the Contacts
or Emails. These are guidelines and so you define the interface as you want. As an example,
eBay displays three-columns: image, description and current bid.
The bottom line is that Magic xpa enables you to develop the display that you want, but it is
advisable to work with the guidelines of the device or at least develop a display that fits all
guidelines.
Landscape Mode
When you rotate your device to Landscape mode, you are able to view more information on
each line. When you use placement on the table you are able to view more of the text. For
example, have a look at the email list below:
Advanced Controls 28
You also have the option of displaying more information on the table. Remember that you can
use the ClientOSEnvGet ('device_orientation') to know whether you are currently in Portrait or
Landscape mode.
Mobile Events
When working with a mobile device, you use your finger as the mouse; your touch is my
command. The touch events are mapped to Magic xpa events as follows:
The mobile “Touch”, “Click” or “Tap” events are equivalent to the Magic xpa mouse-click
event. These events move the focus between fields on a form. Touching on selection
controls changes the controls’ selection. Touching on buttons triggers the buttons’ event.
The “Press” or “Hover” events trigger a Magic xpa OK internal event. This event can then
be handled by the developer.
“Swipe” events scroll within the form or control.
Advanced Controls 29
Selection Lists
A selection list enables you to select a value from a list. This can be a regular control such as
the combo box, check box and the radio button, or a selection program that is defined in
Magic xpa as a Selection program. Remember that the radio button is not supported on all
platforms.
Selection Program
In Magic xpa Online programs and RIA programs, pressing Enter or the double-clicking action
raises the Select event. On your mobile device, you do not have an Enter button and you are
unable to double-click. You need to find other methods to raise the Select event. Two methods
you can implement are:
Selection Controls
Selection controls, such as the Combo Box, appear differently on each device. This is not
something you can control as this is defined by the operating system of the device itself. It
does, however, provide a native look and feel.
Menus
When developing any system, defining the Menu system is an integral part of the screen
design as the menus allow quick access to functionality. A menu system takes up valuable
screen real estate and is impractical in small devices. The Windows pulldown menu is
unsupported in mobile operating systems since there is no MDI On mobile devices. Therefore,
it is recommended to remove the Default pulldown menu entry when developing a mobile
application.
However, the context menu is an important and central user interaction tool. As the screen size
is relatively small, it is common to perform most tasks using the context menu, instead of
“wasting” screen space on buttons and on-screen menus.
In Magic xpa, in Android devices, context menus are available at both the form and the
control level. On iOS devices, context menus are only available at the form level.
Advanced Controls 30
Summary
In this lesson you learned more about how to interact with the mobile device.
You learned about the table and some guidelines provided by mobile manufacturers.
You learned about some events that are unique to mobile devices and how they are defined in
Magic xpa.
You learned about selection lists and you were given some guidelines about menus.
In the next lesson you will learn more about interacting with the mobile device.
Advanced Controls 31
Advanced Controls 32
Lesson
4
Interacting with the Device
The advantage of working with a mobile device is that you are able to use the device’s special
features such as the GPS and camera.
On iOS, the access is allowed only to a temp folder provided by the OS. When using the
ClientFileXXX functions with a relative client filename, the file folder will be the temp folder.
When using these functions with a full path, it is recommended to use
ClientOSEnvGet('temp') to retrieve the temp folder.
On Android, you can access different folders.
Keyword Description
device_udf|getpushid Returns the device ID, which can be used for sending push
notifications to the device.
On Android devices, you can also use Java predefined keys to get additional information, for
example: ClientOSEnvGet ('java.io.tmpdir'). For more information, refer to:
http://developer.android.com/reference/java/lang/System.html#getProperty(java.lang.String)
ClientOSEnvGet ('device_location') – returns the current device location, using any of the
available location options (GPS, Network, etc.). The result is a string in the following format:
OK|Latitude|Longitude, where OK is a fixed part for testing if a result was returned, and
Latitude and Longitude are the coordinates of the current location. If a location could not be
obtained, for any reason, an error message will be returned.
There are other methods of displaying the location in the device by using the Invoke OS Cmd
operation with Execute On=Client. You would therefore not need the subtask:
Camera Support
It is possible to initiate a camera from the device using the ClientFileOpenDlg function.
When this function is used with the following word: camera as the second parameter, the
camera will be opened.
This will enable the user to take a picture and select it. The full path name of the picture will be
returned from the function. It is then possible to upload this picture to the server using the
ClientFileToServer function.
ClientFileOpenDlg('','camera','','FALSE'LOG,'FALSE'LOG)
Gallery Support
You can also get an image file from an image gallery using the ClientFileOpenDlg function.
When this function is used with the following word: images as the second parameter, the
images gallery will be opened.
The full path name of the image will be returned from the function. It is then possible to upload
this image to the server using the ClientFileToServer function.
tel:1-408-555-5555
sms:1-408-555-1212
mailto:[email protected]
mailto:[email protected]&subject=this is a test&body= test mail
http://magicsoftware.com
Note:
The built-in keywords enable you to fetch details about the device and display different
information. For example, you may decide that a certain program is only available if you are
using an iPhone.
What happens when you do not have internet communication? That is where offline
programming is necessary. Magic xpa enables you to develop Offline tasks. Offline programs
allow users to continue to be productive in areas with intermittent, limited or unavailable
internet connectivity. While working offline, data is stored locally on a local database, and
periodically, when internet connectivity resumes, you can synchronize it back to the server.
Offline Implementation 39
Concept
When planning an offline implementation, it is important to understand the challenges and
constraints that you need to overcome to enable applications to work completely offline
without a server connection. Unlike a connected application, server connectivity is either
non-existent or intermittent, and applications need to be adjusted to handle this scenario
properly, without compromising usability and data integrity. As a programmer, you need to
take into account the technical aspect of being disconnected, and the data consistency aspect,
as follows:
You can store a subset of relevant server data or client-only data on the client. You need to
understand what data is constant data, such as a list of countries and which is not updated
often, such as suppliers and items that are updated often, such as stock. However, even
when dealing with stock, you may not need all of the data on the client. For example, a
salesperson who deals with orders involving computer hardware only needs the products
dealing with computers, while a salesperson who handles cleaning products only needs
that subset. You can also have a scenario where the salespeople have access to the entire
catalog but only current stock quantities is kept on the server and needs to be
synchronized.
On systems that require user authentication, consider storing user credentials securely on
the client.
Allow data entry on the client and update client data with server data for data consistency.
Working under intermittent network connectivity (network disconnects, slow connections)
while allowing uninterrupted operation and data consistency.
Keeping application resources such as application metadata, image resources and so on,
locally on the client, while allowing updates during connectivity periods.
The above challenges define an offline pattern that is different from patterns used when
network connectivity is guaranteed, and require the developer to handle additional usage
scenarios. Magic xpa provides tools and features that allow developers to tackle these
challenges and provide a complete offline experience.
Some programs are totally client programs and some are server-based and others are both.
An example of a client program can be something like a university student’s lesson timetable.
This timetable is only updated every semester and, therefore, the data can be kept on the
client. An auction-based client depends entirely on server data and, therefore, you need an
internet connection for this. A customer order can have elements of both server and client
data.
Offline Implementation 40
How Does It Work?
Unlike connected applications, offline applications are designed to work without (or with
intermittent) network connectivity. This limitation defines a different execution flow for offline
applications.
To define an Offline program, you simply define a Rich Client program and select the Offline
check box.
On first invocation, offline applications must download and synchronize all necessary
resources required for the offline operation. These include application metadata, images,
client-side data and so on. This requires an offline application to be connected at least
once before it can work offline. If there was no initial connection, the programs will not
work.
For applications that require user authentication, user credentials should be securely stored
on the client to allow for operation without server authentication. To ensure validity, such
credentials should be re-checked when connected.
Following initial invocation, all user interactions must be done using local resources only
(local data, local images and so on). By using local resources exclusively, the application
is guaranteed to work, regardless of the internet connectivity state and without requiring
server access. All data updates should be stored locally on the local database.
Periodically, at an application-dependent timing, the application must synchronize
modified local data back to the server and download server data that was modified since
the last synchronization. Remember that data objects can be updated by multiple clients
and by the server simultaneously and therefore two clients may update the same data at
the same time. You need to take this scenario into account.
Since Magic xpa automatically synchronizes metadata objects while connected, an
application that runs offline must be allowed to periodically synchronize changes to its
metadata objects. Typically, if an internet connection is available on startup, metadata
objects will be synchronized automatically. The developer should plan for allowing
metadata updates to happen when the application changes.
For more information about how to implement each of the above, and the supporting Magic
xpa features that enable each capability, see the Developing Offline Rich Client
Applications.pdf that can be found in Magic xpa’s Support folder or in the Magic xpa Help.
Offline Implementation 41
Summary
If you decide to give offline capabilities to your application, you need to give thought as to
how to implement the programs and of course which programs are offline and which are not.
You need to think about the following issues and take into account:
Offline Implementation 42
Lesson
6
Customization and Installation
In previous lessons you used the Android emulator and you used the environment that the
installation process provided. In this lesson you will learn how to provide your own
environment.
Note: There are similar methods for creating an iPhone file. Check the Magic xpa Help for
assistance.
When a mobile device client is prepared, it is compiled with a certain execution properties
file. This file tells the client where to find the initial program to load. There are three ways of
defining an execution properties file in the compiled client application:
An empty file – In this scenario, the end user will initially get the dialog box requesting the
address of the properties file. This is the same behavior you saw in the first lesson when
using the generic Magic xpa client. This is very useful during the development process
because it enables you to separate your development and production environments. You
do not want your end user to be prompted to enter your server details.
Entering the server, application and programs – The format will be similar to the devprops
file that you learned about. The end user will not be prompted for the path to the devprops
file. This means that all information will be compiled with the client. The disadvantage here
is that if you make changes to the application name or the program name, such as the
change from start to orders, you will need to recompile the client application and upload it
to the mobile device.
Entering a URL – You enter a URL that is a full URL directing the application to the
devprops file found on your server. The devprops file then directs the client to the
application and program. The advantage here is that if you need to change the
application name or the program name, there is no need to prepare a new client. In the
devprops file, you saw the <property key="server" val="10.1.10.75"/> property. In the
execution properties file, you can use either. To enter a URL you would use the following
property: <property key="url" val="http://example.com/MobileScripts/devprops.txt"/>
You will learn more about compiling a new client in the next section.
Icon
Startup splash screen
Execution properties – You learned about this in the previous section.
Client title
Application version
Package name
Here is an explanation on how to do this for an Android-based mobile application. For iOS-
Property Description
sdk.dir The directory in which the Android SDK is installed. When you
use the \ character, you need to double it: \\
build.dir A temporary folder location used during the build process. This
folder is removed after a successful build. It can be an absolute
or relative path.
Icon – To change the icon, replace the icons’ files in the res\drawable-XXX subfolders. You
will need to provide icon files in all of the following sizes: 36x36, 48x48 and 72x72
pixels.
There are a few stages (which are explain later on) to preparing an APK file:
1. Prepare a keystore file. The keystore file is a file that enables you to “sign” your APK
file. To do this, you use your own keys and certificates. A sample file is provided with
this course.
2. Create the signed APK file.
3. Upload the new APK file to the Android device or emulator.
Keystore File
A sample keystore file is provided in the installation. Remember that when you deploy your
application, you need to provide your own keystore.
To create the keystore, you will use the keytool.exe application installed with the Java SDK,
found in your %JAVA_HOME% folder.
KeyStoreName and AliasName will be replaced with your own details. During the process,
you will be asked for the password of the keystore and the alias. You will be asked for
identifying details such as your name, company and address. At the end of this process the
keystore file will be updated with the new information.
APK File
The APK file is based on both the execution.properties file and the settings.properties file.
Make sure that both are defined as you require. Compilation of the Android project is
performed using the Ant tool. The Ant tool is provided with the installation and is located in
the %EngineDir%\RIAModules\Utils\apache-ant-1.8.3 folder. To continue:
You can edit the build.cmd file in order to troubleshoot the build
process. For example:
To see the full actions, remove the -q from the command in the
build.cmd file.
To save the log to a file, add -l build.log to the command in the
build.cmd file.
Run the APK directly on the Android, after receiving it as an email attachment or similar.
Download the APK via the mobile device’s browser by navigating to the APK file. For
example: http://server_name/magicscripts/myapp.apk.
Download your application from the Android market.
After successfully installing the APK you will see a new icon under the Applications in the
device.
Refer to the Customizing Your Application and Installing an Application on a Mobile Device
or Simulator topics in the Magic xpa Help for more information on how to customize and
install the application on an Android device.
Android
To run the Android emulator, you need to download and install the Java SE Development Kit
(JDK) 6 and the Android SDK. The JDK is installed automatically during the Magic xpa
installation if you installed the Web Services component during the Magic xpa installation.
JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html
SDK: http://developer.android.com/sdk/index.html
You need to select the following components (for each component you need to select the latest
Android versions or at least the versions that Magic xpa is compatible with):
Tools\Android SDK Tools – For Magic xpa 3.0, for example, you will need version 24 or
above.
Tools\Android SDK Platform-tools – For Magic xpa 3.0, for example, you will need
version 21 or above.
SDK Platform – For Magic xpa 3.0, for example, you will need version 21 (the package is
available under the Android 5.0.1 (API 21) section) or above.
The installation package will then start downloading the package to your system. This process
may take a while depending on your download speed.
The Android SDK Manager is installed on your system enabling you to add or remove
packages in the future.
1. Click the Tools menu and start the Manage AVDs (Android Virtual Device) entry in
order to configure the Android emulator and virtual environment.
Run the APK directly on the Android device, after receiving it as an attachment as an
example.
Download the APK via the browser as explained.
Download the APK from the Android market.
To download from the browser or to run the APK directly from the browser, you need to
configure the Web server to support the download of the APK file. This means defining a
MIME type. According to the Microsoft MSDN, Internet Information Services (IIS) serves only
static files with extensions registered in the Multipurpose Internet Mail Exchange (MIME) types
list. IIS is preconfigured to recognize a default set of global MIME types, and also allows you
to configure additional MIME types and change or remove MIME types. These MIME types
are recognized by all Web sites you create in IIS.
Extension=.apk
MIME type=application/vnd.android.package-archive
For IIS 6, you define a MIME type as follows:
Extension=.apk
MIME type=application/vnd.android.package-archive
Troubleshooting
The most common problem regarding the mobile RIA client is that the client fails to connect to
the Web server that is serving the application. There are several scenarios where this problem
can occur:
If the communication is performed using WiFi, verify that the device is connected to the
correct WiFi router.
Try connecting from the device browser to the Web server to see if there is a connection.
For example: http://192.168.137.1/MagicScripts
If you do not get a response, then the Web server may not be configured correctly.
* The external file can be accessed from the mobile device. You can check it by entering
the same URL value on a browser on the device.
* The external file is in ANSI format and all the attributes in this file have the correct
value (case sensitive).
Verify that the Magic xpa RIA server is up and is running the project defined in the settings
properties.
To check your file on the Windows desktop, you can rename the file to execution.properties
(remember that you gave it a txt file extension), place it in the
%EngineDir%\RIAModules\Desktop folder and run the MgxpaRIA.exe application in that
folder. If everything is properly defined, the RIA application should start on the Windows
client.
Debugging
As in the desktop RIA, you can activate debug logs on your mobile client by defining a proper
value for the InternalLogLevel property in the [MAGIC_RIA] section of the Magic.ini file.
Android
The application log is written in the internal device log.
You can see the log by using the Android Debug Bridge (ADB) utility, which is located in the
platform-tools folder in your SDK folder, usually at: C:\Program Files\Android\android-
To use the ADB utility on a mobile device, make sure that the mobile device is defined to:
To view only the RIA client related entries in the device log, run the following command:
adb logcat MAGIC_DEBUG:D *:S. Note that this filtering will not show crashes or illegal
actions.
To clear the log, run the following command: adb logcat -c.
To save the log to a file, run the following command: adb logcat > file.log.
If you need to provide a log of a specific scenario or crash, you need to clear the log first, run
the action that caused the crash and then save the full log to a file.
iOS
The application log can be downloaded to a PC using iTunes.
Simply connect your device to iTunes. In the device apps, select your application and then you
can retrieve the log file.