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 StTimeZoneForm.cpp
19 * @brief This is the implementation file for TimeZoneForm class.
22 #include "StResourceManager.h"
23 #include "StTimeZoneForm.h"
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Utility;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Locales;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
37 static const int ID_GROUP_COUNT = 1;
38 static const int ID_GROUP_MAX_ITEM_COUNT = 10;
40 static const int IDA_FOOTER_ITEM_NAME = 100;
41 static const int IDA_FOOTER_ITEM_TIME = 101;
43 static const int MINUTES_TO_HOUR = 60;
45 static const int GROUP_INDEX_DEFAULT_LABEL_HEIGHT = 40;
47 static const int H_SEARCH_BAR = 86;
48 static const int Y_TABLE_VIEW_AREA = H_SEARCH_BAR;
50 static const int W_GMT_FIXED_SIZE = 200;
52 TimeZoneForm::TimeZoneForm(void)
53 : __isAppControlRequest(false)
54 , __sortTabSelect(IDA_FOOTER_ITEM_NAME)
56 , __timeZoneTotalList(null)
57 , __timeZoneSearchList(null)
61 TimeZoneForm::~TimeZoneForm(void)
66 TimeZoneForm::CreateFooter(void)
68 Footer* pFooter = GetFooter();
71 FooterItem footerItemName;
72 footerItemName.Construct(IDA_FOOTER_ITEM_NAME);
73 footerItemName.SetText(ResourceManager::GetString(L"IDS_ST_BODY_NAME"));
75 FooterItem footerItemTime;
76 footerItemTime.Construct(IDA_FOOTER_ITEM_TIME);
77 footerItemTime.SetText(ResourceManager::GetString(L"IDS_COM_BODY_TIME"));
79 pFooter->SetStyle(FOOTER_STYLE_SEGMENTED_TEXT);
80 pFooter->AddItem(footerItemName);
81 pFooter->AddItem(footerItemTime);
82 pFooter->AddActionEventListener(*this);
84 SetFormBackEventListener(this);
88 TimeZoneForm::GetTimeZoneList(void)
90 IList* pAvailableLocales = null;
92 LocaleManager localeManager;
93 localeManager.Construct();
95 pAvailableLocales = localeManager.GetAvailableTimeZonesN();
96 if (pAvailableLocales)
98 for (int i = 0; i < pAvailableLocales->GetCount(); i++)
106 String* pKey = static_cast<String*>(pAvailableLocales->GetAt(i));
108 StringTokenizer stringTokenizer(*pKey, L"/");
109 stringTokenizer.GetNextToken(region);
110 stringTokenizer.GetNextToken(country);
112 if ((country.IsEmpty() == true) || (country.Equals(L"ACT", false))
113 || (region.Equals(L"SystemV", false)) || (region.Equals(L"Etc", false)))
118 if (stringTokenizer.HasMoreTokens() == true)
120 stringTokenizer.GetNextToken(extraData);
121 country.Append(L"/" + extraData);
124 TimeZone::GetTimeZone(*pKey, timeZone);
125 gmtHour = timeZone.GetRawOffset();
127 SetTimeZoneLocaleList(new (std::nothrow) TimeZoneData(region, country, gmtHour));
128 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(region, country, gmtHour));
137 TimeZoneForm::CreateTableView(void)
139 Rectangle bounds = GetClientAreaBounds();
140 Rectangle tableViewBounds = bounds;
142 tableViewBounds.y = Y_TABLE_VIEW_AREA;
143 tableViewBounds.height = (bounds.height - tableViewBounds.y);
145 __pTableView = new (std::nothrow) GroupedTableView();
146 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
147 __pTableView->SetItemProvider(this);
149 AddControl(__pTableView);
151 __pTableView->AddGroupedTableViewItemEventListener(*this);
153 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
154 if (pRelativeLayout != null)
156 pRelativeLayout->SetHorizontalFitPolicy(*__pSearchBar, FIT_POLICY_PARENT);
157 pRelativeLayout->SetVerticalFitPolicy(*__pSearchBar, FIT_POLICY_FIXED);
158 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
159 pRelativeLayout->SetRelation(*__pTableView, __pSearchBar, RECT_EDGE_RELATION_TOP_TO_BOTTOM);
160 pRelativeLayout->SetRelation(*__pTableView, this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
161 delete pRelativeLayout;
166 TimeZoneForm::OnInitializing(void)
168 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
169 Rectangle bounds = GetClientAreaBounds();
170 Rectangle searchbarBounds = bounds;
172 searchbarBounds.y = 0;
173 searchbarBounds.height = H_SEARCH_BAR;
175 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_TIME_ZONE"));
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);
191 AppLogDebug("ENTER");
197 TimeZoneForm::OnTerminating(void)
200 RemoveAllTimeZoneLocaleList();
203 SetFormBackEventListener(null);
208 TimeZoneForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
212 String categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
214 if (categoryCheck == L"category:TimeZone")
216 __isAppControlRequest = true;
220 __pTableView->UpdateTableView();
224 TimeZoneForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
229 TimeZoneForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
231 SceneManager* pSceneManager = SceneManager::GetInstance();
232 AppAssert(pSceneManager);
234 if (__isAppControlRequest == true)
236 UiApp* pApp = UiApp::GetInstance();
238 AppControlTimeZoneResult();
243 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
248 TimeZoneForm::GetGroupCount(void)
250 AppLogDebug("ENTER");
251 return ID_GROUP_COUNT;
255 TimeZoneForm::GetItemCount(int groupIndex)
257 int itemCount = __timeZoneSearchList->GetCount();
259 AppLogDebug("GetItemCount %d", itemCount);
264 TimeZoneForm::CreateGroupItem(int groupIndex, int itemWidth)
266 AppLogDebug("ENTER");
269 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
271 Label* pLabel = null;
273 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
274 pItem->Construct(Dimension(itemWidth, itemHeight));
276 pLabel = new (std::nothrow) Label();
277 pLabel->Construct(Rectangle(X_GROUP_INDEX_DEFAULT_LABEL, Y_GROUP_INDEX_DEFAULT_LABEL, itemWidth, GROUP_INDEX_DEFAULT_LABEL_HEIGHT), groupText);
278 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
279 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
280 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
282 pItem->AddControl(pLabel);
283 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
284 pItem->SetEnabled(false);
290 TimeZoneForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
292 AppLogDebug("CreateItem group[%d] index[%d]", groupIndex, itemIndex);
296 int computeGmtMin = 0;
302 Rectangle itemMainRectangle;
303 Rectangle itemGMTRectangle;
304 Rectangle itemSubRectangle;
305 int itemHeight = H_GROUP_ITEM_DEFAULT;
307 String noSearchResult = ResourceManager::GetString(L"IDS_COM_BODY_NO_SEARCH_RESULTS");
309 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
310 Label* pLabel = null;
311 int fontSize = GetFontSize();
313 TimeZoneData* pData = static_cast<TimeZoneData*>(__timeZoneSearchList->GetAt(itemIndex));
315 TableViewItem* pItem = new (std::nothrow) TableViewItem();
317 itemMainText = pData->GetCountryData();
318 itemMainText.Replace(L"_",L" ");
319 itemSubText = pData->GetRegionData();
320 itemSubText.Replace(L"_",L" ");
321 gmtMin = pData->GetGMTData();
323 if (itemMainText.Equals(noSearchResult, false))
325 ItemTypeOneLine(itemMainRectangle);
326 itemHeight = (itemMainRectangle.height);
328 RelativeLayout relativeLayout;
329 relativeLayout.Construct();
331 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
332 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
334 pLabel = new (std::nothrow) Label();
335 pLabel->Construct(itemMainRectangle, itemMainText);
336 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
337 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
338 pLabel->SetTextColor(COLOR_MAIN_TEXT);
340 pItem->AddControl(pLabel);
342 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
343 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
344 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
348 gmtHour = (gmtMin.value / MINUTES_TO_HOUR);
349 gmtMin.value %= MINUTES_TO_HOUR;
351 stringGMT.Append(L"GMT");
354 stringGMT.Append(L"+");
356 stringGMT.Append(gmtHour);
360 stringGMT.Append(L":");
362 if (gmtMin.value < 0)
364 computeGmtMin -= (computeGmtMin + gmtMin.value);
365 stringGMT.Append(computeGmtMin);
369 stringGMT.Append(gmtMin.value);
373 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
374 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
375 itemGMTRectangle = itemMainRectangle;
377 RelativeLayout relativeLayout;
378 relativeLayout.Construct();
380 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
381 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
383 itemMainRectangle.width = itemWidth;
384 itemGMTRectangle.width = W_GMT_FIXED_SIZE;
385 itemGMTRectangle.x = itemMainRectangle.width - itemGMTRectangle.width;
386 itemMainRectangle.width = itemMainRectangle.width - itemGMTRectangle.width;
388 pLabel = new (std::nothrow) Label();
389 pLabel->Construct(itemMainRectangle, itemMainText);
390 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
391 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
392 pLabel->SetTextColor(COLOR_MAIN_TEXT);
394 Label* pSecLabel = new (std::nothrow) Label();
395 pSecLabel->Construct(itemGMTRectangle, stringGMT);
396 pSecLabel->SetTextHorizontalAlignment(ALIGNMENT_RIGHT);
397 pSecLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
398 pSecLabel->SetTextColor(COLOR_MAIN_TEXT);
400 pItem->AddControl(pLabel);
401 pItem->AddControl(pSecLabel);
403 relativeLayout.SetHorizontalFitPolicy(*pSecLabel, FIT_POLICY_FIXED);
404 relativeLayout.SetRelation(*pSecLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
405 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
406 relativeLayout.SetRelation(*pLabel, pSecLabel, RECT_EDGE_RELATION_RIGHT_TO_LEFT);
408 pLabel = new (std::nothrow) Label();
409 pLabel->Construct(itemSubRectangle, itemSubText);
410 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
411 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
412 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
413 pLabel->SetTextColor(COLOR_SUB_TEXT);
415 pItem->AddControl(pLabel);
416 relativeLayout.SetMargin(*pLabel, itemSubRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
417 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
418 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
425 TimeZoneForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
427 AppLogDebug("ENTER");
436 TimeZoneForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
438 AppLogDebug("ENTER");
447 TimeZoneForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
449 AppLogDebug("OnTableViewItemStateChanged group[%d] index[%d]", groupIndex, itemIndex);
451 SceneManager* pSceneManager = SceneManager::GetInstance();
452 AppAssert(pSceneManager);
453 String noSearchResult = ResourceManager::GetString(L"IDS_COM_BODY_NO_SEARCH_RESULTS");
455 TimeZoneData* pData = static_cast<TimeZoneData*>(__timeZoneSearchList->GetAt(itemIndex));
457 if (pData->GetCountryData().Equals(noSearchResult, true))
459 AppLogDebug("selected key is \"No Search Result\"");
462 key.Append(pData->GetRegionData() + L"/" + pData->GetCountryData());
463 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_TIME_ZONE, key) == E_SUCCESS)
465 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
470 TimeZoneForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, Tizen::Ui::Controls::SearchBarMode mode)
472 if (mode == SEARCH_BAR_MODE_INPUT)
478 __timeZoneSearchList->RemoveAll();
480 for (int count = 0; count < __timeZoneTotalList->GetCount(); count++)
482 TimeZoneData* pData = null;
483 pData = static_cast<TimeZoneData*>(__timeZoneTotalList->GetAt(count));
484 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(*pData));
488 __pTableView->UpdateTableView();
494 TimeZoneForm::SortTimeZoneData(void)
496 TiemZoneComparer* pTimeZoneSort = null;
498 if (__sortTabSelect == IDA_FOOTER_ITEM_NAME)
500 pTimeZoneSort = new (std::nothrow) TiemZoneComparer(DATA_TYPE_COUNTRY);
504 pTimeZoneSort = new (std::nothrow) TiemZoneComparer(DATA_TYPE_GMT);
506 __timeZoneSearchList->Sort(*pTimeZoneSort);
507 delete pTimeZoneSort;
511 TimeZoneForm::OnTextValueChanged(const Tizen::Ui::Control& source)
514 String searchText = __pSearchBar->GetText();
516 if (searchText.CompareTo(L""))
518 TimeZoneData* pData = null;
519 __timeZoneSearchList->RemoveAll(true);
521 for (int count = 0; count < __timeZoneTotalList->GetCount(); count++)
524 String lowerSearchText;
525 pData = static_cast<TimeZoneData*>(__timeZoneTotalList->GetAt(count));
527 String country(pData->GetCountryData());
529 pData->GetCountryData().ToLower(lowerData);
530 searchText.ToLower(lowerSearchText);
531 lowerData.Replace('_', ' ');
533 if (lowerData.Contains(lowerSearchText))
535 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(*pData));
541 TimeZoneData* pData = null;
542 __timeZoneSearchList->RemoveAll(true);
544 for (int count = 0; count < __timeZoneTotalList->GetCount(); count++)
547 String lowerSearchText;
548 pData = static_cast<TimeZoneData*>(__timeZoneTotalList->GetAt(count));
550 String region(pData->GetRegionData());
551 String country(pData->GetCountryData());
552 Integer gmt = pData->GetGMTData();
554 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(*pData));
558 if (__timeZoneSearchList->GetCount() == 0)
561 String noSearchData(ResourceManager::GetString(L"IDS_COM_BODY_NO_SEARCH_RESULTS"));
562 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(noSearchData, noSearchData, noData));
568 __pTableView->UpdateTableView();
572 TimeZoneForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
574 if (__sortTabSelect == actionId)
580 case IDA_FOOTER_ITEM_NAME:
582 case IDA_FOOTER_ITEM_TIME:
584 __sortTabSelect = actionId;
593 __pTableView->UpdateTableView();
594 __pTableView->ScrollToItem(0, 0, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
598 TimeZoneForm::GetDefaultGroupItemHeight(void)
604 TimeZoneForm::GetDefaultItemHeight(void)
606 return H_GROUP_ITEM_DEFAULT;
610 TimeZoneForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
615 TimeZoneForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
620 TimeZoneForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
625 TimeZoneForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
629 Tizen::Base::Collection::IList*
630 TimeZoneForm::AppControlTimeZoneResult(void)
636 TimeZoneForm::InitTimeZoneLocaleList(void)
638 if (__timeZoneTotalList != null)
643 __timeZoneTotalList = new (std::nothrow) ArrayList(SingleObjectDeleter);
644 return __timeZoneTotalList->Construct();
648 TimeZoneForm::RemoveAllTimeZoneLocaleList(void)
650 if (__timeZoneTotalList != null)
652 delete __timeZoneTotalList;
653 __timeZoneTotalList = null;
656 if (__timeZoneSearchList != null)
658 delete __timeZoneSearchList;
659 __timeZoneSearchList = null;
664 TimeZoneForm::SetTimeZoneLocaleList(TimeZoneData* pTimeZoneData)
666 InitTimeZoneLocaleList();
668 if (__timeZoneTotalList == null)
673 return __timeZoneTotalList->Add(pTimeZoneData);
677 TimeZoneForm::SetTimeZoneLocaleSearchList(TimeZoneData* pTimeZoneData)
679 if (__timeZoneSearchList == null)
681 __timeZoneSearchList = new (std::nothrow) ArrayList(SingleObjectDeleter);
682 __timeZoneSearchList->Construct();
685 return __timeZoneSearchList->Add(pTimeZoneData);
689 TimeZoneForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
691 switch (keypadAction)
693 case KEYPAD_ACTION_SEARCH:
695 __pSearchBar->HideKeypad();
696 __pSearchBar->Invalidate(false);
706 TiemZoneComparer::Compare(const Tizen::Base::Object& obj1, const Tizen::Base::Object& obj2, int& cmp) const
710 case DATA_TYPE_REGION:
712 cmp = static_cast<const TimeZoneData&>(obj1).GetRegionData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetRegionData());
716 case DATA_TYPE_COUNTRY:
718 cmp = static_cast<const TimeZoneData&>(obj1).GetCountryData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetCountryData());
724 cmp = static_cast<const TimeZoneData&>(obj1).GetGMTData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetGMTData());
728 cmp = static_cast<const TimeZoneData&>(obj1).GetCountryData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetCountryData());
737 return GetLastResult();
741 TimeZoneData::GetCountryData(void) const
743 return _timeZoneCountry;
747 TimeZoneData::GetRegionData(void) const
749 return _timeZoneRegion;
753 TimeZoneData::GetGMTData(void) const