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 StFontSizeForm.cpp
19 * @brief This is the implementation file for FontSizeForm class.
22 #include "StFontSizeForm.h"
23 #include "StResourceManager.h"
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
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 ID_GROUP_FONT_SIZE = 0;
36 static const int ID_GROUP_FONT_ITEM_COUNT = 5;
37 static const int ID_ITEM_FONT_SIZE_GIANT = 0;
38 static const int ID_ITEM_FONT_SIZE_HUGE = 1;
39 static const int ID_ITEM_FONT_SIZE_LARGE = 2;
40 static const int ID_ITEM_FONT_SIZE_NORMAL = 3;
41 static const int ID_ITEM_FONT_SIZE_SMALL = 4;
43 static const int ID_GROUP_FONT_TEXT = 1;
44 static const int ID_GROUP_FONT_TEXT_LABEL = -1;
45 static const int ID_GROUP_FONT_TEXT_ITEM_COUNT = 0;
47 static const int ID_GROUP_COUNT = 2;
48 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_FONT_ITEM_COUNT;
50 static const int H_GROUP_INDEX_HELP_TEXT_GAP = 20;
52 static const int DIVIDE_BT_TWO = 2;
54 static const int BASE_FORM_DEFAULT_MARGIN = 32;
56 FontSizeForm::FontSizeForm(void)
57 : __isAppControlRequest(false)
58 , __categoryCheck(L"")
63 FontSizeForm::~FontSizeForm(void)
68 FontSizeForm::CreateFooter(void)
70 Footer* pFooter = GetFooter();
73 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
75 pFooter->AddActionEventListener(*this);
77 SetFormBackEventListener(this);
81 FontSizeForm::OnInitializing(void)
83 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_FONT_SIZE"));
92 FontSizeForm::OnTerminating(void)
96 SetFormBackEventListener(null);
101 FontSizeForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
104 String fontReturnValue;
108 __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
110 if ((__categoryCheck == L"category:FontType") || (__categoryCheck == L"category:FontSize"))
112 __isAppControlRequest = true;
117 __pTableView->UpdateTableView();
119 if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, fontReturnValue) == E_SUCCESS)
121 if (fontReturnValue.Equals(L"giant", false))
123 itemSelect = ID_ITEM_FONT_SIZE_GIANT;
124 __selectedFont = ID_ITEM_FONT_SIZE_GIANT;
126 else if (fontReturnValue.Equals(L"huge", false))
128 itemSelect = ID_ITEM_FONT_SIZE_HUGE;
129 __selectedFont = ID_ITEM_FONT_SIZE_HUGE;
131 else if (fontReturnValue.Equals(L"large", false))
133 itemSelect = ID_ITEM_FONT_SIZE_LARGE;
134 __selectedFont = ID_ITEM_FONT_SIZE_LARGE;
136 else if (fontReturnValue.Equals(L"medium", false))
138 itemSelect = ID_ITEM_FONT_SIZE_NORMAL;
139 __selectedFont = ID_ITEM_FONT_SIZE_NORMAL;
143 itemSelect = ID_ITEM_FONT_SIZE_SMALL;
144 __selectedFont = ID_ITEM_FONT_SIZE_SMALL;
146 __pTableView->SetItemChecked(ID_GROUP_FONT_SIZE, itemSelect, true);
151 FontSizeForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
156 FontSizeForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
158 SceneManager* pSceneManager = SceneManager::GetInstance();
159 AppAssert(pSceneManager);
161 if (__isAppControlRequest == true)
163 UiApp* pApp = UiApp::GetInstance();
165 AppControlFontResult();
170 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
175 FontSizeForm::GetGroupCount(void)
177 AppLogDebug("ENTER");
178 return ID_GROUP_COUNT;
182 FontSizeForm::GetItemCount(int groupIndex)
186 if (groupIndex != ID_GROUP_FONT_TEXT)
188 itemCount = ID_GROUP_MAX_ITEM_COUNT;
191 AppLogDebug("GetItemCount %d", itemCount);
197 FontSizeForm::CreateGroupItem(int groupIndex, int itemWidth)
199 AppLogDebug("ENTER");
201 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
202 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
203 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
204 Rectangle itemMainRectangle;
205 int fontSize = GetFontSize();
207 Label* pLabel = null;
209 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
213 case ID_GROUP_FONT_SIZE:
215 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
216 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
220 case ID_GROUP_FONT_TEXT:
222 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP / DIVIDE_BT_TWO ;
223 groupText = ResourceManager::GetString(L"IDS_ST_BODY_CHANGING_THE_FONT_SIZE_IN_ACCESSIBILITY_SETTINGS_WILL_OVERRIDE_THE_FONT_SIZE_IN_EACH_APPLICATION");
224 itemHeight = GetHeightForStringArea(groupText, itemWidth - BASE_FORM_DEFAULT_MARGIN, fontSize) + H_GROUP_INDEX_HELP_TEXT_GAP;
230 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
231 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
236 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
237 itemMainRectangle.y = yItemOffset;
238 itemMainRectangle.width = itemWidth;
239 itemMainRectangle.height = itemHeight;
241 RelativeLayout relativeLayout;
242 relativeLayout.Construct();
244 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
245 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
247 pLabel = new (std::nothrow) Label();
248 pLabel->Construct(itemMainRectangle, groupText);
249 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
250 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
251 pLabel->SetTextConfig(fontSize, style);
252 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
254 pItem->AddControl(pLabel);
255 pItem->SetEnabled(false);
256 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 0, 0, 0);
257 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
258 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
264 FontSizeForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
266 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
268 Rectangle itemMainRectangle;
269 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_RADIO;
271 String fontReturnValue;
272 Label* pLabel = null;
273 int fontSize = FONT_MAIN_TEXT_SIZE_NORMAL;
274 TableViewItem* pItem = new (std::nothrow) TableViewItem();
276 if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, fontReturnValue) == E_SUCCESS)
278 AppLogDebug("GetValue Fail [%s]", GetErrorMessage(GetLastResult()));
283 case ID_ITEM_FONT_SIZE_GIANT:
285 fontSize = FONT_MAIN_TEXT_SIZE_GIANT;
286 itemMainText = ResourceManager::GetString(L"IDS_EMAIL_POP_GIANT_M_TEXTSIZE");
288 if (fontReturnValue.Equals(L"giant", false))
290 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
291 __selectedFont = ID_ITEM_FONT_SIZE_GIANT;
296 case ID_ITEM_FONT_SIZE_HUGE:
298 fontSize = FONT_MAIN_TEXT_SIZE_HUGE;
299 itemMainText = ResourceManager::GetString(L"IDS_EMAIL_OPT_HUGE_M_TEXTSIZE");
301 if (fontReturnValue.Equals(L"huge", false))
303 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
304 __selectedFont = ID_ITEM_FONT_SIZE_HUGE;
309 case ID_ITEM_FONT_SIZE_LARGE:
311 fontSize = FONT_MAIN_TEXT_SIZE_LARGE;
312 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_TEXTSTYLE_LARGE");
314 if (fontReturnValue.Equals(L"large", false))
316 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
317 __selectedFont = ID_ITEM_FONT_SIZE_LARGE;
322 case ID_ITEM_FONT_SIZE_NORMAL:
324 fontSize = FONT_MAIN_TEXT_SIZE_NORMAL;
325 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONTTYPE_NORMAL");
327 if (fontReturnValue.Equals(L"medium", false))
329 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
330 __selectedFont = ID_ITEM_FONT_SIZE_NORMAL;
335 case ID_ITEM_FONT_SIZE_SMALL:
337 fontSize = FONT_MAIN_TEXT_SIZE_SMALL;
338 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SMALL_M_TEXTSIZE");
340 if (fontReturnValue.Equals(L"small", false))
342 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
343 __selectedFont = ID_ITEM_FONT_SIZE_SMALL;
352 ItemTypeOneLine(itemMainRectangle);
353 itemMainRectangle.height = itemMainRectangle.height + H_GROUP_INDEX_HELP_TEXT_GAP;
355 RelativeLayout relativeLayout;
356 relativeLayout.Construct();
358 pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
359 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
361 pLabel = new (std::nothrow) Label();
362 pLabel->Construct(itemMainRectangle, itemMainText);
363 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
365 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
366 pLabel->SetTextColor(COLOR_MAIN_TEXT);
368 pItem->AddControl(pLabel);
369 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
370 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
371 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
377 FontSizeForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
379 AppLogDebug("ENTER");
388 FontSizeForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
390 AppLogDebug("ENTER");
399 FontSizeForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
401 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
403 String fontSize(L"medium");
405 if (__selectedFont == itemIndex)
407 tableView.SetItemChecked(ID_GROUP_FONT_SIZE, itemIndex, true);
413 case ID_ITEM_FONT_SIZE_GIANT:
419 case ID_ITEM_FONT_SIZE_HUGE:
425 case ID_ITEM_FONT_SIZE_LARGE:
431 case ID_ITEM_FONT_SIZE_NORMAL:
433 fontSize = L"medium";
437 case ID_ITEM_FONT_SIZE_SMALL:
447 int itemCount = tableView.GetItemCountAt(ID_GROUP_FONT_SIZE);
448 for (int count = 0; count < itemCount; count++)
450 int localGroup = ID_GROUP_FONT_SIZE;
451 int localItem = count;
453 if (count == itemIndex)
455 tableView.SetItemChecked(localGroup, localItem, true);
456 if (SettingInfo::SetValue(SETTING_INFO_KEY_FONT_SIZE, fontSize) != E_SUCCESS)
458 AppLogDebug("SetValue Fail");
463 tableView.SetItemChecked(localGroup, localItem, false);
468 __pTableView->ScrollToItem(groupIndex, itemIndex);
469 __selectedFont = itemIndex;
473 FontSizeForm::GetDefaultGroupItemHeight(void)
475 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
479 FontSizeForm::GetDefaultItemHeight(void)
481 return H_GROUP_ITEM_DEFAULT;
485 FontSizeForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
487 if (groupIndex != ID_GROUP_FONT_TEXT)
489 AppLogDebug("groupIndex is not ID_GROUP_FONT_TEXT");
493 Label* pLabel = static_cast<Label*>(pItem->GetControl(0));
496 AppLogDebug("pLabel is null");
500 Rectangle clientRect = GetClientAreaBounds();
501 Rectangle itemRect = pItem->GetBounds();
502 String groupText = pLabel->GetText();
503 int fontSize = GetFontSize();
504 int itemHeight = GetHeightForStringArea(groupText, clientRect.width - BASE_FORM_DEFAULT_MARGIN, fontSize) + H_GROUP_INDEX_HELP_TEXT_GAP;
506 itemRect.height = itemHeight + H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
507 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
508 pLabel->SetBounds(clientRect.x, H_GROUP_INDEX_HELP_TEXT_TOP_GAP, clientRect.width, itemHeight);
509 pItem->SetBounds(itemRect);
514 FontSizeForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
519 FontSizeForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
524 FontSizeForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
529 FontSizeForm::RefreshAllItem(void)
531 int groupCount = __pTableView->GetGroupCount();
533 for (int count = 0; count < groupCount; count++)
535 RefreshGroupAt(count);
536 // RefreshGroupItemAt(count);
541 FontSizeForm::RefreshGroupAt(int groupIndex)
543 __pTableView->RefreshItem(groupIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
547 FontSizeForm::RefreshGroupItemAt(int groupIndex)
549 int itemCount = __pTableView->GetItemCountAt(groupIndex);
551 for (int count = 0; count < itemCount; count++)
553 __pTableView->RefreshItem(groupIndex, count, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
558 FontSizeForm::AppControlFontResult(void)
562 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
564 HashMap* hashMap = new (std::nothrow) HashMap();
565 hashMap->Construct();
567 if (__categoryCheck == L"category:FontType")
569 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, value);
570 hashMap->Add(*(new (std::nothrow) String(L"category")), *(new (std::nothrow) String(L"FontType")));
571 hashMap->Add(*(new (std::nothrow) String(L"type")), *(new (std::nothrow) String(value)));
573 else if (__categoryCheck == L"category:FontSize")
575 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, value);
576 hashMap->Add(*(new (std::nothrow) String(L"category")), *(new (std::nothrow) String(L"FontSize")));
577 hashMap->Add(*(new (std::nothrow) String(L"size")), *(new (std::nothrow) String(value)));
580 pAppManager->SendAppControlResult(reqId, APP_CTRL_RESULT_SUCCEEDED, hashMap);
582 hashMap->RemoveAll();
587 FontSizeForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
589 __pTableView->RefreshItem(ID_GROUP_FONT_TEXT, ID_GROUP_FONT_TEXT_LABEL, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);