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 StLocationForm.cpp
19 * @brief This is the implementation file for LocationForm class.
22 #include "StLocationForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::System;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
36 static const int ID_GROUP_GPS_1 = 0;
37 static const int ID_GROUP_GPS_1_ITEM_COUNT = 1;
38 static const int ID_ITEM_GPS_ON_OFF = 0;
40 #ifdef DISPLAY_SETTING_MENU_FOR_R0
41 static const int ID_GROUP_GPS_2 = 1;
42 static const int ID_GROUP_GPS_2_ITEM_COUNT = 1;
43 static const int ID_ITEM_GPS_NETWORK_POSITION = 0;
44 static const int ID_GROUP_GPS_3 = 2;
45 static const int ID_GROUP_GPS_3_ITEM_COUNT = 0;
47 static const int ID_GROUP_GPS_2 = 1;
48 static const int ID_GROUP_GPS_2_ITEM_COUNT = 3;
49 static const int ID_ITEM_GPS_ADVANCED_GPS = 0;
50 static const int ID_ITEM_GPS_NETWORK_POSITION = 1;
51 static const int ID_ITEM_GPS_MY_POSITION = 2;
53 static const int ID_GROUP_GPS_3 = 2;
54 static const int ID_GROUP_GPS_3_ITEM_COUNT = 2;
55 static const int ID_GROUP_GPS_HOME_SCREEN = 0;
56 static const int ID_GROUP_GPS_ACCU_WEATHER = 1;
59 static const int ID_GROUP_COUNT = 3;
60 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_GPS_2_ITEM_COUNT;
62 static const int ID_LOCATION_FOOTER_SCAN = 0;
63 static const int ID_LOCATION_FOOTER_EMPTY1 = 1;
64 static const int ID_LOCATION_FOOTER_EMPTY2 = 2;
66 static const int ID_FOOTER_ITEM_INDEX_1 = 0;
67 static const int ID_FOOTER_ITEM_INDEX_2 = 1;
69 static const int IDA_FOOTER_ITEM_HELP = 100;
71 static const int W_RESIZE_LABEL_GAP = 170;
72 static const int RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING = 106;
74 LocationForm::LocationForm(void)
75 : __isAppControlRequest(false)
76 , __categoryCheck(L"")
80 LocationForm::~LocationForm(void)
85 LocationForm::CreateFooter(void)
87 Footer* pFooter = GetFooter();
90 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
92 FooterItem footerHelp;
93 footerHelp.Construct(IDA_FOOTER_ITEM_HELP);
94 footerHelp.SetText(ResourceManager::GetString(L"IDS_ST_BODY_HELP"));
96 pFooter->AddItem(footerHelp);
97 pFooter->SetBackButton();
98 pFooter->AddActionEventListener(*this);
99 pFooter->SetItemEnabled(ID_FOOTER_ITEM_INDEX_1, true);
101 SetFormBackEventListener(this);
105 LocationForm::OnInitializing(void)
107 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_LOCATIONS"));
111 AppLogDebug("ENTER");
117 LocationForm::OnTerminating(void)
121 SetFormBackEventListener(null);
126 LocationForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
128 bool itemStatus = false;
129 __pTableView->UpdateTableView();
131 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, itemStatus);
132 if (!IsFailed(GetLastResult())
133 && (itemStatus == true))
135 __pTableView->SetItemChecked(ID_GROUP_GPS_1, ID_ITEM_GPS_ON_OFF, itemStatus);
137 AppLogDebug("Gps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
139 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, itemStatus);
140 if (!IsFailed(GetLastResult())
141 && (itemStatus == true))
143 __pTableView->SetItemChecked(ID_GROUP_GPS_2, ID_ITEM_GPS_NETWORK_POSITION, itemStatus);
145 AppLogDebug("Wps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
149 __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
151 if (__categoryCheck == L"category:Location")
153 __isAppControlRequest = true;
160 LocationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
165 LocationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
167 SceneManager* pSceneManager = SceneManager::GetInstance();
168 AppAssert(pSceneManager);
170 if (__isAppControlRequest == true)
172 UiApp* pApp = UiApp::GetInstance();
174 AppControlLocationResult();
179 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
184 LocationForm::GetGroupCount(void)
186 AppLogDebug("ENTER");
187 return ID_GROUP_COUNT;
191 LocationForm::GetItemCount(int groupIndex)
199 itemCount = ID_GROUP_GPS_1_ITEM_COUNT;
205 itemCount = ID_GROUP_GPS_2_ITEM_COUNT;
211 #ifndef DISPLAY_SETTING_MENU_FOR_R0
212 itemCount = ID_GROUP_GPS_3_ITEM_COUNT;
214 itemCount = ID_GROUP_GPS_3_ITEM_COUNT;
223 AppLogDebug("GetItemCount %d", itemCount);
228 LocationForm::CreateGroupItem(int groupIndex, int itemWidth)
230 AppLogDebug("ENTER");
232 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
233 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
234 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
235 Rectangle itemRectangle;
237 Label* pLabel = null;
239 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
245 yItemOffset = Y_GROUP_INDEX_DEFAULT;
246 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
252 yItemOffset = Y_GROUP_INDEX_DEFAULT;
253 itemHeight = Y_GROUP_INDEX_DEFAULT;
258 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
259 itemRectangle.y = yItemOffset;
260 itemRectangle.width = itemWidth;
261 itemRectangle.height = itemHeight;
263 RelativeLayout relativeLayout;
264 relativeLayout.Construct();
266 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
267 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
269 pLabel = new (std::nothrow) Label();
270 pLabel->Construct(itemRectangle, groupText);
271 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
272 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
273 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
274 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
276 pItem->AddControl(*pLabel);
277 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
278 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
279 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
280 pItem->SetEnabled(false);
286 LocationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
288 Rectangle itemRectangle;
289 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
291 Label* pLabel = null;
292 int fontSize = GetFontSize();
294 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
295 ItemTypeOneLine(itemRectangle);
302 itemText = ResourceManager::GetString(L"IDS_CAM_OPT_GPS");
303 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
304 if (!IsFailed(GetLastResult())
305 && (gpsStatus == true))
307 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
316 case ID_ITEM_GPS_NETWORK_POSITION:
319 itemText = ResourceManager::GetString(L"IDS_LBS_BODY_NETWORK_POSITION");
320 itemRectangle.width -= W_RESIZE_LABEL_GAP;
322 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
323 if (!IsFailed(GetLastResult())
324 && (wpsStatus == true))
326 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
331 #ifndef DISPLAY_SETTING_MENU_FOR_R0
332 case ID_ITEM_GPS_ADVANCED_GPS:
334 itemText = ResourceManager::GetString(L"IDS_ST_BODY_ADVANCED_GPS");
338 case ID_ITEM_GPS_MY_POSITION:
340 style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
341 itemText = ResourceManager::GetString(L"IDS_LBS_BODY_MY_POSITION");
354 #ifndef DISPLAY_SETTING_MENU_FOR_R0
357 case ID_GROUP_GPS_HOME_SCREEN:
359 itemText = ResourceManager::GetString(L"IDS_ST_BODY_HOMESCREEN");
364 case ID_GROUP_GPS_ACCU_WEATHER:
366 // itemText = ResourceManager::GetString(L"IDS_LOCATION_ACCUWEATHER");
381 TableViewItem* pItem = new (std::nothrow) TableViewItem();
383 RelativeLayout relativeLayout;
384 relativeLayout.Construct();
386 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
387 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
389 pLabel = new (std::nothrow) Label();
390 pLabel->Construct(itemRectangle, itemText);
391 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
392 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
393 pLabel->SetTextColor(COLOR_MAIN_TEXT);
395 pItem->AddControl(*pLabel);
396 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
397 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
398 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
404 LocationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
406 AppLogDebug("ENTER");
415 LocationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
417 AppLogDebug("ENTER");
426 LocationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
428 bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
434 if (itemIndex == ID_ITEM_GPS_ON_OFF)
436 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
438 itemSelectStatus = !itemSelectStatus;
441 if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_LOCATION_GPS, itemSelectStatus) == E_SUCCESS)
443 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
451 if (itemIndex == ID_ITEM_GPS_NETWORK_POSITION)
453 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
455 itemSelectStatus = !itemSelectStatus;
458 if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_LOCATION_WPS, itemSelectStatus) == E_SUCCESS)
460 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
463 #ifndef DISPLAY_SETTING_MENU_FOR_R0
464 if (itemIndex == ID_ITEM_GPS_ADVANCED_GPS)
466 // TODO: nothing todo yet.
468 if (itemIndex == ID_ITEM_GPS_MY_POSITION)
470 // TODO: nothing todo yet.
476 #ifndef DISPLAY_SETTING_MENU_FOR_R0
479 if (itemIndex == ID_GROUP_GPS_HOME_SCREEN)
481 // TODO: nothing todo yet.
483 if (itemIndex == ID_GROUP_GPS_ACCU_WEATHER)
485 // TODO: nothing todo yet.
497 LocationForm::OnActionPerformed(const Control& source, int actionId)
499 SceneManager* pSceneManager = SceneManager::GetInstance();
500 AppAssert(pSceneManager);
504 case IDA_FOOTER_ITEM_HELP:
506 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_LOCATION_HELP, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
512 AppLogDebug("ID_HEADER_VOLUME Tab Selected %d", actionId);
519 LocationForm::GetDefaultGroupItemHeight(void)
521 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
525 LocationForm::GetDefaultItemHeight(void)
527 return H_GROUP_ITEM_DEFAULT;
531 LocationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
536 LocationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
541 LocationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
546 LocationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
551 LocationForm::AppControlLocationResult(void)
555 bool gpsStatus = false;
556 bool wpsStatus = false;
558 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
561 IList* pDefaultResultIList = null;
562 ArrayList* pDataList = null;
564 pDataList = new (std::nothrow) ArrayList();
565 pDataList->Construct();
567 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
568 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
570 pDataList->Add(*(new (std::nothrow) String(L"APPCONTROL_RESULT_SUCCEEDED")));
571 pDataList->Add(*(new (std::nothrow) String(L"category:Location")));
573 if (gpsStatus == true)
575 value = L"GPSEnabled";
579 value = L"GPSDisabled";
581 pDataList->Add(*(new (std::nothrow) String(value)));
583 if (wpsStatus == true)
585 value = L"WPSEnabled";
589 value = L"WPSDisabled";
591 pDataList->Add(*(new (std::nothrow) String(value)));
593 pDefaultResultIList = (pDataList->GetItemsN(0, pDataList->GetCount()));
595 pAppManager->SendAppControlResult(reqId, pDefaultResultIList);
597 pDataList->RemoveAll(true);
599 pDefaultResultIList->RemoveAll(true);
600 delete pDefaultResultIList;
603 AppCtrlResult ResultValue = APP_CTRL_RESULT_FAILED;
604 HashMap* hashMap = new (std::nothrow) HashMap();
605 hashMap->Construct();
607 if (__categoryCheck == L"category:Location")
609 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
610 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
612 ResultValue = APP_CTRL_RESULT_SUCCEEDED;
613 hashMap->Add(*(new (std::nothrow) String(L"category")), *(new (std::nothrow) String(L"Location")));
615 if (gpsStatus == true)
617 status = L"GPSEnabled";
621 status = L"GPSDisabled";
623 hashMap->Add(*(new (std::nothrow) String(L"GPS")), *(new (std::nothrow) String(status)));
625 if (wpsStatus == true)
627 status = L"WPSEnabled";
631 status = L"WPSDisabled";
633 hashMap->Add(*(new (std::nothrow) String(L"WPS")), *(new (std::nothrow) String(status)));
636 pAppManager->SendAppControlResult(reqId, ResultValue, hashMap);
638 hashMap->RemoveAll();