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->SetBackButton();
60 pFooter->AddActionEventListener(*this);
62 SetFormBackEventListener(this);
66 LocaleLanguageForm::OnInitializing(void)
68 CreateHeader(ResourceManager::GetString(L"IDS_ST_HEADER_DISPLAY_LANGUAGE"));
72 return SettingInfo::AddSettingEventListener(*this);
76 LocaleLanguageForm::OnTerminating(void)
78 SettingInfo::RemoveSettingEventListener(*this);
81 delete __pLanguageDataList;
82 __pLanguageDataList = null;
84 SetFormBackEventListener(null);
89 LocaleLanguageForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
95 __pLanguageDataList = static_cast<ArrayList*>(pArgs->GetItemsN(0, pArgs->GetCount()));
97 __pTableView->UpdateTableView();
101 LocaleLanguageForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
106 LocaleLanguageForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
108 SceneManager* pSceneManager = SceneManager::GetInstance();
109 AppAssert(pSceneManager);
111 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
115 LocaleLanguageForm::GetGroupCount(void)
117 // Temporary code due to the UI Framework defect
118 if (!__pLanguageDataList)
123 AppLogDebug("ENTER");
124 return ID_GROUP_COUNT;
128 LocaleLanguageForm::GetItemCount(int groupIndex)
130 // Temporary code due to the UI Framework defect
131 if (!__pLanguageDataList)
136 int itemCount = __pLanguageDataList->GetCount();
138 AppLogDebug("GetItemCount %d", itemCount);
144 LocaleLanguageForm::CreateGroupItem(int groupIndex, int itemWidth)
146 AppLogDebug("ENTER");
148 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
149 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
150 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
151 Rectangle itemMainRectangle;
153 Label* pLabel = null;
155 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
157 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
158 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
160 ItemTypeOneLine(itemMainRectangle);
162 RelativeLayout relativeLayout;
163 relativeLayout.Construct();
165 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
166 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
168 pLabel = new (std::nothrow) Label();
169 pLabel->Construct(itemMainRectangle, groupText);
170 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
171 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
172 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
173 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
175 pItem->AddControl(pLabel);
176 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
177 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
178 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
179 pItem->SetEnabled(false);
185 LocaleLanguageForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
187 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
189 Rectangle itemMainRectangle;
190 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
192 String fontReturnValue;
193 Label* pLabel = null;
194 int fontSize = GetFontSize();
195 TableViewItem* pItem = new (std::nothrow) TableViewItem();
196 String* pKey = static_cast<String*>(__pLanguageDataList->GetAt(itemIndex));
198 ItemTypeOneLine(itemMainRectangle);
199 if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
201 itemMainRectangle.height = itemMainRectangle.height + H_FONT_HEIGHT_GAP;
203 itemWidth = itemMainRectangle.width;
205 StringTokenizer stringTokenizer(*pKey, L"/");
206 stringTokenizer.GetNextToken(itemMainText);
208 RelativeLayout relativeLayout;
209 relativeLayout.Construct();
211 pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
212 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
214 pLabel = new (std::nothrow) Label();
215 pLabel->Construct(itemMainRectangle, itemMainText);
216 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
218 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
219 pLabel->SetTextColor(COLOR_MAIN_TEXT);
221 pItem->AddControl(pLabel);
222 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
223 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
224 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
230 LocaleLanguageForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
232 AppLogDebug("ENTER");
241 LocaleLanguageForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
243 AppLogDebug("ENTER");
252 LocaleLanguageForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
254 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
256 SceneManager* pSceneManager = SceneManager::GetInstance();
257 AppAssert(pSceneManager);
260 String* pKey = static_cast<String*>(__pLanguageDataList->GetAt(itemIndex));
262 StringTokenizer stringTokenizer(*pKey, L"/");
264 for (int i = 0; i <= (stringTokenizer.GetTokenCount()); i++)
266 stringTokenizer.GetNextToken(langCode);
269 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, langCode) != E_SUCCESS)
271 AppLogDebug("set langCode[%ls] result[%s]", langCode.GetPointer(), GetErrorMessage(GetLastResult()));
276 LocaleLanguageForm::OnSettingChanged(Tizen::Base::String& key)
278 if (key.Equals(SETTING_INFO_KEY_LOCALE_LANGUAGE, false))
280 SceneManager* pSceneManager = SceneManager::GetInstance();
281 AppAssert(pSceneManager);
283 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
288 LocaleLanguageForm::GetDefaultGroupItemHeight(void)
290 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
294 LocaleLanguageForm::GetDefaultItemHeight(void)
296 return H_GROUP_ITEM_DEFAULT;
300 LocaleLanguageForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
305 LocaleLanguageForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
310 LocaleLanguageForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
315 LocaleLanguageForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)