2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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 itemRectangle;
109 Rectangle itemSelectCount;
111 String itemText = 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 itemRectangle = itemSelectCount = bounds;
119 itemRectangle.y = Y_GROUP_DEFAULT;
120 itemRectangle.height = H_GROUP_ITEM_DEFAULT;
122 __pCheckButton = new (std::nothrow) CheckButton();
123 __pCheckButton->Construct(itemRectangle, CHECK_BUTTON_STYLE_MARK, BACKGROUND_STYLE_NONE, false);
124 __pCheckButton->SetActionId(IDA_BUTTON_CHECKED, IDA_BUTTON_UNCHECKED, IDA_BUTTON_SELECTED);
125 __pCheckButton->SetText(itemText);
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 CreateHeader(ResourceManager::GetString(L"IDS_ST_HEADER_RESET_SETTINGS"));
169 AppLogDebug("ENTER");
175 ResetterSettingForm::OnTerminating(void)
177 __pLabelItemCount = null;
178 __pCheckButton = null;
185 ResetterSettingForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
187 __pTableView->UpdateTableView();
191 ResetterSettingForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
196 ResetterSettingForm::GetGroupCount(void)
198 AppLogDebug("ENTER");
199 return ID_GROUP_COUNT;
203 ResetterSettingForm::GetItemCount(int groupIndex)
205 int itemCount = ID_GROUP_MAX_ITEM_COUNT;
207 AppLogDebug("GetItemCount %d", itemCount);
213 ResetterSettingForm::CreateGroupItem(int groupIndex, int itemWidth)
215 AppLogDebug("ENTER");
221 ResetterSettingForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
223 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
225 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
226 Rectangle itemRectangle;
228 Label* pLabel = null;
229 int fontSize = GetFontSize();
233 case ID_ITEM_LOCATION:
235 itemText = ResourceManager::GetString(L"IDS_ST_BODY_LOCATIONS");
239 case ID_ITEM_NETWORK:
241 itemText = ResourceManager::GetString(L"IDS_ST_BODY_NETWORK");
245 case ID_ITEM_WIFI_DIRECT:
247 itemText = ResourceManager::GetString(L"IDS_ST_HEADER_WI_FI_DIRECT");
251 case ID_ITEM_WALLPAPER:
253 itemText = ResourceManager::GetString(L"IDS_ST_BODY_MAINDISPLAY_WALLPAPER");
259 itemText = ResourceManager::GetString(L"IDS_ST_BODY_SOUNDS");
263 case ID_ITEM_BRIGHTNESS:
265 itemText = ResourceManager::GetString(L"IDS_ST_BODY_BRIGHTNESS");
271 itemText = ResourceManager::GetString(L"IDS_ST_BODY_FONT");
275 case ID_ITEM_DISPLAY:
277 itemText = ResourceManager::GetString(L"IDS_ST_BODY_DISPLAY");
281 case ID_ITEM_AUTO_ROTATE_SCREEN:
283 itemText = ResourceManager::GetString(L"IDS_ST_HEADER_AUTO_ROTATE_SCREEN_ABB");
287 case ID_ITEM_DATE_TIME:
289 itemText = ResourceManager::GetString(L"IDS_ST_BODY_DATE_AND_TIME");
293 case ID_ITEM_LANGUAGE_REGION:
295 itemText = ResourceManager::GetString(L"IDS_ST_BODY_LANGUAGE_AND_REGION_ABB");
299 case ID_ITEM_KEYBOARD:
301 itemText = ResourceManager::GetString(L"IDS_ST_BODY_KEYBOARD");
305 case ID_ITEM_MANAGE_APPLICATION:
307 itemText = ResourceManager::GetString(L"IDS_ST_BODY_MANAGE_APPLICATIONS");
313 itemText = ResourceManager::GetString(L"IDS_ST_BODY_MEMORY");
317 case ID_ITEM_DEVELOPER_OPTION:
319 itemText = ResourceManager::GetString(L"IDS_ST_BODY_DEVELOPER_OPTIONS");
323 case ID_ITEM_ABOUT_PHONE:
325 itemText = ResourceManager::GetString(L"IDS_ST_BODY_ABOUT_PHONE");
333 ItemTypeOneLine(itemRectangle);
335 TableViewItem* pItem = new (std::nothrow) TableViewItem();
337 RelativeLayout relativeLayout;
338 relativeLayout.Construct();
340 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
341 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
343 pLabel = new (std::nothrow) Label();
344 pLabel->Construct(itemRectangle, itemText);
345 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
346 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_BOLD);
347 pLabel->SetTextColor(COLOR_MAIN_TEXT);
349 pItem->AddControl(*pLabel);
351 relativeLayout.SetMargin(*pLabel, itemRectangle.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);
359 ResetterSettingForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
361 AppLogDebug("ENTER");
370 ResetterSettingForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
372 AppLogDebug("ENTER");
381 ResetterSettingForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
385 int checkedItemCount = 0;
388 String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
391 itemCount = tableView.GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
393 if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
395 tableView.SetItemChecked(groupIndex, itemIndex, true);
398 if (status == TABLE_VIEW_ITEM_STATUS_UNCHECKED)
400 tableView.SetItemChecked(groupIndex, itemIndex, false);
403 for (count = 0; count < itemCount; count++)
405 localGroup = ID_GROUP_RESET_SETTING_MAIN;
408 if (__pTableView->IsItemChecked(localGroup, localItem))
414 if (checkedItemCount)
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);
422 __count = TICK_COUNT;
423 __timer.Start(MESSAGE_TIME_OUT);
428 ResetterSettingForm::OnActionPerformed(const Control& source, int actionId)
430 AppLogDebug("Action ID = [%d]", actionId);
435 SceneManager* pSceneManager = SceneManager::GetInstance();
436 AppAssert(pSceneManager);
438 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
442 case IDA_BUTTON_CHECKED:
446 int checkedItemCount = 0;
449 String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
452 itemCount = __pTableView->GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
454 __pTableView->UpdateTableView();
456 for (count = 0; count < itemCount; count++)
458 localGroup = ID_GROUP_RESET_SETTING_MAIN;
460 __pTableView->SetItemChecked(localGroup, localItem, true);
462 if (__pTableView->IsItemChecked(localGroup, localItem))
467 countText.Format(STRING_SIZE_LIMIT, L" (%d)", checkedItemCount);
468 itemSelectedText.Insert(countText, itemSelectedText.GetLength());
470 __pLabelItemCount->SetText(itemSelectedText);
471 __pLabelItemCount->SetShowState(true);
472 __pLabelItemCount->Invalidate(true);
474 __count = TICK_COUNT;
475 __timer.Start(MESSAGE_TIME_OUT);
481 case IDA_BUTTON_UNCHECKED:
488 itemCount = __pTableView->GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
490 __pTableView->UpdateTableView();
491 __pCheckButton->SetSelected(false);
493 for (count = 0; count < itemCount; count++)
495 localGroup = ID_GROUP_RESET_SETTING_MAIN;
498 __pTableView->SetItemChecked(localGroup, localItem, false);
505 AppLogDebug("Reset setting");
512 ResetterSettingForm::OnTimerExpired(Timer& timer)
525 __bTimerExpired = true;
526 __pLabelItemCount->SetShowState(false);
527 __pLabelItemCount->Invalidate(true);
531 __timer.Start(MESSAGE_TIME_OUT);
536 ResetterSettingForm::IsTimerExpired() const
538 return __bTimerExpired;
542 ResetterSettingForm::GetDefaultGroupItemHeight(void)
544 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
548 ResetterSettingForm::GetDefaultItemHeight(void)
550 return H_GROUP_ITEM_DEFAULT;
554 ResetterSettingForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
559 ResetterSettingForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
564 ResetterSettingForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
569 ResetterSettingForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)