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 SettingInfo::GetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, __previousSelectedLanguage);
71 return SettingInfo::AddSettingEventListener(*this);
75 LocaleLanguageForm::OnTerminating(void)
77 SettingInfo::RemoveSettingEventListener(*this);
80 delete __pLanguageDataList;
81 __pLanguageDataList = null;
83 SetFormBackEventListener(null);
88 LocaleLanguageForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
94 __pLanguageDataList = static_cast<ArrayList*>(pArgs->GetItemsN(0, pArgs->GetCount()));
96 __pTableView->UpdateTableView();
100 LocaleLanguageForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
105 LocaleLanguageForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
107 SceneManager* pSceneManager = SceneManager::GetInstance();
108 AppAssert(pSceneManager);
110 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
114 LocaleLanguageForm::GetGroupCount(void)
116 // Temporary code due to the UI Framework defect
117 if (!__pLanguageDataList)
122 AppLogDebug("ENTER");
123 return ID_GROUP_COUNT;
127 LocaleLanguageForm::GetItemCount(int groupIndex)
129 // Temporary code due to the UI Framework defect
130 if (!__pLanguageDataList)
135 int itemCount = __pLanguageDataList->GetCount();
137 AppLogDebug("GetItemCount %d", itemCount);
143 LocaleLanguageForm::CreateGroupItem(int groupIndex, int itemWidth)
145 AppLogDebug("ENTER");
147 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
148 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
149 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
150 Rectangle itemMainRectangle;
152 Label* pLabel = null;
154 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
156 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
157 itemHeight = Y_GROUP_DEFAULT;
159 ItemTypeOneLine(itemMainRectangle);
161 RelativeLayout relativeLayout;
162 relativeLayout.Construct();
164 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
165 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
167 pLabel = new (std::nothrow) Label();
168 pLabel->Construct(itemMainRectangle, groupText);
169 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
170 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
171 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
172 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
174 pItem->AddControl(pLabel);
175 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
176 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
177 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
178 pItem->SetEnabled(false);
184 LocaleLanguageForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
186 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
188 Rectangle itemMainRectangle;
189 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
191 String fontReturnValue;
192 Label* pLabel = null;
193 int fontSize = GetFontSize();
194 TableViewItem* pItem = new (std::nothrow) TableViewItem();
195 String* pKey = static_cast<String*>(__pLanguageDataList->GetAt(itemIndex));
197 ItemTypeOneLine(itemMainRectangle);
198 if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
200 itemMainRectangle.height = itemMainRectangle.height + H_FONT_HEIGHT_GAP;
202 itemWidth = itemMainRectangle.width;
204 if (pKey && pKey->GetLength() > 0)
206 StringTokenizer stringTokenizer(*pKey, L"/");
207 stringTokenizer.GetNextToken(itemMainText);
210 RelativeLayout relativeLayout;
211 relativeLayout.Construct();
213 pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
214 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
216 pLabel = new (std::nothrow) Label();
217 pLabel->Construct(itemMainRectangle, itemMainText);
218 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
220 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
221 pLabel->SetTextColor(COLOR_MAIN_TEXT);
223 pItem->AddControl(pLabel);
224 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
225 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
226 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
232 LocaleLanguageForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
234 AppLogDebug("ENTER");
243 LocaleLanguageForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
245 AppLogDebug("ENTER");
254 LocaleLanguageForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
256 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
258 SceneManager* pSceneManager = SceneManager::GetInstance();
259 AppAssert(pSceneManager);
261 bool ttsStatus = false;
262 result r = E_FAILURE;
265 String* pKey = static_cast<String*>(__pLanguageDataList->GetAt(itemIndex));
267 StringTokenizer stringTokenizer(*pKey, L"/");
269 for (int i = 0; i <= (stringTokenizer.GetTokenCount()); i++)
271 stringTokenizer.GetNextToken(langCode);
274 r = SettingInfo::GetValue(SETTING_INFO_KEY_TTS, ttsStatus);
275 if (r == E_SUCCESS && ttsStatus)
277 if (langCode.CompareTo(L"eng_GB") != 0 && langCode.CompareTo(L"eng_PH") != 0 && langCode.CompareTo(L"eng_US") != 0
278 && langCode.CompareTo(L"spa_ES") != 0 && langCode.CompareTo(L"spa_MX") !=0
279 && langCode.CompareTo(L"fra_CA") != 0 && langCode.CompareTo(L"fra_FR") != 0
280 && langCode.CompareTo(L"deu_DE") != 0 && langCode.CompareTo(L"ita_IT") != 0 && langCode.CompareTo(L"kor_KR") != 0)
282 // 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
283 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
288 if(langCode.CompareTo(__previousSelectedLanguage) != 0)
290 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, langCode) != E_SUCCESS)
292 AppLogDebug("set langCode[%ls] result[%s]", langCode.GetPointer(), GetErrorMessage(GetLastResult()));
297 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
300 __previousSelectedLanguage = langCode;
304 LocaleLanguageForm::OnSettingChanged(Tizen::Base::String& key)
306 if (key.Equals(SETTING_INFO_KEY_LOCALE_LANGUAGE, false))
308 SceneManager* pSceneManager = SceneManager::GetInstance();
309 AppAssert(pSceneManager);
311 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
316 LocaleLanguageForm::GetDefaultGroupItemHeight(void)
318 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
322 LocaleLanguageForm::GetDefaultItemHeight(void)
324 return H_GROUP_ITEM_DEFAULT;
328 LocaleLanguageForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
333 LocaleLanguageForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
338 LocaleLanguageForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
343 LocaleLanguageForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)