2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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;
42 static const int ID_GROUP_LANGUAGE_ITEM_COUNT = 49;
44 LocaleLanguageForm::LocaleLanguageForm(void)
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 __languageDataList;
82 __languageDataList = 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 __languageDataList = 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 AppLogDebug("ENTER");
118 return ID_GROUP_COUNT;
122 LocaleLanguageForm::GetItemCount(int groupIndex)
124 int itemCount = __languageDataList->GetCount();
126 AppLogDebug("GetItemCount %d", itemCount);
132 LocaleLanguageForm::CreateGroupItem(int groupIndex, int itemWidth)
134 AppLogDebug("ENTER");
136 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
137 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
138 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
139 Rectangle itemRectangle;
141 Label* pLabel = null;
143 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
145 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
146 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
148 ItemTypeOneLine(itemRectangle);
150 RelativeLayout relativeLayout;
151 relativeLayout.Construct();
153 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
154 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
156 pLabel = new (std::nothrow) Label();
157 pLabel->Construct(itemRectangle, groupText);
158 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
159 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
160 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
161 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
163 pItem->AddControl(*pLabel);
164 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
165 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
166 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
167 pItem->SetEnabled(false);
173 LocaleLanguageForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
175 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
177 Rectangle itemRectangle;
178 Rectangle itemSecondLineTextRect;
179 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
181 String secondLineText;
182 String fontReturnValue;
183 Label* pLabel = null;
184 int fontSize = GetFontSize();
185 TableViewItem* pItem = new (std::nothrow) TableViewItem();
186 String* pKey = static_cast<String*>(__languageDataList->GetAt(itemIndex));
188 ItemTypeOneLine(itemRectangle);
189 itemWidth = itemRectangle.width;
191 StringTokenizer stringTokenizer(*pKey, L"/");
192 stringTokenizer.GetNextToken(itemText);
194 RelativeLayout relativeLayout;
195 relativeLayout.Construct();
197 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
198 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
200 pLabel = new (std::nothrow) Label();
201 pLabel->Construct(itemRectangle, itemText);
202 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
204 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
205 pLabel->SetTextColor(COLOR_MAIN_TEXT);
207 pItem->AddControl(*pLabel);
208 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
209 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
210 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
216 LocaleLanguageForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
218 AppLogDebug("ENTER");
227 LocaleLanguageForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
229 AppLogDebug("ENTER");
238 LocaleLanguageForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
240 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
242 SceneManager* pSceneManager = SceneManager::GetInstance();
243 AppAssert(pSceneManager);
246 String* pKey = static_cast<String*>(__languageDataList->GetAt(itemIndex));
248 StringTokenizer stringTokenizer(*pKey, L"/");
250 for (int i = 0; i <= (stringTokenizer.GetTokenCount()); i++)
252 stringTokenizer.GetNextToken(langCode);
255 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, langCode) != E_SUCCESS)
257 AppLogDebug("set langCode[%ls] result[%s]", langCode.GetPointer(), GetErrorMessage(GetLastResult()));
262 LocaleLanguageForm::OnSettingChanged(Tizen::Base::String& key)
264 if (key.Equals(SETTING_INFO_KEY_LOCALE_LANGUAGE, false))
266 SceneManager* pSceneManager = SceneManager::GetInstance();
267 AppAssert(pSceneManager);
269 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
274 LocaleLanguageForm::GetDefaultGroupItemHeight(void)
276 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
280 LocaleLanguageForm::GetDefaultItemHeight(void)
282 return H_GROUP_ITEM_DEFAULT;
286 LocaleLanguageForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
291 LocaleLanguageForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
296 LocaleLanguageForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
301 LocaleLanguageForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)