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();
112 result r = E_SUCCESS;
114 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, itemStatus);
116 && (itemStatus == true))
118 __pTableView->SetItemChecked(ID_GROUP_GPS_1, ID_ITEM_GPS_ON_OFF, itemStatus);
120 AppLogDebug("Gps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
122 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, itemStatus);
124 && (itemStatus == true))
126 __pTableView->SetItemChecked(ID_GROUP_GPS_2, ID_ITEM_GPS_NETWORK_POSITION, itemStatus);
128 AppLogDebug("Wps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
132 __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
134 if (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/gps") == 0)
136 __isAppControlRequest = APPCONTROL_REQUEST_LOCATION;
138 else if (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/wps") == 0)
140 __isAppControlRequest = APPCONTROL_REQUEST_LOCATION;
148 LocationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
153 LocationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
155 SceneManager* pSceneManager = SceneManager::GetInstance();
156 AppAssert(pSceneManager);
158 if (__isAppControlRequest != APPCONTROL_REQUEST_DEFAULT)
160 UiApp* pApp = UiApp::GetInstance();
162 AppControlLocationResult();
167 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
172 LocationForm::GetGroupCount(void)
174 AppLogDebug("ENTER");
175 return ID_GROUP_COUNT;
179 LocationForm::GetItemCount(int groupIndex)
187 itemCount = ID_GROUP_GPS_1_ITEM_COUNT;
193 itemCount = ID_GROUP_GPS_2_ITEM_COUNT;
199 itemCount = ID_GROUP_GPS_3_ITEM_COUNT;
207 AppLogDebug("GetItemCount %d", itemCount);
212 LocationForm::CreateGroupItem(int groupIndex, int itemWidth)
214 AppLogDebug("ENTER");
216 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
217 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
218 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
219 Rectangle itemMainRectangle;
221 Label* pLabel = null;
223 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
229 yItemOffset = Y_GROUP_INDEX_DEFAULT;
230 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
236 yItemOffset = Y_GROUP_INDEX_DEFAULT;
237 itemHeight = Y_GROUP_INDEX_DEFAULT;
242 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
243 itemMainRectangle.y = yItemOffset;
244 itemMainRectangle.width = itemWidth;
245 itemMainRectangle.height = itemHeight;
247 RelativeLayout relativeLayout;
248 relativeLayout.Construct();
250 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
251 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
253 pLabel = new (std::nothrow) Label();
254 pLabel->Construct(itemMainRectangle, groupText);
255 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
256 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
257 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
258 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
260 pItem->AddControl(pLabel);
261 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
262 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
263 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
264 pItem->SetEnabled(false);
270 LocationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
272 Rectangle itemMainRectangle;
273 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
275 Label* pLabel = null;
276 int fontSize = GetFontSize();
277 result r = E_SUCCESS;
278 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
279 ItemTypeOneLine(itemMainRectangle);
286 itemMainText = ResourceManager::GetString(L"IDS_CAM_OPT_GPS");
287 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
289 && (gpsStatus == true))
291 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
300 case ID_ITEM_GPS_NETWORK_POSITION:
303 itemMainText = ResourceManager::GetString(L"IDS_LBS_BODY_NETWORK_POSITION");
304 itemMainRectangle.width -= W_RESIZE_LABEL_GAP;
306 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
308 && (wpsStatus == true))
310 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
325 TableViewItem* pItem = new (std::nothrow) TableViewItem();
327 RelativeLayout relativeLayout;
328 relativeLayout.Construct();
330 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
331 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
333 pLabel = new (std::nothrow) Label();
334 pLabel->Construct(itemMainRectangle, itemMainText);
335 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
336 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
337 pLabel->SetTextColor(COLOR_MAIN_TEXT);
339 pItem->AddControl(pLabel);
340 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
341 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
342 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
348 LocationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
350 AppLogDebug("ENTER");
359 LocationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
361 AppLogDebug("ENTER");
370 LocationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
372 bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
378 if (itemIndex == ID_ITEM_GPS_ON_OFF)
380 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
382 itemSelectStatus = !itemSelectStatus;
385 if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_LOCATION_GPS, itemSelectStatus) == E_SUCCESS)
387 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
395 if (itemIndex == ID_ITEM_GPS_NETWORK_POSITION)
397 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
399 itemSelectStatus = !itemSelectStatus;
402 if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_LOCATION_WPS, itemSelectStatus) == E_SUCCESS)
404 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
416 LocationForm::OnActionPerformed(const Control& source, int actionId)
418 SceneManager* pSceneManager = SceneManager::GetInstance();
419 AppAssert(pSceneManager);
423 case IDA_FOOTER_ITEM_HELP:
425 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_LOCATION_HELP, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
431 AppLogDebug("ID_HEADER_VOLUME Tab Selected %d", actionId);
438 LocationForm::GetDefaultGroupItemHeight(void)
440 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
444 LocationForm::GetDefaultItemHeight(void)
446 return H_GROUP_ITEM_DEFAULT;
450 LocationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
455 LocationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
460 LocationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
465 LocationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
470 LocationForm::AppControlLocationResult(void)
474 bool gpsStatus = false;
475 bool wpsStatus = false;
477 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
480 IList* pDefaultResultIList = null;
481 ArrayList* pDataList = null;
483 pDataList = new (std::nothrow) ArrayList();
484 pDataList->Construct();
486 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
487 SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
489 pDataList->Add(*(new (std::nothrow) String(L"APPCONTROL_RESULT_SUCCEEDED")));
490 pDataList->Add(*(new (std::nothrow) String(L"category:Location")));
492 if (gpsStatus == true)
494 value = L"GPSEnabled";
498 value = L"GPSDisabled";
500 pDataList->Add(*(new (std::nothrow) String(value)));
502 if (wpsStatus == true)
504 value = L"WPSEnabled";
508 value = L"WPSDisabled";
510 pDataList->Add(*(new (std::nothrow) String(value)));
512 pDefaultResultIList = (pDataList->GetItemsN(0, pDataList->GetCount()));
514 pAppManager->SendAppControlResult(reqId, pDefaultResultIList);
516 pDataList->RemoveAll(true);
518 pDefaultResultIList->RemoveAll(true);
519 delete pDefaultResultIList;
522 AppCtrlResult ResultValue = APP_CTRL_RESULT_FAILED;
523 HashMap* hashMap = new (std::nothrow) HashMap();
524 hashMap->Construct();
526 if ((__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/gps") == 0)
527 || (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/wps") == 0)
530 result r = E_SUCCESS;
531 ResultValue = APP_CTRL_RESULT_SUCCEEDED;
532 hashMap->Add(new (std::nothrow) String(L"category"), new (std::nothrow) String(L"Location"));
533 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
535 if (r == E_SUCCESS && gpsStatus == true)
537 status = L"GPSEnabled";
541 status = L"GPSDisabled";
544 hashMap->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/location/gps"), new (std::nothrow) String(status));
545 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
547 if (r == E_SUCCESS && wpsStatus == true)
549 status = L"WPSEnabled";
553 status = L"WPSDisabled";
556 hashMap->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/location/wps"), new (std::nothrow) String(status));
559 pAppManager->SendAppControlResult(reqId, ResultValue, hashMap);
561 hashMap->RemoveAll();
568 LocationForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
571 bool itemStatus = false;
572 result r = E_SUCCESS;
574 if (requestId == REFRESH_REQUEST_EVENT)
576 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, itemStatus);
579 __pTableView->SetItemChecked(ID_GROUP_GPS_1, ID_ITEM_GPS_ON_OFF, itemStatus);
581 AppLogDebug("Gps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
583 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, itemStatus);
586 __pTableView->SetItemChecked(ID_GROUP_GPS_2, ID_ITEM_GPS_NETWORK_POSITION, itemStatus);
588 AppLogDebug("Wps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
589 __pTableView->UpdateTableView();