Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StResetSettingForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                StResetSettingForm.cpp
19  * @brief               This is the implementation file for ResetSettingForm class.
20  */
21
22 #include "StResetSettingForm.h"
23 #include "StResourceManager.h"
24 #include "StTypes.h"
25
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Runtime;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Ui;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Ui::Scenes;
33
34 static const int ID_GROUP_RESET_SETTING_MAIN = 0;
35 static const int ID_GROUP_RESET_SETTING_ITEM_COUNT = 16;
36
37 static const int ID_GROUP_COUNT = 1;
38 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_RESET_SETTING_ITEM_COUNT;
39
40 static const int IDA_RESET = 100;
41 static const int IDA_CANCEL = 101;
42
43 static const int IDA_BUTTON_CHECKED = 200;
44 static const int IDA_BUTTON_UNCHECKED = 201;
45 static const int IDA_BUTTON_SELECTED = 202;
46 static const int Y_ITEM_COUNT_DISPLAY = 968;
47
48 static const int TICK_COUNT = 10;
49 static const int MESSAGE_TIME_OUT = 100;
50
51 static const int ID_ITEM_LOCATION = 0;
52 static const int ID_ITEM_NETWORK = 1;
53 static const int ID_ITEM_WIFI_DIRECT = 2;
54 static const int ID_ITEM_WALLPAPER = 3;
55 static const int ID_ITEM_SOUNDS = 4;
56 static const int ID_ITEM_BRIGHTNESS = 5;
57 static const int ID_ITEM_FONT = 6;
58 static const int ID_ITEM_DISPLAY = 7;
59 static const int ID_ITEM_AUTO_ROTATE_SCREEN = 8;
60 static const int ID_ITEM_DATE_TIME = 9;
61 static const int ID_ITEM_LANGUAGE_REGION = 10;
62 static const int ID_ITEM_KEYBOARD = 11;
63 static const int ID_ITEM_MANAGE_APPLICATION = 12;
64 static const int ID_ITEM_MEMORY = 13;
65 static const int ID_ITEM_DEVELOPER_OPTION = 14;
66 static const int ID_ITEM_ABOUT_PHONE = 15;
67
68 static const int STRING_SIZE_LIMIT = 20;
69
70 ResetterSettingForm::ResetterSettingForm(void)
71         : __bTimerExpired(false)
72         , __count(TICK_COUNT)
73         , __pLabelItemCount(null)
74         , __pCheckButton(null)
75 {
76          __timer.Construct(*this);
77 }
78
79 ResetterSettingForm::~ResetterSettingForm(void)
80 {
81 }
82
83 void
84 ResetterSettingForm::CreateFooter(void)
85 {
86         FooterItem footerReset;
87         FooterItem footerCancel;
88
89         Footer* pFooter = GetFooter();
90         AppAssert(pFooter);
91
92         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
93
94         footerReset.Construct(IDA_RESET);
95         footerReset.SetText(ResourceManager::GetString(L"IDS_ST_BODY_RESET"));
96
97         footerCancel.Construct(IDA_CANCEL);
98         footerCancel.SetText(ResourceManager::GetString(L"IDS_ST_BODY_CANCEL"));
99
100         pFooter->AddItem(footerReset);
101         pFooter->AddItem(footerCancel);
102 }
103
104 void
105 ResetterSettingForm::CreateTableView(void)
106 {
107         Rectangle bounds = GetClientAreaBounds();
108         Rectangle itemMainRectangle;
109         Rectangle itemSelectCount;
110
111         String itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SELECT_ALL");
112         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
113
114         bounds.x = X_GROUP_DEFAULT;
115         bounds.y = H_GROUP_ITEM_DEFAULT;
116         bounds.width -= (bounds.x * WIDTH_GAP);
117
118         itemMainRectangle = itemSelectCount = bounds;
119         itemMainRectangle.y = Y_GROUP_DEFAULT;
120         itemMainRectangle.height = H_GROUP_ITEM_DEFAULT;
121
122         __pCheckButton = new (std::nothrow) CheckButton();
123         __pCheckButton->Construct(itemMainRectangle, CHECK_BUTTON_STYLE_MARK, BACKGROUND_STYLE_NONE, false);
124         __pCheckButton->SetActionId(IDA_BUTTON_CHECKED, IDA_BUTTON_UNCHECKED, IDA_BUTTON_SELECTED);
125         __pCheckButton->SetText(itemMainText);
126
127         AddControl(__pCheckButton);
128
129         __pCheckButton->AddActionEventListener(*this);
130
131         __pTableView = new (std::nothrow) GroupedTableView();
132         __pTableView->Construct(bounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FIXED);
133         __pTableView->SetItemProvider(this);
134
135         AddControl(__pTableView);
136
137         __pTableView->AddGroupedTableViewItemEventListener(*this);
138
139         itemSelectCount.y = Y_ITEM_COUNT_DISPLAY;
140         itemSelectCount.height = H_GROUP_INDEX_NO_TITLE_DEFAULT;
141
142         __pLabelItemCount = new (std::nothrow) Label();
143         __pLabelItemCount->Construct(itemSelectCount, itemSelectedText);
144         __pLabelItemCount->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
145         __pLabelItemCount->SetTextConfig(FONT_SIZE_POPUP_TEXT, LABEL_TEXT_STYLE_BOLD);
146         __pLabelItemCount->SetTextColor(COLOR_MAIN_TEXT);
147
148         AddControl(__pLabelItemCount);
149
150         __pLabelItemCount->SetBackgroundColor(COLOR_BG_CHECKBOX);
151         __pLabelItemCount->SetShowState(false);
152
153         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
154         if (pRelativeLayout != null)
155         {
156                 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
157                 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
158                 delete pRelativeLayout;
159         }
160 }
161
162 result
163 ResetterSettingForm::OnInitializing(void)
164 {
165         CreateHeader(ResourceManager::GetString(L"IDS_ST_HEADER_RESET_SETTINGS"));
166         CreateFooter();
167         CreateTableView();
168
169         AppLogDebug("ENTER");
170
171         return E_SUCCESS;
172 }
173
174 result
175 ResetterSettingForm::OnTerminating(void)
176 {
177         __pLabelItemCount = null;
178         __pCheckButton = null;
179         __pTableView = null;
180
181         return E_SUCCESS;
182 }
183
184 void
185 ResetterSettingForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
186 {
187         __pTableView->UpdateTableView();
188 }
189
190 void
191 ResetterSettingForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
192 {
193 }
194
195 int
196 ResetterSettingForm::GetGroupCount(void)
197 {
198         AppLogDebug("ENTER");
199         return ID_GROUP_COUNT;
200 }
201
202 int
203 ResetterSettingForm::GetItemCount(int groupIndex)
204 {
205         int itemCount = ID_GROUP_MAX_ITEM_COUNT;
206
207         AppLogDebug("GetItemCount %d", itemCount);
208
209         return itemCount;
210 }
211
212 TableViewGroupItem*
213 ResetterSettingForm::CreateGroupItem(int groupIndex, int itemWidth)
214 {
215         AppLogDebug("ENTER");
216
217         return null;
218 }
219
220 TableViewItem*
221 ResetterSettingForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
222 {
223         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
224
225         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
226         Rectangle itemMainRectangle;
227         String itemMainText;
228         Label* pLabel = null;
229         int fontSize = GetFontSize();
230
231         switch (itemIndex)
232         {
233         case ID_ITEM_LOCATION:
234                 {
235                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_LOCATIONS");
236                 }
237                 break;
238
239         case ID_ITEM_NETWORK:
240                 {
241                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_NETWORK");
242                 }
243                 break;
244
245         case ID_ITEM_WIFI_DIRECT:
246                 {
247                         itemMainText = ResourceManager::GetString(L"IDS_ST_HEADER_WI_FI_DIRECT");
248                 }
249                 break;
250
251         case ID_ITEM_WALLPAPER:
252                 {
253                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MAINDISPLAY_WALLPAPER");
254                 }
255                 break;
256
257         case ID_ITEM_SOUNDS:
258                 {
259                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SOUNDS");
260                 }
261                 break;
262
263         case ID_ITEM_BRIGHTNESS:
264                 {
265                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_BRIGHTNESS");
266                 }
267                 break;
268
269         case ID_ITEM_FONT:
270                 {
271                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONT");
272                 }
273                 break;
274
275         case ID_ITEM_DISPLAY:
276                 {
277                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DISPLAY");
278                 }
279                 break;
280
281         case ID_ITEM_AUTO_ROTATE_SCREEN:
282                 {
283                         itemMainText = ResourceManager::GetString(L"IDS_ST_HEADER_AUTO_ROTATE_SCREEN_ABB");
284                 }
285                 break;
286
287         case ID_ITEM_DATE_TIME:
288                 {
289                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DATE_AND_TIME");
290                 }
291                 break;
292
293         case ID_ITEM_LANGUAGE_REGION:
294                 {
295                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_LANGUAGE_AND_REGION_ABB");
296                 }
297                 break;
298
299         case ID_ITEM_KEYBOARD:
300                 {
301                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_KEYBOARD");
302                 }
303                 break;
304
305         case ID_ITEM_MANAGE_APPLICATION:
306                 {
307                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MANAGE_APPLICATIONS");
308                 }
309                 break;
310
311         case ID_ITEM_MEMORY:
312                 {
313                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MEMORY");
314                 }
315                 break;
316
317         case ID_ITEM_DEVELOPER_OPTION:
318                 {
319                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DEVELOPER_OPTIONS");
320                 }
321                 break;
322
323         case ID_ITEM_ABOUT_PHONE:
324                 {
325                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_ABOUT_PHONE");
326                 }
327                 break;
328
329         default:
330                 break;
331         }
332
333         ItemTypeOneLine(itemMainRectangle);
334
335         TableViewItem* pItem = new (std::nothrow) TableViewItem();
336
337         RelativeLayout relativeLayout;
338         relativeLayout.Construct();
339
340         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
341         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
342
343         pLabel = new (std::nothrow) Label();
344         pLabel->Construct(itemMainRectangle, itemMainText);
345         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
346         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_BOLD);
347         pLabel->SetTextColor(COLOR_MAIN_TEXT);
348
349         pItem->AddControl(pLabel);
350
351         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
352         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
353         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
354
355         return pItem;
356 }
357
358 bool
359 ResetterSettingForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
360 {
361         AppLogDebug("ENTER");
362
363         delete pItem;
364         pItem = null;
365
366         return true;
367 }
368
369 bool
370 ResetterSettingForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
371 {
372         AppLogDebug("ENTER");
373
374         delete pItem;
375         pItem = null;
376
377         return true;
378 }
379
380 void
381 ResetterSettingForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
382 {
383         int itemCount = 0;
384         int count = 0;
385         int checkedItemCount = 0;
386         int localGroup = 0;
387         int localItem = 0;
388         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
389         String countText;
390
391         itemCount = tableView.GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
392
393         if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
394         {
395                 tableView.SetItemChecked(groupIndex, itemIndex, true);
396         }
397
398         if (status == TABLE_VIEW_ITEM_STATUS_UNCHECKED)
399         {
400                 tableView.SetItemChecked(groupIndex, itemIndex, false);
401         }
402
403         for (count = 0; count < itemCount; count++)
404         {
405                 localGroup = ID_GROUP_RESET_SETTING_MAIN;
406                 localItem = count;
407
408                 if (__pTableView->IsItemChecked(localGroup, localItem))
409                 {
410                         checkedItemCount++;
411                 }
412         }
413
414         if (checkedItemCount)
415         {
416                 countText.Format(STRING_SIZE_LIMIT, L" (%d)", checkedItemCount);
417                 itemSelectedText.Insert(countText, itemSelectedText.GetLength());
418                 __pLabelItemCount->SetText(itemSelectedText);
419                 __pLabelItemCount->SetShowState(true);
420                 __pLabelItemCount->Invalidate(true);
421
422                 __count = TICK_COUNT;
423                 __timer.Start(MESSAGE_TIME_OUT);
424         }
425 }
426
427 void
428 ResetterSettingForm::OnActionPerformed(const Control& source, int actionId)
429 {
430         AppLogDebug("Action ID = [%d]", actionId);
431         switch (actionId)
432         {
433         case IDA_CANCEL:
434                 {
435                         SceneManager* pSceneManager = SceneManager::GetInstance();
436                         AppAssert(pSceneManager);
437
438                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
439                 }
440                 break;
441
442         case IDA_BUTTON_CHECKED:
443                 {
444                         int itemCount = 0;
445                         int count = 0;
446                         int checkedItemCount = 0;
447                         int localGroup = 0;
448                         int localItem = 0;
449                         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
450                         String countText;
451
452                         itemCount = __pTableView->GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
453
454                         __pTableView->UpdateTableView();
455
456                         for (count = 0; count < itemCount; count++)
457                         {
458                                 localGroup = ID_GROUP_RESET_SETTING_MAIN;
459                                 localItem = count;
460                                 __pTableView->SetItemChecked(localGroup, localItem, true);
461
462                                 if (__pTableView->IsItemChecked(localGroup, localItem))
463                                 {
464                                         checkedItemCount++;
465                                 }
466                         }
467                         countText.Format(STRING_SIZE_LIMIT, L" (%d)", checkedItemCount);
468                         itemSelectedText.Insert(countText, itemSelectedText.GetLength());
469
470                         __pLabelItemCount->SetText(itemSelectedText);
471                         __pLabelItemCount->SetShowState(true);
472                         __pLabelItemCount->Invalidate(true);
473
474                         __count = TICK_COUNT;
475                         __timer.Start(MESSAGE_TIME_OUT);
476                 }
477                 break;
478
479         case IDA_RESET:
480                 // fall through
481         case IDA_BUTTON_UNCHECKED:
482                 {
483                         int itemCount = 0;
484                         int count = 0;
485                         int localGroup = 0;
486                         int localItem = 0;
487
488                         itemCount = __pTableView->GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
489
490                         __pTableView->UpdateTableView();
491                         __pCheckButton->SetSelected(false);
492
493                         for (count = 0; count < itemCount; count++)
494                         {
495                                 localGroup = ID_GROUP_RESET_SETTING_MAIN;
496                                 localItem = count;
497
498                                 __pTableView->SetItemChecked(localGroup, localItem, false);
499                         }
500                 }
501                 break;
502
503         default:
504                 {
505                         AppLogDebug("Reset setting");
506                 }
507                 break;
508         }
509 }
510
511 void
512 ResetterSettingForm::OnTimerExpired(Timer& timer)
513 {
514         if (__count > 0)
515         {
516                 __count--;
517         }
518         else
519         {
520                 __count = 0;
521         }
522
523         if (__count <= 0)
524         {
525                 __bTimerExpired = true;
526                 __pLabelItemCount->SetShowState(false);
527                 __pLabelItemCount->Invalidate(true);
528         }
529         else
530         {
531                 __timer.Start(MESSAGE_TIME_OUT);
532         }
533 }
534
535 bool
536 ResetterSettingForm::IsTimerExpired() const
537 {
538         return __bTimerExpired;
539 }
540
541 int
542 ResetterSettingForm::GetDefaultGroupItemHeight(void)
543 {
544         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
545 }
546
547 int
548 ResetterSettingForm::GetDefaultItemHeight(void)
549 {
550         return H_GROUP_ITEM_DEFAULT;
551 }
552
553 void
554 ResetterSettingForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
555 {
556 }
557
558 void
559 ResetterSettingForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
560 {
561 }
562
563 void
564 ResetterSettingForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
565 {
566 }
567
568 void
569 ResetterSettingForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
570 {
571 }