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 FontSizeForm::FontSizeForm(void)
55 : __isAppControlRequest(false)
56 , __categoryCheck(L"")
60 FontSizeForm::~FontSizeForm(void)
65 FontSizeForm::CreateFooter(void)
67 Footer* pFooter = GetFooter();
70 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
71 pFooter->SetBackButton();
72 pFooter->AddActionEventListener(*this);
74 SetFormBackEventListener(this);
78 FontSizeForm::OnInitializing(void)
80 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_FONT_SIZE"));
90 FontSizeForm::OnTerminating(void)
94 SetFormBackEventListener(null);
99 FontSizeForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
102 String fontReturnValue;
106 __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
108 if ((__categoryCheck == L"category:FontType") || (__categoryCheck == L"category:FontSize"))
110 __isAppControlRequest = true;
115 __pTableView->UpdateTableView();
117 if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, fontReturnValue) == E_SUCCESS)
119 if (fontReturnValue.Equals(L"giant", false))
121 itemSelect = ID_ITEM_FONT_SIZE_GIANT;
123 else if (fontReturnValue.Equals(L"huge", false))
125 itemSelect = ID_ITEM_FONT_SIZE_HUGE;
127 else if (fontReturnValue.Equals(L"large", false))
129 itemSelect = ID_ITEM_FONT_SIZE_LARGE;
131 else if (fontReturnValue.Equals(L"medium", false))
133 itemSelect = ID_ITEM_FONT_SIZE_NORMAL;
137 itemSelect = ID_ITEM_FONT_SIZE_SMALL;
139 __pTableView->SetItemChecked(ID_GROUP_FONT_SIZE, itemSelect, true);
144 FontSizeForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
149 FontSizeForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
151 SceneManager* pSceneManager = SceneManager::GetInstance();
152 AppAssert(pSceneManager);
154 if (__isAppControlRequest == true)
156 UiApp* pApp = UiApp::GetInstance();
158 AppControlFontResult();
163 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
168 FontSizeForm::GetGroupCount(void)
170 AppLogDebug("ENTER");
171 return ID_GROUP_COUNT;
175 FontSizeForm::GetItemCount(int groupIndex)
179 if (groupIndex != ID_GROUP_FONT_TEXT)
181 itemCount = ID_GROUP_MAX_ITEM_COUNT;
184 AppLogDebug("GetItemCount %d", itemCount);
190 FontSizeForm::CreateGroupItem(int groupIndex, int itemWidth)
192 AppLogDebug("ENTER");
194 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
195 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
196 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
197 Rectangle itemMainRectangle;
198 int fontSize = GetFontSize();
200 Label* pLabel = null;
202 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
206 case ID_GROUP_FONT_SIZE:
208 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
209 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
213 case ID_GROUP_FONT_TEXT:
215 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP / DIVIDE_BT_TWO ;
216 groupText = ResourceManager::GetString(L"IDS_ST_BODY_CHANGING_THE_FONT_SIZE_IN_ACCESSIBILITY_SETTINGS_WILL_OVERRIDE_THE_FONT_SIZE_IN_EACH_APPLICATION");
217 itemHeight = GetHeightForStringArea(groupText, itemWidth, fontSize) + H_GROUP_INDEX_HELP_TEXT_GAP;
223 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
224 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
229 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
230 itemMainRectangle.y = yItemOffset;
231 itemMainRectangle.width = itemWidth;
232 itemMainRectangle.height = itemHeight;
234 RelativeLayout relativeLayout;
235 relativeLayout.Construct();
237 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
238 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
240 pLabel = new (std::nothrow) Label();
241 pLabel->Construct(itemMainRectangle, groupText);
242 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
243 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
244 pLabel->SetTextConfig(fontSize, style);
245 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
247 pItem->AddControl(pLabel);
248 pItem->SetEnabled(false);
249 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 0, 0, 0);
250 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
251 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
257 FontSizeForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
259 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
261 Rectangle itemMainRectangle;
262 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_RADIO;
264 String fontReturnValue;
265 Label* pLabel = null;
266 int fontSize = FONT_MAIN_TEXT_SIZE_NORMAL;
267 TableViewItem* pItem = new (std::nothrow) TableViewItem();
269 if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, fontReturnValue) == E_SUCCESS)
271 AppLogDebug("GetValue Fail [%s]", GetErrorMessage(GetLastResult()));
276 case ID_ITEM_FONT_SIZE_GIANT:
278 fontSize = FONT_MAIN_TEXT_SIZE_GIANT;
279 itemMainText = ResourceManager::GetString(L"IDS_EMAIL_POP_GIANT_M_TEXTSIZE");
281 if (fontReturnValue.Equals(L"giant", false))
283 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
288 case ID_ITEM_FONT_SIZE_HUGE:
290 fontSize = FONT_MAIN_TEXT_SIZE_HUGE;
291 itemMainText = ResourceManager::GetString(L"IDS_EMAIL_OPT_HUGE_M_TEXTSIZE");
293 if (fontReturnValue.Equals(L"huge", false))
295 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
300 case ID_ITEM_FONT_SIZE_LARGE:
302 fontSize = FONT_MAIN_TEXT_SIZE_LARGE;
303 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_TEXTSTYLE_LARGE");
305 if (fontReturnValue.Equals(L"large", false))
307 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
312 case ID_ITEM_FONT_SIZE_NORMAL:
314 fontSize = FONT_MAIN_TEXT_SIZE_NORMAL;
315 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONTTYPE_NORMAL");
317 if (fontReturnValue.Equals(L"medium", false))
319 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
324 case ID_ITEM_FONT_SIZE_SMALL:
326 fontSize = FONT_MAIN_TEXT_SIZE_SMALL;
327 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SMALL_M_TEXTSIZE");
329 if (fontReturnValue.Equals(L"small", false))
331 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
340 ItemTypeOneLine(itemMainRectangle);
341 itemMainRectangle.height = itemMainRectangle.height + H_GROUP_INDEX_HELP_TEXT_GAP;
343 RelativeLayout relativeLayout;
344 relativeLayout.Construct();
346 pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
347 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
349 pLabel = new (std::nothrow) Label();
350 pLabel->Construct(itemMainRectangle, itemMainText);
351 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
353 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
354 pLabel->SetTextColor(COLOR_MAIN_TEXT);
356 pItem->AddControl(pLabel);
357 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
358 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
359 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
365 FontSizeForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
367 AppLogDebug("ENTER");
376 FontSizeForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
378 AppLogDebug("ENTER");
387 FontSizeForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
389 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
391 String fontSize(L"medium");
395 case ID_ITEM_FONT_SIZE_GIANT:
401 case ID_ITEM_FONT_SIZE_HUGE:
407 case ID_ITEM_FONT_SIZE_LARGE:
413 case ID_ITEM_FONT_SIZE_NORMAL:
415 fontSize = L"medium";
419 case ID_ITEM_FONT_SIZE_SMALL:
429 int itemCount = tableView.GetItemCountAt(ID_GROUP_FONT_SIZE);
430 for (int count = 0; count < itemCount; count++)
432 int localGroup = ID_GROUP_FONT_SIZE;
433 int localItem = count;
435 if (count == itemIndex)
437 tableView.SetItemChecked(localGroup, localItem, true);
438 SettingInfo::SetValue(SETTING_INFO_KEY_FONT_SIZE, fontSize);
442 tableView.SetItemChecked(localGroup, localItem, false);
446 __pTableView->ScrollToItem(groupIndex, itemIndex);
450 FontSizeForm::GetDefaultGroupItemHeight(void)
452 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
456 FontSizeForm::GetDefaultItemHeight(void)
458 return H_GROUP_ITEM_DEFAULT;
462 FontSizeForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
464 if (groupIndex != ID_GROUP_FONT_TEXT)
466 AppLogDebug("groupIndex is not ID_GROUP_FONT_TEXT");
470 Label* pLabel = static_cast<Label*>(pItem->GetControl(0));
473 AppLogDebug("pLabel is null");
477 Rectangle clientRect = GetClientAreaBounds();
478 Rectangle itemRect = pItem->GetBounds();
479 String groupText = pLabel->GetText();
480 int fontSize = GetFontSize();
481 int itemHeight = GetHeightForStringArea(groupText, clientRect.width, fontSize) + H_GROUP_INDEX_HELP_TEXT_GAP;
483 itemRect.height = itemHeight + H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
484 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
485 pLabel->SetBounds(clientRect.x, H_GROUP_INDEX_HELP_TEXT_TOP_GAP, clientRect.width, itemHeight);
486 pItem->SetBounds(itemRect);
491 FontSizeForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
496 FontSizeForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
501 FontSizeForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
506 FontSizeForm::RefreshAllItem(void)
508 int groupCount = __pTableView->GetGroupCount();
510 for (int count = 0; count < groupCount; count++)
512 RefreshGroupAt(count);
513 // RefreshGroupItemAt(count);
518 FontSizeForm::RefreshGroupAt(int groupIndex)
520 __pTableView->RefreshItem(groupIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
524 FontSizeForm::RefreshGroupItemAt(int groupIndex)
526 int itemCount = __pTableView->GetItemCountAt(groupIndex);
528 for (int count = 0; count < itemCount; count++)
530 __pTableView->RefreshItem(groupIndex, count, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
535 FontSizeForm::AppControlFontResult(void)
539 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
541 HashMap* hashMap = new (std::nothrow) HashMap();
542 hashMap->Construct();
544 if (__categoryCheck == L"category:FontType")
546 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, value);
547 hashMap->Add(*(new (std::nothrow) String(L"category")), *(new (std::nothrow) String(L"FontType")));
548 hashMap->Add(*(new (std::nothrow) String(L"type")), *(new (std::nothrow) String(value)));
550 else if (__categoryCheck == L"category:FontSize")
552 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, value);
553 hashMap->Add(*(new (std::nothrow) String(L"category")), *(new (std::nothrow) String(L"FontSize")));
554 hashMap->Add(*(new (std::nothrow) String(L"size")), *(new (std::nothrow) String(value)));
557 pAppManager->SendAppControlResult(reqId, APP_CTRL_RESULT_SUCCEEDED, hashMap);
559 hashMap->RemoveAll();
564 FontSizeForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
566 __pTableView->RefreshItem(ID_GROUP_FONT_TEXT, ID_GROUP_FONT_TEXT_LABEL, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);