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 StLanguageForm.cpp
19 * @brief This is the implementation file for LanguageForm class.
23 #include "StLanguageForm.h"
24 #include "StResourceManager.h"
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Base::Utility;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Locales;
33 using namespace Tizen::System;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
38 static const int ID_GROUP_LANGUAGE = 0;
39 static const int ID_GROUP_COUNT = 1;
40 static const int ITEM_WIDTH_GAP = 100;
41 static const int H_FONT_HEIGHT_GAP = 20;
43 LocaleLanguageForm::LocaleLanguageForm(void)
44 : __pLanguageDataList(null)
48 LocaleLanguageForm::~LocaleLanguageForm(void)
53 LocaleLanguageForm::CreateFooter(void)
55 Footer* pFooter = GetFooter();
58 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
59 pFooter->AddActionEventListener(*this);
61 SetFormBackEventListener(this);
65 LocaleLanguageForm::OnInitializing(void)
67 CreateHeader(ResourceManager::GetString(L"IDS_ST_HEADER_DISPLAY_LANGUAGE"));
70 return SettingInfo::AddSettingEventListener(*this);
74 LocaleLanguageForm::OnTerminating(void)
76 SettingInfo::RemoveSettingEventListener(*this);
79 delete __pLanguageDataList;
80 __pLanguageDataList = null;
82 SetFormBackEventListener(null);
87 LocaleLanguageForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
93 __pLanguageDataList = static_cast<ArrayList*>(pArgs->GetItemsN(0, pArgs->GetCount()));
95 __pTableView->UpdateTableView();
99 LocaleLanguageForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
104 LocaleLanguageForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
106 SceneManager* pSceneManager = SceneManager::GetInstance();
107 AppAssert(pSceneManager);
109 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
113 LocaleLanguageForm::GetGroupCount(void)
115 // Temporary code due to the UI Framework defect
116 if (!__pLanguageDataList)
121 AppLogDebug("ENTER");
122 return ID_GROUP_COUNT;
126 LocaleLanguageForm::GetItemCount(int groupIndex)
128 // Temporary code due to the UI Framework defect
129 if (!__pLanguageDataList)
134 int itemCount = __pLanguageDataList->GetCount();
136 AppLogDebug("GetItemCount %d", itemCount);
142 LocaleLanguageForm::CreateGroupItem(int groupIndex, int itemWidth)
144 AppLogDebug("ENTER");
146 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
147 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
148 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
149 Rectangle itemMainRectangle;
151 Label* pLabel = null;
153 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
155 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
156 itemHeight = Y_GROUP_DEFAULT;
158 ItemTypeOneLine(itemMainRectangle);
160 RelativeLayout relativeLayout;
161 relativeLayout.Construct();
163 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
164 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
166 pLabel = new (std::nothrow) Label();
167 pLabel->Construct(itemMainRectangle, groupText);
168 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
169 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
170 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
171 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
173 pItem->AddControl(pLabel);
174 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
175 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
176 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
177 pItem->SetEnabled(false);
183 LocaleLanguageForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
185 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
187 Rectangle itemMainRectangle;
188 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
190 String fontReturnValue;
191 Label* pLabel = null;
192 int fontSize = GetFontSize();
193 TableViewItem* pItem = new (std::nothrow) TableViewItem();
194 String* pKey = static_cast<String*>(__pLanguageDataList->GetAt(itemIndex));
196 ItemTypeOneLine(itemMainRectangle);
197 if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
199 itemMainRectangle.height = itemMainRectangle.height + H_FONT_HEIGHT_GAP;
201 itemWidth = itemMainRectangle.width;
203 if (pKey && pKey->GetLength() > 0)
205 StringTokenizer stringTokenizer(*pKey, L"/");
206 stringTokenizer.GetNextToken(itemMainText);
209 RelativeLayout relativeLayout;
210 relativeLayout.Construct();
212 pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
213 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
215 pLabel = new (std::nothrow) Label();
216 pLabel->Construct(itemMainRectangle, itemMainText);
217 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
219 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
220 pLabel->SetTextColor(COLOR_MAIN_TEXT);
222 pItem->AddControl(pLabel);
223 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
224 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
225 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
231 LocaleLanguageForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
233 AppLogDebug("ENTER");
242 LocaleLanguageForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
244 AppLogDebug("ENTER");
253 LocaleLanguageForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
255 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
257 SceneManager* pSceneManager = SceneManager::GetInstance();
258 AppAssert(pSceneManager);
260 bool ttsStatus = false;
261 result r = E_FAILURE;
264 String* pKey = static_cast<String*>(__pLanguageDataList->GetAt(itemIndex));
266 StringTokenizer stringTokenizer(*pKey, L"/");
268 for (int i = 0; i <= (stringTokenizer.GetTokenCount()); i++)
270 stringTokenizer.GetNextToken(langCode);
273 r = SettingInfo::GetValue(SETTING_INFO_KEY_TTS, ttsStatus);
274 if (r == E_SUCCESS && ttsStatus)
276 if (langCode.CompareTo(L"eng_GB") != 0 && langCode.CompareTo(L"eng_PH") != 0 && langCode.CompareTo(L"eng_US") != 0
277 && langCode.CompareTo(L"spa_ES") != 0 && langCode.CompareTo(L"spa_MX") !=0
278 && langCode.CompareTo(L"fra_CA") != 0 && langCode.CompareTo(L"fra_FR") != 0
279 && langCode.CompareTo(L"deu_DE") != 0 && langCode.CompareTo(L"ita_IT") != 0 && langCode.CompareTo(L"kor_KR") != 0)
281 // TTS on, language other than eng_GB, eng_PH, eng_US, spa_ES, spa_MX, fra_CA, fra_FR, deu_DE,ita_IT, kor_KR are not supported
282 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
287 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, langCode) != E_SUCCESS)
289 AppLogDebug("set langCode[%ls] result[%s]", langCode.GetPointer(), GetErrorMessage(GetLastResult()));
294 LocaleLanguageForm::OnSettingChanged(Tizen::Base::String& key)
296 if (key.Equals(SETTING_INFO_KEY_LOCALE_LANGUAGE, false))
298 SceneManager* pSceneManager = SceneManager::GetInstance();
299 AppAssert(pSceneManager);
301 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
306 LocaleLanguageForm::GetDefaultGroupItemHeight(void)
308 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
312 LocaleLanguageForm::GetDefaultItemHeight(void)
314 return H_GROUP_ITEM_DEFAULT;
318 LocaleLanguageForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
323 LocaleLanguageForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
328 LocaleLanguageForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
333 LocaleLanguageForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)