2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file StResetSettingForm.cpp
19 * @brief This is the implementation file for ResetSettingForm class.
22 #include "StResetSettingForm.h"
23 #include "StResourceManager.h"
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;
34 static const int ID_GROUP_RESET_SETTING_MAIN = 0;
35 static const int ID_GROUP_RESET_SETTING_ITEM_COUNT = 16;
37 static const int ID_GROUP_COUNT = 1;
38 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_RESET_SETTING_ITEM_COUNT;
40 static const int IDA_RESET = 100;
41 static const int IDA_CANCEL = 101;
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;
48 static const int TICK_COUNT = 10;
49 static const int MESSAGE_TIME_OUT = 100;
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;
68 static const int STRING_SIZE_LIMIT = 20;
70 ResetterSettingForm::ResetterSettingForm(void)
71 : __bTimerExpired(false)
73 , __pLabelItemCount(null)
74 , __pCheckButton(null)
76 __timer.Construct(*this);
79 ResetterSettingForm::~ResetterSettingForm(void)
84 ResetterSettingForm::CreateFooter(void)
86 FooterItem footerReset;
87 FooterItem footerCancel;
89 Footer* pFooter = GetFooter();
92 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
94 footerReset.Construct(IDA_RESET);
95 footerReset.SetText(ResourceManager::GetString(L"IDS_ST_BODY_RESET"));
97 footerCancel.Construct(IDA_CANCEL);
98 footerCancel.SetText(ResourceManager::GetString(L"IDS_ST_BODY_CANCEL"));
100 pFooter->AddItem(footerReset);
101 pFooter->AddItem(footerCancel);
105 ResetterSettingForm::CreateTableView(void)
107 Rectangle bounds = GetClientAreaBounds();
108 Rectangle itemMainRectangle;
109 Rectangle itemSelectCount;
111 String itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SELECT_ALL");
112 String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
114 bounds.x = X_GROUP_DEFAULT;
115 bounds.y = H_GROUP_ITEM_DEFAULT;
116 bounds.width -= (bounds.x * WIDTH_GAP);
118 itemMainRectangle = itemSelectCount = bounds;
119 itemMainRectangle.y = Y_GROUP_DEFAULT;
120 itemMainRectangle.height = H_GROUP_ITEM_DEFAULT;
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);
127 AddControl(__pCheckButton);
129 __pCheckButton->AddActionEventListener(*this);
131 __pTableView = new (std::nothrow) GroupedTableView();
132 __pTableView->Construct(bounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FIXED);
133 __pTableView->SetItemProvider(this);
135 AddControl(__pTableView);
137 __pTableView->AddGroupedTableViewItemEventListener(*this);
139 itemSelectCount.y = Y_ITEM_COUNT_DISPLAY;
140 itemSelectCount.height = H_GROUP_INDEX_NO_TITLE_DEFAULT;
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);
148 AddControl(__pLabelItemCount);
150 __pLabelItemCount->SetBackgroundColor(COLOR_BG_CHECKBOX);
151 __pLabelItemCount->SetShowState(false);
153 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
154 if (pRelativeLayout != null)
156 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
157 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
158 delete pRelativeLayout;
163 ResetterSettingForm::OnInitializing(void)
165 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
166 CreateHeader(ResourceManager::GetString(L"IDS_ST_HEADER_RESET_SETTINGS"));
170 AppLogDebug("ENTER");
176 ResetterSettingForm::OnTerminating(void)
178 __pLabelItemCount = null;
179 __pCheckButton = null;
186 ResetterSettingForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
188 __pTableView->UpdateTableView();
192 ResetterSettingForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
197 ResetterSettingForm::GetGroupCount(void)
199 AppLogDebug("ENTER");
200 return ID_GROUP_COUNT;
204 ResetterSettingForm::GetItemCount(int groupIndex)
206 int itemCount = ID_GROUP_MAX_ITEM_COUNT;
208 AppLogDebug("GetItemCount %d", itemCount);
214 ResetterSettingForm::CreateGroupItem(int groupIndex, int itemWidth)
216 AppLogDebug("ENTER");
222 ResetterSettingForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
224 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
226 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
227 Rectangle itemMainRectangle;
229 Label* pLabel = null;
230 int fontSize = GetFontSize();
234 case ID_ITEM_LOCATION:
236 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_LOCATIONS");
240 case ID_ITEM_NETWORK:
242 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_NETWORK");
246 case ID_ITEM_WIFI_DIRECT:
248 itemMainText = ResourceManager::GetString(L"IDS_ST_HEADER_WI_FI_DIRECT");
252 case ID_ITEM_WALLPAPER:
254 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MAINDISPLAY_WALLPAPER");
260 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SOUNDS");
264 case ID_ITEM_BRIGHTNESS:
266 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_BRIGHTNESS");
272 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONT");
276 case ID_ITEM_DISPLAY:
278 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DISPLAY");
282 case ID_ITEM_AUTO_ROTATE_SCREEN:
284 itemMainText = ResourceManager::GetString(L"IDS_ST_HEADER_AUTO_ROTATE_SCREEN_ABB");
288 case ID_ITEM_DATE_TIME:
290 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DATE_AND_TIME");
294 case ID_ITEM_LANGUAGE_REGION:
296 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_LANGUAGE_AND_REGION_ABB");
300 case ID_ITEM_KEYBOARD:
302 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_KEYBOARD");
306 case ID_ITEM_MANAGE_APPLICATION:
308 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MANAGE_APPLICATIONS");
314 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MEMORY");
318 case ID_ITEM_DEVELOPER_OPTION:
320 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DEVELOPER_OPTIONS");
324 case ID_ITEM_ABOUT_PHONE:
326 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_ABOUT_PHONE");
334 ItemTypeOneLine(itemMainRectangle);
336 TableViewItem* pItem = new (std::nothrow) TableViewItem();
338 RelativeLayout relativeLayout;
339 relativeLayout.Construct();
341 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
342 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
344 pLabel = new (std::nothrow) Label();
345 pLabel->Construct(itemMainRectangle, itemMainText);
346 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
347 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_BOLD);
348 pLabel->SetTextColor(COLOR_MAIN_TEXT);
350 pItem->AddControl(pLabel);
352 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
353 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
354 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
360 ResetterSettingForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
362 AppLogDebug("ENTER");
371 ResetterSettingForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
373 AppLogDebug("ENTER");
382 ResetterSettingForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
386 int checkedItemCount = 0;
389 String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
392 itemCount = tableView.GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
394 if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
396 tableView.SetItemChecked(groupIndex, itemIndex, true);
399 if (status == TABLE_VIEW_ITEM_STATUS_UNCHECKED)
401 tableView.SetItemChecked(groupIndex, itemIndex, false);
404 for (count = 0; count < itemCount; count++)
406 localGroup = ID_GROUP_RESET_SETTING_MAIN;
409 if (__pTableView->IsItemChecked(localGroup, localItem))
415 if (checkedItemCount)
417 countText.Format(STRING_SIZE_LIMIT, L" (%d)", checkedItemCount);
418 itemSelectedText.Insert(countText, itemSelectedText.GetLength());
419 __pLabelItemCount->SetText(itemSelectedText);
420 __pLabelItemCount->SetShowState(true);
421 __pLabelItemCount->Invalidate(true);
423 __count = TICK_COUNT;
424 __timer.Start(MESSAGE_TIME_OUT);
429 ResetterSettingForm::OnActionPerformed(const Control& source, int actionId)
431 AppLogDebug("Action ID = [%d]", actionId);
436 SceneManager* pSceneManager = SceneManager::GetInstance();
437 AppAssert(pSceneManager);
439 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
443 case IDA_BUTTON_CHECKED:
447 int checkedItemCount = 0;
450 String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
453 itemCount = __pTableView->GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
455 __pTableView->UpdateTableView();
457 for (count = 0; count < itemCount; count++)
459 localGroup = ID_GROUP_RESET_SETTING_MAIN;
461 __pTableView->SetItemChecked(localGroup, localItem, true);
463 if (__pTableView->IsItemChecked(localGroup, localItem))
468 countText.Format(STRING_SIZE_LIMIT, L" (%d)", checkedItemCount);
469 itemSelectedText.Insert(countText, itemSelectedText.GetLength());
471 __pLabelItemCount->SetText(itemSelectedText);
472 __pLabelItemCount->SetShowState(true);
473 __pLabelItemCount->Invalidate(true);
475 __count = TICK_COUNT;
476 __timer.Start(MESSAGE_TIME_OUT);
482 case IDA_BUTTON_UNCHECKED:
489 itemCount = __pTableView->GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
491 __pTableView->UpdateTableView();
492 __pCheckButton->SetSelected(false);
494 for (count = 0; count < itemCount; count++)
496 localGroup = ID_GROUP_RESET_SETTING_MAIN;
499 __pTableView->SetItemChecked(localGroup, localItem, false);
506 AppLogDebug("Reset setting");
513 ResetterSettingForm::OnTimerExpired(Timer& timer)
526 __bTimerExpired = true;
527 __pLabelItemCount->SetShowState(false);
528 __pLabelItemCount->Invalidate(true);
532 __timer.Start(MESSAGE_TIME_OUT);
537 ResetterSettingForm::IsTimerExpired() const
539 return __bTimerExpired;
543 ResetterSettingForm::GetDefaultGroupItemHeight(void)
545 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
549 ResetterSettingForm::GetDefaultItemHeight(void)
551 return H_GROUP_ITEM_DEFAULT;
555 ResetterSettingForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
560 ResetterSettingForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
565 ResetterSettingForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
570 ResetterSettingForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)