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 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 X_FIRST_LINE_SUB_TEXT = 520;
44 static const int W_FIRST_LINE_SUB_TEXT = 180;
46 static const int TEXT_SIZE = 10;
48 static const int MINUTES_TO_HOUR = 60;
49 static const int GMT_START = -12;
50 static const int GMT_END = 14;
52 static const int NEXT_INDEX = 1;
53 static const int DIVIDE_BY_TEN = 10;
54 static const int DIVIDE_BY_TWO = 2;
55 static const int MULTI_BY_SEVEN = 7;
56 static const int MULTI_BY_THREE = 3;
57 static const int MULTI_BY_EIGHT = 8;
58 static const int MULTI_BY_TWO = 2;
60 static const int GMT_TEXT_GAP = 20;
61 static const int GROUP_INDEX_DEFAULT_LABEL_HEIGHT = 40;
63 static const int H_SEARCH_BAR_ITEM = H_GROUP_ITEM_DEFAULT;
64 static const int Y_TABLE_VIEW_AREA = H_GROUP_ITEM_DEFAULT;
66 static const int H_PORTRAIT_KEY_PAD_INPUT_MODE_GAP = 0;
67 static const int H_LANDSCAPE_KEY_PAD_INPUT_MODE_GAP = 0;
69 static const int W_GMT_FIXED_SIZE = 200;
70 static const int COUNTRY_TEXT_GAP = 30;
72 TimeZoneForm::TimeZoneForm(void)
73 : __isAppControlRequest(false)
74 , __sortTabSelect(IDA_FOOTER_ITEM_NAME)
76 , __timeZoneTotalList(null)
77 , __timeZoneSearchList(null)
81 TimeZoneForm::~TimeZoneForm(void)
86 TimeZoneForm::CreateFooter(void)
88 Footer* pFooter = GetFooter();
91 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
93 FooterItem footerItemName;
94 footerItemName.Construct(IDA_FOOTER_ITEM_NAME);
95 footerItemName.SetText(ResourceManager::GetString(L"IDS_ST_BODY_NAME"));
97 FooterItem footerItemTime;
98 footerItemTime.Construct(IDA_FOOTER_ITEM_TIME);
99 footerItemTime.SetText(ResourceManager::GetString(L"IDS_COM_BODY_TIME"));
101 pFooter->SetStyle(FOOTER_STYLE_SEGMENTED_TEXT);
102 pFooter->AddItem(footerItemName);
103 pFooter->AddItem(footerItemTime);
104 pFooter->SetBackButton();
105 pFooter->AddActionEventListener(*this);
107 SetFormBackEventListener(this);
111 TimeZoneForm::GetTimeZoneList(void)
113 IList* pAvailableLocales = null;
115 LocaleManager localeManager;
116 localeManager.Construct();
118 pAvailableLocales = localeManager.GetAvailableTimeZonesN();
119 if (pAvailableLocales)
121 for (int i = 0; i < pAvailableLocales->GetCount(); i++)
129 String* pKey = static_cast<String*>(pAvailableLocales->GetAt(i));
131 StringTokenizer stringTokenizer(*pKey, L"/");
132 stringTokenizer.GetNextToken(region);
133 stringTokenizer.GetNextToken(country);
135 if ((country.IsEmpty() == true) || (country.IsEmpty() == true) || (country.Equals(L"ACT", false))
136 || (region.Equals(L"SystemV", false)) || (region.Equals(L"Etc", false)))
141 if (stringTokenizer.HasMoreTokens() == true)
143 stringTokenizer.GetNextToken(extraData);
144 country.Append(L"/" + extraData);
147 TimeZone::GetTimeZone(*pKey, timeZone);
148 gmtHour = timeZone.GetRawOffset();
150 SetTimeZoneLocaleList(new (std::nothrow) TimeZoneData(region, country, gmtHour));
151 SetTimeZoneLocaleSearchList( new (std::nothrow) TimeZoneData(region, country, gmtHour));
160 TimeZoneForm::CreateTableView(void)
162 Rectangle bounds = GetClientAreaBounds();
163 Rectangle tableViewBounds = bounds;
165 tableViewBounds.y = Y_TABLE_VIEW_AREA;
166 tableViewBounds.height = (bounds.height - tableViewBounds.y);
168 __pTableView = new (std::nothrow) GroupedTableView();
169 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
170 __pTableView->SetItemProvider(this);
172 AddControl(*__pTableView);
174 __pTableView->AddGroupedTableViewItemEventListener(*this);
176 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
177 if (pRelativeLayout != null)
179 pRelativeLayout->SetHorizontalFitPolicy(*__pSearchBar, FIT_POLICY_PARENT);
180 pRelativeLayout->SetVerticalFitPolicy(*__pSearchBar, FIT_POLICY_FIXED);
181 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
182 pRelativeLayout->SetRelation(*__pTableView, *__pSearchBar, RECT_EDGE_RELATION_TOP_TO_BOTTOM);
183 pRelativeLayout->SetRelation(*__pTableView, *this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
184 delete pRelativeLayout;
189 TimeZoneForm::OnInitializing(void)
191 Rectangle bounds = GetClientAreaBounds();
192 Rectangle searchbarBounds = bounds;
194 searchbarBounds.y = 0;
195 searchbarBounds.height = H_GROUP_ITEM_DEFAULT;
197 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_TIME_ZONE"));
200 __pSearchBar = new (std::nothrow) SearchBar();
201 __pSearchBar->Construct(searchbarBounds, true, KEYPAD_ACTION_SEARCH);
202 __pSearchBar->SetGuideText(L"Search");
203 __pSearchBar->AddSearchBarEventListener(*this);
204 __pSearchBar->AddTextEventListener(*this);
205 __pSearchBar->AddKeypadEventListener(*this);
206 __pSearchBar->SetContentAreaSize(Dimension(0, 0));
208 AddControl(*__pSearchBar);
213 AppLogDebug("ENTER");
219 TimeZoneForm::OnTerminating(void)
222 RemoveAllTimeZoneLocaleList();
225 SetFormBackEventListener(null);
230 TimeZoneForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
234 String categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
236 if (categoryCheck == L"category:TimeZone")
238 __isAppControlRequest = true;
242 __pTableView->UpdateTableView();
246 TimeZoneForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
251 TimeZoneForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
253 SceneManager* pSceneManager = SceneManager::GetInstance();
254 AppAssert(pSceneManager);
256 if (__isAppControlRequest == true)
258 UiApp* pApp = UiApp::GetInstance();
260 AppControlTimeZoneResult();
265 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
270 TimeZoneForm::GetGroupCount(void)
272 AppLogDebug("ENTER");
273 return ID_GROUP_COUNT;
277 TimeZoneForm::GetItemCount(int groupIndex)
279 int itemCount = __timeZoneSearchList->GetCount();
281 AppLogDebug("GetItemCount %d", itemCount);
286 TimeZoneForm::CreateGroupItem(int groupIndex, int itemWidth)
288 AppLogDebug("ENTER");
291 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
293 Label* pLabel = null;
295 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
296 pItem->Construct(Dimension(itemWidth, itemHeight));
298 pLabel = new (std::nothrow) Label();
299 pLabel->Construct(Rectangle(X_GROUP_INDEX_DEFAULT_LABEL, Y_GROUP_INDEX_DEFAULT_LABEL, itemWidth, GROUP_INDEX_DEFAULT_LABEL_HEIGHT), groupText);
300 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
301 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
302 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
304 pItem->AddControl(*pLabel);
305 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
306 pItem->SetEnabled(false);
312 TimeZoneForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
314 AppLogDebug("CreateItem group[%d] index[%d]", groupIndex, itemIndex);
318 int computeGmtMin = 0;
322 String firstLineText;
323 String secondLineText;
324 Rectangle itemRectangle;
325 Rectangle itemGMTRectangle;
326 Rectangle itemSecondLineTextRect;
327 int itemHeight = H_GROUP_ITEM_DEFAULT;
329 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
330 Label* pLabel = null;
331 int fontSize = GetFontSize();
333 TimeZoneData* pData = static_cast<TimeZoneData*>(__timeZoneSearchList->GetAt(itemIndex));
335 TableViewItem* pItem = new (std::nothrow) TableViewItem();
337 firstLineText = pData->GetCountryData();
338 secondLineText = pData->GetRegionData();
339 gmtMin = pData->GetGMTData();
341 if (firstLineText.Equals(L"No Search Result", false))
343 ItemTypeOneLine(itemRectangle);
344 itemHeight = (itemRectangle.height);
346 RelativeLayout relativeLayout;
347 relativeLayout.Construct();
349 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
350 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
352 pLabel = new (std::nothrow) Label();
353 pLabel->Construct(itemRectangle, firstLineText);
354 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
355 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
356 pLabel->SetTextColor(COLOR_MAIN_TEXT);
358 pItem->AddControl(*pLabel);
360 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
361 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
362 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
366 gmtHour = (gmtMin.value / MINUTES_TO_HOUR);
367 gmtMin.value %= MINUTES_TO_HOUR;
369 stringGMT.Append(L"GMT");
372 stringGMT.Append(L"+");
374 stringGMT.Append(gmtHour);
378 stringGMT.Append(L":");
380 if (gmtMin.value < 0)
382 computeGmtMin -= (computeGmtMin + gmtMin.value);
383 stringGMT.Append(computeGmtMin);
387 stringGMT.Append(gmtMin.value);
391 ItemTypeTwoLine(itemRectangle, itemSecondLineTextRect, fontSize);
392 itemHeight = (itemRectangle.height + itemSecondLineTextRect.height);
393 itemGMTRectangle = itemRectangle;
395 RelativeLayout relativeLayout;
396 relativeLayout.Construct();
398 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
399 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
401 itemRectangle.width = itemWidth;
402 itemGMTRectangle.width = W_GMT_FIXED_SIZE;
403 itemGMTRectangle.x = itemRectangle.width - itemGMTRectangle.width;
404 itemRectangle.width = itemRectangle.width - itemGMTRectangle.width;
406 pLabel = new (std::nothrow) Label();
407 pLabel->Construct(itemRectangle, firstLineText);
408 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
409 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
410 pLabel->SetTextColor(COLOR_MAIN_TEXT);
412 Label* pSecLabel = new (std::nothrow) Label();
413 pSecLabel->Construct(itemGMTRectangle, stringGMT);
414 pSecLabel->SetTextHorizontalAlignment(ALIGNMENT_RIGHT);
415 pSecLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
416 pSecLabel->SetTextColor(COLOR_MAIN_TEXT);
418 pItem->AddControl(*pLabel);
419 pItem->AddControl(*pSecLabel);
421 relativeLayout.SetHorizontalFitPolicy(*pSecLabel, FIT_POLICY_FIXED);
422 relativeLayout.SetRelation(*pSecLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
423 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
424 relativeLayout.SetRelation(*pLabel, *pSecLabel, RECT_EDGE_RELATION_RIGHT_TO_LEFT);
426 pLabel = new (std::nothrow) Label();
427 pLabel->Construct(itemSecondLineTextRect, secondLineText);
428 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
429 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
430 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
431 pLabel->SetTextColor(COLOR_SUB_TEXT);
433 pItem->AddControl(*pLabel);
434 relativeLayout.SetMargin(*pLabel, itemSecondLineTextRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
435 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
436 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
443 TimeZoneForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
445 AppLogDebug("ENTER");
454 TimeZoneForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
456 AppLogDebug("ENTER");
465 TimeZoneForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
467 AppLogDebug("OnTableViewItemStateChanged group[%d] index[%d]", groupIndex, itemIndex);
469 SceneManager* pSceneManager = SceneManager::GetInstance();
470 AppAssert(pSceneManager);
473 TimeZoneData* pData = static_cast<TimeZoneData*>(__timeZoneSearchList->GetAt(itemIndex));
475 if (pData->GetCountryData().Equals(L"No Search Result", true))
477 AppLogDebug("selected key is \"No Search Result\"");
481 key.Append(pData->GetRegionData() + L"/" + pData->GetCountryData());
482 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_TIME_ZONE, key) == E_SUCCESS)
484 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
489 TimeZoneForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, Tizen::Ui::Controls::SearchBarMode mode)
491 if (mode == SEARCH_BAR_MODE_INPUT)
497 __timeZoneSearchList->RemoveAll();
499 for(int count = 0; count < __timeZoneTotalList->GetCount(); count++)
501 TimeZoneData* pData = null;
502 pData = static_cast<TimeZoneData*>(__timeZoneTotalList->GetAt(count));
503 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(*pData));
507 __pTableView->UpdateTableView();
513 TimeZoneForm::SortTimeZoneData(void)
515 TiemZoneComparer* pTimeZoneSort = null;
517 if (__sortTabSelect == IDA_FOOTER_ITEM_NAME)
519 pTimeZoneSort = new TiemZoneComparer(DATA_TYPE_COUNTRY);
523 pTimeZoneSort = new TiemZoneComparer(DATA_TYPE_GMT);
525 __timeZoneSearchList->Sort(*pTimeZoneSort);
526 delete pTimeZoneSort;
530 TimeZoneForm::OnKeypadClosed(Tizen::Ui::Control& source)
532 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
537 TimeZoneForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
539 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, false);
543 TimeZoneForm::OnKeypadOpened(Tizen::Ui::Control& source)
549 TimeZoneForm::OnTextValueChanged(const Tizen::Ui::Control& source)
552 String searchText = __pSearchBar->GetText();
554 if (searchText.CompareTo(L""))
556 TimeZoneData* pData = null;
557 __timeZoneSearchList->RemoveAll(true);
559 for (int count = 0; count < __timeZoneTotalList->GetCount(); count++)
562 String lowerSearchText;
563 pData = static_cast<TimeZoneData*>(__timeZoneTotalList->GetAt(count));
565 String country(pData->GetCountryData());
567 pData->GetCountryData().ToLower(lowerData);
568 searchText.ToLower(lowerSearchText);
570 if (lowerData.Contains(lowerSearchText))
572 SetTimeZoneLocaleSearchList(new (std::nothrow) TimeZoneData(*pData));
578 TimeZoneData* pData = null;
579 __timeZoneSearchList->RemoveAll(true);
581 for (int count = 0; count < __timeZoneTotalList->GetCount(); count++)
584 String lowerSearchText;
585 pData = static_cast<TimeZoneData*>(__timeZoneTotalList->GetAt(count));
587 String region(pData->GetRegionData());
588 String country(pData->GetCountryData());
589 Integer gmt = pData->GetGMTData();
591 SetTimeZoneLocaleSearchList(new (std::nothrow)TimeZoneData(*pData));
595 if (__timeZoneSearchList->GetCount() == 0)
598 String noSearchData(L"No Search Result");
599 SetTimeZoneLocaleSearchList(new (std::nothrow)TimeZoneData(noSearchData, noSearchData, noData));
605 __pTableView->UpdateTableView();
609 TimeZoneForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
613 case IDA_FOOTER_ITEM_NAME:
615 case IDA_FOOTER_ITEM_TIME:
617 __sortTabSelect = actionId;
626 __pTableView->UpdateTableView();
630 TimeZoneForm::GetDefaultGroupItemHeight(void)
636 TimeZoneForm::GetDefaultItemHeight(void)
638 return H_GROUP_ITEM_DEFAULT;
642 TimeZoneForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
647 TimeZoneForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
652 TimeZoneForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
657 TimeZoneForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
661 Tizen::Base::Collection::IList*
662 TimeZoneForm::AppControlTimeZoneResult(void)
669 TimeZoneForm::InitTimeZoneLocaleList(void)
671 if (__timeZoneTotalList != null)
676 __timeZoneTotalList = new (std::nothrow) ArrayList(SingleObjectDeleter);
677 return __timeZoneTotalList->Construct();
681 TimeZoneForm::RemoveAllTimeZoneLocaleList(void)
683 if (__timeZoneTotalList != null)
685 delete __timeZoneTotalList;
686 __timeZoneTotalList = null;
689 if (__timeZoneSearchList != null)
691 delete __timeZoneSearchList;
692 __timeZoneSearchList = null;
697 TimeZoneForm::SetTimeZoneLocaleList(TimeZoneData* pTimeZoneData)
699 InitTimeZoneLocaleList();
701 if (__timeZoneTotalList == null)
706 return __timeZoneTotalList->Add(pTimeZoneData);
710 TimeZoneForm::SetTimeZoneLocaleSearchList(TimeZoneData* pTimeZoneData)
712 if (__timeZoneSearchList == null)
714 __timeZoneSearchList = new (std::nothrow) ArrayList(SingleObjectDeleter);
715 __timeZoneSearchList->Construct();
718 return __timeZoneSearchList->Add(pTimeZoneData);
722 TimeZoneForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
724 switch (keypadAction)
726 case KEYPAD_ACTION_SEARCH:
728 __pSearchBar->HideKeypad();
729 __pSearchBar->Invalidate(false);
739 TiemZoneComparer::Compare(const Tizen::Base::Object& obj1, const Tizen::Base::Object& obj2, int& cmp) const
743 case DATA_TYPE_REGION:
745 cmp = static_cast<const TimeZoneData&>(obj1).GetRegionData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetRegionData());
749 case DATA_TYPE_COUNTRY:
751 cmp = static_cast<const TimeZoneData&>(obj1).GetCountryData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetCountryData());
757 cmp = static_cast<const TimeZoneData&>(obj1).GetGMTData().CompareTo(static_cast<const TimeZoneData&>(obj2).GetGMTData());
765 return GetLastResult();
769 TimeZoneData::GetCountryData(void) const
771 return _timeZoneCountry;
775 TimeZoneData::GetRegionData(void) const
777 return _timeZoneRegion;
781 TimeZoneData::GetGMTData(void) const