Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StMoreSystemForm.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                StMoreSystemForm.cpp
19  * @brief               This is the implementation file for MoreSystemForm class.
20  */
21
22 #include <FSystem.h>
23 #include "StMoreSystemForm.h"
24 #include "StResourceManager.h"
25 #include "StSettingScenesList.h"
26 #include "StTypes.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::System;
31 using namespace Tizen::Ui;
32 using namespace Tizen::Ui::Controls;
33 using namespace Tizen::Ui::Scenes;
34
35 static const int ID_GROUP_SYSTEM = 0;
36 static const int ID_GROUP_SYSTEM_ITEM_COUNT = 8;
37 static const int ID_ITEM_SYSTEM_FONT = 0;
38 static const int ID_ITEM_SYSTEM_AUTO_ROTATE_SCREEN = 1;
39 static const int ID_ITEM_SYSTEM_DATE_AND_TIME = 2;
40 static const int ID_ITEM_SYSTEM_LANGUAGE_AND_REGION = 3;
41 static const int ID_ITEM_SYSTEM_KEYBOARD = 4;
42 static const int ID_ITEM_SYSTEM_MANAGE_APPLICATION = 5;
43 static const int ID_ITEM_SYSTEM_DEVELOPER_OPTIONS = 6;
44 static const int ID_ITEM_SYSTEM_ABOUT_PHONE = 7;
45
46 static const int ID_GROUP_COUNT = 1;
47 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_SYSTEM_ITEM_COUNT;
48
49 static const int W_RESIZE_LABEL_GAP = 150;
50
51 MoreSystemForm::MoreSystemForm(void)
52 {
53 }
54
55 MoreSystemForm::~MoreSystemForm(void)
56 {
57 }
58
59 void
60 MoreSystemForm::CreateFooter(void)
61 {
62         Footer* pFooter = GetFooter();
63         AppAssert(pFooter);
64
65         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
66         pFooter->SetBackButton();
67         pFooter->AddActionEventListener(*this);
68
69         SetFormBackEventListener(this);
70 }
71
72 result
73 MoreSystemForm::OnInitializing(void)
74 {
75         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MORE_SYSTEM_SETTINGS"));
76         CreateFooter();
77         CreateTableView();
78         SettingInfo::AddSettingEventListener(*this);
79         AppLogDebug("ENTER");
80         return E_SUCCESS;
81 }
82
83 result
84 MoreSystemForm::OnTerminating(void)
85 {
86         __pTableView = null;
87         SettingInfo::RemoveSettingEventListener(*this);
88         SetFormBackEventListener(null);
89         return E_SUCCESS;
90 }
91
92 void
93 MoreSystemForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
94 {
95         bool autoRotation = false;
96
97         Header* pHeader = GetHeader();
98         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_ST_BODY_MORE_SYSTEM_SETTINGS"));
99
100         __pTableView->Draw(true);
101
102         if (SettingInfo::GetValue(SETTING_INFO_KEY_SCREEN_ROTAION_AUTO, autoRotation) == E_SUCCESS)
103         {
104                 __pTableView->SetItemChecked(ID_GROUP_SYSTEM, ID_ITEM_SYSTEM_AUTO_ROTATE_SCREEN, autoRotation);
105         }
106 }
107
108 void
109 MoreSystemForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
110 {
111 }
112
113 void
114 MoreSystemForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
115 {
116         SceneManager* pSceneManager = SceneManager::GetInstance();
117         AppAssert(pSceneManager);
118
119         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
120 }
121
122 int
123 MoreSystemForm::GetGroupCount(void)
124 {
125         AppLogDebug("ENTER");
126         return ID_GROUP_COUNT;
127 }
128
129 int
130 MoreSystemForm::GetItemCount(int groupIndex)
131 {
132         int itemCount = ID_GROUP_MAX_ITEM_COUNT;
133
134         AppLogDebug("GetItemCount %d", itemCount);
135
136         return itemCount;
137 }
138
139 TableViewGroupItem*
140 MoreSystemForm::CreateGroupItem(int groupIndex, int itemWidth)
141 {
142         AppLogDebug("GroupIndex [%d]", groupIndex);
143
144         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
145         LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
146         Rectangle itemRectangle;
147         String groupText;
148         Label* pLabel = null;
149
150         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
151
152         itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
153         itemRectangle.y = Y_GROUP_ITEM_DEFAULT_LABEL;
154         itemRectangle.width = itemWidth;
155         itemRectangle.height = itemHeight;
156
157         RelativeLayout relativeLayout;
158         relativeLayout.Construct();
159
160         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
161         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
162
163         pLabel = new (std::nothrow) Label();
164         pLabel->Construct(itemRectangle, groupText);
165         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
166         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
167         pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
168
169         pItem->AddControl(pLabel);
170         relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
171         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
172         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
173         pItem->SetEnabled(false);
174
175         return pItem;
176 }
177
178 TableViewItem*
179 MoreSystemForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
180 {
181         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
182
183         Rectangle itemRectIcon;
184         Rectangle itemRectLabel;
185         Rectangle itemRectIconAndLabel;
186         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
187         Bitmap* pBitmap = null;
188         String itemText;
189         Label* pLabel = null;
190         int fontSize = GetFontSize();
191
192         TableViewItem* pItem = new (std::nothrow) TableViewItem();
193
194         ItemTypeIconAndOneLine(itemRectIcon, itemRectLabel);
195
196         switch (itemIndex)
197         {
198         case ID_ITEM_SYSTEM_FONT:
199                 {
200                         pBitmap = ResourceManager::GetBitmapN(IDB_FONT);
201                 }
202                 break;
203
204         case ID_ITEM_SYSTEM_AUTO_ROTATE_SCREEN:
205                 {
206                         style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
207                         itemRectLabel.width -= W_RESIZE_LABEL_GAP;
208                         pBitmap = ResourceManager::GetBitmapN(IDB_AUTO_ROTATE_SCREEN);
209                 }
210                 break;
211
212         case ID_ITEM_SYSTEM_DATE_AND_TIME:
213                 {
214                         pBitmap = ResourceManager::GetBitmapN(IDB_DATE_AND_TIME);
215                 }
216                 break;
217
218         case ID_ITEM_SYSTEM_LANGUAGE_AND_REGION:
219                 {
220                         pBitmap = ResourceManager::GetBitmapN(IDB_LANGUAGE_KEYBOARD);
221                 }
222                 break;
223
224         case ID_ITEM_SYSTEM_KEYBOARD:
225                 {
226                         pBitmap = ResourceManager::GetBitmapN(IDB_LANGUAGE_KEYBOARD);
227                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_KEYBOARD");
228                 }
229                 break;
230
231         case ID_ITEM_SYSTEM_MANAGE_APPLICATION:
232                 {
233                         pBitmap = ResourceManager::GetBitmapN(IDB_MANAGE_APPLICATION);
234                 }
235                 break;
236
237         case ID_ITEM_SYSTEM_DEVELOPER_OPTIONS:
238                 {
239                         pBitmap = ResourceManager::GetBitmapN(IDB_DEVELOPER_OPTION);
240                 }
241                 break;
242
243         case ID_ITEM_SYSTEM_ABOUT_PHONE:
244                 {
245                         pBitmap = ResourceManager::GetBitmapN(IDB_ABOUT_PHONE);
246                 }
247                 break;
248
249         default:
250                 break;
251         }
252
253         itemText = GetTableViewItemString(groupIndex, itemIndex);
254
255         RelativeLayout relativeLayout;
256         relativeLayout.Construct();
257
258         pItem->Construct(relativeLayout, Dimension(itemWidth, itemRectLabel.height), style);
259         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
260
261         if (pBitmap == null)
262         {
263                 pLabel = new (std::nothrow) Label();
264                 pLabel->Construct(itemRectLabel, itemText);
265                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
266                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
267                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
268
269                 pItem->AddControl(pLabel);
270                 if (style == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
271                 {
272                         relativeLayout.SetMargin(*pLabel, itemRectLabel.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
273                 }
274                 else
275                 {
276                         relativeLayout.SetMargin(*pLabel, itemRectLabel.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
277                 }
278                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
279                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
280         }
281         else
282         {
283                 pLabel = new (std::nothrow) Label();
284                 pLabel->Construct(itemRectIcon, L"");
285                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
286                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
287                 pLabel->SetBackgroundBitmap(*pBitmap);
288
289                 pItem->AddControl(pLabel);
290
291                 pLabel = new (std::nothrow) Label();
292                 pLabel->Construct(itemRectLabel, itemText);
293                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
294                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
295                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
296
297                 pItem->AddControl(pLabel);
298                 if (style == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
299                 {
300                         relativeLayout.SetMargin(*pLabel, itemRectLabel.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
301                 }
302                 else
303                 {
304                         relativeLayout.SetMargin(*pLabel, itemRectLabel.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
305                 }
306                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
307                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
308         }
309
310         return pItem;
311 }
312
313 bool
314 MoreSystemForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
315 {
316         AppLogDebug("ENTER");
317
318         delete pItem;
319         pItem = null;
320
321         return true;
322 }
323
324 bool
325 MoreSystemForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
326 {
327         AppLogDebug("ENTER");
328
329         delete pItem;
330         pItem = null;
331
332         return true;
333 }
334
335 void
336 MoreSystemForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
337 {
338         const wchar_t* pSceneName(L"");
339         SceneManager* pSceneManager = SceneManager::GetInstance();
340         AppAssert(pSceneManager);
341
342         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
343
344         switch (itemIndex)
345         {
346         case ID_ITEM_SYSTEM_FONT:
347                 {
348                         pSceneName = IDSCN_FONT;
349                 }
350                 break;
351
352         case ID_ITEM_SYSTEM_AUTO_ROTATE_SCREEN:
353                 {
354                         bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
355
356                         if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
357                         {
358                                 itemSelectStatus = !itemSelectStatus;
359                         }
360
361                         if (SettingInfo::SetValue(SETTING_INFO_KEY_SCREEN_ROTAION_AUTO, itemSelectStatus) == E_SUCCESS)
362                         {
363                                 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
364                         }
365                 }
366                 break;
367
368         case ID_ITEM_SYSTEM_DATE_AND_TIME:
369                 {
370                         pSceneName = IDSCN_DATE_TIME;
371                 }
372                 break;
373
374         case ID_ITEM_SYSTEM_LANGUAGE_AND_REGION:
375                 {
376                         pSceneName = IDSCN_LOCALE;
377                 }
378                 break;
379
380         case ID_ITEM_SYSTEM_KEYBOARD:
381                 {
382                         pSceneName = IDSCN_KEYBOARD;
383                 }
384                 break;
385
386         case ID_ITEM_SYSTEM_MANAGE_APPLICATION:
387                 {
388                         pSceneName = IDSCN_MANAGE_APPLICATION;
389                 }
390                 break;
391
392         case ID_ITEM_SYSTEM_DEVELOPER_OPTIONS:
393                 {
394                         pSceneName = IDSCN_DEVELOPER_OPTION;
395                 }
396                 break;
397
398         case ID_ITEM_SYSTEM_ABOUT_PHONE:
399                 {
400                         pSceneName = IDSCN_PHONE_INFO;
401                 }
402                 break;
403
404         default:
405                 {
406                         pSceneName = L"";
407                         AppLogDebug("Default Case");
408                 }
409                 break;
410         }
411
412         if (pSceneName != null)
413         {
414                 pSceneManager->GoForward(ForwardSceneTransition(pSceneName, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
415         }
416 }
417
418 int
419 MoreSystemForm::GetDefaultGroupItemHeight(void)
420 {
421         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
422 }
423
424 int
425 MoreSystemForm::GetDefaultItemHeight (void)
426 {
427         return H_GROUP_ITEM_DEFAULT;
428 }
429
430 void
431 MoreSystemForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
432 {
433 }
434
435 void
436 MoreSystemForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
437 {
438         String itemText;
439         int fontSize = GetFontSize();
440         Rectangle iconRect;
441         Rectangle oneLineRect;
442         Rectangle pItemBounds = pItem->GetBounds();
443
444         ItemTypeIconAndOneLine(iconRect, oneLineRect);
445
446         pItemBounds.height = oneLineRect.height;
447
448         pItem->SetBounds(pItemBounds);
449
450         Label* pLabel = static_cast<Label*>(pItem->GetControl(1));
451         itemText = GetTableViewItemString(groupIndex, itemIndex);
452
453         pLabel->SetBounds(oneLineRect);
454         pLabel->SetText(itemText);
455         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
456
457         pLabel->Invalidate(false);
458
459         Invalidate(true);
460 }
461
462 void
463 MoreSystemForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
464 {
465 }
466
467 void
468 MoreSystemForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
469 {
470 }
471
472 Tizen::Base::String
473 MoreSystemForm::GetTableViewItemString(int groupIndex, int itemIndex)
474 {
475         String itemText;
476
477         switch (itemIndex)
478         {
479         case ID_ITEM_SYSTEM_FONT:
480                 {
481                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_FONT");
482                 }
483                 break;
484
485         case ID_ITEM_SYSTEM_AUTO_ROTATE_SCREEN:
486                 {
487                         itemText = ResourceManager::GetString(L"IDS_ST_HEADER_AUTO_ROTATE_SCREEN_ABB");
488                 }
489                 break;
490
491         case ID_ITEM_SYSTEM_DATE_AND_TIME:
492                 {
493                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_DATE_AND_TIME");
494                 }
495                 break;
496
497         case ID_ITEM_SYSTEM_LANGUAGE_AND_REGION:
498                 {
499                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_LANGUAGE_AND_REGION_ABB");
500                 }
501                 break;
502
503         case ID_ITEM_SYSTEM_KEYBOARD:
504                 {
505                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_KEYBOARD");
506                 }
507                 break;
508
509         case ID_ITEM_SYSTEM_MANAGE_APPLICATION:
510                 {
511                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_MANAGE_APPLICATIONS");
512                 }
513                 break;
514
515         case ID_ITEM_SYSTEM_DEVELOPER_OPTIONS:
516                 {
517                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_DEVELOPER_OPTIONS");
518                 }
519                 break;
520
521         case ID_ITEM_SYSTEM_ABOUT_PHONE:
522                 {
523                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_ABOUT_PHONE");
524                 }
525                 break;
526
527         default:
528                 {
529                         itemText = L"";
530                 }
531                 break;
532         }
533         return itemText;
534 }
535
536 void
537 MoreSystemForm::RefreshGroupItemAt(int groupIndex)
538 {
539         int itemCount = __pTableView->GetItemCountAt(groupIndex);
540
541         for (int count = 0; count < itemCount; count++)
542         {
543                 __pTableView->RefreshItem(groupIndex, count, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
544         }
545 }
546
547 void
548 MoreSystemForm::OnSettingChanged (Tizen::Base::String &key)
549 {
550         AppLogDebug("MoreSystemForm::key changed [%ls]", key.GetPointer());
551
552         if (key.Equals(SETTING_INFO_KEY_FONT_SIZE, false)
553                 ||key.Equals(SETTING_INFO_KEY_FONT_TYPE, false)
554                 ||key.Equals(SETTING_INFO_KEY_LOCALE_LANGUAGE, false))
555         {
556                 int groupCount = __pTableView->GetGroupCount();
557
558                 for (int count = 0; count < groupCount; count++)
559                 {
560                         RefreshGroupItemAt(count);
561                 }
562         }
563 }