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->SetBackButton();
83 pFooter->AddActionEventListener(*this);
85 SetFormBackEventListener(this);
89 TimeZoneForm::GetTimeZoneList(void)
91 IList* pAvailableLocales = null;
93 LocaleManager localeManager;
94 localeManager.Construct();
96 pAvailableLocales = localeManager.GetAvailableTimeZonesN();
97 if (pAvailableLocales)
99 for (int i = 0; i < pAvailableLocales->GetCount(); i++)
107 String* pKey = static_cast<String*>(pAvailableLocales->GetAt(i));
109 StringTokenizer stringTokenizer(*pKey, L"/");
110 stringTokenizer.GetNextToken(region);
111 stringTokenizer.GetNextToken(country);
113 if ((country.IsEmpty() == true) || (country.IsEmpty() == true) || (country.Equals(L"ACT", false))
114 || (region.Equals(L"SystemV", false)) || (region.Equals(L"Etc", false)))
119 if (stringTokenizer.HasMoreTokens() == true)
121 stringTokenizer.GetNextToken(extraData);
122 country.Append(L"/" + extraData);
125 TimeZone::GetTimeZone(*pKey, timeZone);
126 gmtHour = timeZone.GetRawOffset();
128 SetTimeZoneLocaleList(new (std::nothrow) TimeZoneData(region, country, gmtHour));
129 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(region, country, gmtHour));
138 TimeZoneForm::CreateTableView(void)
140 Rectangle bounds = GetClientAreaBounds();
141 Rectangle tableViewBounds = bounds;
143 tableViewBounds.y = Y_TABLE_VIEW_AREA;
144 tableViewBounds.height = (bounds.height - tableViewBounds.y);
146 __pTableView = new (std::nothrow) GroupedTableView();
147 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
148 __pTableView->SetItemProvider(this);
150 AddControl(__pTableView);
152 __pTableView->AddGroupedTableViewItemEventListener(*this);
154 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
155 if (pRelativeLayout != null)
157 pRelativeLayout->SetHorizontalFitPolicy(*__pSearchBar, FIT_POLICY_PARENT);
158 pRelativeLayout->SetVerticalFitPolicy(*__pSearchBar, FIT_POLICY_FIXED);
159 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
160 pRelativeLayout->SetRelation(*__pTableView, __pSearchBar, RECT_EDGE_RELATION_TOP_TO_BOTTOM);
161 pRelativeLayout->SetRelation(*__pTableView, this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
162 delete pRelativeLayout;
167 TimeZoneForm::OnInitializing(void)
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 itemSubText = pData->GetRegionData();
319 gmtMin = pData->GetGMTData();
321 if (itemMainText.Equals(noSearchResult, false))
323 ItemTypeOneLine(itemMainRectangle);
324 itemHeight = (itemMainRectangle.height);
326 RelativeLayout relativeLayout;
327 relativeLayout.Construct();
329 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
330 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
332 pLabel = new (std::nothrow) Label();
333 pLabel->Construct(itemMainRectangle, itemMainText);
334 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
335 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
336 pLabel->SetTextColor(COLOR_MAIN_TEXT);
338 pItem->AddControl(pLabel);
340 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
341 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
342 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
346 gmtHour = (gmtMin.value / MINUTES_TO_HOUR);
347 gmtMin.value %= MINUTES_TO_HOUR;
349 stringGMT.Append(L"GMT");
352 stringGMT.Append(L"+");
354 stringGMT.Append(gmtHour);
358 stringGMT.Append(L":");
360 if (gmtMin.value < 0)
362 computeGmtMin -= (computeGmtMin + gmtMin.value);
363 stringGMT.Append(computeGmtMin);
367 stringGMT.Append(gmtMin.value);
371 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
372 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
373 itemGMTRectangle = itemMainRectangle;
375 RelativeLayout relativeLayout;
376 relativeLayout.Construct();
378 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
379 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
381 itemMainRectangle.width = itemWidth;
382 itemGMTRectangle.width = W_GMT_FIXED_SIZE;
383 itemGMTRectangle.x = itemMainRectangle.width - itemGMTRectangle.width;
384 itemMainRectangle.width = itemMainRectangle.width - itemGMTRectangle.width;
386 pLabel = new (std::nothrow) Label();
387 pLabel->Construct(itemMainRectangle, itemMainText);
388 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
389 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
390 pLabel->SetTextColor(COLOR_MAIN_TEXT);
392 Label* pSecLabel = new (std::nothrow) Label();
393 pSecLabel->Construct(itemGMTRectangle, stringGMT);
394 pSecLabel->SetTextHorizontalAlignment(ALIGNMENT_RIGHT);
395 pSecLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
396 pSecLabel->SetTextColor(COLOR_MAIN_TEXT);
398 pItem->AddControl(pLabel);
399 pItem->AddControl(pSecLabel);
401 relativeLayout.SetHorizontalFitPolicy(*pSecLabel, FIT_POLICY_FIXED);
402 relativeLayout.SetRelation(*pSecLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
403 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
404 relativeLayout.SetRelation(*pLabel, pSecLabel, RECT_EDGE_RELATION_RIGHT_TO_LEFT);
406 pLabel = new (std::nothrow) Label();
407 pLabel->Construct(itemSubRectangle, itemSubText);
408 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
409 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
410 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
411 pLabel->SetTextColor(COLOR_SUB_TEXT);
413 pItem->AddControl(pLabel);
414 relativeLayout.SetMargin(*pLabel, itemSubRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
415 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
416 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
423 TimeZoneForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
425 AppLogDebug("ENTER");
434 TimeZoneForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
436 AppLogDebug("ENTER");
445 TimeZoneForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
447 AppLogDebug("OnTableViewItemStateChanged group[%d] index[%d]", groupIndex, itemIndex);
449 SceneManager* pSceneManager = SceneManager::GetInstance();
450 AppAssert(pSceneManager);
451 String noSearchResult = ResourceManager::GetString(L"IDS_COM_BODY_NO_SEARCH_RESULTS");
453 TimeZoneData* pData = static_cast<TimeZoneData*>(__timeZoneSearchList->GetAt(itemIndex));
455 if (pData->GetCountryData().Equals(noSearchResult, true))
457 AppLogDebug("selected key is \"No Search Result\"");
461 key.Append(pData->GetRegionData() + L"/" + pData->GetCountryData());
462 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_TIME_ZONE, key) == E_SUCCESS)
464 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
469 TimeZoneForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, Tizen::Ui::Controls::SearchBarMode mode)
471 if (mode == SEARCH_BAR_MODE_INPUT)
477 __timeZoneSearchList->RemoveAll();
479 for (int count = 0; count < __timeZoneTotalList->GetCount(); count++)
481 TimeZoneData* pData = null;
482 pData = static_cast<TimeZoneData*>(__timeZoneTotalList->GetAt(count));
483 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(*pData));
487 __pTableView->UpdateTableView();
493 TimeZoneForm::SortTimeZoneData(void)
495 TiemZoneComparer* pTimeZoneSort = null;
497 if (__sortTabSelect == IDA_FOOTER_ITEM_NAME)
499 pTimeZoneSort = new (std::nothrow) TiemZoneComparer(DATA_TYPE_COUNTRY);
503 pTimeZoneSort = new (std::nothrow) TiemZoneComparer(DATA_TYPE_GMT);
505 __timeZoneSearchList->Sort(*pTimeZoneSort);
506 delete pTimeZoneSort;
510 TimeZoneForm::OnTextValueChanged(const Tizen::Ui::Control& source)
513 String searchText = __pSearchBar->GetText();
515 if (searchText.CompareTo(L""))
517 TimeZoneData* pData = null;
518 __timeZoneSearchList->RemoveAll(true);
520 for (int count = 0; count < __timeZoneTotalList->GetCount(); count++)
523 String lowerSearchText;
524 pData = static_cast<TimeZoneData*>(__timeZoneTotalList->GetAt(count));
526 String country(pData->GetCountryData());
528 pData->GetCountryData().ToLower(lowerData);
529 searchText.ToLower(lowerSearchText);
531 if (lowerData.Contains(lowerSearchText))
533 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(*pData));
539 TimeZoneData* pData = null;
540 __timeZoneSearchList->RemoveAll(true);
542 for (int count = 0; count < __timeZoneTotalList->GetCount(); count++)
545 String lowerSearchText;
546 pData = static_cast<TimeZoneData*>(__timeZoneTotalList->GetAt(count));
548 String region(pData->GetRegionData());
549 String country(pData->GetCountryData());
550 Integer gmt = pData->GetGMTData();
552 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(*pData));
556 if (__timeZoneSearchList->GetCount() == 0)
559 String noSearchData(ResourceManager::GetString(L"IDS_COM_BODY_NO_SEARCH_RESULTS"));
560 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(noSearchData, noSearchData, noData));
566 __pTableView->UpdateTableView();
570 TimeZoneForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
572 if (__sortTabSelect == actionId)
578 case IDA_FOOTER_ITEM_NAME:
580 case IDA_FOOTER_ITEM_TIME:
582 __sortTabSelect = actionId;
591 __pTableView->UpdateTableView();
595 TimeZoneForm::GetDefaultGroupItemHeight(void)
601 TimeZoneForm::GetDefaultItemHeight(void)
603 return H_GROUP_ITEM_DEFAULT;
607 TimeZoneForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
612 TimeZoneForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
617 TimeZoneForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
622 TimeZoneForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
626 Tizen::Base::Collection::IList*
627 TimeZoneForm::AppControlTimeZoneResult(void)
633 TimeZoneForm::InitTimeZoneLocaleList(void)
635 if (__timeZoneTotalList != null)
640 __timeZoneTotalList = new (std::nothrow) ArrayList(SingleObjectDeleter);
641 return __timeZoneTotalList->Construct();
645 TimeZoneForm::RemoveAllTimeZoneLocaleList(void)
647 if (__timeZoneTotalList != null)
649 delete __timeZoneTotalList;
650 __timeZoneTotalList = null;
653 if (__timeZoneSearchList != null)
655 delete __timeZoneSearchList;
656 __timeZoneSearchList = null;
661 TimeZoneForm::SetTimeZoneLocaleList(TimeZoneData* pTimeZoneData)
663 InitTimeZoneLocaleList();
665 if (__timeZoneTotalList == null)
670 return __timeZoneTotalList->Add(pTimeZoneData);
674 TimeZoneForm::SetTimeZoneLocaleSearchList(TimeZoneData* pTimeZoneData)
676 if (__timeZoneSearchList == null)
678 __timeZoneSearchList = new (std::nothrow) ArrayList(SingleObjectDeleter);
679 __timeZoneSearchList->Construct();
682 return __timeZoneSearchList->Add(pTimeZoneData);
686 TimeZoneForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
688 switch (keypadAction)
690 case KEYPAD_ACTION_SEARCH:
692 __pSearchBar->HideKeypad();
693 __pSearchBar->Invalidate(false);
703 TiemZoneComparer::Compare(const Tizen::Base::Object& obj1, const Tizen::Base::Object& obj2, int& cmp) const
707 case DATA_TYPE_REGION:
709 cmp = static_cast<const TimeZoneData&>(obj1).GetRegionData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetRegionData());
713 case DATA_TYPE_COUNTRY:
715 cmp = static_cast<const TimeZoneData&>(obj1).GetCountryData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetCountryData());
721 cmp = static_cast<const TimeZoneData&>(obj1).GetGMTData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetGMTData());
725 cmp = static_cast<const TimeZoneData&>(obj1).GetCountryData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetCountryData());
734 return GetLastResult();
738 TimeZoneData::GetCountryData(void) const
740 return _timeZoneCountry;
744 TimeZoneData::GetRegionData(void) const
746 return _timeZoneRegion;
750 TimeZoneData::GetGMTData(void) const