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 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 LocaleRegionForm::LocaleRegionForm(void)
49 : __pTotalLocale(null)
50 , __pSearchedText(null)
54 LocaleRegionForm::~LocaleRegionForm(void)
59 LocaleRegionForm::CreateFooter(void)
61 Footer* pFooter = GetFooter();
64 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
65 pFooter->SetBackButton();
66 pFooter->AddActionEventListener(*this);
68 SetFormBackEventListener(this);
72 LocaleRegionForm::CreateTableView(void)
74 Rectangle bounds = GetClientAreaBounds();
75 Rectangle tableViewBounds = bounds;
77 tableViewBounds.y = Y_TABLE_VIEW_AREA;
78 tableViewBounds.height = (bounds.height - tableViewBounds.y);
80 __pTableView = new (std::nothrow) GroupedTableView();
81 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
82 __pTableView->SetItemProvider(this);
84 AddControl(*__pTableView);
86 __pTableView->AddGroupedTableViewItemEventListener(*this);
88 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
89 if (pRelativeLayout != null)
91 pRelativeLayout->SetHorizontalFitPolicy(*__pSearchBar, FIT_POLICY_PARENT);
92 pRelativeLayout->SetVerticalFitPolicy(*__pSearchBar, FIT_POLICY_FIXED);
93 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
94 pRelativeLayout->SetRelation(*__pTableView, *__pSearchBar, RECT_EDGE_RELATION_TOP_TO_BOTTOM);
95 pRelativeLayout->SetRelation(*__pTableView, *this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
96 delete pRelativeLayout;
101 LocaleRegionForm::GetLocaleList(void)
103 String localeLanguage;
104 if (SettingInfo::GetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, localeLanguage) != E_SUCCESS)
106 AppLogDebug("GetValue: SETTING_INFO_KEY_LOCALE_LANGUAGE failed [%s]", GetErrorMessage(GetLastResult()));
107 localeLanguage = L"eng_GB";
110 LanguageCode langCode = LANGUAGE_INVALID;
111 CountryCode countryCode = COUNTRY_INVALID;
112 StringTokenizer strTok(localeLanguage, L"_");
115 if (strTok.HasMoreTokens())
117 strTok.GetNextToken(token);
118 langCode = Locale::StringToLanguageCode(token);
121 if (strTok.HasMoreTokens())
123 strTok.GetNextToken(token);
124 countryCode = Locale::StringToCountryCode(token);
127 Locale currentLocale(langCode, countryCode);
129 LocaleManager localeManager;
130 localeManager.Construct();
132 IList* pAvailableLocales = localeManager.GetAvailableLocalesN();
133 String test = localeManager.GetSelectedLanguage();
135 __pTotalLocale = new (std::nothrow) ArrayList(SingleObjectDeleter);
136 __pTotalLocale->Construct();
138 __pSearchedText = new (std::nothrow) ArrayList(SingleObjectDeleter);
139 __pSearchedText->Construct();
141 for (int i = 0; i < pAvailableLocales->GetCount(); i++)
143 Locale* pLocale = (Locale*) (pAvailableLocales->GetAt(i));
150 pLocale->GetLanguageName(currentLocale, localeData);
151 pLocale->GetCountryName(currentLocale, country);
153 variantCode = pLocale->GetVariantCodeString();
154 languageCode = pLocale->GetLanguageCodeString();
155 countryCode = pLocale->GetCountryCodeString();
156 languageCode.Append(L"_" + countryCode);
158 localeData.Append(L" (" + country + L")" + L":" + languageCode);
160 if (languageCode.Equals(L"eng_US", false))
162 if (variantCode.IsEmpty() == false)
167 __pTotalLocale->Add((new (std::nothrow) String(localeData)));
168 __pSearchedText->Add((new (std::nothrow) String(localeData)));
171 __pTotalLocale->Sort(StringComparer());
172 __pSearchedText->Sort(StringComparer());
176 LocaleRegionForm::CreateSearchBar(void)
178 Rectangle bounds = GetClientAreaBounds();
179 Rectangle searchbarBounds = bounds;
181 searchbarBounds.y = 0;
182 searchbarBounds.height = H_GROUP_ITEM_DEFAULT;
184 __pSearchBar = new (std::nothrow) SearchBar();
185 __pSearchBar->Construct(searchbarBounds, true, KEYPAD_ACTION_SEARCH);
186 __pSearchBar->SetGuideText(L"Search");
187 __pSearchBar->AddSearchBarEventListener(*this);
188 __pSearchBar->AddTextEventListener(*this);
189 __pSearchBar->AddKeypadEventListener(*this);
190 __pSearchBar->SetContentAreaSize(Dimension(0, 0));
192 AddControl(*__pSearchBar);
196 LocaleRegionForm::OnInitializing(void)
198 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_REGION"));
208 LocaleRegionForm::OnTerminating(void)
212 SetFormBackEventListener(null);
217 LocaleRegionForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
219 if (__pSearchedText == null)
221 AppLogDebug("__pSearchedText is null");
224 __pTableView->UpdateTableView();
225 SceneManager* pSceneManager = SceneManager::GetInstance();
226 AppAssert(pSceneManager);
229 if (SettingInfo::GetValue(SETTING_INFO_KEY_LOCALE_COUNTRY, selectData) != E_SUCCESS)
231 AppLogDebug("GetValue: SETTING_INFO_KEY_LOCALE_COUNTRY failed [%s]", GetErrorMessage(GetLastResult()));
239 LocaleRegionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
244 LocaleRegionForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
246 SceneManager* pSceneManager = SceneManager::GetInstance();
247 AppAssert(pSceneManager);
249 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
253 LocaleRegionForm::GetGroupCount(void)
255 AppLogDebug("ENTER");
256 return ID_GROUP_COUNT;
260 LocaleRegionForm::GetItemCount(int groupIndex)
262 int itemCount = __pSearchedText->GetCount();
264 AppLogDebug("GetItemCount %d", itemCount);
270 LocaleRegionForm::CreateGroupItem(int groupIndex, int itemWidth)
272 AppLogDebug("ENTER");
274 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
275 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
276 Rectangle itemRectangle;
278 Label* pLabel = null;
280 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
282 itemRectangle.y = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
283 itemRectangle.height = itemHeight;
284 itemRectangle.width = itemWidth;
286 RelativeLayout relativeLayout;
287 relativeLayout.Construct();
289 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
290 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
292 pLabel = new (std::nothrow) Label();
293 pLabel->Construct(itemRectangle, groupText);
294 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
295 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
296 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
297 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
299 pItem->AddControl(*pLabel);
300 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
301 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
302 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
303 pItem->SetEnabled(false);
309 LocaleRegionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
311 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
313 Rectangle itemRectangle;
314 Rectangle itemSecondLineTextRect;
315 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
318 String currentRegion;
320 Label* pLabel = null;
321 int FontSize = GetFontSize();
322 LocaleManager localeManager;
323 localeManager.Construct();
325 Locale systemLocale = localeManager.GetSystemLocale();
326 systemLocale.GetCountryName(currentRegion);
328 pKey = static_cast<String*>(__pSearchedText->GetAt(itemIndex));
330 StringTokenizer stringTokenizer(*pKey, L":");
331 stringTokenizer.GetNextToken(itemText);
333 TableViewItem* pItem = new (std::nothrow) TableViewItem();
335 if (itemText.Contains(currentRegion) == true)
337 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
340 ItemTypeOneLine(itemRectangle);
341 itemRectangle.width = itemWidth;
343 RelativeLayout relativeLayout;
344 relativeLayout.Construct();
346 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
347 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
349 pLabel = new (std::nothrow) Label();
350 pLabel->Construct(itemRectangle, itemText);
351 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
352 pLabel->SetTextConfig(FontSize, LABEL_TEXT_STYLE_NORMAL);
353 pLabel->SetTextColor(COLOR_MAIN_TEXT);
355 pItem->AddControl(*pLabel);
357 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
358 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
364 LocaleRegionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
366 AppLogDebug("ENTER");
375 LocaleRegionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
377 AppLogDebug("ENTER");
386 LocaleRegionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
388 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
390 SceneManager* pSceneManager = SceneManager::GetInstance();
391 AppAssert(pSceneManager);
392 bool checkStatus = false;
395 String key = *(static_cast<String*>(__pSearchedText->GetAt(itemIndex)));
396 AppLogDebug("selected key [%ls]", key.GetPointer());
398 if (key.Equals(L"No Search Result", true))
400 AppLogDebug("selected key is \"No Search Result\"");
404 for (int count = 0; count < __pSearchedText->GetCount(); count++)
406 if (count == itemIndex)
408 checkStatus = !checkStatus;
410 pKey = (static_cast<String*>(__pSearchedText->GetAt(count)));
412 StringTokenizer stringTokenizer(*pKey, L":");
413 for (int i = 0; i <= stringTokenizer.GetTokenCount(); i++)
415 stringTokenizer.GetNextToken(selectData);
418 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_COUNTRY, selectData) != E_SUCCESS)
420 AppLogDebug("SetValue: SETTING_INFO_KEY_LOCALE_COUNTRY failed [%s]", GetErrorMessage(GetLastResult()));
424 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
426 tableView.SetItemChecked(groupIndex, count, true);
430 tableView.SetItemChecked(groupIndex, count, false);
437 LocaleRegionForm::GetDefaultGroupItemHeight(void)
439 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
443 LocaleRegionForm::GetDefaultItemHeight(void)
445 return H_GROUP_ITEM_DEFAULT;
449 LocaleRegionForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
454 LocaleRegionForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
459 LocaleRegionForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
464 LocaleRegionForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
469 LocaleRegionForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, Tizen::Ui::Controls::SearchBarMode mode)
471 if (mode == SEARCH_BAR_MODE_INPUT)
477 __pSearchedText->RemoveAll();
478 __pSearchedText = static_cast<ArrayList*>(__pTotalLocale->GetItemsN(0, __pTotalLocale->GetCount()));
480 __pTableView->UpdateTableView();
486 LocaleRegionForm::OnKeypadClosed(Tizen::Ui::Control& source)
488 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
493 LocaleRegionForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
495 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, false);
499 LocaleRegionForm::OnKeypadOpened(Tizen::Ui::Control& source)
505 LocaleRegionForm::OnTextValueChanged(const Tizen::Ui::Control& source)
508 String inputsearchText = __pSearchBar->GetText();
509 int GetItemCount = __pTotalLocale->GetCount();
511 if (inputsearchText.CompareTo(L"") != 0)
513 __pSearchedText->RemoveAll();
515 for (int i = 0; i < GetItemCount; i++)
517 String toLowerSearchData;
518 String toLowerInputSearchText;
519 searchData = *(static_cast<String*>(__pTotalLocale->GetAt(i)));
521 searchData.ToLower(toLowerSearchData);
522 inputsearchText.ToLower(toLowerInputSearchText);
524 if ((toLowerSearchData).Contains(toLowerInputSearchText))
526 if (searchData != null)
528 __pSearchedText->Add(*(new (std::nothrow) String(searchData)));
535 __pSearchedText->RemoveAll();
536 __pSearchedText = static_cast<ArrayList*>(__pTotalLocale->GetItemsN(0, __pTotalLocale->GetCount()));
539 if (__pSearchedText->GetCount() <= 0)
541 __pSearchedText->Add(*(new (std::nothrow) String(L"No Search Result")));
544 __pTableView->UpdateTableView();
548 LocaleRegionForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
550 switch (keypadAction)
552 case KEYPAD_ACTION_SEARCH:
554 __pSearchBar->HideKeypad();
555 __pSearchBar->Invalidate(false);