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 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 char APPCONTROL_REQUEST_DEFAULT = 0x00;
37 static const char APPCONTROL_REQUEST_LOCATION = 0x20;
39 static const int ID_GROUP_GPS_1 = 0;
40 static const int ID_GROUP_GPS_1_ITEM_COUNT = 1;
41 static const int ID_ITEM_GPS_ON_OFF = 0;
43 static const int ID_GROUP_GPS_2 = 1;
44 static const int ID_GROUP_GPS_2_ITEM_COUNT = 1;
45 static const int ID_ITEM_GPS_NETWORK_POSITION = 0;
46 static const int ID_GROUP_GPS_3 = 2;
47 static const int ID_GROUP_GPS_3_ITEM_COUNT = 0;
49 static const int ID_GROUP_COUNT = 3;
50 static const int ID_FOOTER_ITEM_INDEX_1 = 0;
52 static const int IDA_FOOTER_ITEM_HELP = 100;
54 static const int W_RESIZE_LABEL_GAP = 170;
56 LocationForm::LocationForm(void)
57 : __isAppControlRequest(APPCONTROL_REQUEST_DEFAULT)
58 , __categoryCheck(L"")
62 LocationForm::~LocationForm(void)
67 LocationForm::CreateFooter(void)
69 Footer* pFooter = GetFooter();
72 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
74 FooterItem footerHelp;
75 footerHelp.Construct(IDA_FOOTER_ITEM_HELP);
76 footerHelp.SetText(ResourceManager::GetString(L"IDS_ST_BODY_HELP"));
78 pFooter->AddItem(footerHelp);
79 pFooter->AddActionEventListener(*this);
80 pFooter->SetItemEnabled(ID_FOOTER_ITEM_INDEX_1, true);
82 SetFormBackEventListener(this);
86 LocationForm::OnInitializing(void)
88 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
89 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_LOCATIONS"));
99 LocationForm::OnTerminating(void)
103 SetFormBackEventListener(null);
108 LocationForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
110 bool itemStatus = false;
111 __pTableView->UpdateTableView();
113 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, itemStatus);
114 if (!IsFailed(GetLastResult())
115 && (itemStatus == true))
117 __pTableView->SetItemChecked(ID_GROUP_GPS_1, ID_ITEM_GPS_ON_OFF, itemStatus);
119 AppLogDebug("Gps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
121 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, itemStatus);
122 if (!IsFailed(GetLastResult())
123 && (itemStatus == true))
125 __pTableView->SetItemChecked(ID_GROUP_GPS_2, ID_ITEM_GPS_NETWORK_POSITION, itemStatus);
127 AppLogDebug("Wps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
131 __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
133 if (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/gps") == 0)
135 __isAppControlRequest = APPCONTROL_REQUEST_LOCATION;
137 else if (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/wps") == 0)
139 __isAppControlRequest = APPCONTROL_REQUEST_LOCATION;
147 LocationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
152 LocationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
154 SceneManager* pSceneManager = SceneManager::GetInstance();
155 AppAssert(pSceneManager);
157 if (__isAppControlRequest != APPCONTROL_REQUEST_DEFAULT)
159 UiApp* pApp = UiApp::GetInstance();
161 AppControlLocationResult();
166 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
171 LocationForm::GetGroupCount(void)
173 AppLogDebug("ENTER");
174 return ID_GROUP_COUNT;
178 LocationForm::GetItemCount(int groupIndex)
186 itemCount = ID_GROUP_GPS_1_ITEM_COUNT;
192 itemCount = ID_GROUP_GPS_2_ITEM_COUNT;
198 itemCount = ID_GROUP_GPS_3_ITEM_COUNT;
206 AppLogDebug("GetItemCount %d", itemCount);
211 LocationForm::CreateGroupItem(int groupIndex, int itemWidth)
213 AppLogDebug("ENTER");
215 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
216 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
217 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
218 Rectangle itemMainRectangle;
220 Label* pLabel = null;
222 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
228 yItemOffset = Y_GROUP_INDEX_DEFAULT;
229 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
235 yItemOffset = Y_GROUP_INDEX_DEFAULT;
236 itemHeight = Y_GROUP_INDEX_DEFAULT;
241 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
242 itemMainRectangle.y = yItemOffset;
243 itemMainRectangle.width = itemWidth;
244 itemMainRectangle.height = itemHeight;
246 RelativeLayout relativeLayout;
247 relativeLayout.Construct();
249 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
250 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
252 pLabel = new (std::nothrow) Label();
253 pLabel->Construct(itemMainRectangle, groupText);
254 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
255 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
256 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
257 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
259 pItem->AddControl(pLabel);
260 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
261 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
262 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
263 pItem->SetEnabled(false);
269 LocationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
271 Rectangle itemMainRectangle;
272 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
274 Label* pLabel = null;
275 int fontSize = GetFontSize();
277 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
278 ItemTypeOneLine(itemMainRectangle);
285 itemMainText = ResourceManager::GetString(L"IDS_CAM_OPT_GPS");
286 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
287 if (!IsFailed(GetLastResult())
288 && (gpsStatus == true))
290 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
299 case ID_ITEM_GPS_NETWORK_POSITION:
302 itemMainText = ResourceManager::GetString(L"IDS_LBS_BODY_NETWORK_POSITION");
303 itemMainRectangle.width -= W_RESIZE_LABEL_GAP;
305 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
306 if (!IsFailed(GetLastResult())
307 && (wpsStatus == true))
309 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
324 TableViewItem* pItem = new (std::nothrow) TableViewItem();
326 RelativeLayout relativeLayout;
327 relativeLayout.Construct();
329 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), 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);
339 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
340 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
341 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
347 LocationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
349 AppLogDebug("ENTER");
358 LocationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
360 AppLogDebug("ENTER");
369 LocationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
371 bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
377 if (itemIndex == ID_ITEM_GPS_ON_OFF)
379 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
381 itemSelectStatus = !itemSelectStatus;
384 if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_LOCATION_GPS, itemSelectStatus) == E_SUCCESS)
386 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
394 if (itemIndex == ID_ITEM_GPS_NETWORK_POSITION)
396 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
398 itemSelectStatus = !itemSelectStatus;
401 if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_LOCATION_WPS, itemSelectStatus) == E_SUCCESS)
403 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
415 LocationForm::OnActionPerformed(const Control& source, int actionId)
417 SceneManager* pSceneManager = SceneManager::GetInstance();
418 AppAssert(pSceneManager);
422 case IDA_FOOTER_ITEM_HELP:
424 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_LOCATION_HELP, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
430 AppLogDebug("ID_HEADER_VOLUME Tab Selected %d", actionId);
437 LocationForm::GetDefaultGroupItemHeight(void)
439 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
443 LocationForm::GetDefaultItemHeight(void)
445 return H_GROUP_ITEM_DEFAULT;
449 LocationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
454 LocationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
459 LocationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
464 LocationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
469 LocationForm::AppControlLocationResult(void)
473 bool gpsStatus = false;
474 bool wpsStatus = false;
476 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
479 IList* pDefaultResultIList = null;
480 ArrayList* pDataList = null;
482 pDataList = new (std::nothrow) ArrayList();
483 pDataList->Construct();
485 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
486 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
488 pDataList->Add(*(new (std::nothrow) String(L"APPCONTROL_RESULT_SUCCEEDED")));
489 pDataList->Add(*(new (std::nothrow) String(L"category:Location")));
491 if (gpsStatus == true)
493 value = L"GPSEnabled";
497 value = L"GPSDisabled";
499 pDataList->Add(*(new (std::nothrow) String(value)));
501 if (wpsStatus == true)
503 value = L"WPSEnabled";
507 value = L"WPSDisabled";
509 pDataList->Add(*(new (std::nothrow) String(value)));
511 pDefaultResultIList = (pDataList->GetItemsN(0, pDataList->GetCount()));
513 pAppManager->SendAppControlResult(reqId, pDefaultResultIList);
515 pDataList->RemoveAll(true);
517 pDefaultResultIList->RemoveAll(true);
518 delete pDefaultResultIList;
521 AppCtrlResult ResultValue = APP_CTRL_RESULT_FAILED;
522 HashMap* hashMap = new (std::nothrow) HashMap();
523 hashMap->Construct();
525 if ((__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/gps") == 0)
526 || (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/wps") == 0)
529 result r = E_SUCCESS;
530 ResultValue = APP_CTRL_RESULT_SUCCEEDED;
531 hashMap->Add(*(new (std::nothrow) String(L"category")), *(new (std::nothrow) String(L"Location")));
532 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
534 if (r == E_SUCCESS && gpsStatus == true)
536 status = L"GPSEnabled";
540 status = L"GPSDisabled";
543 hashMap->Add(*(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/location/gps")), *(new (std::nothrow) String(status)));
544 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
546 if (r == E_SUCCESS && wpsStatus == true)
548 status = L"WPSEnabled";
552 status = L"WPSDisabled";
555 hashMap->Add(*(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/location/wps")), *(new (std::nothrow) String(status)));
558 pAppManager->SendAppControlResult(reqId, ResultValue, hashMap);
560 hashMap->RemoveAll();
567 LocationForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
570 bool itemStatus = false;
571 result r = E_SUCCESS;
573 if (requestId == REFRESH_REQUEST_EVENT)
575 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, itemStatus);
578 __pTableView->SetItemChecked(ID_GROUP_GPS_1, ID_ITEM_GPS_ON_OFF, itemStatus);
580 AppLogDebug("Gps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
582 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, itemStatus);
585 __pTableView->SetItemChecked(ID_GROUP_GPS_2, ID_ITEM_GPS_NETWORK_POSITION, itemStatus);
587 AppLogDebug("Wps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
588 __pTableView->UpdateTableView();