AMP Studio Developer Version4.0
AMP Studio Developer Version4.0
AMP™ Studio
Version 4.0
ANTENNA PROPRIETARY & CONFIDENTIAL
Contents
BlackBerry Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
iPhone Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Windows Mobile Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Android Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Hello World Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Creating a UI Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Data Project Using VRPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
VDSC Data Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Data Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Sorting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Unique Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Query Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Link Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Virtual Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
TimestampField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Converting a String to an Integer for Sorting Purposes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
VRPC Data Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Data Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
VRPC sample code snippet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
UI Projects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
UI Project mScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Strings Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Images Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Colors Editor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Sound Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Styles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Services and Managers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
PhoneManager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
MessagingManager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Message Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Reference to a Data Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Screens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Creating a Screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Setting a Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Message Box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Panels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
HorizontalPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
VerticalPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
FormPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
BorderPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
TablePanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
GridPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
TabbedPanel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
StackPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
SectionedPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
CalendarPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Panel Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Reusing Panels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Models. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Text Format Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Table Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
BarChart Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
PieChart Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Choice Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Multi Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Text Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
TimeStamp Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
TimestampFormat Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Time Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
TimeFormat Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
NumberFormat Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Date Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
DateFormat Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Setting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Application Callbacks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
On Close. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
UI Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Bar Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Pie Chart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Button. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
CheckBox. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Choice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Combo Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Date Box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Label. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Ticker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
PasswordField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
TextField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
E-mailField. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
NumericField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
PinpadField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
InteractiveImageField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Picture Box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Progress Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Separator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Rich Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Sticky Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Sticky Table (Grouped) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Text Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Text Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
ToolBar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
RadioGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Browser/HTML Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Title Bar Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Map Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Animated Image Control (Customizable Animation) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Horizontal Page Swipe Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Video Player. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Document Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Callbacks for UI Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Add Visual Style. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
On Click . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
On Focus Gained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
On Focus Lost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
On Value Change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Data Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
VRPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
AMP Studio Debugging Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Eclipse.ini File Troubleshooting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
AMP Studio Frequently Asked Questions (FAQs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Coding Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Class Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Variable Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Method Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
One Liners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Introduction
Antenna is the leader in mobility solutions for the enterprise. We extend run-the-business data, processes, and applications
in real-time to any mobile device over any network, worldwide. Combining mobile solution software applications, and an
integrated development environment, Antenna Mobility Platform (AMP™) solutions are straightforward to implement
and simple to manage and use.
AMP Studio is an open source Eclipse-based IDE used to develop mobile applications. With AMP Studio, you can create
one application for multiple devices and generate code for multiple devices (currently Windows Mobile, BlackBerry,
Android, iPhone, and iPad). AMP Studio includes Eclipse-based backend integration tools for Web Services and database
access. The AMP Studio scripting language, mScript, allows the programmer to create rich UI applications, define
business logic, access the local data store, and communicate with backend Web Services.
AMP Studio serves to create applications that can be installed on various devices without the need to adjust code for each
device. After an application is created, AMP Studio generates code for target platforms. For example, the same
application can be converted to Android Java, BlackBerry Java, iPhone Objective C, and .NET to be compiled for
different platforms. The AMP Studio application consists of a data project and a UI project. A data project defines data to
work with and a UI project defines the UI of the application.
A connector connects the AMP Server to the customer backend (e.g. Web Services or a database). It defines what data
objects the application can use. A data object is similar to a table in a database and has fields.
The guide is designed for Application Developers and IT consultants who will develop applications using AMP Studio.
The Antenna Mobility PlatformTM (AMP) provides a wireless business solution with easy to assemble mobile
application components that connect quickly and efficiently to your existing business. It is an event-driven, Service-
Oriented Architecture (SOA) platform that sustains the core principles of dynamic Information Technology, thus
delivering business process rich applications for the mobile workforce.
The AMP suite of tools enables you to integrate the Antenna Mobility Platform within your organization's existing
infrastructure, to organize and manage the flow of information for your workforce.
■ AMP™ Mobile Application: AMP Mobile Applications are run-able configurations of developer built projects,
natively compiled for Windows® Mobile®, RIM BlackBerry®, Android®, iPhone® and/or iPad® platforms.
■ AMP™ Studio: AMP Studio is a powerful development environment used to build wireless applications. Built
using the Eclipse platform, it enables developers to create and simulate applications for BlackBerry, Android,
iPhone, iPad, Windows Mobile Professional, and Windows Mobile Standard devices.
■ AMP™ Server: Provides connectivity to the back-end enterprise systems. It manages the connectivity of the
user device and the server.
■ AMP Installation Guide for Standard Edition (SE): This guide describes the minimum system requirements,
prerequisites and step-by-step instructions for installing AMP™ Server Standard Edition (SE). The Standard
Edition consists of a single server instance that supports both Authentication and Application data access
functions in a single Java process. The Cluster Coordinator is not installed and there is no replication of user
state.
■ AMP Installation Guide for Enterprise Edition (EE): This guide describes the minimum system requirements,
prerequisites and step-by-step instructions for installing AMP™ Server Enterprise Edition (EE). Enterprise
Edition is a high availability set-up with no single point of failure. This set-up requires minimum of two AMP
Servers with a load balancer front-end. It also requires two independent machines to host cluster coordinators
(the Terracotta engine). The load balancer is used to direct mobile device traffic to one of the AMP servers in the
cluster.
■ AMP Installation Guide for Advanced Edition (AE): This guide describes the minimum system requirements,
prerequisites and step-by-step instructions for installing AMP™ Server Advanced Edition (AE). AMP Server
Advanced Edition is comprised of multiple AMP Servers behind a Load Balancer connected to an AMP
Database and a back-end application server. Advanced Edition supports multiple clusters in which each cluster
can support a different set of applications. New applications can either be deployed by adding them to all servers
in an existing cluster or by creating a new cluster for this application.
■ AMP Configuration Guide: This guide describes steps for configuring various types of AMP Servers.
■ AMP Planning Guide: This guide describes AMP Server components, configurations, AMP database,
application management, and procedures for disaster recovery planning.
■ AMP Administration Guide: This guide describes the logs, configuration files, tables and statistics used for
proper monitoring and maintenance of AMP Server High Availability (HA).
■ Web Services Connector Designer Guide: This document describes how to design a Web Services connector
within Eclipse.
■ Database Connector Designer Guide: This document describes how to design a Web Services connector within
Eclipse.
■ Composite Connector Designer Guide: This document describes how to build a Composite Connector using
existing pre-built connectors.
Prerequisites
This section describes the system requirements needed to install AMP Studio.
Generic Requirements
The following are the generic requirements:
■ A carrier data plan or wireless networking for each device. Unlimited data plans are recommended but may not
be available everywhere.
■ Approximately 5 MB of free device memory to install the AMP SmartClient application and 10-15 MB of excess
space to download data. This number depends upon the amount of data you may need to download. Note that
more memory may be required depending on the implementation specific data requirements.
■ A WinZip® program on the user’s PC may be required if you install the AMP SmartClient application via
Microsoft ActiveSync.
BlackBerry Requirements
The following requirements are for the BlackBerry device:
Android Requirements
In order to develop for Android devices, the Android SDK and Android Development Tools (ADT) Eclipse plugin must
be installed and configured using the following steps:
3 In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for
the Location:
https://dl-ssl.google.com/android/eclipse/
NOTE: If you have trouble acquiring the plugin, try using "http" in the Location URL, instead
of "https" (https is preferred for security reasons).
Click OK.
4 In the Available Software dialog, select the check box next to Developer Tools and click Next.
5 In the next window, you will see a list of the tools to be downloaded. Click Next.
You can launch the Android SDK and AVD Manager in one of the following ways:
… From within Eclipse, select Window > Android SDK and AVD Manager.
… On Windows, double-click the SDK Manager.exe file at the root of the Android SDK directory.
… On Mac or Linux, open a terminal and navigate to the tools/ directory in the Android SDK, then
execute:
android
Select the desired Android platform, its corresponding SDK Platform-tools, and any desired optional
components and ensure the installation completes.
Pre-installation Requirements
Before you install AMP Studio, make sure your PC meets the following hardware and software requirements:
Hardware Recommendation
Hardware Recommendation
Software Recommendation
Apple iPhone ■ Apple Xcode 3.2.5 and iOS SDK 4.2 or latest (requires
membership to iPhone developer program)
■ Apple iPhone Developers Agreement to allow deployment of
application on device
Android SmartPhones ■ Android SDK r07 or latest is required and needs to be installed
prior to use.
■ Android version 2.0 and above
■ Android Eclipse plugin version 0.9.9 is bundled with the AMP
Studio installer.
■ Developer needs to generate marketplace keys using Android
SDK.
Installation Components
The AMP Studio installation package includes the following components:
■ Studio for creating Data and UI projects for different Mobile devices
■ Web Services Connector designer
■ Database Connector designer
■ Composite Connector designer
■ Web Services sample connector (VRPC connector)
■ Database sample connector (VDSC connector)
■ Eclipse toolbar
■ Creating Data Projects
■ Creating UI Projects
■ Choosing Device Compatibility
■ Windows Mobile Setup
■ BlackBerry Setup
■ iPhone Setup
■ Authentication Server Setup
■ Application Startup Setup
■ Multi-Lingual Setup
Eclipse Toolbar
AMP Studio adds a set of icons to the Eclipse toolbar so you can easily access the tools.
The following are the icon definitions starting from the first icon in the red highlighted rectangle:
1 Launch Eclipse.
2 Double-click Connection from the left panel. The connection dialog box appears.
4 From the left panel options, highlight VDSC or VRPC and expand getObjectRows.mscript and right-click
Request to Add Object.
.
6 Click Finish to add data objects to the created data project. The following image displays a sample project with
the added data objects.
1 Double-click a data object. By default, all fields of a data object are not selected.
2 Select fields to be used in the project. The selected objects are shown in AMP Studio in the Outline tab. The
project and each data object have mScript files.
Creating UI Projects
To create a new UI project, do the following:
1 Launch Eclipse.
6 Click Next. The UI Project Wizard is displayed with the existing data project.
7 Check the data project to link the existing data project with the new UI project.
1 From the menu, click Window and select Preferences. The Preferences screen appears.
2 Select AMP Studio from the left panel and click Client.
3 Optionally, you can click on the black arrow to the right of the blue compile button to select the devices for
which you want to compile.
2 Select AMP Studio from the left panel and click Client.
4 Click Apply.
BlackBerry Setup
The BlackBerry setup screen is used to define the JDE, MDS simulator, and Device simulator to be used for development.
1 From the menu, click Windows and select Preferences. The Preferences screen appears.
2 Select AMP Studio from the left panel and click Client. Expand the Client folder on the left panel.
3 Click BlackBerry.
4 Click Apply.
iPhone Setup
AMP Studio generates objective C source files for iPhone compatible projects. These source files are compiled on a Mac
with iPhone SDK development tools and can be run on a simulator or device.
1 From the menu, click Windows and select Preferences. The Preferences screen appears.
2 Select AMP Studio from the left panel and click Client. Expand the Client folder in the left panel.
3 Click iPhone.
5 To find the AppID on your Mac machine, select Developer Profile under Organizer. The App Identifier is listed
under Provisioning Profiles.
6 Click Apply.
Android Setup
1 From the Windows menu, click Preferences and select Android and set the SDK.
1 From the menu, click Windows and select Preferences. The Preferences screen appears.
2 Select Android from the left panel and select the SDK tab.
3 Browse to the android-sdk-windows file from the directory and select the Android Virtual Device.
4 Click Apply.
Server Setup
AMP Studio can be set up to access an internal or external AMP Server Authentication server.
1 From the menu, click Windows and select Preferences. The Preferences dialog box is displayed.
2 Select AMP Studio from the left panel and click Server.
3 Click Apply.
Multi-Lingual Setup
AMP Studio provides the ability to set up a project for multi-lingual deployment.
1 From the menu, click Windows and select Preferences. The Preferences screen appears.
2 Select AMP Studio from the left panel and click Languages.
The Languages dialog box appears on the right panel. The default installed language is English.
3 You can add languages by moving the appropriate language definition from the left to right in previous control.
After the languages are added, the selected languages are displayed in the Strings node in the UI project.
Strings Setup
You can also set up the Strings as constants in a project.
3 In the Strings Bundle Name, type Constants. The Constants icon is created and is displayed in the left panel.
The string bundle can be used inside the code as shown below:
lblHeader.setText(Constants.SCR_HOME.getString());
btnBack.setText(Constants.BACK.getString());
1 From the menu, click Windows and select Preferences. The Preferences screen appears.
2 Select AMP Studio from the left panel and click Server. The Server Settings screen appears.
3 Select Log Properties. The Log Properties dialog box appears on the right panel.
You can view the log properties of the server settings in the screen.
Application Development
AMP Studio provides the ability to run BlackBerry, Windows Mobile, Android, and desktop simulators. The application
development process consists of following steps:
NOTE: You do not need to run MDS because by default, you can use a Direct TCP connection and not an
MDS connection.
■ After compiling, you need to switch to a Mac and compile and run the application in xCode.
■ Run the Android emulator (for Android applications).
Code Generation
AMP Studio generates device-specific native code for application data and UI projects. Native code is used for the
following device types:
Application code is supplemented by the AMP Server and AMP Studio device-specific runtimes.
The code generation process is activated when you select the mscript compile toolbar button from the Antenna >
Compile menu options.
AMP Studio generates device-specific source files and they are located under the project folder. These files are recreated
whenever the application is compiled within AMP Studio. You can force a cleanup of these directories before compiling
by selecting Project from the menu, then Clean.
BlackBerry Simulator
1 From the menu, click AMP Studio and select BlackBerry
■ Additionally, you can launch the BlackBerry Device Simulator from the toolbar:
or,
■ Select Start JDE to run the BlackBerry JDE with the AMP Studio application project that is pre-configured. Use
F5 within the JDE to launch the simulator.
iPhone Simulator
AMP Studio generates Objective C source files for iPhone compatible projects. These source files are compiled on a Mac
with iPhone SDK development tools and can be run on a simulator or device. Do the following to build an application in
the iPhone simulator.
2 Select Client.
3 Select AMP Studio from the left panel and select Client. Expand the Client folder in the left panel.
5 Click Apply.
6 Click OK.
8 Copy your workspace to one of the folders inside the Mac mini.
NOTE: Ensure that the Client.properties file contains the CLIENTSERVICE$AUTH_SERVER as the IP
address of the machine where your AMP Server is running.
10 After the build is completed, the iPhone-4 simulator is displayed with the application’s Login screen.
NOTE: This file will be generated by AMP Studio. You may not copy all the files every time. If you are
making changes only to the UI after the first copy, then copy only the UI project compile code ending with
objc. In case you are adding an image or a bundle, you can copy all the files.
— Optionally, you can launch the Windows Mobile from the toolbar:
The Run process launches a new process for managing Windows Mobile simulators. This launch includes a DOS
window and Antenna Device Manager:
The Device list is based on simulators installed in Visual Studio and any additional device skins downloaded
from the Web.
3 Right-click the appropriate device simulator and perform the following steps:
A Select Connect. This will launch the simulator along with activating Microsoft ActiveSync.
B Select Deploy Compact Framework. This step is required only once for each simulator (provided you have
saved the state when you closed the simulator).
C Select Deploy. This loads the application package to the device simulator.
D Select Run. This launches the application. (This step may take a few minutes as the application loads.)
E Select Bring to Front. This will bring the simulator window to the foreground.
Android Simulator
1 Download the latest Android SDK from Google for Windows. From the Windows menu, select Preferences and
click Android.
2 Browse to the location where the Android SDK is located in your local Mac. You will see all the supported
API’s.
3 From the Windows menu, select Android SDK and AVD Manager. You need to create new device simulator
for testing.
4 Click New. The Create new Android Virtual Device screen appears.
5 Name the Simulator and select the target. You can create as many device simulators you need and test against
different target APIs.
6 Create a project in AMP Studio as explained for other devices and ensure that Android is selected in the Client
list under AMP Studio.
8 If the splash screen is specified, the Android device simulator starts and displays the splash screen before
displaying the Hello World Screen.
Creating a UI Project
To create a UI project, do the following:
2 Select UI Project.
A From the toolbar, select the New UI project icon, or from the File menu, click New and select UI Project.
or,
10 Declare a new label at the top of the screen (within the screen brackets but before the first callback), as shown in
the following example.
11 In the onCreate() callback, set the text on the label and add the label to the Screen.
lblHelloWorld.setText("Hello World!");
add(lblHelloWorld,"hfill=fill");
StartScreen scrStart;
callback onStart(){
scrStart.push();
NOTE: Ensure that the JDE and Device Simulator settings are valid.
17 Click OK.
NOTE: Check the Problems tab to make sure that there are no errors. You can ignore warning messages.
20 Click the drop-down arrow to the right of the Run BlackBerry Device Simulator selection button and select a
BlackBerry simulator. When the simulator starts, find the Antenna application icon (it may be in the
Applications or Downloads folder) and select it. You can view the Hello World label on your device.
2 From the File menu, click New and select Data Project. The Data Project Wizard screen appears.
5 Click Finish.
7 Click Connect.
12 Right-click Reply, select Add Object, select TEST, and then click Finish.
13 Double-click the SelectionCriteria Request object and move the NumRows and ObjectIndex fields from left to
right.
NOTE: SelectionCriteria Request objects are moved to the right for them to used by the application.
14 Double-click the SelectionCriteria Reply object and move the TEXT field from left to right.
15 Double-click the HelloWorld.mscript file and declare and instantiate the Data Project, the VRPC object, and the
MessageService:
16 In the HelloWorld.mscript's onStart() callback, set the user name to the deviceID, log in the user, start the
message service, and instantiate the StartScreen:
callback onStart(){
setUser(getDeviceID());
login();
messageService.start(true);
scrStart.push();
callback onLoggedIn(){
open(dp);
18 Double-click the SelectionCriteria.mscript file. Add a prepareVRPC() method. This method will create a new
DataRow and set the NumRows field of this DataRow.
VRPCInputObject {
void prepareVRPC(){
SelectionCriteria.ID.setStringValue("0", dtRwSelectionCriteria);
SelectionCriteria.NumRows.setStringValue("10", dtRwSelectionCriteria);
SelectionCriteria.ObjectIndex.setStringValue("0", dtRwSelectionCriteria);
dtRwSelectionCriteria.applyUpdates();
VRPCRequest {
void sendVRPC() {
reset();
SelectionCriteria.prepareVRPC();
send();
vrpcGetObjectRows.sendVRPC();
24 Click the Compile mScript button in AMP Studio. Check the Problems tab to make sure that there are no errors.
You can safely ignore Warning messages.
25 Start the AMP Studio server by clicking the Run Server button.
26 Click the Run BlackBerry Device Simulator button and select a BlackBerry simulator.
27 When the simulator starts, find the Antenna application icon (it may be in the Applications or Downloads folder)
and select it. You should see VRPC Reply Received pop-up message when the VRPC is returned.
Data Objects
A data project uses data provided by a data connector. A data connector exposes data objects and their fields. To add a
data object to a data project, right-click VDSC in the AMP Studio Explorer:
A data object's field is the DataAttribute type. There are a number of specific DataAttribute types:
■ BinaryAttribute
■ BooleanAttribute
■ CurrencyAttribute
■ DateAttribute
■ FloatAttribute
■ IDAttribute
■ IntegerAttribute
■ StringAttribute
■ TimeAttribute
■ TimestampAttribute
Query
The following is a sample empty query:
query myQuery<>{}
By default, a query takes data from the current data object. Because this query does not have any constraints, it will return
all rows from this data object. Each returned row has all fields of the current data object. In the following examples,
assume that the current data object has these fields:
where:
query myQuery<>{
This query will return all valid users. The where clause is similar to SQL, but as you will see it is not the same. It is
possible to impose several constraints:
query myQuery<>{
This query will return all valid users with a score higher than 10.
The following operators can be used in where clause: ==, !=, <, >, <=, >=, startsWith, contains. An operator must be used
for two objects of the same type. For example, it is possible to use == between two boolean objects: valid == true but not
between a boolean object and a string: valid == "true" (this is illegal).
NOTE: Notice that valid is of type BooleanAttribute whereas true is of type boolean. Formally, these are
different types and cannot be used in the same operation. Nevertheless, within the query clause AMP Studio
performs automatic conversion between these types, and they can be used in the same operation. The same is
true for the DataAttribute type.
Sorting
The results of a query can be sorted in ascending or descending order:
query myQuery<>{
ascendingBy username;
This query will return all valid users with a score higher than 10 sorted by their user name in ascending order. Unlike the
where clause, a query may have only one sorting statement and only by one field.
Unique Keywords
In cases when unique results are required, use a unique keyword:
query myQuery<>{
ascendingBy username;
unique;
This query will return all unique valid users with a score higher than 10 sorted by their user name in ascending order.
Counting
In some cases, it is necessary to count the number of results from a query. In this case the number of results should be
stored in one of the fields of a data object.
query myQuery<>{
ascendingBy username;
This query returns all unique valid users sorted by their user name in ascending order, and the number of these users is
stored in the score field.
Query Parameters
A query can have parameters:
ascendingBy sortBy;
unique;
In this example, the query receives three parameters: state (valid or not), minScore (minimum score) and sortBy (a field of
this data object by which the sorting will be performed).
Constraints imposed by the where clause are basic comparison operations. When more advanced constraints must be
imposed, it is possible to define a rowfilter. A rowfilter is basically a method that returns true or false:
This rowfilter takes a user's city as an input and returns true if a user is either from Ottawa or from Montreal.
cannadaUser<city>;
ascendingBy sortBy;
unique;
cannadaUser<city>;
legalHobby<hobby>;
ascendingBy sortBy;
unique;
Index
For a faster lookup of data, it is possible to define an index. A data object may have only one index definition:
index myIndex{
username ascending;
country descending;
NOTE: In an index definition, the sorting keywords are ascending/descending and not ascendingBy/
descendingBy as in a query
Link Fields
A Link Field is a field of type DataAttribute that obtains its value from another DataAttribute in a way similar to the SQL
join.
Assume that the current data object is Company. Company has the AccountManagerID attribute. There is a need to obtain
the name of a manager by AccountManagerID from another data object Employee that has an EmployeeID and
EmployeeName for each employee.
A Link Field that obtains the manager’s name will look like:
A Link Field definition consists of several parts separated by =>. The first part is a field inside the current data object.
Therefore there is no need to write the full name Company.AccountManagerID. It is enough to write just
AccountManagerID. The next parts are usually from other data objects and the name of a data object is mandatory in the
first half of -> expression but not in the second:
Both parts of the -> expression must be from the same data objects. It is possible to chain several data objects:
This example obtains the job description of the current account manager.
Virtual Fields
Fields of a data object are defined by a data connector. In some cases, it is necessary to define additional fields. Such
fields are called virtual fields.
■ BinaryField
■ BooleanField
■ CurrencyField
■ DateField
■ FloatField
■ IDField
■ IntegerField
■ StringField
■ TimeField
TimestampField
Example:
BooleanField isFrequent{
This example defines a virtual field isFrequent of type BooleanField that returns true if a user is valid and has a high
score.
It is impossible to set a value to a virtual field. For example, the following line is incorrect:
isFrequent = true;
The regular data objects are defined in a data connector. Virtual data objects are defined in mScript. The first step in a
definition of a virtual data object is to define one or more mappings. A mapping defines a new view over data objects.
Example:
This mapping defines a join by a user ID between two data objects: User and UserHistory. Then this mapping exposes
three fields under slightly different names. Now it is possible to run queries over this mapping:
descendingBy actionDate;
This query returns the username, action date and action type sorted by action date in descending order and it filters results
by date. Use it to specify mappings over which a query is executed.
NOTE: The query that uses the mapping does not use the original names of data object fields (data,
action_type), but names exposed by the mapping: actionDate, actionType
VRPCOutputObject {
query qryGetAll<> {
ascendingBy intKeyAttr;
}
IntegerField intKeyAttr {
return Platform.createInteger(v_vms_key_attr_);
}
}
To invoke a VRPC, the application must obtain the VRPC Request object for each object that is being exposed by the
VRPC connector. Once each of the VRPC Requests has been populated with VRPCRows, send() is called to make the
call.
When the server results are available, the application is notified via the onReplyReceived callback. The VRPC Reply
object will contain rows with the values returned by the server.
To use VRPC, VRPC support must be enabled in the connector. A connector can have support for both VDSC and VRPC,
resulting in a hybrid application.
VRPC can be asynchronous, meaning that the calls are executed in a non-blocking scheme, allowing the main program
flow to continue processing.
VRPC is more efficient than having the client make Web Service calls directly. The connector removes the headers before
routing the response to the client, leading to reduced computation on the client and less data transmitted over the wireless
network.
The Client does not make direct Web Service calls. Instead, the connector and the server do the heavy lifting. The
connector creates Request and Reply objects for each Web Service call listed in the WSDL file. It creates Request objects
for the Request Elements and creates Reply objects for the Response Elements.
Data Objects
VRPC data objects are added to projects in the same way as VDSC data objects.
void prepareVRPC(){
RetrieveAggregatedAccountSummaryReq.IncludeCustomerDetail.setBooleanValue
(Platform.createBoolean(true), dtRwAggAcctSummaryReq);
dtRwAggAcctSummaryReq.applyUpdates();
Create a sendVRPC() method in the VRPC object mScript and call the prepareVRPC methods that you created:
reset();
VRPCHeader.prepareVRPC();
RetrieveAggregatedAccountSummaryReqDocument.prepareVRPC();
RetrieveAggregatedAccountSummaryReq.prepareVRPC();
Id.prepareVRPC(strUser);
send();
vrpcAccountSummary.sendVRPC(strUser);
The VRPC Reply should be listened for in the onReplyReceived() callback. The UI can then be updated based on the
VRPC Reply.
dtRwSetError = vrpcAccountSummary.VRPCError.createQuery().getRowSet();
if(dtRwSetError.first() != null){
// show error
else {
tblPnlAccountSummary.rchTblMdlAccounts.setRows
(vrpcAccountSummary.SummaryDocument_24_Summary.qryGetTypes());
You can refer to more information about VRPC error handling in Best Practices for Error Handling on page 191.
UI Projects
A UI project consists of the following:
■ mScript file
■ Strings Editor
■ Images Editor
■ Colors Editor
■ Styles folder
■ Screens
■ Panels
■ Folders
UI Project mScript
A UI project is created with one project level as mScript. For example, if a project is called as LearnUI, the mScript file
will be named as LearnUI.mscript. This top level mScript is used to define visible fields and is used in all mScript files of
the UI project. Usually it contains the definitions of the following:
■ Strings
■ Images
■ Styles
■ Services
■ Reference to a data project
■ Top level screens
It also contains important callbacks such as the onStart and onApplicationStyleSetup. It may also contain callbacks for
services and data project events.
Strings Editor
Strings are used to define string resources for localization purposes. You should add appropriate locales.
2 Enter the name of a string and enter the corresponding actual value.
An existing string resource can be deleted by right-clicking its name and selecting the Delete option.
Images Editor
Images are defined under the Images node of a UI project. To add an image, do the following:
1 Right-click Images and select Add Image Bundle. The Image Bundle screen appears. The Strings dialog box
appears in the right panel.
3 Enter the Name of the Image Bundle Wizard, and select the device in the Type field. Each image bundle has a
properties page that can be accessed by double-clicking an image bundle name.
4 Select the device compatibility for each image bundle. This enables AMP Studio to package only relevant
images with WM, BB, or iPhone executables.
Each image has a name and an appropriate image file can be assigned for each of the bundles. The .png file is
recommended, but you can also add .jpeg or .bmp files.
Colors Editor
Colors are defined under the Colors node of a UI project. All standard Java colors are listed in the left panel. The Colors
screen appears.
To add a new color, click the New button. The new color will be called NewColor and be listed in alphabetical order.
To edit an existing color, rename it in the Color name field, type in the appropriate RGB colors, and click the Save
button. Colors can be used in mScript as static fields in the class Colors.
Example:
txtMdlAccount.setForeColor(Colors.MobileTradingBlue);
txtMdlAccount.setFocusedForeColor(Colors.White);
Colors can also be defined with mScript. Colors defined with mScript also allow the developer to set the alpha as the first
(optional) parameter. This can provide a transparent effect.
Example:
Background bg = Background.createColorRectangleBackground(clrWhite);
rchTblAccounts.setOddUIRowBackground(bg);
rchTblAccounts.setEvenUIRowBackground(bg);
Sound Effects
The following is a sample code to add the sound effects:
btn1.setText("Click here");
btn1.setOnClickSoundEffect(SoundEffects.btn_click);
txtData.setTextHint("Type here");
txtData.setOnValueChangeSoundEffect(SoundEffects.val_changed);
Styles
Styles are defined under the Styles folder of a UI project. In order to add a style, right-click either the UI project icon or
Styles in the AMP Studio Explorer.
You can use a style to define that the text color of a button is red. This red text color will be applied to all buttons of a UI
project.
■ Button
■ TextField
■ Table
■ Rich_Table
■ Label
■ Message_box
Example:
Table.setCellBackColor(Color.WhiteSmoke);
This line sets the default color of a cell in all tables to Color.WhiteSmoke
Usually in order to create a consistent look, more than one visual setting must be applied to more than one type of UI
control. These settings are grouped in a Style definition. Each Style definition is in a separate mscript file. Each UI project
may have more than one Style.
Assume that the LearnUI has three styles: Default, Bright, Dark. It means that there are three mscript files:
DefaultStyle.mscript, BrightStyle.mscript and DarkStyle.mscript.
Style {
Label.setBackColor(Colors.LightGray);
Label.setForeColor(Colors.Black);
TextField.setBackColor(Colors.LightGray);
TextField.setForeColor(Colors.Black);
//more settings
Styles are often used for different device models or types. In order to apply a style to the LearnUI project, the following
code must be placed in LearnUI.mscript:
if (Device.isBlackberry()) {
styleReceptor.applyVisualStyle(styBB);
else if (Device.isWindowsMobile()) {
styleReceptor.applyVisualStyle(styWM);
else if (Device.isIPhone()) {
styleReceptor.applyVisualStyle(styIPhone);
if (Device.isBlackberry()) {
styleReceptor.applyVisualStyle(styDetailsBB);
} else if (Device.isWindowsMobile()) {
styleReceptor.applyVisualStyle(styDetailsWM);
} else if (Device.isIPhone()) {
styleReceptor.applyVisualStyle(styDetailsIPhone);
A style can be overwritten locally. The following code overwrites the background color set globally:
someLabel.setBackColor(Color.DimGray);
//Strings
String defaultFontFamily;
String titleFontFamily;
Label defHeaderLabel;
Label defTitleLabel;
Label defSectionLabel;
//Fonts
//Font Sizes
int fntLabelSize;
int fntButtonSize;
int fntBackgroundButtonSize;
int fntTextFieldSize;
int fntTextAreaSize;
int fntComobBoxSize;
int fntScrHeaderSize;
int fntScrTitleSize;
int fntScrSectionSize;
//Callback onStyleCreation
defaultFontFamily = "";
/*
These generic labels can be used on any screen (or pop-up message, etc.) in the project. The text of these labels will be set
according to the parent screen. These labels can be used on multiple screens. Therefore, they save memory and
programming efforts.
*/
//Font Sizes
if (Device.isBlackberry()) {
fntLabelSize = 6;
fntButtonSize = 5;
fntBackgroundButtonSize = 5;
fntTextFieldSize = 6;
fntTextAreaSize = 5;
fntComobBoxSize = 6;
fntScrHeaderSize = 8;
fntScrTitleSize = 6;
fntScrSectionSize = 5;
fntLabelSize = 6;
fntButtonSize = 5;
fntBackgroundButtonSize = 5;
fntTextFieldSize = 6;
fntTextAreaSize = 5;
fntComobBoxSize = 6;
fntScrHeaderSize = 8;
fntScrTitleSize = 6;
fntScrSectionSize = 5;
fntLabelSize = 6;
fntButtonSize = 5;
fntBackgroundButtonSize = 5;
fntTextFieldSize = 6;
fntTextAreaSize = 5;
fntComobBoxSize = 6;
fntScrHeaderSize = 8;
fntScrTitleSize = 6;
fntScrSectionSize = 5;
} else if (Device.isIPhone()) {
defaultFontFamily = "Helvetica";
titleFontFamily = "Georgia-Bold";
fntLabelSize = 14;
fntButtonSize = 10;
fntBackgroundButtonSize = 10;
fntTextFieldSize = 14;
fntTextAreaSize = 12;
fntComobBoxSize = 12;
fntScrHeaderSize = 18;
fntScrTitleSize = 10;
fntScrSectionSize =14;
} else {
defaultFontFamily = "Helvetica";
titleFontFamily = "Georgia-Bold";
fntLabelSize = 14;
fntButtonSize = 10;
fntBackgroundButtonSize = 10;
fntTextFieldSize = 14;
fntTextAreaSize = 12;
fntComobBoxSize = 12;
fntScrHeaderSize =18;
fntScrTitleSize = 10;
fntScrSectionSize = 14;
fontType.setFamily(fontFamily);
fontType.setSize(fontSize);
fontType.setBold();
Label.setFont(fontType);
Label.setForeColor(Colors.Black);
fontType.setFamily(fontFamily);
fontType.setSize(fontSize);
Button.setFont(fontType);
Button.setBackColor(Colors.Blue);
Button.setFocusedBackColor(Colors.Green);
Button.setForeColor(Colors.White);
Button.setFocusedForeColor(Colors.White);
fontType.setFamily(fontFamily);
fontType.setSize(fontSize);
fontType.setBold();
fontType.setFamily(defaultFontFamily);
fontType.setSize(fontSize);
TextField.setFont(fontType);
TextField.setBorder(Border.createSimpleBorder(Colors.CadetBlue));
TextField.setForeColor(Colors.MediumBlue);
TextField.setFocusedForeColor(Colors.Black);
TextField.setBackColor(Colors.White);
TextField.setFocusedBackColor(Colors.MintCream);
fontType.setFamily(defaultFontFamily);
fontType.setSize(fontSize);
TextArea.setFont(fontType);
TextArea.setBorder(Border.createSimpleBorder(Colors.CadetBlue));
TextArea.setForeColor(Colors.Black);
TextArea.setFocusedForeColor(Colors.Black);
TextArea.setBackColor(Colors.White);
TextArea.setFocusedBackColor(Colors.MintCream);
fontType.setFamily(fontFamily);
fontType.setSize(fontSize);
ComboBox.setFont(fontType);
ComboBox.setBorder(Border.createSimpleBorder(Colors.CadetBlue));
ComboBox.setForeColor(Colors.White);
ComboBox.setFocusedForeColor(Colors.MidnightBlue);
ComboBox.setBackColor(Colors.LightSlateGray);
ComboBox.setFocusedBackColor(Colors.White);
fontType.setFamily(fontFamily);
fontType.setSize(fontSize);
fontType.setBold();
txtShadow.setShadowColor(Colors.DarkGray);
txtShadow.setShadowOffset(0,5);
defHeaderLabel.setFont(fontType);
defHeaderLabel.setForeColor(Colors.White);
fontType.setFamily(fontFamily);
fontType.setSize(fontSize);
fontType.setBold();
defTitleLabel.setFont(fontType);
defTitleLabel.setForeColor(Colors.Silver);
fontType.setFamily(fontFamily);
fontType.setSize(fontSize);
fontType.setBold();
defSectionLabel.setFont(fontType);
defSectionLabel.setForeColor(Colors.Silver);
Log
Every platform may have its own destination for log messages.
PhoneManager
PhoneManager serves to make and receive calls.
MessagingManager
MessagingManager serves to send and receive e-mail and SMS messages.
AMP™ Studio Developer Guide 76
ANTENNA PROPRIETARY & CONFIDENTIAL AMP™ Studio Developer Guide
Message Service
MessageService is used to allow the client and server to communicate with each other. It has a number of useful methods
and callbacks. The following example checks the server status:
if (status == Service.AVAILABLE) {
//do something
else {
/*
*/
if (displayServerUpgradeMsg) {
if(applicationPermission.getStatus() = ApplicationPermission.STATUS_MUST_UPGRADE){
arOptions.addItem("Upgrade");
goToWebPage(applicationPermission.getLatestUrl());
if(applicationPermission.getStatus() == ApplicationPermission.STATUS_MUST_UPGRADE){
arOptions.addItem("Upgrade");
goToWebPage(applicationPermission.getLatestUrl());
if (displayServerUpgradeMsg) {
if(applicationPermission.getStatus() == ApplicationPermission.STATUS_CAN_UPGRADE){
arOptions.addItem("Continue");
arOptions.addItem("Upgrade");
if(response == 1) {
if(Device.isBlackberry()) shutdown();
goToWebPage(applicationPermission.getLatestUrl());
if(applicationPermission.getStatus() == ApplicationPermission.STATUS_CAN_UPGRADE){
arOptions.addItem("Continue to Login");
arOptions.addItem("Upgrade");
if(response == 1) {
goToWebPage(applicationPermission.getLatestUrl());
Assume that the data project is a VDSC data project named LearnDP. Then the object will be:
Assume that the data project is a VRPC data project named LearnDP. Then the object will be:
Screens
A screen is a UI component. Some applications have a login screen, a main screen, and a number of other screens. The
following features describe the characteristics of a screen:
■ Title
■ Menu
■ Controls such as labels, buttons, text fields, etc.
■ Open message dialogs
■ A number of callbacks that are called during the lifecycle events of a screen: onCreate, onOpen, onActivate, etc.
You can add a screen by selecting Add Screen from the menu.
After a screen's folder and mscript are created in AMP Studio, the screen may be declared in the UI project's mscript
(LearnUI.mscript):
Creating a Screen
Use the following code to create a screen:
//Setting a Title
loginScreen.setTitle("Login");
Setting a Menu
Use the following code to set a menu:
actHelp.setText("Help");
actClose.setText("Close");
mn.add(actHelp);
mn.add(actClose);
setMenu(mn);
Message Box
MessageBox is used to display a non-modal, platform-native pop-up dialog box.
int fontSize,cnt=0;
setBackgroundButtonProperties(b1);
setBackgroundButtonProperties(b2);
setBackgroundButtonProperties(b3);
b4.setText("Error Sample");
setBackgroundButtonProperties(b4);
b5.setText("Info Sample");
setBackgroundButtonProperties(b5);
b6.setText("Warning Sample");
setBackgroundButtonProperties(b6);
askOptions.addItem("Option 1");
askOptions.addItem("Option 2");
askOptions.addItem("Option 3");
askOptions.addItem("Option 4");
add(b1,"hfill=fill");
add(b2,"hfill=fill");
add(b3,"hfill=fill");
add(b4,"hfill=fill");
add(b5,"hfill=fill");
add(b6,"hfill=fill");
msgBox.ask(1,"This is ask");
msgBox.error(4,"This is error");
msgBox.info(5,"This is info");
if(dismissalType==MessageBox.DISMISS_UI){
dismType="UI Dismissed";
else if(dismissalType==MessageBox.DISMISS_PROGRAMMATIC){
dismType="Programatically Dismissed";
Panels
A panel is a container for controls and other panels. The difference between the panels is in how they lay out their
controls. The basic panels are HorizontalPanel and VerticalPanel.
■ HorizontalPanel
■ VerticalPanel
■ FormPanel
■ BorderPanel
■ TablePanel
■ GridPanel
■ TabbedPanel
■ StackPanel
■ SectionedPanel
■ CalendarPanel
HorizontalPanel
The HorizontalPanel places controls one after another horizontally.
Controls are added by using the add(Drawable) method. Both panels and controls inherit from the Drawable method. This
means that it is possible to add either a control or another panel with its own controls and panels. This provides the ability
to create complex layouts.
lbl1.setText("Peter Parker");
lbl2.setText(" Is ");
lbl3.setText("SPIDERMAN");
myHorizontalPanel.setColumnWidth(0,Sizing.PERCENTS,40);
myHorizontalPanel.setColumnWidth(1,Sizing.PERCENTS,20);
myHorizontalPanel.setColumnWidth(2,Sizing.PERCENTS,40);
myHorizontalPanel.setPanelHeight(Sizing.PERCENTS,60);
myHorizontalPanel.add(lbl1,"vfill=fill,hfill=fill");
myHorizontalPanel.add(lbl2,"halign=center");
myHorizontalPanel.add(lbl3,"vfill=fill,hfill=fill");
add(myHorizontalPanel,"hfill=fill");
VerticalPanel
VerticalPanel lays out the controls vertically.
The previous example shows a simple case of TablePanel with one column. It simplifies adding elements to the table. The
number of rows is unlimited. The width of the column equals the maximal width of table elements. Panels and controls are
added using add(Drawable) method.
myVerticalPanel.add(lblName);
myVerticalPanel.add(txtName);
myVerticalPanel.add(lblDob);
myVerticalPanel.add(txtDob);
myVerticalPanel.add(lblContact);
myVerticalPanel.add(txtContact);
myVerticalPanel.add(btnSubmit);
add(myVerticalPanel,"hfill=fill");
FormPanel
FormPanel lays the controls in two columns. The left control must be a Label.
myFormPanel.add(lblName,"halign=right", txtName,"halign=left,hfill=fill");
myFormPanel.add(lblDob,"halign=right",txtDob,"halign=left,hfill=fill");
myFormPanel.add(lblContact,"halign=right",txtContact,"halign=left,hfill=fill");
myFormPanel.add(lblAddress,"halign=right",txtAddress,"halign=left,hfill=fill");
add(myFormPanel,"hfill=fill");
BorderPanel
A BorderPanel lays out the control in the top, bottom, left, right and center of a panel.
This container accommodates up to five layout elements. Four elements are along the borders and one in the center.
Border elements receive all the space needed. The remaining space goes to the center. North and South elements are
placed first; they receive full panel width. East and West elements receive the height remaining between North and South.
You should not attempt to place North and South elements whose height is greater than the panel height, and East or West
elements whose width is greater than the panel width.
btnEast.setText("East");
btnWest.setText("West");
btnNorth.setText("North");
btnSouth.setText("South");
btnCenter.setText("Center");
myBorderPanel.setEast(btnEast);
myBorderPanel.setWest(btnWest);
myBorderPanel.setNorth(btnNorth);
myBorderPanel.setSouth(btnSouth);
myBorderPanel.setCenter(btnCenter);
add(myBorderPanel,"hfill=fill,vfill=fill");
TablePanel
TablePanel lays out controls in columns and rows. It has no grid lines. It has both horizontal and vertical scrollbars on
devices that support scrollbars.
It arranges various layout elements in columns and rows. It has methods to automatically regulate row/column width and
element positioning inside table cells.
The controls are added horizontally, one after another. Each control will be placed in the next spare cell. To begin a new
row, startNewRow() must be called.
panel.add(label, null);
panel.startNewRow();
This example creates a 1 column x 100 rows table. The second parameter of add method is used to set constraints on the
added control. The constraints specify the alignment of a control within its cell, if the control must fill the cell, and if the
control must span several columns or rows.
tblPanel.setColumnWidth(0,Sizing.PERCENTS,30);
tblPanel.setColumnWidth(1,Sizing.PERCENTS,30);
tblPanel.setColumnWidth(2,Sizing.PERCENTS,30);
tblPanel.setRowHeight(0,Sizing.PERCENTS,30);
tblPanel.setRowHeight(1,Sizing.PERCENTS,30);
tblPanel.add(label1);
tblPanel.add(label2);
tblPanel.add(label3);
tblPanel.startNewRow();
tblPanel.add(label4);
tblPanel.add(label5);
tblPanel.add(label6);
add(tblPanel,"halign=center");
The last label spans two cells. The E button has colspan = 2, and it expands to fill the two columns.
Sizes of grid cells are determined automatically using elements’ preferred sizes. Sizes of grid cells can be overridden
using setRowHeight() and setColumnWidth(). Sizing.PIXELS should be used when the element size is known, for
example, for an image. Sizing.PERCENTS should be used when the element size is variable. The percentage base is the
panel size.
Example:
tblPnlRoot.setColumnWidth(0,Sizing.PREFERRED,1);
GridPanel
GridPanel lays out the controls in columns and rows. It has gridlines and only a vertical scrollbar. Instead of having a
horizontal scrollbar, it has left and right buttons.
This container arranges controls in a rectangular grid. It also provides special means for scrolling such as scroll buttons
(which can be hidden and disabled) or arrow keys for touch scrolling. The grid can have frozen columns and rows.
Both columns and row numbers must be set. It has no constraints. It has frozen columns. A frozen column is a column that
does not move during scrolling. If a GridPanel has two frozen columns, the first two columns do not move during
scrolling.
panel.setColumnCount = 5;
panel.setRowCount = 100;
Panel.setCellControl(label, 1, 2);
This example creates a 5 X 100 grid and sets a label in the row 1, column 2. Rows and columns are counted from 0. So
from a user’s point of view the label is added to row 2, column 3.
myGridPanel.setColumnCount(3);
myGridPanel.setRowCount(4);
myGridPanel.setCellControl(lblHeader, 0, 1);
myGridPanel.setCellControl(lbl1, 1, 0);
myGridPanel.setCellControl(lbl2, 1, 2);
myGridPanel.setCellControl(lbl3, 2, 1);
myGridPanel.setCellControl(lbl4, 3, 0);
myGridPanel.setCellControl(lbl5, 3, 2);
myGridPanel.setGridLineStyle(2);
add(myGridPanel,"halign=center");
TabbedPanel
TabbedPanel has one or more tabs. Each tab is a panel with its own controls.
It manages a set of overlapping panels, switchable by a tab control. The Tab control location is platform-specific and can
be either at the top or bottom.
Panels and controls are added by add(Drawable, String). The string is the name of a tab. In the previous example the tabs
are named Tab 1 and Tab 2.
tbHeader1.setText("Tab1");
tbHeader2.setText("Tab2");
vertPanel1.add(lbl1);
vertPanel1.add(btnNext);
myTabbedPanel.add(tbHeader1,vertPanel1);
vertPanel2.add(lbl2);
vertPanel2.add(btnPrevious);
myTabbedPanel.add(tbHeader2, vertPanel2);
add(myTabbedPanel,"hfill=fill,vfill=fill");
myTabbedPanel.showTab(1);
myTabbedPanel.showTab(0);
StackPanel
StackPanel has a number of panels or controls but shows only one at a time. On different platforms this may look
different. It manages a set of overlapping panels with no switching control—switching must be programmed in mscript.
lbl1.setText("Section A");
lbl2.setText("Section B");
lbl3.setText("Section C");
lbl1.setBackColor(Colors.Lavender);
lbl2.setBackColor(Colors.Lavender);
lbl3.setBackColor(Colors.Lavender);
vertPanel1.add(lbl1);
myStackPanel.add(vertPanel1);
vertPanel2.add(lbl2);
myStackPanel.add(vertPanel2);
vertPanel3.add(lbl3);
myStackPanel.add(vertPanel3);
hzPanel.setColumnWidth(0,Sizing.PERCENTS,100);
hzPanel.setPanelHeight(Sizing.PERCENTS,80);
hzPanel.add(myStackPanel,"valign=center,hfill=fill");
add(hzPanel,"valign=top");
btn1.setFocusedImage(Images.toolbarbtn3.getImage());
btn1.setImage(Images.toolbarbtn.getImage());
btn1.setSelectedImage(Images.toolbarbtn2.getImage());
btn1.setText(" A");
btn2.setFocusedImage(Images.toolbarbtn3.getImage());
btn2.setImage(Images.toolbarbtn.getImage());
btn2.setSelectedImage(Images.toolbarbtn2.getImage());
btn2.setText(" B");
btn3.setFocusedImage(Images.toolbarbtn3.getImage());
btn3.setImage(Images.toolbarbtn.getImage());
btn3.setSelectedImage(Images.toolbarbtn2.getImage());
btn3.setText(" C");
rdGrp.addButton(btn1);
rdGrp.addButton(btn2);
rdGrp.addButton(btn3);
rdGrp.setButtonSpacing(5);
rdGrp.setNavigationType(ToolBar.SCROLLER);
add(rdGrp,"hfill=fill");
if(idxClicked==0){
myStackPanel.select(vertPanel1,Animation.UNCOVER_FROM_BOTTOM);
else if(idxClicked==1){
myStackPanel.select(vertPanel2,Animation.CURL_UP);
else if(idxClicked==2){
myStackPanel.select(vertPanel3,Animation.UNCOVER_FROM_TOP);
The following is output for the StackPanel sample code. (The Button B is selected and Button C has the focus.)
SectionedPanel
SectionedPanel is a panel container that contains panels with rounded corners and space between the panels. This is a
popular layout on iPhones. SectionedPanel is supported by iPhone and BlackBerry devices, but not by Windows Mobile
devices.
CalendarPanel
CalendarPanel is an advanced calendar widget. The output for the CalendarPanel would be:
Panel Methods
In addition to methods that serve to add controls, panels also have methods that do the following:
Reusing Panels
Some controls are reusable across multiple screens. Such panels may be defined in their own mscript file. Right-click a UI
project icon or a folder to add a panel.
You can define generic panels and then reuse them in different screens of the project. For adding a panel, right-click the
project name in the Project Explorer window and select Add Panel. Now select the type of panel you want to define.
Inside the panel script, you can define and view properties. See HorizontalPanel on page 99 for an example.
HorizontalPanel
//Callback methods
setBackground(Background.createHorizontalTiledImageRectangle
Background(Images.image_Header.getImage(), 2, 2));
setVGap(10);
setHGap(5);
setColumnWidth(0,Sizing.PERCENTS,25);
setColumnWidth(1,Sizing.PERCENTS,50);
setColumnWidth(2,Sizing.PERCENTS,25);
You can use the defined panels in as many screens as you want. They also help to make the view of all project screens
more uniform. To use a defined panel, instantiate it and then use it like a regular panel.
..........
headerPanel.add(btnAbout,"hfill=fill");
headerPanel.add(lblHeader,"halign=center");
headerPanel.add(btnNext,"hfill=fill");
add(headerPanel,null);
contentsPanel.add(lblContent1);
contentsPanel.add(lblContent2);
contentsPanel.add(lblContent3);
contentsPanel.add(lblContent4);
add(contentsPanel,"halign=center");
footerPanel.add(lblFooter,"halign=center");
add(footerPanel,null);
Tables
Table displays data in a grid of columns and rows. It is used to display a data rowset, along with TableModel. The
following is a sample code to set an image in a Grouped Table programmatically:
callback grpTbl onCellInfo (Control c, Section section, int row, Cell info, boolean
focused) {
if(section == sct){
imgMdl.setImage(Images.imgTest.getImage());
} else {
imgMdl.setImage(Images.imgArrow.getImage());
Folders
A folder serves to group screens and panels in order to create neatly organized projects. To add a folder, right-click a UI
project icon or an existing folder.
A folder becomes a part of the full name of a screen or panel. For example, in order to create an instance of
UserActionDetailsPanel that is located in ActionPanels folder which is a subfolder of UserPanels in LearnUI project, it
may be necessary to use its full name (depending on the current scope):
Models
Models refer to data models assigned to various panels and UI controls. The following models are included when a
callback is available for it.
■ Bar Chart
■ Browser
■ Calendar
■ Chart
■ Check Box
■ Choice
■ Date
■ Date Format
■ Image
■ Multi-Model
■ Number Format
■ Pie Chart
■ Table
■ Text Format
■ Text
■ Time Format
■ Time
■ Timestamp
■ Timestamp Format
txtFmtMdlPeers.addField(vrpcGetThemeDataCallBack.Instrument.Name);
txtFmtMdlPeers.addField(vrpcGetThemeDataCallBack.Instrument.Ticker);
txtFmtMdlPeers.setFormat("{0} {1}");
Table Model
The following is a sample code snippet for the Table model:
tbl.setColumnCount(2);
tblMdl.addStringColumn("EMPID", dp.MYEMP.EMPID);
tblMdl.addStringColumn("EMPNAME", dp.MYEMP.EMPNAME);
tblMdl.setRows(dp.MYEMP.getAll());
tbl.setGridLineStyle(1);
tbl.setDataModel(tblMdl);
add(tbl,"hfill=fill,vfill=fill,valign=top");
BarChart Model
The following is a sample code snippet for the BarChart model:
barChart.setBarBorderDrawn(true);
barChart.setBarLabelShown(true);
barModel.setRows(dp.MYEMP.getAll());
barModel.addAttribute(dp.MYEMP. EMPSALARY);
barModel.setLabelAttribute(dp.MYEMP.EMPNAME);
barChart.setDataModel(barModel);
add(barChart,"hfill=fill,vfill=fill");
PieChart Model
The following is a sample code snippet for the PieChart model:
pieModel.setRows(dp.MYEMP.getAll());
pieModel.setDataAttribute(dp.MYEMP.EMPSALARY);
pieModel.setLabelAttribute(dp.MYEMP.EMPNAME);
pieChart.setBorderDrawn(true);
pieChart.setLabelShown(true);
pieChart.setDataModel(pieModel);
add(pieChart,"hfill=fill");
Choice Model
The following is a sample code snippet for the Choice model:
empNameMdl.setChoicesAttribute(dp.MYEMP.EMPNAME);
empNameMdl.setChoicesKeyAttribute(dp.MYEMP.EMPID);
empNameMdl.setRows(dp.MYEMP.getAll());
pkrEl.setText("select one");
pkr.setDataModel(empNameMdl);
pkr.setPlaceHolder(pkrEl);
add(pkr,"valign=top,hfill=fill");
comboEName.setDataModel(empNameMdl);
Multi Model
The following is a sample code snippet for the Multi model:
mltMdl.setRow(dp.MYEMP.getFilteredByNAME("ashish").getRowSet().first());
txtMdlEmpID.addField(dp.MYEMP.EMPID);
lblEmpIDValue.setBackColor(Colors.Gainsboro);
lblEmpIDValue.setDataModel(txtMdlEmpID);
mltMdl.add(txtMdlEmpID);
txtMdlEmpName.addField(dp.MYEMP.EMPNAME);
lblEmpNameValue.setBackColor(Colors.Gainsboro);
lblEmpNameValue.setDataModel(txtMdlEmpName);
mltMdl.add(txtMdlEmpName);
Text Model
The following is a sample code snippet for the Text model:
txtMdlEmpID.addField(dp.MYEMP.EMPID);
txtMdlEmpID.setRow(dp.MYEMP.getFilteredByNAME("ashish").getRowSet().first());
lblEmpIDValue.setBackColor(Colors.Gainsboro);
lblEmpIDValue.setDataModel(txtMdlEmpID);
TimeStamp Model
The following is a sample code snippet for the TimeStamp model:
tsMdlEmpDoj.addField(dp.MYEMP.EMPDOJ);
tsMdlEmpDoj.setRow(dp.MYEMP.getFilteredByNAME("ashish").getRowSet().first());
datebox.setDataModel(tsMdlEmpDoj);
TimestampFormat Model
The following is a sample code snippet for the TimestampFormat model:
tsMdlEmpDoj.addField(dp.MYEMP.EMPDOJ);
tsMdlEmpDoj.setStyle(DateStyles.DATE_SHORT);
tsMdlEmpDoj.setRow(dp.MYEMP.getFilteredByNAME("ashish").getRowSet().first());
datebox.setDataModel(tsMdlEmpDoj);
Time Model
The following is a sample code snippet for the Time model:
tmMdlEmpDoj.addField(dp.MYEMP.EMPDOJ);
tmMdlEmpDoj.setRow(dp.MYEMP.getFilteredByNAME("ashish").getRowSet().first());
datebox.setDataModel(tmMdlEmpDoj);
TimeFormat Model
The following is a sample code snippet for the TimeFormat model:
tfMdlEmpDoj.addField(dp.MYEMP.EMPDOJ);
tfMdlEmpDoj.setStyle(DateStyles. TIME_MEDIUM);tfMdlEmpDoj.setRow
(dp.MYEMP.getFilteredByNAME("ashish").getRowSet().first());
datebox.setDataModel(tfMdlEmpDoj);
NumberFormat Model
The following is a sample code snippet for the NumberFormat model:
tblMdl.setRows(dp.MYEMP.getAll());
numFmtMdl.addField(dp.MYEMP.EMPID);
numFmtMdl.setShortenedDisplay(true);
numFmtMdl.setPositiveSign ( "+" );
numFmtMdl.setNegativeAsRed(true);
tblMdl.addFormattedColumn("EMPID", numFmtMdl);
tbl.setDataModel(tblMdl);
Date Model
The following is a sample code snippet for the Date model:
dtMdlEmpDoj.addField(dp.MYEMP.EMPDOJ);
dtMdlEmpDoj.setRow(dp.MYEMP.getFilteredByNAME("ashish").getRowSet().first());
datebox.setDataModel(dtMdlEmpDoj);
DateFormat Model
The following is a sample code snippet for the DateFormat model:
dtFmtMdlEmpDoj.addField(dp.MYEMP.EMPDOJ);
dtFmtMdlEmpDoj.setStyle(DateStyles.TIME_SHORT);
dtFmtMdlEmpDoj.setRow(dp.MYEMP.getFilteredByNAME("ashish").getRowSet().first());
datebox.setDataModel(dtFmtMdlEmpDoj);
Setting Data
There are two ways to set data in a control. One way is to set data directly using a corresponding method:
The second way is to use a data model and pass it to a control. A data model is a class that inherits from a DataModel.
There are several data model classes: BarChartModel, BrowserModel, CalendarDataModel, etc. Each data model class is
used with its corresponding control: BarChartModel is used with BarChart, etc. Some classes use only the direct way of
setting data as in the previous examples.
Some controls use both ways of setting data. For example, DateBox has two methods for setting data: setDate(Date) and
setDataModel(DataModel) that receives a DateModel instance.
Some classes use only data models to set data. Data models serve as a bridge between a data project and the controls in a
UI project. Data for a data model is obtained from data objects’ queries.
Example 1
Assume there is a data project named LearnDB that has a data object User. There is a query getUsersByName that returns
users sorted by name. The following example will show the results of this query in a list.
As you remember from the section about the UI project, the UI project’s mscript creates a reference to the data project:
Then this reference is used to obtain data from the data project:
model.addField(dp.User.username);
model.setRows(dp.User.getUsersByName());
Choice.setDataModel(model);
The example creates a model. Then it specifies which of the User data object's fields will be shown in the list. Then it sets
rows from the query to the model. Then it creates the list and sets its model.
Now assume that a user selected a row in the list, opened a text editor and changed the value of the row, the datastore from
where the data is taken using the query can be updated. In order to do this, the code must obtain the selected row of the
list, update its value and save it:
dp.User.username.setStringValue(newValue,row);
row.applyUpdates();
dp.startSync("Username Update");
startSync stores data in a file on a device and also sends it to be stored in the backend storage such as the database. The
parameter of startSync can be any text that identified the operation for logging purposes on the server.
Application Callbacks
Application callbacks provide mechanisms for device-specific runtime to communicate with the application and have it
take actions as necessary. It is not necessary to respond to all the callbacks. Runtime will invoke the callback only if it is
referenced in an application.
There are classes of callbacks for the UI application, Panels, UI controls, and, each callback outlines wherever it is
applicable. All associated Panels and UI controls are described in subsequent sections.
On Close
This callback is called when a panel or a screen is closed.
scrHome.lblStatus.setText("Returned");
UI Controls
The following examples are assumed to be written inside play.mscript.
Bar Chart
This control displays business charts as groups of vertical bars.
barChart.setBarLabelShown(true);
barChart.setNRows(3);
barChart.setNSeries(4);
barChart.setRowLabel(0,"January");
barChart.setRowLabel(1,"February");
barChart.setRowLabel(2,"March");
barChart.setSeriesColor(0,Colors.Blue);
barChart.setSeriesColor(1,Colors.Green);
barChart.setSeriesColor(2,Colors.Yellow);
barChart.setSeriesColor(3,Colors.Red);
add(barChart,"hfill=fill,vfill=fill");
Pie Chart
This control displays business charts as a circle divided into sections.
pieChart.setBorderDrawn(true);
pieChart.setLabelShown(true);
pieChart.setNRows(4);
pieChart.setSectorColor(0,Colors.Blue);
pieChart.setSectorColor(1,Colors.Yellow);
pieChart.setSectorColor(2,Colors.Green);
pieChart.setSectorColor(3,Colors.Orange);
pieChart.setValue(0,25);
pieChart.setValue(1,46);
pieChart.setValue(2,14);
pieChart.setValue(3,15);
add(pieChart,"hfill=fill,vfill=fill");
Button
A button shows an image or text.
button.setForeColor(Colors.Yellow);
button.setBackColor(Colors.Lavender);
button.setBorderColor(Colors.Gray);
button.setText("Submit");
Native
Button btnContinue = new Button();
btnContinue.setText("Continue");
Full Graphic
BackgroundButton btn = new BackgroundButton();
btn.setImage(Images.image_reload.getImage());
Tiled Graphic (single image with the left/right cap and tiled center portion)
Button bgrBtn = new Button();
bgrBtn.setText("TRADE");
bgrBtn.setBackground(Background.createHorizontalTiledImageRoundedBack-
ground(Images.image_activeBtnG.getImage(),3,3));
bgrBtn.setFocusedBackground(Background.createHorizontalTiledImageRoundedBack-
ground(Images.image_activeBtnR.getImage(),3,3));
bgrBtn.setHorizontalTextAlignment(HorizontalAlignmentType.CENTER);
CheckBox
A CheckBox uses a Boolean control. It appears as a check box on BlackBerry and Windows Mobile devices. It appears as
a Yes/No toggle field on an iPhone device.
label1.setText("Male");
label2.setText("Female");
add(label1,"hfill=fill");
add(checkBox1,"hfill=fill,vfill=fill");
add(label2,"hfill=fill");
add(checkBox2,"hfill=fill,vfill=fill");
Boolean b = chkBox.getChecked();
Choice
The Choice control allows a user to select a single item from multiple string choices. A choice is a vertical list where only
one line can be selected.
empNameMdl.setChoicesAttribute(dp.MYEMP.EMPNAME);
empNameMdl.setChoicesKeyAttribute(dp.MYEMP.EMPID);
empNameMdl.setRows(dp.MYEMP.getAll());
pkrEl.setText("select one");
pkr.setDataModel(empNameMdl);
pkr.setPlaceHolder(pkrEl);
add(pkr,"valign=top,hfill=fill");
comboEName.setDataModel(empNameMdl);
Combo Box
A Combo Box is a ChoiceControl with a drop-down list of choices. ComboBox, also called a drop-down list or a picklist
on many systems, combines a text field and a list. You can view a text field. When the text field is clicked, a list of choices
shows. When you select a line, the list disappears and the selected line is shown in the text field.
You can add elements to the combobox one by one as in the following example:
comboBox.addChoice("Apple");
comboBox.addChoice("Fruit");
comboBox.addChoice("Banana");
comboBox.addChoice("Pineapple");
Or, you can populate the options in an array and then set the array to the combobox.
list.addItem("Camel");
list.addItem("Elephant");
list.addItem("Tiger");
list.addItem("Lion");
comboBox.setChoices(list);
Date Box
A DateBox is a simple date selection control.
dateBox.setDate(Platform.createDate());
dateBox.setDate(cal.getDate(2011,11,25,0,0,0,0));
Label
A Label displays text.
lblName.setText("Name");
lblName.setForeColor(Colors.Lavender);
lblName.setBackColor(Colors.Gray);
Link
link.setBorder(Border.createRoundedBorder(Colors.Black));
link.setText("Antenna Softwares");
goToWebPage("www.antennasoftware.com");
Ticker
int cnt = 0;
tkrField.setHeight(50);
tkrField.setInterItemGap(10);
tkrField.setIntraItemGap(5);
tkrField.setScrollInterval(100);
tkrField.setScrollType(TickerField.SCROLL_TYPE_PIXELS,10);
add(tkrField,"hfill=fill");
add(btnStart,"halign=center");
add(btnStop,"halign=center");
tkrField.startScrolling();
tkrField.stopScrolling();
info.setStyle(TickerItem.TEXT_AND_IMAGE);
info.setText("London");
info.setStyle(TickerItem.TEXT_AND_IMAGE);
info.setImage(Images.image_activeBtnR.getImage());
cnt++;
if(cnt==1){
info.setStyle(TickerItem.TEXT_AND_IMAGE);
info.setText("Boston");
info.setImage(Images.image_activeBtnG.getImage());
else if(cnt==2){
info.setStyle(TickerItem.TEXT_AND_IMAGE);
info.setText("Toronto");
info.setImage(Images.image_activeBtnR.getImage());
else if(cnt==3){
info.setIsLast(true);
cnt++;
PasswordField
A PasswordField control is a one-line text input control that masks the entered text.
passField.setTextHint("Your Password");
lblPwd.setText("Enter Password");
passField.setLabel(lblPwd);
add(passField,"halign=center,valign=center");
TextField
TextField textField = new TextField();
textField.setText("Type here");
This example creates a TextField object. When the Play screen is created, the onCreate callback is called. This callback
sets text in the text field. When the text changes inside the text field, the onValueChange callback is called on textField.
You can create and customize any control using this principle.
txtName.setBorder(Border.createRoundedBorder(Colors.Black));
txtName.setForeColor(Colors.Blue);
txtName.setText("Merry Christmas");
E-mailField
label1.setText("Enter Email");
hzPanel.add(label1,"hfill=fill");
hzPanel.add(emailField,"hfill=fill");
NumericField
label1.setText("Enter Contact:");
hzPanel.add(label1,"hfill=fill");
hzPanel.add(numField,"hfill=fill");
PinpadField
label1.setText("Enter Pin:");
hzPanel.add(label1,"hfill=fill");
hzPanel.add(pinField,"hfill=fill");
InteractiveImageField
add(btnStart,null);
add(btnStop,null);
intImg.setImage(Images.back.getImage());
ai.addImage(Images.anim1.getImage());
ai.addImage(Images.anim2.getImage());
ai.addImage(Images.anim3.getImage());
ai.addImage(Images.anim4.getImage());
ai.setDuration(1000);
intImg.setAnimation(ai);
intImg.setAnimationPosition(25,25);
add(intImg,null);
......
intImg.stopAnimating();
intImg.startAnimating();
Picture Box
A PictureBox control displays an image on a screen to the user.
picBox.setImage(Images.flowers.getImage());
picBox.setBorder(Border.createRoundedBorder(Colors.Black));
Progress Bar
A ProgressBar displays the progress of a process.
HomeScreen scrHome;
....
setUser("Test");
login();
messageService.start(true);
setImageBundle();
openDP(passwordField.getPassword());
dp.startFDR("MANUAL_FDR");
dp.startSync("MANUAL_SYNC");
scrHome.push();
switch(eventType) {
case SyncEvent.DATADOWNLOAD_INCEND:
scrHome.prgBar.setValue(dp.getCurrentSyncSegment());
break;
case SyncEvent.DATADOWNLOAD_INCSTART:
scrHome.prgBar.setMax(dp.getTotalSyncSegments());
break;
..........
scrHome.prgBar.setMin(0);
....
Separator
A Separator is an empty control whose sole use is to create spacing between other controls.
vertPanel.add(label1);
separator.setHeight(15);
separator.setWidth(50);
vertPanel.add(separator);
vertPanel.add(label2);
Rich Table
myRichTableModel.setRows(dp.MYEMP.getAll());
headerLabel0.setText("ID");
myRichTableModel.addHeaderComponent(headerLabel0,"hfill=fill,vfill=fill");
headerLabel1.setText("NAME");
myRichTableModel.addHeaderComponent(headerLabel1,"hfill=fill,vfill=fill");
headerLabel2.setText("DESIGNATION");
myRichTableModel.addHeaderComponent(headerLabel2,"hfill=fill,vfill=fill");
myRichTableModel.startNewHeaderLine();
headerLabel3.setText("DOJ");
myRichTableModel.addHeaderComponent(headerLabel3,"hfill=fill,vfill=fill");
myRichTableModel.setHeaderColumnWidth(0, Sizing.PERCENTS,40);
myRichTableModel.setHeaderColumnWidth(1, Sizing.PERCENTS,25);
myRichTableModel.setHeaderColumnWidth(2, Sizing.PERCENTS,35);
myRichTableModel.setHeaderLineHeight(0, Sizing.PIXELS,30);
myRichTableModel.setHeaderLineHeight(1, Sizing.PIXELS,30);
component0.addField(dp.MYEMP.EMPID);
component1.addField(dp.MYEMP.EMPNAME);
component2.addField(dp.MYEMP.EMPDESG);
component3.addField(dp.MYEMP.EMPDOJ);
myRichTableModel.addUIRowComponent(component0,"halign=left");
myRichTableModel.addUIRowComponent(component1,"halign=left");
myRichTableModel.addUIRowComponent(component2,"halign=left");
myRichTableModel.startNewUIRowLine();
font.setSize(14);
component3.setFont(font);
myRichTableModel.addUIRowComponent(component3,"halign=left");
myRichTableModel.setUIRowColumnWidth(0, Sizing.PERCENTS,40);
myRichTableModel.setUIRowColumnWidth(1, Sizing.PERCENTS,25);
myRichTableModel.setUIRowColumnWidth(2, Sizing.PERCENTS,35);
myRichTableModel.setUIRowLineHeight(0, Sizing.PIXELS,30);
myRichTableModel.setUIRowLineHeight(1, Sizing.PIXELS,30);
myRichTable.setDataModel(myRichTableModel);
myRichTable.setOddUIRowBackground(Background.createColorRectangleBackground
(Colors.Cornsilk,Colors.DarkOrchid,1));
myRichTable.setEvenUIRowBackground(Background.createColorRectangleBackground
(Colors.Cyan,Colors.Fuchsia,2));
myRichTable.setFocusedUIRowBackground(Background.createColorRectangleBackground
(Colors.Green,Colors.Black,3));
myRichTable.setGridLineThickness(5);
svPanel.add(myRichTable);
tPanel.setColumnWidth(0,Sizing.PERCENTS,100);
tPanel.setRowHeight(0,Sizing.PERCENTS,80);
tPanel.add(svPanel,"hfill=fill,vfill=fill");
add(tPanel,"hfill=fill,vfill=fill");
Sticky Table
while(dtRowLoc != null){
arrRows.addItem(dtRowLoc);
dtRowLoc = rsLocRows.next();
stkTable.setBackColor(Colors.Cornsilk);
stkTable.setNumberOfGroups(1);
stkTable.refresh();
stkTable.setGridLineThickness(1);
add(stkTable,"hfill=fill, vfill=fill,valign=center");
cell.setHeight(Sizing.PIXELS, rowHeight);
cell.setWidth(Sizing.PERCENTS, 100);
lblEmploye.setText("Employe Details");
headerCell.add(lblEmploye,"hfill=fill");
lbl1.setText("EID");
lbl2.setText("Employe");
horzPanel.setColumnWidth(0,Sizing.PERCENTS,20);
horzPanel.setColumnWidth(1,Sizing.PERCENTS,80);
horzPanel.add(lbl1,null);
horzPanel.add(lbl2,null);
headerCell.startNewRow();
headerCell.add(horzPanel,"hfill=fill");
AMP™ Studio Developer Guide 132
ANTENNA PROPRIETARY & CONFIDENTIAL AMP™ Studio Developer Guide
headerCell.setBackColor(Colors.MediumPurple);
info.setPanel(headerCell);
info.setPanel(new EmployeCell());
sizeInfo.setHeight(rowHeight);
3 Enter the name for the TableViewCell in the Panel wizard window. (In the following example, it is
EmployeeCell.)
4 Click Finish. You can design cells for the sticky table with the EmployeeCell.mscript.
hzPanel.setPanelHeight(Sizing.PIXELS,40);
hzPanel.setBackColor(Colors.Fuchsia);
hzPanel.add(lblEmpId,null);
hzPanel.add(lblEmpName,null);
picBox.setImage(Images.minus.getImage());
hzPanel.add(picBox,"valign=center,vfill=fill");
add(hzPanel,"hfill=fill, vfill=fill,valign=center");
setBackColor(Colors.Coral);
if(scrTblView.arrRows != null)
dtRowLoc = scrTblView.arrRows.getItem(row);
return;
}else{
lblEmpId.setText(empId);
lblEmpName.setText(dtRowLoc.getString(3));
dtRowLoc = null;
NOTE: The two examples have been separated. The first example shows how to create a single group
(Header,Contents and Footer), while this example shows how to create multiple groups in the StickyTable. In
this example, you are checking the group number. According to the group number you are setting the header
and the contents. In the previous example, the condition was not checked, since there was one group.
Screen {
while(dtRowLoc != null){
arrRows.addItem(dtRowLoc);
dtRowLoc = rsLocRows.next();
stkTable.setBackColor(Colors.Cornsilk);
stkTable.setNumberOfGroups(2);
stkTable.refresh();
//stkTable.setGridLineThickness(1);
add(stkTable,"hfill=fill, vfill=fill,valign=center");
cell.setHeight(Sizing.PIXELS, rowHeight);
cell.setWidth(Sizing.PERCENTS, 100);
lblEmploye.setText("Employe Details");
headerCell.add(lblEmploye,"hfill=fill");
if(group==0){
lbl1.setText("EID");
lbl2.setText("Employe");
else if(group==1){
lbl1.setText("DESG");
lbl2.setText("Date Of Joining");
horzPanel.setColumnWidth(0,Sizing.PERCENTS,20);
horzPanel.setColumnWidth(1,Sizing.PERCENTS,80);
horzPanel.add(lbl1,null);
horzPanel.add(lbl2,null);
headerCell.startNewRow();
headerCell.add(horzPanel,"hfill=fill");
headerCell.setBackColor(Colors.MediumPurple);
info.setPanel(headerCell);
if(group==0)
info.setPanel(new EmployeCell());
else if(group==1)
info.setPanel(new EmployeDetailCell());
sizeInfo.setHeight(rowHeight);
NOTE: The sample code for EmployeeCell.mscript has already been provided in the section Sticky Table on
page 131.
EmployeeDetailCell.mscript
TableViewCell {
hzPanel.setPanelHeight(Sizing.PIXELS,40);
hzPanel.setBackColor(Colors.AntiqueWhite);
hzPanel.add(lblEmpDesg,null);
hzPanel.add(lblEmpDoj,null);
picBox.setImage(Images.minus.getImage());
hzPanel.add(picBox,"valign=center,vfill=fill");
add(hzPanel,"hfill=fill, vfill=fill,valign=center");
setBackColor(Colors.Chartreuse);
if(scrTblView.arrRows != null)
dtRowLoc = scrTblView.arrRows.getItem(row);
return;
}else{
lblEmpDesg.setText(empDesg);
lblEmpDoj.setText(dtRowLoc.getString(1));
dtRowLoc = null;
Text Controls
Text Area
A TextArea is a multi-line text input control.
txtArea.setText("TextAre….");
ToolBar
A ToolBar is a strip that usually contains images (ToolbarButton instances). It is often called a slider. The ToolBarButton
is a button placed on a ToolBar.
btn1.setFocusedImage(Images.plus_focused.getImage());
btn1.setImage(Images.plus.getImage());
btn1.setSelectedImage(Images.plus.getImage());
btn2.setFocusedImage(Images.minus_focused.getImage());
btn2.setImage(Images.minus.getImage());
btn2.setSelectedImage(Images.minus.getImage());
btn3.setFocusedImage(Images.multiply_focused.getImage());
btn3.setImage(Images.multiply.getImage());
btn3.setSelectedImage(Images.multiply.getImage());
btn4.setFocusedImage(Images.equal_focused.getImage());
btn4.setImage(Images.equal.getImage());
btn4.setSelectedImage(Images.equal.getImage());
toolBar.addButton(btn1);
toolBar.addButton(btn2);
toolBar.addButton(btn3);
toolBar.addButton(btn4);
toolBar.setButtonSpacing(5);
toolBar.setNavigationType(ToolBar.SCROLLER);
RadioGroup
A RadioGroup is a type of toolbar that displays toolbar buttons in a "pressed" mode, indicating which ToolbarButton has
been selected.
tlBrBtnSignIn.setFocusedImage(Images.sicSignIn_f.getImage());
tlBrBtnSignIn.setImage(Images.sicSignIn_u.getImage());
tlBrBtnSignIn.setSelectedImage(Images.sicSignIn_s.getImage());
tlBrBtnMyAccounts.setFocusedImage(Images.sicAccounts_f.getImage());
tlBrBtnMyAccounts.setImage(Images.sicAccounts_u.getImage());
tlBrBtnMyAccounts.setSelectedImage(Images.sicAccounts_s.getImage());
..
rdGrpSlider.setNavigationType(ToolBar.SCROLLER);
rdGrpSlider.addButton(tlBrBtnSignIn);
rdGrpSlider.addButton(tlBrBtnMyAccounts);
rdGrpSlider.addButton(tlBrBtnTransferMoney);
rdGrpSlider.addButton(tlBrBtnBillPay);
Browser/HTML Control
A Browser is a Web browser.
btnSetHtml.setText("Set Html");
btnSetUrl.setText("Set Url");
btnStart.setText("Start");
btnStop.setText("Stop");
hzPanel.setColumnWidth(0,Sizing.PERCENTS,100);
hzPanel.setPanelHeight(Sizing.PERCENTS,80);
hzPanel1.setColumnWidth(0,Sizing.PERCENTS,50);
hzPanel1.setColumnWidth(1,Sizing.PERCENTS,50);
hzPanel2.setColumnWidth(0,Sizing.PERCENTS,50);
hzPanel2.setColumnWidth(1,Sizing.PERCENTS,50);
hzPanel.add(browser,"hfill=fill,vfill=fill");
hzPanel1.add(btnSetHtml,"hfill=fill");
hzPanel1.add(btnStart,"hfill=fill");
hzPanel2.add(btnSetUrl,"hfill=fill");
hzPanel2.add(btnStop,"hfill=fill");
vertPanel.add(hzPanel);
vertPanel.add(hzPanel1);
vertPanel.add(hzPanel2);
add(vertPanel,"hfill=fill,vfill=fill");
browser.setURL("http://www.antennasoftware.com");
browser.start();
browser.stop();
........
leftAction.setBackground(Background.createHorizontalTiledImageRoundedBackground
(Images.image_activeBtnR.getImage(),3,3));
leftAction.setFocusedBackground(Background.createHorizontalTiledImageRoundedBack
ground(Images.image_activeBtnG.getImage(),3,3));
rightAction.setBackground(Background.createHorizontalTiledImageRoundedBackground
(Images.image_activeBtnR.getImage(),3,3));
rightAction.setFocusedBackground(Background.createHorizontalTiledImageRounded
Background(Images.image_activeBtnG.getImage(),3,3));
setTitle("Home Screen");
titleBarStyle.setBackground(Background.createHorizontalTiledImageRoundedBackgrou
nd(Images.image_Header.getImage(),2,2));
setTitleBarStyle(titleBarStyle);
setLeftTitleBarAction(leftAction);
setRightTitleBarAction(rightAction);
showTitleBar(true,false);
Map Control
A Map control displays an interactive map.
headerPanel.setColumnWidth(0,Sizing.PERCENTS,25);
headerPanel.setColumnWidth(1,Sizing.PERCENTS,25);
headerPanel.setColumnWidth(2,Sizing.PERCENTS,25);
headerPanel.setColumnWidth(3,Sizing.PERCENTS,25);
headerPanel.add(lbllat,"hfill=fill");
headerPanel.add(numlat,"hfill=fill");
headerPanel.add(lbllng,"hfill=fill");
headerPanel.add(numlng,"hfill=fill");
add(headerPanel,"hfill=fill,vfill=fill");
add(btnFind,"halign=center");
add(mfield,"valign=top,hfill=fill,vfill=fill");
mfield.clearLocations();
mapAnot.setShowCallout(true);
mapAnot.setEnabled(true);
mapAnot.setTitle("Your Location");
mapAnot.setSubTitle("Here is it");
mapAnot.setImageType(MapAnnotation .IMAGE_TYPE_DEFAULT);
mfield.addLocation(latitude,longitude, mapAnot);
..................
animImgList.addImage(Images.anim1.getImage());
animImgList.addImage(Images.anim2.getImage());
animImgList.addImage(Images.anim3.getImage());
animImgList.addImage(Images.anim4.getImage());
animImgList.setDuration(1000);
animImgList.setRepeatCount(10);
animField.applyImageList(animImgList);
add(animField,"hfill=fill,vfill=fill");
..............
animField.startAnimating();
animField.stopAnimating();
animField.stopAnimating();
lbl1.setText("Beverages");
lbl1.setForeColor(Colors.White);
lbl2.setText("Jwellery");
lbl2.setForeColor(Colors.White);
lbl3.setText("Furniture");
lbl3.setForeColor(Colors.White);
lbl4.setText("Clothes");
lbl4.setForeColor(Colors.White);
vertPanel1.add(lbl1);
vertPanel2.add(lbl2);
vertPanel3.add(lbl3);
vertPanel4.add(lbl4);
vertPanel1.setBackColor(Colors.MediumOrchid);
vertPanel2.setBackColor(Colors.LightSkyBlue);
vertPanel3.setBackColor(Colors.Crimson);
vertPanel4.setBackColor(Colors.SlateGray);
pgHrPnl.setPage(vertPanel1,0);
pgHrPnl.setPage(vertPanel2,1);
pgHrPnl.setPage(vertPanel3,2);
pgHrPnetPage(vertPanel4,3);
add(pgHrPnl,"hfill=fill,vfill=fill");
Video Player
btnLoadVideo1.setText("Video 1");
btnLoadVideo2.setText("Video 2");
btnPlay.setText("Play");
btnPause.setText("Pause");
btnStop.setText("Stop");
lblStatus.setText("Video Player");
lblStatus.setForeColor(Colors.Tomato);
hzPanel.setColumnWidth(0,Sizing.PERCENTS,50);
hzPanel.setColumnWidth(1,Sizing.PERCENTS,50);
hzPanel.add(btnLoadVideo1,"hfill=fill");
hzPanel.add(btnLoadVideo2,"hfill=fill");
hzPanelControls.setColumnWidth(0,Sizing.PERCENTS,33);
hzPanelControls.setColumnWidth(1,Sizing.PERCENTS,33);
hzPanelControls.setColumnWidth(2,Sizing.PERCENTS,33);
hzPanelControls.add(btnPlay,"hfill=fill");
hzPanelControls.add(btnPause,"hfill=fill");
hzPanelControls.add(btnStop,"hfill=fill");
medControl.setAutoPlay(false);
add(hzPanel,"hfill=fill");
add(hzPanelControls,"hfill=fill");
add(lblStatus,"halign=right");
add(medControl,"hfill=fill,vfill=fill");
medControl.setResourceContent(Videos.video_sample);
medControl.setResourceContent(Videos.video_sample2);
if(ready==true)
medControl.play();
else
medControl.pause();
medControl.stop();
Document Viewer
btnLoadPdf1.setText("PDF 1");
btnLoadPdf2.setText("PDF 2");
btnLoadPdf3.setText("PDF 3");
btnLoadPdf4.setText("PDF 4");
btnOptions.setText("Show Options");
btnShowPrev.setEnabled(false);
btnOptions.setEnabled(false);
lblStatus.setText("Document Preview");
lblStatus.setForeColor(Colors.Blue);
ancPos1.setAnchor(btnOptions);
hzPanel.setColumnWidth(0,Sizing.PERCENTS,25);
hzPanel.setColumnWidth(1,Sizing.PERCENTS,25);
hzPanel.setColumnWidth(2,Sizing.PERCENTS,25);
hzPanel.setColumnWidth(3,Sizing.PERCENTS,25);
hzPanel.add(btnLoadPdf1,"hfill=fill");
hzPanel.add(btnLoadPdf2,"hfill=fill");
hzPanel.add(btnLoadPdf3,"hfill=fill");
hzPanel.add(btnLoadPdf4,"hfill=fill");
add(hzPanel,"hfill=fill");
add(btnLoadUrl,"hfill=fill");
add(btnShowPrev,"hfill=fill");
add(btnOptions,"hfill=fill");
add(lblStatus,"halign=center");
btnShowPrev.setEnabled(false);
btnOptions.setEnabled(false);
lblStatus.setText("");
flag = docPrev.startLoadingDocument(Documents.String_pdf);
btnShowPrev.setEnabled(false);
btnOptions.setEnabled(false);
lblStatus.setText("");
flag = docPrev.startLoadingDocumentFromURL("http://blog.timesunion.com/success/
files/2010
/11/success_baby.jpg");
flag = docPrev.showOptionsMenuFrom(ancPos1,true);
flag = show(docPrev,true);
lblStatus.setText("Loading.....");
lblStatus.setText("--Loaded--");
btnShowPrev.setEnabled(true);
btnOptions.setEnabled(true);
On Click
Callback when a control is clicked on.
On Focus Gained
Called when a control gains focus.
On Focus Lost
Called when a control loses focus.
On Value Change
Called when a control changes its value.
Data Attributes
The following data attributes are included when a callback is available for Data:
■ Binary
■ Boolean
■ Currency
■ Date
■ Float
■ ID
■ Integer
■ String
■ Time
■ Timestamp
String selectedFeature;
String selectedCategory;
String txtSearched;
StringReference fromScreen;
//int
int selectedFeatureIndex = 0;
int selectedCategoryIndex = 0;
//boolean
Get Value
This callback is available for all Data attributes.
Row Changed
This event is generated whenever a row or rowset being used by models is changed by some other mechanism (such as
sync) or changed elsewhere within the application.
Panel Callbacks
This section describes callbacks that are available for all Panels:
■ On Activate
■ On Deactivate
■ On Open
■ On Close
■ On Create
■ On Click
■ On Orientation Change
On Activate
This callback is available for all panels. This is called when a panel or a screen appears on the top of a screen and some of
the child controls receive user input focus.
On DeActivate
This callback is available when a panel or a screen loses user in/out focus.
On Open
This callback is called when a panel or a screen is opened.
contentsPanel.add(lbl);
On Close
This callback is called when a panel or a screen is closed.
scrHome.lblStatus.setText("Returned");
On Create
This callback is called when a panel or a screen is created but not yet opened or displayed.
On Selection Changed
This callback is called when the selection is changed (for example, gains or loses focus).
On Orientation Change
This callback is called when a screen changes its orientation from Portrait to Landscape mode or vice versa.
Messaging Callbacks
Messaging callbacks reference integration with a native email client. The following callbacks are supported as part of
email integration.
Phone Callbacks
Phone callbacks reference integration with a native phone dialer. This callback provides information about whether the
call is incoming, outgoing, or being terminated.
Login Callbacks
The following callbacks are available in the Login screen as well as in the UI Project.
On LoggedIn
This callback is called when a user is successfully logged in.
callback onLoggedIn(){
scrHome.push();
On LoggedOut
This callback is called when a user is logged out.
scrLogin.push();
On Login Completed
This callback is called when the login process is completed. (It could be successful or failed.)
scrLogin.btnLogin.setEnabled(true);
On Login Failed
This callback is called when the Login process failed.
scrLogin.lblStatus.setText("Login Failed");
On Login Starting
This callback is called when the login process is started. It can be used to show activity while this has started but the
process has not been completed.
callback onLoginStarting(){
scrLogin.lblStatus.setText("Logging In....");
scrLogin.btnLogin.setEnabled(false);
On Data Deleted
This callback is called when the datastore is completely deleted.
On Data Ready
This callback is called when the datastore has some data.
UIProject {
//services
BarChartSample scrBar
setUser("Test");
login();
messageService.start(true);
setImageBundle();
openDP(passwordField.getPassword());
dp.startFDR("MANUAL_FDR");
dp.startSync("MANUAL_SYNC");
callback dp onDataReady(){
scrBar.push();
On Lease Expired
This callback is called when the datastore lease has expired. No further access to datastore is allowed until the lease is
renewed.
On Lease Renewed
This callback is called when the lease is successfully renewed.
On Rowset Event
This callback is called when the rowset has been modified or has become dirty.
On Row Event
This callback is called when a specific row has been modified or has become dirty.
On Sync Event
This callback is called whenever there is a sync event. A sync event can be started by any of the following methods:
switch(eventType) {
case SyncEvent.DATADOWNLOAD_INCEND:
scrHome.prgBar.setValue(dp.getCurrentSyncSegment());
break;
case SyncEvent.DATADOWNLOAD_INCSTART:
scrHome.prgBar.setMax(dp.getTotalSyncSegments());
break;
NOTE: Refer to sample code given for Progress Bar on page 126.
On Request Sent
This callback is called when a VRPC request has been sent.
On Request Failed
This callback is called when a request for a VRPC was not sent.
On Data Ready
This callback is called when a VRPC response has come back.
UIProject {
//services
//Status variables
..
serverStatus = "available";
serverStatus = "recovering";
serverStatus = "starting";
serverReqStatus = "attempted";
String getServerStatus(){
return serverStatus;
String getServerReqStatus(){
return serverReqStatus;
NOTE: The above two functions can be called from any screen to get the corresponding status.
On Server Available
This callback is called when the Server is available for Sync or Mobile Web Service (VRPC).
On Server Recovering
This callback is called when the client lost connection to its server and is in process of reconnecting.
On Server Unavailable
This callback is called when the server becomes unavailable and no sync or VRPC requests can be sent.
On Server Starting
This callback is called when the client is attempting to connect to the server for the first time.
UI Project Callbacks
The following callbacks are available at the project or application level.
On Start
This callback is called when an application has started.
On Stop
This callback is called when an application is being terminated.
On Day Change
This callback is called whenever a day changes on the device so you can refresh date-related screens.
UIProject {
//services
//Global variables
Date todaysDate;
..
setUser("Test");
login();
messageService.start(true);
setImageBundle();
openDP(passwordField.getPassword());
dp.startFDR("MANUAL_FDR");
dp.startSync("MANUAL_SYNC");
todaysDate = Platform.createDate();
scrHome.push();
callback onDayChanged(){
todaysDate = Platform.createDate();
Application Upgrades
This section explains how to set the properties on the server.
Version Management
For version management follow the steps below. Add the following section on the cluster config (located at
server\vas\config):
[AUTH $ APPLICATION]
CLASS = com.vaultus.auth.toolkit.apps.PropertyAppManager
LATEST_URL = www.appdownload.com/idirectory/defaultlink
LATEST_VERSION = 0.0.40
MESSAGE = Special message for this particular OS under this app name
REQUIRED_VERSION = 0.0.38
LATEST_URL = www.appdownload.com/idirectory/iphoneos1
LATEST_VERSION = 0.0.41
REQUIRED_VERSION = 0.0.38
LATEST_URL = www.appdownload.com/idirectory/android
LATEST_VERSION = 0.0.41
REQUIRED_VERSION = 0.0.38
LATEST_URL = www.appdownload.com/idirectory/blackberry
LATEST_VERSION = 0.0.45
REQUIRED_VERSION = 0.0.45
1 AppName represents the name of the app mentioned on the jobjar. It is the value before DP. For example,
IDIRECTORY
2 [AUTH $ APPLICATION $ AppName] - Is the section for the device that is not specified in the cluster.config
7 For Mandatory Upgrade, set the REQUIRED_VERSION to an app version greater than the version that the user
has on the device.
8 For Optional Upgrade, set the LATEST_VERSION to an app version greater than the version that the user has
on the device.
9 If the app version in the device is less than the REQUIRED_VERSION specified, then the user is presented
with a message when he logs in.
if (displayServerUpgradeMsg) {
if(applicationPermission.getStatus() == ApplicationPermission.STATUS_MUST_UPGRADE){
arOptions.addItem("Upgrade");
goToWebPage(applicationPermission.getLatestUrl());
if(applicationPermission.getStatus() == ApplicationPermission.STATUS_MUST_UPGRADE){
arOptions.addItem("Upgrade");
goToWebPage(applicationPermission.getLatestUrl());
if (displayServerUpgradeMsg) {
if(applicationPermission.getStatus() == ApplicationPermission.STATUS_CAN_UPGRADE){
arOptions.addItem("Continue");
arOptions.addItem("Upgrade");
if(response == 1) {
if(Device.isBlackberry()) shutdown();
goToWebPage(applicationPermission.getLatestUrl());
if(applicationPermission.getStatus() == ApplicationPermission.STATUS_CAN_UPGRADE){
arOptions.addItem("Continue to Login");
arOptions.addItem("Upgrade");
if(response == 1) {
goToWebPage(applicationPermission.getLatestUrl());
mScript Basics
Comments
Comments are parts of code that are not executed. Comments should be written to make the code easier to understand.
There are two types of comments: single line and multiline.
Multiline comment
Any text within /* and */ is treated as a comment across multiple lines.
boolean
A boolean can have the value of true or false.
char
A char can have a value of a single character in single quotes: 'a'
In some cases, a char must contain the value of a single quote. However, writing ''' is illegal. In this case, use '\''
\t for a tab
byte
A byte has an 8-bit numeric value between the minimum value of -128 and maximum value of +127. A byte number is a
number that cannot have a decimal component. For example 1.0, 0.1, -0.2, 1.1 are not byte numbers, 1, -2 are byte
numbers.
short
A short has a 32-bit numeric value between the minimum value of -32,768 and maximum value of +32,767. A short
number cannot have a decimal component.
int
An int has a 32-bit numeric value between the minimum value of -2,147,483,648 and maximum value of +2,147,483,647.
An int number cannot have a decimal component.
long
A long has a 64-bit numeric value between the minimum value of -9223372036854775808 and maximum value of +
9223372036854775807. A long number cannot have a decimal component.
float
A float has a numeric value with a decimal component. For example 0.1, -0.2, 1.0, 1.1 are float numbers. A float number
is a 32-bit number.
double
A double has a numeric value with a decimal component. A double number is a 64-bit number.
Variables
A variable declaration must contain the variable's type and name:
boolean b;
This code declares a variable named b whose type is boolean. It means that operations of other data types are invalid on b.
For example, it is invalid to write b + 1 because adding a number is a mathematical and not a boolean operation.
After a variable is declared, it can be used and its value can be changed.
In order to use a variable, it must have a value. A value can be assigned during the declaration:
char c = 'b';
This line of code declares a variable c of type char with the initial value 'b'.
short s;
s = 0;
Four of the types are integral types: byte, short, int, long. Two types are floating point types: float and double.
When declaring a variable, choose a type best suited for the use of the variable. The first decision should be whether a
variable is a whole number or it will have a fractional part. For example, if a variable holds the number of countries, it
should be integral. If a variable holds a price, it should probably be a floating-point number.
The second decision is the range of the value of a variable. For example, if a variable holds the number of countries, it
should be short. If it holds the world population, it must be long.
Operations
This section describes the following operations:
int a = 2;
int b = 3;
int result = a + b;
result = a * b / 6;
The commonly known rules of order of operations and grouping by parentheses are used in mScript.
Remainder Operator %
This returns the remainder of division. For example, 5 % 2 = 1.
int i = 0;
i++;
i++;
In this code, a variable i is created with the initial value 0 and then its value is increased by 1. As a result, its value equals
1. Then its value is increased by 1 again and equals 2.
This operator is shorthand for i = i + 1 (add 1 to i and store the resulting value in i).
The increment/decrement operator can be placed before or after a variable. The position of the operator is important as
shown in the following examples:
int i = 0;
int j = ++i;
In this code, the value of i is increased before the assignment of its value to j. The previous code is the same as:
int i = 0;
i = i + 1;
int j = i;
The value of j is 1.
int i = 0;
int j = i++;
In this code, the value of i is increased after it is assigned to j. The previous code is the same as:
int i = 0;
int j = i;
i = i + 1;
The value of j is 0.
Assignment Operators
The basic assignment operator is =. It is used to assign a value to a variable:
int i = 6;
i = i + 8;
Example:
Bitwise Operations
mScript has bitwise operators (& | ^ ~), arithmetic shifts (<< >>) and logical right shift (>>>).
Equality Operators
Equals (==) returns true if the value of the left side and the value of the right side are equal.
For example:
int a = 7;
int b = 7;
boolean result = a == b;
The result will be true because both a and b have the value 7;
int a = 7;
int b = 8;
boolean result = a == b;
The result will be false because the values of a and b are not the same.
Not equal (!=) returns true if the left side and the right side are not equal.
int a = 7;
int b = 8;
boolean result = a != b;
Relational Operators
Less than (<) , greater than (>) , less or equal (<=), greater or equal (>=)
int a = 7;
int b = 8;
Conditional Operators
And (&&), or (||) compare two Boolean expressions:
boolean a = true;
boolean b = true;
result = a && b || c
In this case they are executed in the order in which they are written as in the case of algebraic expressions. So the previous
code is the same as:
result = temp || c;
result = a && (b || c)
boolean temp = b || c;
result = a && c;
Conditions
Conditional clauses exist to direct an algorithm in a certain direction in certain conditions. For example, you may want to
execute certain code only when the number of rows returned by a query is greater than 100:
//some code
There are three forms of conditions: if, switch and the ?: expression.
if
The format of the if clause is this:
if(condition) expression;
boolean b = true;
if(b == true) …
if(b)…
because the value of b is boolean (true/false) and testing if its value is true or false is unnecessary.
Relational (< > <= >=) operators also return a boolean value. Therefore it is possible to compare numeric values:
int c = 9;
int d = 10;
boolean b = true;
int c = 9;
int d = 10;
int e = 11;
int f = 12;
The code that follows the condition is the code that is executed when this condition is true. It can be one expression:
if(a == b) i++;
When several expressions must follow the condition, they must be placed inside braces or curly brackets:
if(a == b){
i++;
j--;
It is a good practice to always use the curly brackets because this makes the code easier to understand and prevents
mistakes.
When a condition is not true, the algorithm may follow another path. In this situation, else may be used:
if(condition){
else{
if(a){
else if(b){
else if(c){
else{
}
AMP™ Studio Developer Guide 176
ANTENNA PROPRIETARY & CONFIDENTIAL AMP™ Studio Developer Guide
switch
A switch statement takes an int value and tests if it is equal to a list of int numbers one by one:
switch(i){
case 0: ….
break;
case 1: ….
break;
default: …
In this case, if the value of i equals 0, the execution goes into the block of case 0. If the value of i equals 1, then the block
of case 1 is executed.
If none of the case conditions is met, the block of default is executed. The use of default is not mandatory, but it is a good
practice because it leaves no holes.
?:
A brief form of if-else clause is condition ? if-true : if-false
For example:
a ? 1 : 0
Although compared to if-else which can have multiple else if blocks, this clause seems less powerful, this clause unlike if-
else can return a value.
For example:
int i = a ? 1 : 0;
The if-else clause does not return a value that can be directly assigned to a variable.
This clause may lead to unreadable code. Use it only when necessary.
For example
if(a != b){
int i = 0;
else{
int j = i;
int k = i;
In this example, i is declared in the if block and it will be visible neither in else block nor outside the whole if-else clause.
So both j = i and k = i will throw errors.
Loops
When the same block of code must be executed sequentially a number of times, use loops. There are three types of loops:
for, while, do-while. All types of loop keep repeating their block of code until some condition is met.
for
An initial expression is any expression that is performed before entering the first loop. Usually it is used to set the initial
value of a counter used to count the number of iterations.
When final condition equals true, the loop exits. It is usually used to check if the value of the counter reaches a certain
value. The expression performed after each loop usually serves to increase or decrease the value of the counter after each
loop. Each of the three expressions inside for() is optional and using them for the counter is not mandatory.
This code declares a counter i with the initial value 0. Then this counter is increased by 1 after each loop. When i equals
10 the loop exits.
while
The format is:
while(some condition){
Example:
int i = 0;
//some code
i++;
do-while
The format is:
do{
}while(some condition);
Example:
int i = 0;
do{
//some code
i++;
break
In some cases, it is necessary to exit a loop without waiting for the loop's final condition to become true. In this case,
break can be used:
while(true){
//some code
continue
In some cases, it is necessary to skip to the next iteration of a loop without executing the rest of the code inside the block
of the loop.
Example:
int i = 0
int remainder = i % 3;
if(remainder == 0){
i++;
continue;
//some code
i++;
When i is a multiple of three, the code will not continue and a new iteration of the loop will run.
Methods
In some cases, the same code is used in different parts of a program. For example, the code that calculates an average
number may be used in the calculation of the average age, average income, etc. The only difference is that a different list
of numbers is processed.
In order not to repeat the same code in different places, such code can be placed in a method. A method is a block of code
that can have input parameters and one return value.
In the previous example, there is only one input parameter, a list of numbers and the return parameter is the average
number.
return_type method_name(parameters){
code
The return type of a method is the data type of the value that this method returns. The parameters can be either one
parameter or a comma-separated list of parameters.
Example:
return result;
The method in this example returns a positive power of a number. As the input, it takes a number and a power in which the
number must be raised. The data types of the input parameters and the output value must be declared.
The result is returned by using a return anywhere in the method. Because the variable result is declared inside this method,
it is visible only inside the method. When a method does not return anything, it should be declared void:
It makes sense to declare a void method when this method changes a variable declared in the scope above the method. For
example:
if(power == 0) {
result = 1;
if(power == 1) {
result = number;
} else {
result = number;
In this example, the method sets the value of a result that is declared not inside the method but outside on the same level
(scope) as the method.
The return value of this method is float because when the power is negative, the method returns a fraction of 1.
number *= number;
counter--;
m(number, counter);
It is preferable to find algorithms alternative to recursion because recursion can easily lead to memory exhaustion. For
example, the previous method can be rewritten as:
number *= number;
It is important to know that a change in the value of a parameter whose data type is primitive is visible inside a method
only. The following example clarifies this statement:
int a(){
int i = 0;
b(i);
return i;}
i = 10;
Method a declares a variable i with the initial value 0. Then i is passed to method b. Method b changes the value of i to 10.
This change is visible inside method b only. Method a does not know that the value of i has changed and from the point of
view of method a the value of i is still 0.
This happens because when a primitive data type is passed to a method, it is copied and its copy is passed to the method.
The original copy stays inside its original scope. This rule is valid for primitive data types only.
Classes
In some cases, several variables describe the same entity. For example, country name, population size and official
language are variables that describe a country. Such variables can be grouped in a Class.
There is a way to define a class. Right-click on the UI Project and select Add Class, This is used to define variables or
methods that are used for business logic and not UI. Variables grouped in a class are called class fields.
In addition to fields, a class can contain methods related to this class and its fields. In many cases, methods hide fields, and
the only way to change the value of a field is only through its access methods. For example, in order to set or get the text
of an mScript Button, you must use the methods setText(some text) and getText(). A field that holds the text is hidden.
Objects
A class is a description of a concept. For example, a class Country with its fields countryName, population Size and
official Language just means that any country has these properties: name, population size and an official language. Each
concrete country is called an instance of this class.
In order to use a class, its instance must be created. Another name of instance is "object".
new
One way to create an object of a class is to use new:
Button b;
b = new Button();
Such coding practices should be avoided when possible because it easily leads to the situation when some code uses a
variable that has not been initialized yet.
When it is necessary to initialize a variable after its declaration, methods that use the variable should check if it is
initialized. When a variable refers to no object, its value is null. It is possible to declare a variable with null value:
Button b = null;
if(b == null){
//do something
//Labels
b. setShowFocusRectangle(true);
This code creates a button that shows a rectangle when the button gains focus.
Object Reference
As previously explained, when a variable of a primitive data type is passed to a method, its copy is created and passed to
the method, and all changes inside the called method are performed on the copy. As the result, the calling method is
unaware of the changes on the copy because it only contains the original variable.
When an object is passed to a method, the object is not copied, and both the calling and the called method have references
to the same object.
Another thing to remember about a reference to an object is that there is an object, and there can be several references to
this object.
This line creates an object of class Button and a reference to this object called a.
Button b = a;
a.setShowFocusRectangle(true);
then
b.isFocusRectangleShown(); will return true because both methods operate on the same object.
Only an object can have several references. Primitive data types will be copied in this situation:
int a = 25;
int b = a;
b = 30;
In this example a has the value 25. Then the variable b is created with an initial value 25. This initial value is copied from
the value of a. Then b receives a new value 30. The value of a is not changed because both a and b have their own values.
b.setShowFocusRectangle(true);//line 2
b = new Button();//line 3
b.setShowFocusRectangle(false);//line 4
In the third line, a new Button object is created and b is redirected to point to this new object. The first Button object still
exists. b does not point to it any longer.
Strings
In written English, individual characters form words. In mScript, char represents one character. A data type that consists
of two or more characters is called a String. A char is represented by single quotes: 'a'. A String is represented by double
quotes: "this is a string". A string can be one character long: "a" but its data type is still String and not char.
String s = "hello";
\t for a tab
A String is not a primitive data type. It is an object. As such its value can be null:
String s = null;
Because String is a class, it has a number of useful methods. For example, this code concatenates two String objects:
String b = "Earth";
String c = a.concat(b);
String c = a.concat("Earth");
The value of a is not changed when "Earth" is appended to it. Instead, a new String object is created with a concatenated
value of a and b.
Important: Although a String is an object, it is passed by copy as a primitive type. When a String is passed to an object, its
copy is passed.
There is no need to create a String by using new. A String is created like a char:
For example, the class Platform has a method toString(int) that converts an int to a String:
int i = 21;
String s = Platform.toString(i);
As you see, there is no need to create an instance of the class Platform in order to use its method toString.
An example of a class that has static fields is Colors that has predefined colors exposed as static fields: Colors.Blue,
Colors.White, Colors.Aqua, etc.
Usually a field is static when it serves as a constant. A method is usually static when it is a utility.
Factories
Factory is a class that creates an instance of classes. In some cases, it is possible to create an instance of a mScript class by
using new:
Some mScript classes cannot be instantiated directly but can be created through a factory.
For example, the class Platform is used to create instances of Boolean, Calendar, Date, Float and Integer classes:
Calendar c = Platform.createCalendar(false);
This code creates a Calendar object initialized to the computer's current time.
Inheritance
A class can have a parent class. In this case, in addition to its own fields and methods, a child class has its parent's fields
and methods.
Many classes have parent classes and classes that inherit from them. All top level classes inherit from the class Object.
Polymorphism
Polymorphism is the ability of a child class to appear as and be used like its parent class.
It means that StringAttribute may be used where a DataAttribute is expected. For example, the class TableModel has a
method addStringColumn(String, DataAttribute). Because addStringColumn receives a DataAttribute, it is possible to
pass it an instance of StringAttribute.
Callbacks
Callback is a special type of method. A callback cannot be called by the mScript code. For example, a method cannot call
a callback. A callback is called by the platform that executes mScript when an event that must be handled by this callback
takes place.
For example, the class Screen has a callback onOpen. This callback is called before a Screen object is open.
And a callback:
//some code
This callback will be called when call event will occur in this instance of phoneManager.
//callbacks on fields
//methods
For example:
Screen{
//header:
//callbacks on Screen
button.setText("Click me");
//callbacks on fields:
respond();
//methods
void respond(){
It is Important to remember that the header section must contain field declarations only. Any operation will result in an
error. For example, the following line in the header section:
button.setText("Click me");
Create new class named "Fields" and add things that will be changed from screen/panel to this class:
DataAttribute FiveYearChange;
DataAttribute GainLoss;
DataAttribute NetPriceChange;
DataAttribute OneMonthChange;
DataAttribute OneYearChange;
DataAttribute PurchaseDate;
DataAttribute PurchasePrice;
DataAttribute PurchaseQuantity;
DataAttribute Symbol;
DataAttribute ThreeMonthChange;
DataAttribute ValueAttribute,
Query link;
Create one instance of this "Fields" object per every DataObject you want screen/panel to support:
defaultWatchlistFields.FiveYearChange = vrpcGetDefaultWatchlist.
SymbolDetail.FiveYearChange;
defaultWatchlistFields.GainLoss = vrpcGetDefaultWatchlist.SymbolDetail.GainLoss;
defaultWatchlistFields.NetPriceChange = vrpcGetDefaultWatchlist.SymbolDetail.
NetPriceChange;
defaultWatchlistFields.OneMonthChange = vrpcGetDefaultWatchlist.SymbolDetail.
OneMonthChange;
defaultWatchlistFields.OneYearChange = vrpcGetDefaultWatchlist.SymbolDetail.OneYearChange;
defaultWatchlistFields.PurchaseDate = vrpcGetDefaultWatchlist.SymbolDetail.PurchaseDate;
defaultWatchlistFields.PurchasePrice = vrpcGetDefaultWatchlist.SymbolDetail.PurchasePrice;
defaultWatchlistFields.PurchaseQuantity = vrpcGetDefaultWatchlist.SymbolDetail.
PurchaseQuantity;
defaultWatchlistFields.SymbolDesc = vrpcGetDefaultWatchlist.SymbolDetail.SymbolDesc;
defaultWatchlistFields.Symbol = vrpcGetDefaultWatchlist.SymbolDetail.Symbol;
defaultWatchlistFields.ThreeMonthChange = vrpcGetDefaultWatchlist.SymbolDetail.
ThreeMonthChange;
defaultWatchlistFields.Value = vrpcGetDefaultWatchlist.SymbolDetail.Value;
defaultWatchlistFields.link = vrpcGetDefaultWatchlist.SymbolDetail.getSymbols
(arraySymbolKey);
NOTE: The tip is to add the Fields instance to the screen/panel and assign it to the appropriately initialized
Fields instance when the screen or panel was created and ONLY uses fields from Fields inside the mscript.
Fields fields;
cellValuesNmbrFmtMdl.addField(fields.ValueAttribute);
Login
■ onLoginFailed: Shows an error message to the user that indicates that the login to the authentication server has
failed.
■ onLoggedOut: Checks the logout code and displays the appropriate error message to the user.
— LOGGED_OUT: User is manually logged out.
— LOGGED_OUT_BY_SERVER: User was logged out from the server. For example, the user logged in
with a different device or the user was logged out by the administrator using the Antenna Management
Console.
— LOGGED_OUT_SESSION_EXPIRED
— LOGGED_OUT_LOGIN_EXPIRED
NOTE: There is a callback named onUserInactivity() that can be used to log the user out of the
authentication server after a period of inactivity. For example, you can make a VRPC call to a Web Service to
log the user out of the application.
VRPC
When making a VRPC call that should only be sent if the network is available, do the following:
1 Call isNetworkAvailable().
2 If isNetworkAvailable() returns false, call isNetworkSuspended(). If it returns false, show an error message to
the user alerting the user that he/she is out of network coverage. If isNetworkSuspended() returns true, alert that
user that the data network is unavailable. (On a 2G BlackBerry, this may indicate that the user is on the phone.)
3 If the network is available, check if the MessageService is available. If it is unavailable, start the
MessageService.
if (messageService.getMessageServiceStatus() == Service.UNAVAILABLE) {
messageService.start(true);
4 If the network is available, check to see if VRPCProject.isAvailable().If this returns false, show an error, "Server
unavailable."
5 If VRPCProject.isAvailable() returns true, call VRPCRequest.setReplyTimeout(int minutes). This will set the
VRPC timeout period. If the client has not received a reply from the server in this time period, you can show an
error message to the user.
6 After setting the reply timeout, call your data project's sendVRPC() method that you created .
8 In the onError() callback, display an error message to the user and hide the wait cursor. This callback is called for
generic error conditions (for example, the appropriate configuration is not found).
9 In the onReplyReceived callback, first check if a VRPCError object is returned. If it is, display an error message
to the user and hide the wait cursor. Otherwise, proceed with filling the UI elements with the returned data and
hide the wait cursor.
10 The onRequestFailed callback indicates that the VRPC request was not able to be sent. In this callback, display
an error message to the user and hide the wait cursor.
11 The onRequestBounced callback indicates that the server received the VRPC request, but the response was never
sent to the client. In this callback, display an error message to the user and hide the wait cursor.
12 The onRequestTimeout callback is used in conjunction with the setReplyTimeout() method. If the client has not
received a reply from the server within the specified timeframe, this callback will be called. In this callback,
display an error message to the user and hide the wait cursor.
2 If you still do not see the menus/buttons, in Eclipse.ini, add the following lines:
-vm
C:\Program Files\java\jdk1.6.0_13\bin
If that does not resolve the issue, ensure that the JDK directory is in the computer's path.
3 If you receive an error about the home directory, edit the Eclipse.ini file to hard-code the home directory, for
example,
B Edit the AMP Studio shortcut and remove the -clean option.
NOTE: You only need to start Eclipse in clean mode after installing a new AMP Studio build so that all of
the updated plugins get reloaded.
Troubleshooting
The following are some basic troubleshooting tips for checking connectivity between the server and device.
1 Verify the client logs and ensure that there are no errors/exceptions from your UIP.
— Client logs can be accesses by using the CTRL+LGLG shortcut with the computer keyboard while focus is
on the BlackBerry home screen.
— The client log level can be set by selecting the Window menu, then Preferences, AMP Studio, Client, and
finally, Log Properties. If you want to debug, ensure that VMP_SYS is set to FINE.
— To do logging, first initialize the logger by Log logApp = getLog(); Then you can use the log such as,
logApp.log(Log.FINE, "onStart() called");
— In the BlackBerry Simulator, select Options, then Antenna AUTH_SERVER and check whether it is
pointing to the correct server. (The Antenna option will appear only if the application is invoked at least
once). If not, edit it to point to the correct server and restart. If Antenna is not launching, use the clean.bat
inside the simulator folder and re-try. Another option is clear all .dmp, .debug, and .cod files relevant to your
project and re-try.
11:34:51 VMP_AUTH_JOB <WARN > Login Successful for: test; Always approved
11:34:51 VMP_AUTH_JOB <INFO > Got client request service for ADDUI from test
For example,
to
3 I changed or added images in the image panel and they are not showing up in the image panel and/or the
simulator.
— You have not associated each image bundle with a device type.
— Your image bundle is empty (corrupt).
— Try to restart Eclipse and check the images again.
5 Results in the simulator do not reflect recent changes or there are errors.
pushAccountDetails();
pushAccountDetails();
void pushAccountDetails() {
if(rchTblMdlAccounts.hasRow()){
scrAccountDetails = getNewAccountsDetailsScreen();
scrAccountDetails.dtaRowAccount = dtaRowAccount;
pushScreen(scrAccountDetails);
7 How can I close the existing screen and return to the previous screen with the same session data?
… Then double-click the UIP. Set the log to FINE. From the Window menu, select Preferences and set
the client log from VMP_SYS to FINE.
… On the BlackBerry device, use the ALT-LGLG shortcut key (or use CTRL-LGLG on a computer's
keyboard) to see the log.
… For the server, you can set server log properties in the Window\Preferences screen and see the logging
in the AMP Studio server console or in project\com.vaultus.studio\server\vas\logs.
9 Where can I get the default Font and other Styles such as buttons, etc. for BlackBerry, iPhone and
Android devices?
— You can refer to the default style code snippet from any project or samples within the AMP Studio Developer
Guide.
10 Using VDSC, how can I create an Object for multiple table join conditions?
— You can use a virtual object, but it is probably easier to create a view in the DP and handle the join there.
11 Where will authentication occur in the DB? Do we need to perform any explicit authentication?
— Authentication against the AMP Server Authentication server occurs when you call login() in the UIP. The
connector may require a second level login in some cases. But for a simple DB connector, no authentication
should be required for the connector.
12 How can I integrate GPRS in BlackBerry and iPhone in AMP Studio? Is there a provision to check some
static locations using GPRS coordinates?
13 How can I set a wait cursor when the response is being delayed?
wc.setVerticalAlignment(WaitCursor.CENTER);
wc.setHorizontalAlignment(WaitCursor.CENTER);
wc.setBackground(Background.createColorRoundedBackground(Color.create(192,0,0,0),
Colors.White, LineStyle.SOLID));
wc.setForeColor(Colors.White);
wc.setHeight(Sizing.PIXELS, giWidth/6);
wc.setWidth(Sizing.PIXELS, giWidth/2);
wc.setFont(StyDefault.fntDetails);
wc.setText(displayString);
scrUserID.setWaitCursor(waitCursor);
14 Suppose I do not have table headers to my table and it contains two or more columns. How can I set
ReseultSet data (i.e. Query retrieved data) for that table?
tblMdlHelloWorld.addStringColumn("", vrpcGetObjectRows.TEST.ID);
tblMdlHelloWorld.addStringColumn("", vrpcGetObjectRows.TEST.TEXT);
tblMdlHelloWorld.setRows(vrpcGetObjectRows.TEST.qryGetAll());
15 How is exception propagation performed in AMP Studio? (For example, if I received an exception in my
connector, how will I realize it? )
16 I have developed a sample UI and DP. I was able to get a response from the DP, but after I restart Eclipse,
sometimes I am not getting any response from the server, i.e. the 'onReplyReceived' callback is not
invoked. How should I debug such issues? I am using the VRPC connector.
— In the Window/Preferences screen, set VMP_VRPC and VMP_SYS to FINE. Start your server. Check the
log for any errors.
17 I am experiencing some problem after initiating the AMP Server for a VDSC Data Project.
— You will need to run the DB Connector installer from the build distribution. It will install the EMF jars for
you. After that, replace the DB connector that the installer put into vmsserver/connectors with the version
that you obtain from AMP Studio.
12:09:47 VMP_SYS_NET <CONFIG > Configured for client traffic via: TCP, MDS
at com.vaultus.vmsserver.DataSourceJob.getDriver(DataSourceJob.java:579)
at com.vaultus.vmsserver.DataSourceJob.getDriver(DataSourceJob.java:597)
at com.vaultus.vmsserver.DataSourceJob.initializeDocument(DataSourceJob.java:659)
at
com.vaultus.vmsserver.DataSourceJob.initializeAllDocuments(DataSourceJob.java:352)
at com.vaultus.vmsserver.DataSourceJob.initializeOrReload(DataSourceJob.java:263)
at com.vaultus.vmsserver.DataSourceJob.onStart(DataSourceJob.java:201)
at com.vaultus.vmsserver.VRPCJob.onStart(VRPCJob.java:144)
at com.vaultus.vmsserver.core.SyncJob.onStart(SyncJob.java:122)
at com.vaultus.vmsserver.VMSJob.onStart(VMSJob.java:107)
at com.vaultus.server.core.GenericServer.startJobs(GenericServer.java:2430)
at com.vaultus.server.core.GenericServer.start(GenericServer.java:1049)
at com.vaultus.server.core.GenericServer.runUntilShutdown(GenericServer.java:1252)
at com.vaultus.server.core.GenericServer.main(GenericServer.java:2248)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:2
5)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.vaultus.server.runner.ServerRunner.doMain(ServerRunner.java:208)
at com.vaultus.server.runner.AuthRunner.main(AuthRunner.java:24)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl
.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAcce
ssorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.vaultus.vmsserver.DataSourceJob.getDriver(DataSourceJob.java:568)
... 18 more
at com.vaultus.vms.db.driver.DBDriver.loadConfig(DBDriver.java:94)
at com.vaultus.vms.db.driver.DBDriver.executeDBDriverTasks(DBDriver.java:88)
at com.vaultus.vms.db.driver.DBDriver.<init>(DBDriver.java:84)
... 23 more
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 26 more
12:09:50 VMP_SYS <INFO > Up since 2010.09.16 12:09:42 IST Thu (0 days 0
hours 0 minutes 8 seconds)
12:09:50 VMP_AUTH_JOB <INFO > Stopping comm stats carrier statistics logging
...
12:09:50 VMP_VMSJOB <INFO > Stopping comm stats carrier statistics logging ...
Coding Conventions
It is a good practice to follow some convention when you write code. It will create code that is easy to work with.
It is recommended that you review Java Code Convention and Hungarian notation and apply relevant parts to mScript.
Names
Abbreviate names only when a name is too long.
Class Names
Each word in the names of projects, styles, screens, panels, and folders should be capitalized:
Variable Names
Variable and parameter names should start with a lowercase letter and each word should be capitalized:
myVariableName
Method Names
Queries, rowfilters, indexes, mappings and methods should start with a lowercase letter and each word should be
capitalized:
query qryGetAllRows<>{}
index idxID {
etc.
Indentation
Use tab indentation to create a clear hierarchy within an mscript.
Spaces
Add extra spaces to make code more readable:
int i = 35;
instead of:
int i=35;
One Liners
Write one command per line. Do not write several commands in one line:
dp.User.username.setStringValue(newValue, model.getRow());
dp.User.username.setStringValue(newValue, row);
It is recommended that you use the following coding conventions for building variable names using the following table:
Action - act
Area - ar
Array - arr
Bar - bar
Background - bck
Border - brd
Box - bx
Browser - brw
Button - btn
Calendar - cal
Chart - cht
Check - chk
Choice - ch
Combo - cmb
Data - dta
Date - dt
Edit - edt
Field - fld
Font - fnt
Form - frm
Format - fmt
Horizontal - hrz
Image - img
Images - imgs
Index - idx
Item - itm
Label - lbl
Log - log
[Exampe: Log logApp = getLog();]
Menu - mn
Model - mdl
Multi - mlt
Number - num
Numeric - num
Panel - pnl
Password - pwd
Picture - pic
Pie - pie
Progress - prg
Query - qry
Rich - rch
Screen - scr
Separator - sep
Stack - stk
Style - sty
Tabbed - tab
Table - tbl
Text - txt
Tool - tl
Vertical - vrt
ImageModel - imgMdlSearch
TextField - txtUser
BorderPanel - brdPnlRoot
ImageModel - imgMdlImage
Label - lblHeader
MenuItem - mnItmClose
PictureBox - picBxTitle
Table - tblTable
TableModel - tblMdlSummary
TextModel - txtMdlHeader
ToolBar - tbToolbar
ToolBarButton - tlBrBtnSkiers
Type Example
Boolean - bDataReceived
float - fValue
int - iCount
Type Example
String - strName
Date - dtToday
Timestamp - tsToday
■ For global variables (UIP variables), start with g. For example: gStrGlobalVariable
■ For virtual fields (DP variables), start with v. For example,
— vFVirtualField - float field at the object level
— vStrVirtualField - String field
■ For linked fields, start with l. For example:
StringAttribute lAccountName = AID=>Accounts.AID->Accounts.Name
Images Conventions
Button - btn
if(odd == 0){
item.setBackColor((isSelected)?Color.LightGreen : Color.LightGray);
else {
item.setBackColor((isSelected)?Color.LightGreen : Color.WhiteSmoke);