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 StAccessibilityForm.cpp
19 * @brief This is the implementation file for AccessibilityForm class.
22 #include "StAccessibilityForm.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_SCREEN_READER = 0;
36 static const int ID_ITEM_SCREEN_READER = 0;
37 static const int ID_ITEM_RATE_SPEECH_RATE = 1;
38 static const int ID_GROUP_SCREEN_READER_ITEM_COUNT = 2;
40 static const int ID_GROUP_SPEECH_RATE_LIST = 1;
41 static const int ID_ITEM_RATE_SPEECH_RATE_VERY_SLOW = 0;
42 static const int ID_ITEM_RATE_SPEECH_RATE_SLOW = 1;
43 static const int ID_ITEM_RATE_SPEECH_RATE_NORMAL = 2;
44 static const int ID_ITEM_RATE_SPEECH_RATE_FAST = 3;
45 static const int ID_ITEM_RATE_SPEECH_RATE_VERY_FAST = 4;
46 static const int ID_GROUP_SPEECH_RATE_ITEM_COUNT = 5;
48 static const int ID_GROUP_SPEED_AT_WHICH_THE_TEXT_IS_SPOKEN = 2;
50 static const int ID_GROUP_COUNT = 3;
51 static const int REFRESH_GROUP_INDEX = -1;
53 AccessibilityForm::AccessibilityForm(void)
58 AccessibilityForm::~AccessibilityForm(void)
63 AccessibilityForm::CreateFooter(void)
65 Footer* pFooter = GetFooter();
68 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
69 pFooter->SetBackButton();
70 pFooter->AddActionEventListener(*this);
72 SetFormBackEventListener(this);
76 AccessibilityForm::OnInitializing(void)
78 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_ACCESSIBILITY"));
88 AccessibilityForm::OnTerminating(void)
92 SetFormBackEventListener(null);
97 AccessibilityForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
106 __pTableView->UpdateTableView();
108 bool ttsStatus = false;
109 if ((r = SettingInfo::GetValue(SETTING_INFO_KEY_TTS, ttsStatus)) != E_SUCCESS)
111 AppLogDebug("GetValue fail.. TTS Result [%s]", GetErrorMessage(r));
114 __pTableView->SetItemChecked(0, 0, ttsStatus);
117 if (SettingInfo::GetValue(SETTING_INFO_KEY_TTS_RATE, ttsRate) == E_SUCCESS)
119 AppLogDebug("GetValue Success.. TTS Rate Result [%s]", GetErrorMessage(r));
121 for (int count = 0; count < __pTableView->GetItemCountAt(ID_GROUP_SPEECH_RATE_LIST); count++)
123 bool check = ((count == ttsRate)?(true):(false));
124 __pTableView->SetItemChecked(ID_GROUP_SPEECH_RATE_LIST, count, check);
129 AppLogDebug("GetValue fail.. TTS Rate Result [%s]", GetErrorMessage(r));
131 __pTableView->CollapseGroup(ID_GROUP_SPEECH_RATE_LIST);
135 AccessibilityForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
140 AccessibilityForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
142 SceneManager* pSceneManager = SceneManager::GetInstance();
143 AppAssert(pSceneManager);
145 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
149 AccessibilityForm::GetGroupCount(void)
151 AppLogDebug("ENTER");
152 return ID_GROUP_COUNT;
156 AccessibilityForm::GetItemCount(int groupIndex)
162 case ID_GROUP_SCREEN_READER:
164 itemCount = ID_GROUP_SCREEN_READER_ITEM_COUNT;
168 case ID_GROUP_SPEECH_RATE_LIST:
170 itemCount = ID_GROUP_SPEECH_RATE_ITEM_COUNT;
177 AppLogDebug("GetItemCount %d", itemCount);
183 AccessibilityForm::CreateGroupItem(int groupIndex, int itemWidth)
185 AppLogDebug("ENTER");
187 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
188 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
189 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
190 Rectangle itemMainRectangle;
191 int fontSize = GetFontSize();
193 Label* pLabel = null;
195 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
199 case ID_GROUP_SPEED_AT_WHICH_THE_TEXT_IS_SPOKEN:
201 groupText = ResourceManager::GetString(L"IDS_ST_BODY_SPEED_AT_WHICH_THE_TEXT_IS_SPOKEN");
203 itemHeight = GetHeightForStringArea(groupText, itemWidth, fontSize);
215 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
216 itemMainRectangle.y = yItemOffset;
217 itemMainRectangle.width = itemWidth;
218 itemMainRectangle.height = itemHeight;
220 RelativeLayout relativeLayout;
221 relativeLayout.Construct();
223 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
224 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
226 pLabel = new (std::nothrow) Label();
227 pLabel->Construct(itemMainRectangle, groupText);
228 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
229 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
230 pLabel->SetTextConfig(fontSize, style);
231 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
233 pItem->AddControl(pLabel);
234 pItem->SetEnabled(false);
235 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 0, 0, 0);
236 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
237 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
243 AccessibilityForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
245 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
247 Rectangle itemMainRectangle;
248 Rectangle itemSubRectangle;
249 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
252 String fontReturnValue;
253 Label* pLabel = null;
254 int fontSize = GetFontSize();
256 TableViewItem* pItem = new (std::nothrow) TableViewItem();
258 ItemTypeOneLine(itemMainRectangle);
262 case ID_GROUP_SCREEN_READER:
266 case ID_ITEM_SCREEN_READER:
268 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
269 itemMainText = ResourceManager::GetString(L"IDS_ST_MBODY_SCREEN_READER_HTTS");
273 case ID_ITEM_RATE_SPEECH_RATE:
275 result r = E_FAILURE;
276 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
277 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SPEECH_RATE");
281 if ((r = SettingInfo::GetValue(SETTING_INFO_KEY_TTS_RATE, ttsRate)) == E_SUCCESS)
285 case ID_ITEM_RATE_SPEECH_RATE_VERY_SLOW:
287 itemSubText = ResourceManager::GetString(L"IDS_ST_POP_VERY_SLOW");
291 case ID_ITEM_RATE_SPEECH_RATE_SLOW:
293 itemSubText = ResourceManager::GetString(L"IDS_ST_POP_SLOW");
297 case ID_ITEM_RATE_SPEECH_RATE_NORMAL:
299 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_FONTTYPE_NORMAL");
303 case ID_ITEM_RATE_SPEECH_RATE_FAST:
305 itemSubText = ResourceManager::GetString(L"IDS_ST_POP_FAST");
309 case ID_ITEM_RATE_SPEECH_RATE_VERY_FAST:
311 itemSubText = ResourceManager::GetString(L"IDS_ST_POP_VERY_FAST");
321 AppLogDebug("GetValue Fail.. TTS rate Result[%s]", GetErrorMessage(r));
332 case ID_GROUP_SPEECH_RATE_LIST:
334 style = TABLE_VIEW_ANNEX_STYLE_RADIO;
335 startGap = RELATIVE_LAYOUT_LEFT_MARGIN;
339 case ID_ITEM_RATE_SPEECH_RATE_VERY_SLOW:
341 itemMainText = ResourceManager::GetString(L"IDS_ST_POP_VERY_SLOW");
345 case ID_ITEM_RATE_SPEECH_RATE_SLOW:
347 itemMainText = ResourceManager::GetString(L"IDS_ST_POP_SLOW");
351 case ID_ITEM_RATE_SPEECH_RATE_NORMAL:
353 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONTTYPE_NORMAL");
357 case ID_ITEM_RATE_SPEECH_RATE_FAST:
359 itemMainText = ResourceManager::GetString(L"IDS_ST_POP_FAST");
363 case ID_ITEM_RATE_SPEECH_RATE_VERY_FAST:
365 itemMainText = ResourceManager::GetString(L"IDS_ST_POP_VERY_FAST");
379 RelativeLayout relativeLayout;
380 relativeLayout.Construct();
382 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
383 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
385 pLabel = new (std::nothrow) Label();
386 pLabel->Construct(itemMainRectangle, itemMainText);
387 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
389 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
390 pLabel->SetTextColor(COLOR_MAIN_TEXT);
392 pItem->AddControl(pLabel);
394 if (style == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
396 relativeLayout.SetMargin(*pLabel, startGap, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
400 relativeLayout.SetMargin(*pLabel, startGap, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
402 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
403 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
405 if (itemSubText.IsEmpty() == false)
407 pLabel = new (std::nothrow) Label();
408 pLabel->Construct(itemSubRectangle, itemSubText);
409 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
410 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
411 pLabel->SetTextColor(COLOR_SUB_TEXT);
413 pItem->AddControl(pLabel);
415 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
416 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
417 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
424 AccessibilityForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
426 AppLogDebug("ENTER");
435 AccessibilityForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
437 AppLogDebug("ENTER");
446 AccessibilityForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
448 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
450 result r = E_FAILURE;
454 case ID_GROUP_SCREEN_READER:
458 case ID_ITEM_SCREEN_READER:
460 bool itemStatus = tableView.IsItemChecked(groupIndex, itemIndex);
462 if ((r = SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_TTS, itemStatus)) == E_SUCCESS)
464 tableView.SetItemChecked(groupIndex, itemIndex, itemStatus);
468 AppLogDebug("SetValue Fail.. TTS Result[%s]", GetErrorMessage(r));
473 case ID_ITEM_RATE_SPEECH_RATE:
475 if (tableView.IsGroupExpanded(ID_GROUP_SPEECH_RATE_LIST) == false)
477 tableView.ExpandGroup(ID_GROUP_SPEECH_RATE_LIST);
481 tableView.CollapseGroup(ID_GROUP_SPEECH_RATE_LIST);
492 case ID_GROUP_SPEECH_RATE_LIST:
494 int itemCount = tableView.GetItemCountAt(ID_GROUP_SPEECH_RATE_LIST);
496 for (int count = 0; count < itemCount; count++)
498 bool check = ((count == itemIndex)?(true):(false));
499 tableView.SetItemChecked(groupIndex, count, check);
503 r = SettingInfo::SetValue(SETTING_INFO_KEY_TTS_RATE, count);
504 AppLogDebug("SetValue. TTS Rate Result[%s] ", GetErrorMessage(r));
505 tableView.RefreshItem(ID_GROUP_SCREEN_READER, ID_ITEM_RATE_SPEECH_RATE, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
508 RefreshGroupItemAt(ID_GROUP_SPEECH_RATE_LIST);
518 AccessibilityForm::GetDefaultGroupItemHeight(void)
520 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
524 AccessibilityForm::GetDefaultItemHeight(void)
526 return H_GROUP_ITEM_DEFAULT;
530 AccessibilityForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
535 AccessibilityForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
539 case ID_GROUP_SCREEN_READER:
541 if (itemIndex == ID_ITEM_RATE_SPEECH_RATE)
543 result r = E_FAILURE;
544 Label* secondLine = static_cast<Label*>(pItem->GetControl(ID_ITEM_RATE_SPEECH_RATE));
549 if ((r = SettingInfo::GetValue(SETTING_INFO_KEY_TTS_RATE, ttsRate)) == E_SUCCESS)
553 case ID_ITEM_RATE_SPEECH_RATE_VERY_SLOW:
555 itemSubText = ResourceManager::GetString(L"IDS_ST_POP_VERY_SLOW");
556 secondLine->SetText(itemSubText);
560 case ID_ITEM_RATE_SPEECH_RATE_SLOW:
562 itemSubText = ResourceManager::GetString(L"IDS_ST_POP_SLOW");
563 secondLine->SetText(itemSubText);
567 case ID_ITEM_RATE_SPEECH_RATE_NORMAL:
569 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_FONTTYPE_NORMAL");
570 secondLine->SetText(itemSubText);
574 case ID_ITEM_RATE_SPEECH_RATE_FAST:
576 itemSubText = ResourceManager::GetString(L"IDS_ST_POP_FAST");
577 secondLine->SetText(itemSubText);
581 case ID_ITEM_RATE_SPEECH_RATE_VERY_FAST:
583 itemSubText = ResourceManager::GetString(L"IDS_ST_POP_VERY_FAST");
584 secondLine->SetText(itemSubText);
592 secondLine->Invalidate(false);
597 pItem->Invalidate(false);
602 case ID_GROUP_SPEECH_RATE_LIST:
604 pItem->Invalidate(false);
614 AccessibilityForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
619 AccessibilityForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
624 AccessibilityForm::RefreshAllItem(void)
626 int groupCount = __pTableView->GetGroupCount();
628 for (int count = 0; count < groupCount; count++)
630 RefreshGroupAt(count);
635 AccessibilityForm::RefreshGroupAt(int groupIndex)
637 __pTableView->RefreshItem(groupIndex, REFRESH_GROUP_INDEX, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
641 AccessibilityForm::RefreshGroupItemAt(int groupIndex)
643 int itemCount = __pTableView->GetItemCountAt(groupIndex);
645 for (int count = 0; count < itemCount; count++)
647 __pTableView->RefreshItem(groupIndex, count, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
652 AccessibilityForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)