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 StDisplayForm.cpp
19 * @brief This is the implementation file for DisplayForm class.
23 #include "StDisplayForm.h"
24 #include "StResourceManager.h"
25 #include "StSettingScenesList.h"
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;
35 static const int W_RESIZE_LABEL_GAP = 110;
36 static const int RELATIVE_LAYOUT_ITEM_RIGHT_MARGIN = 140;
38 static const int BACKLIGHT_TIME_15_SECONDS = 15;
39 static const int BACKLIGHT_TIME_30_SECONDS = 30;
40 static const int BACKLIGHT_TIME_1_MINUTE = 60;
41 static const int BACKLIGHT_TIME_2_MINUTES = 120;
42 static const int BACKLIGHT_TIME_5_MINUTES = 300;
43 static const int BACKLIGHT_TIME_10_MINUTES = 600;
45 static const int ID_GROUP_AUTO_ROTATE_SCREEN = 0;
46 static const int ID_ITEM_AUTO_ROTATE_SCREEN = 0;
48 static const int ID_GROUP_BACKLIGHT_TIME = 1;
49 static const int ID_ITEM_BACKLIGHT_TIME = 0;
51 static const int ID_GROUP_BACKLIGHT_TIME_LIST = 2;
52 static const int ID_GROUP_BACKLIGHT_TIME_LIST_ITEM_COUNT = 6;
53 static const int ID_ITEM_BACKLIGHT_TIME_15_SECONDS = 0;
54 static const int ID_ITEM_BACKLIGHT_TIME_30_SECONDS = 1;
55 static const int ID_ITEM_BACKLIGHT_TIME_1_MINUTE = 2;
56 static const int ID_ITEM_BACKLIGHT_TIME_2_MINUTES = 3;
57 static const int ID_ITEM_BACKLIGHT_TIME_5_MINUTES = 4;
58 static const int ID_ITEM_BACKLIGHT_TIME_10_MINUTES = 5;
60 static const int ID_GROUP_FONT = 3;
61 static const int ID_ITEM_FONT = 0;
63 static const int ID_GROUP_DISPLAY_MAX_COUNT = 6;
64 static const int ID_GROUP_DEFAULT_ITEM_COUNT = 1;
66 static const int ID_GROUP_COUNT = 4;
67 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_DISPLAY_MAX_COUNT;
69 DisplayForm::DisplayForm(void)
73 DisplayForm::~DisplayForm(void)
78 DisplayForm::CreateFooter(void)
80 Footer* pFooter = GetFooter();
83 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
84 pFooter->SetBackButton();
85 pFooter->AddActionEventListener(*this);
87 SetFormBackEventListener(this);
91 DisplayForm::OnInitializing(void)
93 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_DISPLAY"));
103 DisplayForm::OnTerminating(void)
107 SetFormBackEventListener(null);
112 DisplayForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
114 if (previousSceneId == IDSCN_FONT)
116 __pTableView->RefreshAllItems();
119 __pTableView->UpdateTableView();
121 bool autoRotation = false;
122 if (SettingInfo::GetValue(SETTING_INFO_KEY_SCREEN_ROTAION_AUTO, autoRotation) == E_SUCCESS)
124 __pTableView->SetItemChecked(ID_GROUP_AUTO_ROTATE_SCREEN, ID_ITEM_AUTO_ROTATE_SCREEN, autoRotation);
126 __pTableView->SetItemChecked(ID_GROUP_BACKLIGHT_TIME_LIST, GetBackLightTimeIndex(), true);
127 __pTableView->CollapseGroup(ID_GROUP_BACKLIGHT_TIME_LIST);
131 DisplayForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
136 DisplayForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
138 SceneManager* pSceneManager = SceneManager::GetInstance();
139 AppAssert(pSceneManager);
141 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
145 DisplayForm::GetGroupCount(void)
147 AppLogDebug("ENTER");
148 return ID_GROUP_COUNT;
152 DisplayForm::GetItemCount(int groupIndex)
154 int itemCount = ID_GROUP_DEFAULT_ITEM_COUNT;
156 if (groupIndex == ID_GROUP_BACKLIGHT_TIME_LIST)
158 itemCount = ID_GROUP_BACKLIGHT_TIME_LIST_ITEM_COUNT;
160 AppLogDebug("GetItemCount %d", itemCount);
166 DisplayForm::CreateGroupItem(int groupIndex, int itemWidth)
168 AppLogDebug("ENTER");
170 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
171 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
172 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
173 Rectangle itemMainRectangle;
175 Label* pLabel = null;
177 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
179 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
180 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
182 if (groupIndex == ID_GROUP_BACKLIGHT_TIME_LIST)
188 itemMainRectangle.x = X_GROUP_INDEX_DEFAULT_LABEL;
189 itemMainRectangle.y = yItemOffset;
190 itemMainRectangle.width = itemWidth;
191 itemMainRectangle.height = itemHeight;
193 RelativeLayout relativeLayout;
194 relativeLayout.Construct();
196 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
197 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
199 pLabel = new (std::nothrow) Label();
200 pLabel->Construct(itemMainRectangle, groupText);
201 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
202 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
203 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
204 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
206 pItem->AddControl(pLabel);
207 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
208 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
209 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
210 pItem->SetEnabled(false);
216 DisplayForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
218 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
220 Rectangle itemMainRectangle;
221 Rectangle itemSubRectangle;
222 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
225 Label* pLabel = null;
226 int fontSize = GetFontSize();
229 Rectangle detailArrow;
230 Bitmap* pBitmap = null;
232 TableViewItem* pItem = new (std::nothrow) TableViewItem();
234 ItemTypeOneLine(itemMainRectangle);
235 itemHeight = itemMainRectangle.height;
239 case ID_GROUP_AUTO_ROTATE_SCREEN:
241 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
242 itemMainRectangle.width -= W_RESIZE_LABEL_GAP;
243 itemMainText = ResourceManager::GetString(L"IDS_ST_HEADER_AUTO_ROTATE_SCREEN_ABB");
247 case ID_GROUP_BACKLIGHT_TIME:
249 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle,fontSize);
250 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
252 if (__pTableView->IsGroupExpanded(ID_GROUP_BACKLIGHT_TIME_LIST) == false)
254 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_OPENED);
258 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_CLOSED);
261 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_BACKLIGHT_TIME");
262 int index = GetBackLightTimeIndex();
263 subText = GetBackLightTimeIndexString(index);
267 case ID_GROUP_BACKLIGHT_TIME_LIST:
269 style = TABLE_VIEW_ANNEX_STYLE_RADIO;
270 itemMainText = GetBackLightTimeIndexString(itemIndex);
276 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONT");
284 RelativeLayout relativeLayout;
285 relativeLayout.Construct();
287 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
288 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
290 pLabel = new (std::nothrow) Label();
291 pLabel->Construct(itemMainRectangle, itemMainText);
292 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
293 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
294 pLabel->SetTextColor(COLOR_MAIN_TEXT);
296 pItem->AddControl(pLabel);
300 case TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING:
302 rightMargin = RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING;
306 case TABLE_VIEW_ANNEX_STYLE_RADIO:
308 leftMargin = RELATIVE_LAYOUT_LEFT_MARGIN;
309 rightMargin = RELATIVE_LAYOUT_ITEM_RIGHT_MARGIN;
315 rightMargin = RELATIVE_LAYOUT_ITEM_RIGHT_MARGIN;
319 relativeLayout.SetMargin(*pLabel, leftMargin, rightMargin, 0, 0);
320 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
321 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
325 detailArrow = itemMainRectangle;
326 detailArrow.y = itemMainRectangle.y + ((itemHeight - W_DETAIL_ARROW_BUTTON) / DIVIDE_BY_TWO);
327 detailArrow.height = W_DETAIL_ARROW_BUTTON;
328 detailArrow.width = W_DETAIL_ARROW_BUTTON;
330 pLabel = new (std::nothrow) Label();
331 pLabel->Construct(detailArrow, L"");
333 pLabel->SetBackgroundBitmap(*pBitmap);
335 pItem->AddControl(pLabel);
336 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_DETAIL_ARROW_BUTTON, 0, 0);
337 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
339 pLabel = new (std::nothrow) Label();
340 pLabel->Construct(itemSubRectangle, subText);
341 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
342 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
343 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
344 pLabel->SetTextColor(COLOR_SUB_TEXT);
346 pItem->AddControl(pLabel);
347 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
348 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
349 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
356 DisplayForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
358 AppLogDebug("ENTER");
367 DisplayForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
369 AppLogDebug("ENTER");
378 DisplayForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
380 AppLogDebug("ENTER");
381 AppLogDebug("RequestFrom[%d]", requestId);
382 if (requestId == FRFRESH_REQUEST_EVENT)
384 int itemCount = __pTableView->GetItemCountAt(ID_GROUP_BACKLIGHT_TIME_LIST);
386 for (int index = 0; index < itemCount; index++)
388 if (index == GetBackLightTimeIndex())
390 __pTableView->SetItemChecked(ID_GROUP_BACKLIGHT_TIME_LIST, index, true);
394 __pTableView->SetItemChecked(ID_GROUP_BACKLIGHT_TIME_LIST, index, false);
397 __pTableView->UpdateTableView();
402 DisplayForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
404 SceneManager* pSceneManager = SceneManager::GetInstance();
405 AppAssert(pSceneManager);
407 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
411 case ID_GROUP_AUTO_ROTATE_SCREEN:
413 bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
415 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
417 itemSelectStatus = !itemSelectStatus;
420 if (SettingInfo::SetValue(SETTING_INFO_KEY_SCREEN_ROTAION_AUTO, itemSelectStatus) == E_SUCCESS)
422 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
427 case ID_GROUP_BACKLIGHT_TIME:
429 if (tableView.IsGroupExpanded(ID_GROUP_BACKLIGHT_TIME_LIST) == true)
431 tableView.CollapseGroup(ID_GROUP_BACKLIGHT_TIME_LIST);
435 tableView.ExpandGroup(ID_GROUP_BACKLIGHT_TIME_LIST);
437 tableView.RefreshItem(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
441 case ID_GROUP_BACKLIGHT_TIME_LIST:
443 SetBackLightTime(itemIndex);
445 int itemCount = tableView.GetItemCountAt(groupIndex);
447 for (int index = 0; index < itemCount; index++)
449 if (index == itemIndex)
451 tableView.SetItemChecked(groupIndex, index, true);
455 tableView.SetItemChecked(groupIndex, index, false);
458 tableView.RefreshItem(ID_GROUP_BACKLIGHT_TIME, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
464 SceneManager* pSceneManager = SceneManager::GetInstance();
465 AppAssert(pSceneManager);
467 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FONT, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
477 DisplayForm::GetDefaultGroupItemHeight(void)
479 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
483 DisplayForm::GetDefaultItemHeight(void)
485 return H_GROUP_ITEM_DEFAULT;
489 DisplayForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
494 DisplayForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
499 Label* pSubLabel = null;
505 case ID_GROUP_AUTO_ROTATE_SCREEN:
507 case ID_GROUP_BACKLIGHT_TIME_LIST:
509 int fontSize = GetFontSize();
510 Label* pLabel = static_cast<Label*>(pItem->GetControl(0));
512 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
513 pLabel->Invalidate(false);
517 case ID_GROUP_BACKLIGHT_TIME:
519 Bitmap* pBitmap = null;
520 Label* pLabel = static_cast<Label*>(pItem->GetControl(0));
521 Label* pLabelBitmap = static_cast<Label*>(pItem->GetControl(1));
522 pSubLabel = static_cast<Label*>(pItem->GetControl(2));
524 int fontSize = GetFontSize();
525 Rectangle mainRectangle;
526 Rectangle subRectangle;
527 Rectangle pItemRectangle;
528 Rectangle detailArrow;
530 pItemRectangle = pItem->GetBounds();
531 ItemTypeTwoLine(mainRectangle, subRectangle, fontSize);
533 pLabel->SetBounds(mainRectangle);
534 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
536 pItemRectangle.height = (mainRectangle.height + subRectangle.height);
537 pItem->SetBounds(pItemRectangle);
539 if (__pTableView->IsGroupExpanded(ID_GROUP_BACKLIGHT_TIME_LIST))
541 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_OPENED);
545 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_CLOSED);
547 pLabelBitmap->SetBackgroundBitmap(*pBitmap);
549 detailArrow = mainRectangle;
550 detailArrow.y = mainRectangle.y + ((pItemRectangle.height - W_DETAIL_ARROW_BUTTON) / DIVIDE_BY_TWO);
551 detailArrow.height = W_DETAIL_ARROW_BUTTON;
552 detailArrow.width = W_DETAIL_ARROW_BUTTON;
553 pLabelBitmap->SetBounds(detailArrow);
555 index = GetBackLightTimeIndex();
556 itemSubText = GetBackLightTimeIndexString(index);
557 pSubLabel->SetBounds(subRectangle);
558 pSubLabel->SetText(itemSubText);
559 pSubLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
561 pLabel->Invalidate(false);
562 pLabelBitmap->Invalidate(false);
563 pSubLabel->Invalidate(false);
564 pItem->Invalidate(false);
573 DisplayForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
578 DisplayForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
583 DisplayForm::GetBackLightTime(void)
585 int backlightTime = 0;
587 result r = SettingInfo::GetValue(SETTING_INFO_KEY_BACKLIGHT_TIME, backlightTime);
590 AppLogDebug("GetValue Backlight Time fail [%s]", GetErrorMessage(r));
592 return backlightTime;
596 DisplayForm::SetBackLightTime(int itemIndex)
598 int backlightTime = 0;
601 case ID_ITEM_BACKLIGHT_TIME_15_SECONDS:
603 backlightTime = BACKLIGHT_TIME_15_SECONDS;
607 case ID_ITEM_BACKLIGHT_TIME_30_SECONDS:
609 backlightTime = BACKLIGHT_TIME_30_SECONDS;
613 case ID_ITEM_BACKLIGHT_TIME_1_MINUTE:
615 backlightTime = BACKLIGHT_TIME_1_MINUTE;
619 case ID_ITEM_BACKLIGHT_TIME_2_MINUTES:
621 backlightTime = BACKLIGHT_TIME_2_MINUTES;
625 case ID_ITEM_BACKLIGHT_TIME_5_MINUTES:
627 backlightTime = BACKLIGHT_TIME_5_MINUTES;
631 case ID_ITEM_BACKLIGHT_TIME_10_MINUTES:
633 backlightTime = BACKLIGHT_TIME_10_MINUTES;
638 result r = SettingInfo::SetValue(SETTING_INFO_KEY_BACKLIGHT_TIME, backlightTime);
641 AppLogDebug("SetValue Backlight Time fail [%s]", GetErrorMessage(r));
646 DisplayForm::GetBackLightTimeIndex(void)
649 int backlightTime = GetBackLightTime();
651 switch (backlightTime)
653 case BACKLIGHT_TIME_15_SECONDS:
655 itemIndex = ID_ITEM_BACKLIGHT_TIME_15_SECONDS;
659 case BACKLIGHT_TIME_30_SECONDS:
661 itemIndex = ID_ITEM_BACKLIGHT_TIME_30_SECONDS;
665 case BACKLIGHT_TIME_1_MINUTE:
667 itemIndex = ID_ITEM_BACKLIGHT_TIME_1_MINUTE;
671 case BACKLIGHT_TIME_2_MINUTES:
673 itemIndex = ID_ITEM_BACKLIGHT_TIME_2_MINUTES;
677 case BACKLIGHT_TIME_5_MINUTES:
679 itemIndex = ID_ITEM_BACKLIGHT_TIME_5_MINUTES;
683 case BACKLIGHT_TIME_10_MINUTES:
685 itemIndex = ID_ITEM_BACKLIGHT_TIME_10_MINUTES;
694 DisplayForm::GetBackLightTimeIndexString(int itemIndex)
700 case ID_ITEM_BACKLIGHT_TIME_15_SECONDS:
702 itemText = ResourceManager::GetString(L"IDS_ST_BODY_15_SECONDS");
706 case ID_ITEM_BACKLIGHT_TIME_30_SECONDS:
708 itemText = ResourceManager::GetString(L"IDS_ST_BODY_30_SECONDS");
712 case ID_ITEM_BACKLIGHT_TIME_1_MINUTE:
714 itemText = ResourceManager::GetString(L"IDS_ST_BODY_1_MINUTE");
718 case ID_ITEM_BACKLIGHT_TIME_2_MINUTES:
720 itemText = ResourceManager::GetString(L"IDS_ST_BODY_2_MINUTES");
724 case ID_ITEM_BACKLIGHT_TIME_5_MINUTES:
726 itemText = ResourceManager::GetString(L"IDS_ST_BODY_5_MINUTES");
730 case ID_ITEM_BACKLIGHT_TIME_10_MINUTES:
732 itemText = ResourceManager::GetString(L"IDS_ST_BODY_10_MINUTES");