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 StRegionForm.cpp
19 * @brief This is the implementation file for RegionForm class.
23 #include "StRegionForm.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_REGION_MAIN = 0;
39 static const int ID_GROUP_COUNT = 1;
40 static const int ITEM_WIDTH_GAP = 100;
42 static const int H_SEARCH_BAR_ITEM = H_GROUP_ITEM_DEFAULT;
43 static const int Y_TABLE_VIEW_AREA = H_GROUP_ITEM_DEFAULT;
45 static const int H_PORTRAIT_KEY_PAD_INPUT_MODE_GAP = 0;
46 static const int H_LANDSCAPE_KEY_PAD_INPUT_MODE_GAP = 0;
48 static const int H_SEARCH_BAR = 86;
50 LocaleRegionForm::LocaleRegionForm(void)
51 : __pTotalLocale(null)
52 , __pSearchedText(null)
56 LocaleRegionForm::~LocaleRegionForm(void)
61 LocaleRegionForm::CreateFooter(void)
63 Footer* pFooter = GetFooter();
66 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
67 pFooter->SetBackButton();
68 pFooter->AddActionEventListener(*this);
70 SetFormBackEventListener(this);
74 LocaleRegionForm::CreateTableView(void)
76 Rectangle bounds = GetClientAreaBounds();
77 Rectangle tableViewBounds = bounds;
79 tableViewBounds.y = Y_TABLE_VIEW_AREA;
80 tableViewBounds.height = (bounds.height - tableViewBounds.y);
82 __pTableView = new (std::nothrow) GroupedTableView();
83 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
84 __pTableView->SetItemProvider(this);
86 AddControl(__pTableView);
88 __pTableView->AddGroupedTableViewItemEventListener(*this);
90 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
91 if (pRelativeLayout != null)
93 pRelativeLayout->SetHorizontalFitPolicy(*__pSearchBar, FIT_POLICY_PARENT);
94 pRelativeLayout->SetVerticalFitPolicy(*__pSearchBar, FIT_POLICY_FIXED);
95 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
96 pRelativeLayout->SetRelation(*__pTableView, __pSearchBar, RECT_EDGE_RELATION_TOP_TO_BOTTOM);
97 pRelativeLayout->SetRelation(*__pTableView, this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
98 delete pRelativeLayout;
103 LocaleRegionForm::GetLocaleList(void)
105 String localeLanguage;
106 if (SettingInfo::GetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, localeLanguage) != E_SUCCESS)
108 AppLogDebug("GetValue: SETTING_INFO_KEY_LOCALE_LANGUAGE failed [%s]", GetErrorMessage(GetLastResult()));
109 localeLanguage = L"eng_GB";
112 LanguageCode langCode = LANGUAGE_INVALID;
113 CountryCode countryCode = COUNTRY_INVALID;
114 StringTokenizer strTok(localeLanguage, L"_");
117 if (strTok.HasMoreTokens())
119 strTok.GetNextToken(token);
120 langCode = Locale::StringToLanguageCode(token);
123 if (strTok.HasMoreTokens())
125 strTok.GetNextToken(token);
126 countryCode = Locale::StringToCountryCode(token);
129 Locale currentLocale(langCode, countryCode);
131 LocaleManager localeManager;
132 localeManager.Construct();
134 IList* pAvailableLocales = localeManager.GetAvailableLocalesN();
135 String test = localeManager.GetSelectedLanguage();
137 __pTotalLocale = new (std::nothrow) ArrayList(SingleObjectDeleter);
138 __pTotalLocale->Construct();
140 __pSearchedText = new (std::nothrow) ArrayList(SingleObjectDeleter);
141 __pSearchedText->Construct();
143 for (int i = 0; i < pAvailableLocales->GetCount(); i++)
145 Locale* pLocale = (Locale*) (pAvailableLocales->GetAt(i));
152 pLocale->GetLanguageName(currentLocale, localeData);
153 pLocale->GetCountryName(currentLocale, country);
155 variantCode = pLocale->GetVariantCodeString();
156 languageCode = pLocale->GetLanguageCodeString();
157 countryCode = pLocale->GetCountryCodeString();
158 languageCode.Append(L"_" + countryCode);
160 localeData.Append(L" (" + country + L")" + L":" + languageCode);
162 if (languageCode.Equals(L"eng_US", false))
164 if (variantCode.IsEmpty() == false)
169 __pTotalLocale->Add((new (std::nothrow) String(localeData)));
170 __pSearchedText->Add((new (std::nothrow) String(localeData)));
173 __pTotalLocale->Sort(StringComparer());
174 __pSearchedText->Sort(StringComparer());
178 LocaleRegionForm::CreateSearchBar(void)
180 Rectangle bounds = GetClientAreaBounds();
181 Rectangle searchbarBounds = bounds;
183 searchbarBounds.y = 0;
184 searchbarBounds.height = H_SEARCH_BAR;
186 __pSearchBar = new (std::nothrow) SearchBar();
187 __pSearchBar->Construct(searchbarBounds, true, KEYPAD_ACTION_SEARCH);
188 __pSearchBar->SetGuideText(ResourceManager::GetString(L"IDS_COM_BODY_SEARCH"));
189 __pSearchBar->AddSearchBarEventListener(*this);
190 __pSearchBar->AddTextEventListener(*this);
191 __pSearchBar->AddKeypadEventListener(*this);
192 __pSearchBar->SetContentAreaSize(Dimension(0, 0));
194 AddControl(__pSearchBar);
198 LocaleRegionForm::OnInitializing(void)
200 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_REGION"));
210 LocaleRegionForm::OnTerminating(void)
214 SetFormBackEventListener(null);
219 LocaleRegionForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
221 if (__pSearchedText == null)
223 AppLogDebug("__pSearchedText is null");
226 __pTableView->UpdateTableView();
227 SceneManager* pSceneManager = SceneManager::GetInstance();
228 AppAssert(pSceneManager);
231 if (SettingInfo::GetValue(SETTING_INFO_KEY_LOCALE_COUNTRY, selectData) != E_SUCCESS)
233 AppLogDebug("GetValue: SETTING_INFO_KEY_LOCALE_COUNTRY failed [%s]", GetErrorMessage(GetLastResult()));
241 LocaleRegionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
246 LocaleRegionForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
248 SceneManager* pSceneManager = SceneManager::GetInstance();
249 AppAssert(pSceneManager);
251 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
255 LocaleRegionForm::GetGroupCount(void)
257 AppLogDebug("ENTER");
258 return ID_GROUP_COUNT;
262 LocaleRegionForm::GetItemCount(int groupIndex)
264 int itemCount = __pSearchedText->GetCount();
266 AppLogDebug("GetItemCount %d", itemCount);
272 LocaleRegionForm::CreateGroupItem(int groupIndex, int itemWidth)
274 AppLogDebug("ENTER");
276 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
277 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
278 Rectangle itemMainRectangle;
280 Label* pLabel = null;
282 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
284 itemMainRectangle.y = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
285 itemMainRectangle.height = itemHeight;
286 itemMainRectangle.width = itemWidth;
288 RelativeLayout relativeLayout;
289 relativeLayout.Construct();
291 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
292 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
294 pLabel = new (std::nothrow) Label();
295 pLabel->Construct(itemMainRectangle, groupText);
296 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
297 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
298 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
299 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
301 pItem->AddControl(pLabel);
302 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
303 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
304 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
305 pItem->SetEnabled(false);
311 LocaleRegionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
313 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
315 Rectangle itemMainRectangle;
316 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
319 String currentRegion;
321 Label* pLabel = null;
322 int FontSize = GetFontSize();
323 LocaleManager localeManager;
324 localeManager.Construct();
326 Locale systemLocale = localeManager.GetSystemLocale();
327 systemLocale.GetCountryName(currentRegion);
329 pKey = static_cast<String*>(__pSearchedText->GetAt(itemIndex));
331 StringTokenizer stringTokenizer(*pKey, L":");
332 stringTokenizer.GetNextToken(itemMainText);
334 TableViewItem* pItem = new (std::nothrow) TableViewItem();
336 if (itemMainText.Contains(currentRegion) == true)
338 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
341 ItemTypeOneLine(itemMainRectangle);
342 itemMainRectangle.width = itemWidth;
344 RelativeLayout relativeLayout;
345 relativeLayout.Construct();
347 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
348 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
350 pLabel = new (std::nothrow) Label();
351 pLabel->Construct(itemMainRectangle, itemMainText);
352 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
353 pLabel->SetTextConfig(FontSize, LABEL_TEXT_STYLE_NORMAL);
354 pLabel->SetTextColor(COLOR_MAIN_TEXT);
356 pItem->AddControl(pLabel);
358 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
359 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
365 LocaleRegionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
367 AppLogDebug("ENTER");
376 LocaleRegionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
378 AppLogDebug("ENTER");
387 LocaleRegionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
389 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
391 SceneManager* pSceneManager = SceneManager::GetInstance();
392 AppAssert(pSceneManager);
393 bool checkStatus = false;
396 String key = *(static_cast<String*>(__pSearchedText->GetAt(itemIndex)));
397 AppLogDebug("selected key [%ls]", key.GetPointer());
399 String noSearchResult = ResourceManager::GetString(L"IDS_COM_BODY_NO_SEARCH_RESULTS");
401 if (key.Equals(noSearchResult, true))
403 AppLogDebug("selected key is \"No Search Result\"");
407 for (int count = 0; count < __pSearchedText->GetCount(); count++)
409 if (count == itemIndex)
411 checkStatus = !checkStatus;
413 pKey = (static_cast<String*>(__pSearchedText->GetAt(count)));
415 StringTokenizer stringTokenizer(*pKey, L":");
416 for (int i = 0; i <= stringTokenizer.GetTokenCount(); i++)
418 stringTokenizer.GetNextToken(selectData);
421 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_COUNTRY, selectData) != E_SUCCESS)
423 AppLogDebug("SetValue: SETTING_INFO_KEY_LOCALE_COUNTRY failed [%s]", GetErrorMessage(GetLastResult()));
427 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
429 tableView.SetItemChecked(groupIndex, count, true);
433 tableView.SetItemChecked(groupIndex, count, false);
440 LocaleRegionForm::GetDefaultGroupItemHeight(void)
442 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
446 LocaleRegionForm::GetDefaultItemHeight(void)
448 return H_GROUP_ITEM_DEFAULT;
452 LocaleRegionForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
457 LocaleRegionForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
462 LocaleRegionForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
467 LocaleRegionForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
472 LocaleRegionForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, Tizen::Ui::Controls::SearchBarMode mode)
474 if (mode == SEARCH_BAR_MODE_INPUT)
480 __pSearchedText->RemoveAll();
481 __pSearchedText = static_cast<ArrayList*>(__pTotalLocale->GetItemsN(0, __pTotalLocale->GetCount()));
483 __pTableView->UpdateTableView();
489 LocaleRegionForm::OnTextValueChanged(const Tizen::Ui::Control& source)
492 String inputsearchText = __pSearchBar->GetText();
493 int GetItemCount = __pTotalLocale->GetCount();
494 String noSearchResult = ResourceManager::GetString(L"IDS_COM_BODY_NO_SEARCH_RESULTS");
496 if (inputsearchText.CompareTo(L"") != 0)
498 __pSearchedText->RemoveAll();
500 for (int i = 0; i < GetItemCount; i++)
502 String toLowerSearchData;
503 String toLowerInputSearchText;
504 searchData = *(static_cast<String*>(__pTotalLocale->GetAt(i)));
506 searchData.ToLower(toLowerSearchData);
507 inputsearchText.ToLower(toLowerInputSearchText);
509 StringTokenizer strTok(toLowerSearchData, L":");
511 strTok.GetNextToken(token);
513 if ((token).Contains(toLowerInputSearchText))
515 if (searchData != null)
517 __pSearchedText->Add(*(new (std::nothrow) String(searchData)));
524 __pSearchedText->RemoveAll();
525 __pSearchedText = static_cast<ArrayList*>(__pTotalLocale->GetItemsN(0, __pTotalLocale->GetCount()));
528 if (__pSearchedText->GetCount() <= 0)
530 __pSearchedText->Add(*(new (std::nothrow) String(noSearchResult)));
533 __pTableView->UpdateTableView();
537 LocaleRegionForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
539 switch (keypadAction)
541 case KEYPAD_ACTION_SEARCH:
543 __pSearchBar->HideKeypad();
544 __pSearchBar->Invalidate(false);