-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathWorkspaceLayout.cpp
More file actions
396 lines (331 loc) · 10.8 KB
/
WorkspaceLayout.cpp
File metadata and controls
396 lines (331 loc) · 10.8 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
/*
Copyright (C) 2013 MoSync AB
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License,
version 2, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
/*
* WorkspaceScreen.cpp
*
* Created on: Jan 31, 2013
* Author: Spiridon Alexandru
*/
#include <conprint.h>
#include <wchar.h>
#include <ma.h>
#include <maassert.h>
#include <mawstring.h>
#include <mastdlib.h>
#include "WorkspaceLayout.h"
#include "WorkspaceLayoutUtils.h"
#include "MAHeaders.h"
/**
* Constructor.
* @param os The current os.
* @param orientation The current device orientation.
*/
WorkspaceLayout::WorkspaceLayout(MAUtil::String os, int orientation) :
VerticalLayout()
{
mSelectedProject = -1;
mSelectedProjectName = "";
mOS = os;
mCurrentOrientation = orientation;
setScreenValues();
createMainLayout();
}
/**
* Destructor.
*/
WorkspaceLayout::~WorkspaceLayout()
{
mListView->removeListViewListener(this);
mReloadUIListeners.clear();
}
/**
* Creates and adds main layout to the screen.
*/
void WorkspaceLayout::createMainLayout() {
// Create the main layout.
HorizontalLayout *controlButtonsContainer = new HorizontalLayout();
controlButtonsContainer->fillSpaceHorizontally();
controlButtonsContainer->setHeight(mWidgetHeight);
if(mOS == "iPhone OS")
{
mRefreshButton = new ImageButton();
((ImageButton*)mRefreshButton)->addButtonListener(this);
((ImageButton*)mRefreshButton)->setBackgroundImage(RELOAD_BG);
mRefreshButton->setFontColor(0x000000);
mDisconnectButton = new ImageButton();
((ImageButton*)mDisconnectButton)->addButtonListener(this);
((ImageButton*)mDisconnectButton)->setBackgroundImage(RELOAD_BG);
mDisconnectButton->setFontColor(0x000000);
mSaveButton = new ImageButton();
((ImageButton*)mSaveButton)->addButtonListener(this);
((ImageButton*)mSaveButton)->setBackgroundImage(RELOAD_BG);
mSaveButton->setFontColor(0x000000);
mReloadButton = new ImageButton();
((ImageButton*)mReloadButton)->addButtonListener(this);
((ImageButton*)mReloadButton)->setBackgroundImage(CONNECT_BG);
mReloadButton->setFontColor(0x000000);
}
else
{
mRefreshButton = new Button();
((Button*)mRefreshButton)->addButtonListener(this);
mDisconnectButton = new Button();
((Button*)mDisconnectButton)->addButtonListener(this);
mSaveButton = new Button();
((Button*)mSaveButton)->addButtonListener(this);
mReloadButton = new Button();
((Button*)mReloadButton)->addButtonListener(this);
}
mRefreshButton->setText(REFRESH_LIST_BUTTON_TEXT);
mRefreshButton->setHeight(mWidgetHeight);
mRefreshButton->fillSpaceHorizontally();
mDisconnectButton->setText(DISCONNECT_BUTTON_TEXT);
mDisconnectButton->setHeight(mWidgetHeight);
mDisconnectButton->fillSpaceHorizontally();
controlButtonsContainer->addChild(mDisconnectButton);
controlButtonsContainer->addChild(mRefreshButton);
// Create Project Control Buttons SAVE and RELOAD
mSaveButton->setText(SAVE_BUTTON_TEXT);
mSaveButton->setWidth((int)(mScreenWidth * mSaveButtonWidthRatio));
mReloadButton->setText(RELOAD_BUTTON_TEXT);
mReloadButton->setWidth((int)(mScreenWidth * mReloadButtonWidthRatio));
mListView = new ListView();
mListView->allowSelection(true);
mListView->addListViewListener(this);
if(mOS.find("iPhone") >= 0)
{
this->setBackgroundColor(0x000000);
mListView->setProperty(MAW_WIDGET_BACKGROUND_COLOR,"00000000");
}
this->addChild(controlButtonsContainer);
this->addChild(mListView);
// Create the activity indicator widgets
mActivityIndicatorContainer = new RelativeLayout();
mActivityIndicatorContainer->fillSpaceHorizontally();
mActivityIndicatorContainer->fillSpaceVertically();
/**
* FIXME Removing listView and adding Activity indicator causes
* the list view not getting events until some point,
* when removing activity indicator to add the list again.
*/
//ActivityIndicator *loadingProjectsIndicator = new ActivityIndicator();
//loadingProjectsIndicator->setSize(80,80);
//loadingProjectsIndicator->setPosition((int)(mScreenWidth*0.5) - 40, (int)(mScreenHeight*0.5) - 80 );
//mActivityIndicatorContainer->addChild(loadingProjectsIndicator);
}
/**
* If there is no list populates the List View Widget with the project data
* from mProjects vector. Else destroys and deallocates previous list items
* and creates new ones.
*/
void WorkspaceLayout::updateProjectList(MAUtil::Vector <reloadProject> * projects)
{
// Remove The ListView and add An Activity Indicator
lprintfln("Updating Project List");
mListView->setVisible(false);
/**
* FIXME Removing listView and adding Activity indicator causes
* the list view not getting events until some point,
* when removing activity indicator to add the list again.
*/
//this->removeChild(mListView);
//this->addChild(mActivityIndicatorContainer);
// If there was a project Selected before update remove the
// control buttons
if(mSelectedProject != -1)
{
Widget *h = mListView->getChild(mSelectedProject)->getChild(0);
h->removeChild(h->getChild(1));
h->removeChild(h->getChild(1));
}
// ReInitialize selected project
mSelectedProject = -1;
mSelectedProjectName = "";
// Delete all the widgets from the ListView
int prProjects = mListView->countChildWidgets();
if(prProjects != 0)
{
for(int i = 0; i < prProjects; i++)
{
Widget *listItemWidget = mListView->getChild(0); // list Item Widget
Widget *hLayout = listItemWidget->getChild(0); // horizontal layout widget
for( int j = 0; j < hLayout->countChildWidgets(); j++)
{
Widget * w = hLayout->getChild(0);
hLayout->removeChild(w);
delete w;
}
listItemWidget->removeChild(hLayout);
delete hLayout;
mListView->removeChild(listItemWidget);
delete listItemWidget;
}
}
// Re-populate the ListView with projects
for (MAUtil::Vector <reloadProject>::iterator i = projects->begin(); i != projects->end(); i++)
{
// New List Itemprojects
ListViewItem* item = new ListViewItem();
item->setHeight(mWidgetHeight);
item->fillSpaceHorizontally();
// New Horizontal Layout
HorizontalLayout *itemHorizontalLayout = new HorizontalLayout();
itemHorizontalLayout->fillSpaceHorizontally();
itemHorizontalLayout->setHeight(mWidgetHeight);
// New Label
Label* projectNameLabel = new Label();
projectNameLabel->setTextHorizontalAlignment(MAW_ALIGNMENT_LEFT);
projectNameLabel->setTextVerticalAlignment(MAW_ALIGNMENT_CENTER);
projectNameLabel->setText(i->name);
projectNameLabel->fillSpaceHorizontally();
projectNameLabel->fillSpaceVertically();
if (mOS.find("iPhone") >= 0)
{
itemHorizontalLayout->setWidth(item->getWidth());
projectNameLabel->setFontColor(0xffffff);
}
itemHorizontalLayout->addChild(projectNameLabel);
item->addChild(itemHorizontalLayout);
mListView->addChild(item);
}
mListView->setVisible(true);
// Remove Indicator and Add Project ListView
//this->addChild(mListView);
//this->removeChild(mActivityIndicatorContainer);
}
/**
* This method is called if the touch-up event was inside the
* bounds of the button.
* @param button The button object that generated the event.
*/
void WorkspaceLayout::buttonClicked(Widget* button)
{
if (button == mRefreshButton)
{
for (int i = 0; i < mReloadUIListeners.size(); i++)
{
mReloadUIListeners[i]->refreshWorkspaceProjectsButtonClicked();
}
}
else if (button == mDisconnectButton)
{
for (int i = 0; i < mReloadUIListeners.size(); i++)
{
mReloadUIListeners[i]->disconnectButtonClicked();
}
}
else if (button == mSaveButton)
{
for (int i = 0; i < mReloadUIListeners.size(); i++)
{
mReloadUIListeners[i]->saveProjectClicked(mSelectedProjectName);
}
}
else if (button == mReloadButton)
{
for (int i = 0; i < mReloadUIListeners.size(); i++)
{
mReloadUIListeners[i]->reloadProjectClicked(mSelectedProjectName);
}
}
}
/**
* This method is called when a list view item is clicked.
* @param listView The list view object that generated the event.
* @param listViewItem The ListViewItem object that was clicked.
*/
void WorkspaceLayout::listViewItemClicked(
ListView * listView,
int index )
{
lprintfln("@@@ RELOAD: Project Selected No: %d", index);
Widget *project = listView->getChild(index);
ListViewItem *tmp = (ListViewItem*)project;
tmp->setSelected(false, false);
Widget *hLayout = project->getChild(0);
Label *projectName = (Label*)hLayout->getChild(0);
// Diselect previous item
if (mSelectedProject != -1)
{
Widget *delItem = listView->getChild(mSelectedProject);
Widget *delHLayout = delItem->getChild(0);
delHLayout->removeChild(mSaveButton);
delHLayout->removeChild(mReloadButton);
}
// Add control Buttons to the currently selected Project
hLayout->addChild(mSaveButton);
hLayout->addChild(mReloadButton);
if (mOS.find("iPhone") >= 0)
{
hLayout->setWidth(project->getWidth());
}
mSelectedProject = index;
mSelectedProjectName = projectName->getText();
lprintfln("@@@ RELOAD: Selected Project No:%d, Name:%s", index, mSelectedProjectName.c_str());
}
/**
* Add a reload UI event listener.
* @param listener The listener that will receive reload UI events.
*/
void WorkspaceLayout::addReloadUIListener(ReloadUIListener* listener)
{
for (int i = 0; i < mReloadUIListeners.size(); i++)
{
if (listener == mReloadUIListeners[i])
{
return;
}
}
mReloadUIListeners.add(listener);
}
/**
* Remove a reload UI listener.
* @param listener The listener that receives reload UI events.
*/
void WorkspaceLayout::removeReloadUIListener(ReloadUIListener* listener)
{
for (int i = 0; i < mReloadUIListeners.size(); i++)
{
if (listener == mReloadUIListeners[i])
{
mReloadUIListeners.remove(i);
break;
}
}
}
/**
* Sets the screen height/width values and the screen width ratio
* for the save and reload buttons.
*/
void WorkspaceLayout::setScreenValues()
{
int orientation = maScreenGetCurrentOrientation();
MAExtent ex = maGetScrSize();
mScreenWidth = EXTENT_X(ex);
mScreenHeight = EXTENT_Y(ex);
if (orientation == MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT ||
orientation == MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT)
{
mSaveButtonWidthRatio = SAVE_BUTTON_LANDSCAPE_WIDTH_RATIO;
mReloadButtonWidthRatio = RELOAD_BUTTON_LANDSCAPE_WIDTH_RATIO;
mWidgetHeight = (int)((float)mScreenWidth * WIDGET_HEIGHT_RATIO);
}
else
{
mSaveButtonWidthRatio = SAVE_BUTTON_PORTRAIT_WIDTH_RATIO;
mReloadButtonWidthRatio = RELOAD_BUTTON_PORTRAIT_WIDTH_RATIO;
mWidgetHeight = (int)((float)mScreenHeight * WIDGET_HEIGHT_RATIO);
}
}