-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
214 lines (172 loc) · 4.64 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include <ma.h> // Syscalls
#include <MAUtil/String.h> // C++ String class
#include <MAUtil/Moblet.h> // Moblet class
#include <conprint.h> // lprintfln for logging
#include <NativeUI/Widgets.h>// Include all widgets
#include "ScreenMain.h" // Main UI screen
#include "Util.h"
// How often the timer will be invoked
#define TIMER_PERIOD 60000
using namespace MAUtil;
using namespace NativeUI;
/**
* Moblet for the application.
*/
class NativeUIMoblet : public Moblet, public FocusListener, public TimerListener
{
public:
/**
* Constructor that creates the UI.
*/
NativeUIMoblet()
{
addTimer(this, TIMER_PERIOD, 0);
addFocusListener(this);
maScreenSetOrientation(SCREEN_ORIENTATION_DYNAMIC);
// iOS and Windows Phone.
maScreenSetSupportedOrientations(
MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT |
MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT |
MA_SCREEN_ORIENTATION_PORTRAIT |
MA_SCREEN_ORIENTATION_PORTRAIT_UPSIDE_DOWN);
// Update the display.
drawScreen();
// Create the main user interface screen.
mMainScreen = new ScreenMain();
// Show the screen.
mMainScreen->show();
}
// send timer event to trackingTabObject
void runTimerEvent()
{
mMainScreen->pullRequest();
}
/**
* Method for handling events that do not have predefined methods.
*/
void customEvent(const MAEvent& event)
{
// If the event type is screen changed we update the display.
if (EVENT_TYPE_SCREEN_CHANGED == event.type)
{
drawScreen();
}
}
/**
* Method that draws display data to the screen.
*/
void drawScreen()
{
MAExtent screenSize = maGetScrSize();
int width = EXTENT_X(screenSize);
int height = EXTENT_Y(screenSize);
int x = 20;
int y = height / 2;
char orientationText[128];
if (width > height) // Landscape
{
// Set the background color.
maSetColor(0x000099);
// Set text.
sprintf(orientationText, "Landscape %d %d", width, height);
}
else // Portrait
{
// Set the background color.
maSetColor(0x009900);
// Set text.
sprintf(orientationText, "Portrait %d %d", width, height);
}
// Fill background
maFillRect(0, 0, width, height);
// Use white to display the text.
maSetColor(0xFFFFFF);
// Draw the text.
maDrawText(x, y, orientationText);
// Redraw the screen.
maUpdateScreen();
}
/**
* Destructor.
*/
virtual ~NativeUIMoblet()
{
delete mMainScreen;
}
/**
* Called when a key is pressed.
* This is a callback method declared in class Moblet.
*/
void keyPressEvent(int keyCode, int nativeCode)
{
if(keyCode == MAK_1 || keyCode == MAK_SOFTRIGHT)
{
// maSendToBackground(); //
// maAlert("Application Update Available", "test" , "Yes", "", "No");
// lprintfln("maBringToForeground() = %d" ,maBringToForeground());
// lprintfln("maSendToBackground() = %d" ,maSendToBackground());
// lprintfln("aprés wait");
exit();
// lprintfln("maBringToForeground() = %d" ,maBringToForeground());
// maBringToForeground();
}
// Let the screen handle the keypress.
mMainScreen->handleKeyPress(keyCode);
}
/**
* Called when the screen was touched.
* This is a callback method declared in class Moblet.
*/
void pointerPressEvent(MAPoint2d point)
{
if(getPlatform() != WINDOWSPHONE7) mMainScreen->handlePointerPressed(point);
}
/**
* Called when the pointer was moved on the screen.
* This is a callback method declared in class Moblet.
*/
void pointerMoveEvent(MAPoint2d point)
{
if(getPlatform() != WINDOWSPHONE7) mMainScreen->handlePointerMoved(point);
}
/**
* Called when the screen was released.
* This is a callback method declared in class Moblet.
*/
void pointerReleaseEvent(MAPoint2d point)
{
mMainScreen->handlePointerReleased(point);
}
virtual void focusLost(){lprintfln("focus lost"); toto = 1;}
virtual void focusGained(){lprintfln("focus gained"); toto = 0;}
// void customEvent(const MAEvent& event);
// {
//// if(event.type == EVENT_TYPE_FOCUS_LOST)
//// {
//// //Do things when sent to background
//// }
//// else if(event.type == EVENT_TYPE_FOCUS_GAINED)
//// {
//// //Do things when brought back from background
//// }
// }
private:
ScreenMain* mMainScreen;
int toto;
};
/**
* Main function that is called when the program starts.
*/
//int MAMain() GCCATTRIB(noreturn);
static int RUN = 0;
extern "C" int MAMain()
{
// lprintfln("maBringToForeground() = %d" ,maBringToForeground());
// maLockKeypad();
if (RUN == 0)
{
RUN=1;
Moblet::run(new NativeUIMoblet());
}
// return 0;
}