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_COUNT = 1;
39 static const int Y_TABLE_VIEW_AREA = H_GROUP_ITEM_DEFAULT;
41 static const int H_SEARCH_BAR = 86;
43 LocaleRegionForm::LocaleRegionForm(void)
44 : __pTotalLocale(null)
45 , __pSearchedText(null)
49 LocaleRegionForm::~LocaleRegionForm(void)
54 LocaleRegionForm::CreateFooter(void)
56 Footer* pFooter = GetFooter();
59 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
60 pFooter->AddActionEventListener(*this);
62 SetFormBackEventListener(this);
66 LocaleRegionForm::CreateTableView(void)
68 Rectangle bounds = GetClientAreaBounds();
69 Rectangle tableViewBounds = bounds;
71 tableViewBounds.y = Y_TABLE_VIEW_AREA;
72 tableViewBounds.height = (bounds.height - tableViewBounds.y);
74 __pTableView = new (std::nothrow) GroupedTableView();
75 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
76 __pTableView->SetItemProvider(this);
78 AddControl(__pTableView);
80 __pTableView->AddGroupedTableViewItemEventListener(*this);
82 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
83 if (pRelativeLayout != null)
85 pRelativeLayout->SetHorizontalFitPolicy(*__pSearchBar, FIT_POLICY_PARENT);
86 pRelativeLayout->SetVerticalFitPolicy(*__pSearchBar, FIT_POLICY_FIXED);
87 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
88 pRelativeLayout->SetRelation(*__pTableView, __pSearchBar, RECT_EDGE_RELATION_TOP_TO_BOTTOM);
89 pRelativeLayout->SetRelation(*__pTableView, this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
90 delete pRelativeLayout;
95 LocaleRegionForm::GetLocaleList(void)
97 String localeLanguage;
98 if (SettingInfo::GetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, localeLanguage) != E_SUCCESS)
100 AppLogDebug("GetValue: SETTING_INFO_KEY_LOCALE_LANGUAGE failed [%s]", GetErrorMessage(GetLastResult()));
101 localeLanguage = L"eng_GB";
104 LanguageCode langCode = LANGUAGE_INVALID;
105 CountryCode countryCode = COUNTRY_INVALID;
106 StringTokenizer strTok(localeLanguage, L"_");
109 if (strTok.HasMoreTokens())
111 strTok.GetNextToken(token);
112 langCode = Locale::StringToLanguageCode(token);
115 if (strTok.HasMoreTokens())
117 strTok.GetNextToken(token);
118 countryCode = Locale::StringToCountryCode(token);
121 Locale currentLocale(langCode, countryCode);
123 LocaleManager localeManager;
124 localeManager.Construct();
126 IList* pAvailableLocales = localeManager.GetAvailableLocalesN();
127 String test = localeManager.GetSelectedLanguage();
129 __pTotalLocale = new (std::nothrow) ArrayList(SingleObjectDeleter);
130 __pTotalLocale->Construct();
132 __pSearchedText = new (std::nothrow) ArrayList(SingleObjectDeleter);
133 __pSearchedText->Construct();
135 for (int i = 0; i < pAvailableLocales->GetCount(); i++)
137 Locale* pLocale = (Locale*) (pAvailableLocales->GetAt(i));
144 pLocale->GetLanguageName(currentLocale, localeData);
145 pLocale->GetCountryName(currentLocale, country);
147 variantCode = pLocale->GetVariantCodeString();
148 languageCode = pLocale->GetLanguageCodeString();
149 countryCode = pLocale->GetCountryCodeString();
150 languageCode.Append(L"_" + countryCode);
152 localeData.Append(L" (" + country + L")" + L":" + languageCode);
154 if (languageCode.Equals(L"eng_US", false))
156 if (variantCode.IsEmpty() == false)
161 __pTotalLocale->Add((new (std::nothrow) String(localeData)));
162 __pSearchedText->Add((new (std::nothrow) String(localeData)));
165 __pTotalLocale->Sort(StringComparer());
166 __pSearchedText->Sort(StringComparer());
170 LocaleRegionForm::CreateSearchBar(void)
172 Rectangle bounds = GetClientAreaBounds();
173 Rectangle searchbarBounds = bounds;
175 searchbarBounds.y = 0;
176 searchbarBounds.height = H_SEARCH_BAR;
178 __pSearchBar = new (std::nothrow) SearchBar();
179 __pSearchBar->Construct(searchbarBounds, true, KEYPAD_ACTION_SEARCH);
180 __pSearchBar->SetGuideText(ResourceManager::GetString(L"IDS_COM_BODY_SEARCH"));
181 __pSearchBar->AddSearchBarEventListener(*this);
182 __pSearchBar->AddTextEventListener(*this);
183 __pSearchBar->AddKeypadEventListener(*this);
184 __pSearchBar->SetContentAreaSize(Dimension(0, 0));
186 AddControl(__pSearchBar);
190 LocaleRegionForm::OnInitializing(void)
192 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_REGION"));
193 SettingInfo::GetValue(SETTING_INFO_KEY_LOCALE_COUNTRY, __previousSelectedRegion);
202 LocaleRegionForm::OnTerminating(void)
206 SetFormBackEventListener(null);
211 LocaleRegionForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
213 if (__pSearchedText == null)
215 AppLogDebug("__pSearchedText is null");
218 __pTableView->UpdateTableView();
219 SceneManager* pSceneManager = SceneManager::GetInstance();
220 AppAssert(pSceneManager);
223 if (SettingInfo::GetValue(SETTING_INFO_KEY_LOCALE_COUNTRY, selectData) != E_SUCCESS)
225 AppLogDebug("GetValue: SETTING_INFO_KEY_LOCALE_COUNTRY failed [%s]", GetErrorMessage(GetLastResult()));
233 LocaleRegionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
238 LocaleRegionForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
240 SceneManager* pSceneManager = SceneManager::GetInstance();
241 AppAssert(pSceneManager);
243 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
247 LocaleRegionForm::GetGroupCount(void)
249 AppLogDebug("ENTER");
250 return ID_GROUP_COUNT;
254 LocaleRegionForm::GetItemCount(int groupIndex)
256 int itemCount = __pSearchedText->GetCount();
258 AppLogDebug("GetItemCount %d", itemCount);
264 LocaleRegionForm::CreateGroupItem(int groupIndex, int itemWidth)
266 AppLogDebug("ENTER");
268 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
269 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
270 Rectangle itemMainRectangle;
272 Label* pLabel = null;
274 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
276 itemMainRectangle.y = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
277 itemMainRectangle.height = itemHeight;
278 itemMainRectangle.width = itemWidth;
280 RelativeLayout relativeLayout;
281 relativeLayout.Construct();
283 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
284 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
286 pLabel = new (std::nothrow) Label();
287 pLabel->Construct(itemMainRectangle, groupText);
288 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
289 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
290 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
291 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
293 pItem->AddControl(pLabel);
294 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
295 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
296 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
297 pItem->SetEnabled(false);
303 LocaleRegionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
305 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
307 Rectangle itemMainRectangle;
308 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
311 String currentRegion;
313 Label* pLabel = null;
314 int FontSize = GetFontSize();
315 LocaleManager localeManager;
316 localeManager.Construct();
318 Locale systemLocale = localeManager.GetSystemLocale();
319 systemLocale.GetCountryName(currentRegion);
321 pKey = static_cast<String*>(__pSearchedText->GetAt(itemIndex));
323 StringTokenizer stringTokenizer(*pKey, L":");
324 stringTokenizer.GetNextToken(itemMainText);
326 TableViewItem* pItem = new (std::nothrow) TableViewItem();
328 if (itemMainText.Contains(currentRegion) == true)
330 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
333 ItemTypeOneLine(itemMainRectangle);
334 itemMainRectangle.width = itemWidth;
336 RelativeLayout relativeLayout;
337 relativeLayout.Construct();
339 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
340 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
342 pLabel = new (std::nothrow) Label();
343 pLabel->Construct(itemMainRectangle, itemMainText);
344 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
345 pLabel->SetTextConfig(FontSize, LABEL_TEXT_STYLE_NORMAL);
346 pLabel->SetTextColor(COLOR_MAIN_TEXT);
348 pItem->AddControl(pLabel);
350 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
351 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
357 LocaleRegionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
359 AppLogDebug("ENTER");
368 LocaleRegionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
370 AppLogDebug("ENTER");
379 LocaleRegionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
381 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
383 SceneManager* pSceneManager = SceneManager::GetInstance();
384 AppAssert(pSceneManager);
385 bool checkStatus = false;
388 String key = *(static_cast<String*>(__pSearchedText->GetAt(itemIndex)));
389 AppLogDebug("selected key [%ls]", key.GetPointer());
391 String noSearchResult = ResourceManager::GetString(L"IDS_COM_BODY_NO_SEARCH_RESULTS");
393 if (key.Equals(noSearchResult, true))
395 AppLogDebug("selected key is \"No Search Result\"");
399 for (int count = 0; count < __pSearchedText->GetCount(); count++)
401 if (count == itemIndex)
403 checkStatus = !checkStatus;
405 pKey = (static_cast<String*>(__pSearchedText->GetAt(count)));
407 StringTokenizer stringTokenizer(*pKey, L":");
408 for (int i = 0; i <= stringTokenizer.GetTokenCount(); i++)
410 stringTokenizer.GetNextToken(selectData);
412 if(selectData.CompareTo(__previousSelectedRegion) != 0)
414 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_COUNTRY, selectData) != E_SUCCESS)
416 AppLogDebug("SetValue: SETTING_INFO_KEY_LOCALE_COUNTRY failed [%s]", GetErrorMessage(GetLastResult()));
420 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
425 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
428 __previousSelectedRegion = selectData;
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);