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 StDeveloperOptionForm.cpp
19 * @brief This is the implementation file for DeveloperOptionForm class.
23 #include "StDeveloperOptionForm.h"
24 #include "StResourceManager.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_DEVELOPER_MAIN = 0;
37 static const int ID_GROUP_DEVELOPER_MAIN_ITEM_COUNT = 1;
38 static const int ID_ITEM_DEVELOPER_MAIN_USB_DEBUGGING = 0;
40 static const int ID_GROUP_DEVELOPER_CPU = 1;
41 static const int ID_GROUP_DEVELOPER_CPU_ITEM_COUNT = 1;
42 static const int ID_ITEM_DEVELOPER_CPU_USAGE = 0;
44 static const int ID_GROUP_DEVELOPER_CPU_RENDERING = 2;
45 static const int ID_GROUP_DEVELOPER_CPU_RENDERING_ITEM_COUNT = 1;
46 static const int ID_ITEM_DEVELOPER_CPU_RENDERING = 0;
48 static const int ID_GROUP_DEVELOPER_LIMIT_PROCESS = 3;
49 static const int ID_GROUP_DEVELOPER_LIMIT_PROCESS_ITEM_COUNT = 1;
50 static const int ID_ITEM_DEVELOPER_LIMIT_PROCESS = 0;
52 static const int IDA_USB_DEBUGGING_POPUP_OK = 100;
53 static const int IDA_USB_DEBUGGING_POPUP_CANCEL = 200;
55 static const int ID_GROUP_COUNT = 2;
56 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_DEVELOPER_LIMIT_PROCESS_ITEM_COUNT;
57 static const int H_HELP_TEXT_GAP = 3;
58 static const int W_RESIZE_LABEL_GAP = 170;
60 static const int Y_ALERT_POPUP_CLIENT_RECT_DEFAULT = 160;
61 static const int Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 20;
62 static const int H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 340;
63 static const int W_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 690;
64 static const int X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 12;
65 static const int Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 360;
66 static const int W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 310;
67 static const int H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 80;
68 static const int X_ALERT_POPUP_ITEM_RECT_RHS_BUTTON_RESIZE = 20;
69 static const int ALERT_POPUP_LABEL_FONT_SIZE = 40;
71 static const int W_ALERT_POPUP_CLIENT_RECT_DEFAULT = 700;
72 static const int H_ALERT_POPUP_CLIENT_RECT_DEFAULT = 550;
73 static const int RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING = 230;
75 DeveloperOptionForm::DeveloperOptionForm(void)
76 : __isAppControlRequest(false)
77 , __usbDebuggingPopup(null)
81 DeveloperOptionForm::~DeveloperOptionForm(void)
86 DeveloperOptionForm::CreateFooter(void)
88 Footer* pFooter = GetFooter();
91 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
92 pFooter->SetBackButton();
93 pFooter->AddActionEventListener(*this);
95 SetFormBackEventListener(this);
99 DeveloperOptionForm::OnInitializing(void)
101 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_DEVELOPER_OPTIONS"));
104 AppLogDebug("ENTER");
110 DeveloperOptionForm::OnTerminating(void)
112 delete __usbDebuggingPopup;
113 __usbDebuggingPopup = null;
116 SetFormBackEventListener(null);
121 DeveloperOptionForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
123 bool usbStatus= false;
127 String categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
129 if (categoryCheck == L"category:USB")
131 __isAppControlRequest = true;
135 __pTableView->UpdateTableView();
137 if (SettingInfo::GetValue(SETTING_INFO_KEY_USB_DEBUGGING, usbStatus) == E_SUCCESS)
139 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_MAIN, ID_ITEM_DEVELOPER_MAIN_USB_DEBUGGING, usbStatus);
141 AppLogDebug("result Read usbDebugging [%s] value[%d]", GetErrorMessage(GetLastResult()), usbStatus);
145 DeveloperOptionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
150 DeveloperOptionForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
152 SceneManager* pSceneManager = SceneManager::GetInstance();
153 AppAssert(pSceneManager);
155 if (__isAppControlRequest == true)
157 UiApp* pApp = UiApp::GetInstance();
163 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
168 DeveloperOptionForm::GetGroupCount(void)
170 AppLogDebug("ENTER");
171 return ID_GROUP_COUNT;
175 DeveloperOptionForm::GetItemCount(int groupIndex)
181 case ID_GROUP_DEVELOPER_MAIN:
183 itemCount = ID_GROUP_MAX_ITEM_COUNT;
191 AppLogDebug("GetItemCount %d", itemCount);
196 DeveloperOptionForm::CreateGroupItem(int groupIndex, int itemWidth)
198 AppLogDebug("ENTER");
200 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
201 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
202 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
203 Rectangle itemRectangle;
205 Label* pLabel = null;
206 int fontSize = GetFontSize();
208 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
212 case ID_GROUP_DEVELOPER_MAIN:
214 yItemOffset = Y_GROUP_INDEX_DEFAULT;
215 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
219 case ID_GROUP_DEVELOPER_CPU:
221 style = LABEL_TEXT_STYLE_NORMAL;
222 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
223 itemHeight = (((fontSize * H_HELP_TEXT_GAP) * LINE_COUNT_2) + H_GROUP_INDEX_NO_TITLE_TEXT_GAP);
225 groupText = ResourceManager::GetString(L"IDS_ST_BODY_DEBUGGING_MODE_LAUNCHES_WHEN_USB_IS_CONNECTED");
229 case ID_GROUP_DEVELOPER_CPU_RENDERING:
231 style = LABEL_TEXT_STYLE_NORMAL;
232 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
233 itemHeight = ((H_GROUP_INDEX_HELP_TEXT * LINE_COUNT_2) + H_GROUP_INDEX_NO_TITLE_TEXT_GAP);
237 case ID_GROUP_DEVELOPER_LIMIT_PROCESS:
239 style = LABEL_TEXT_STYLE_NORMAL;
240 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
241 itemHeight = ((H_GROUP_INDEX_HELP_TEXT * LINE_COUNT_2) + H_GROUP_INDEX_NO_TITLE_TEXT_GAP);
247 yItemOffset = Y_GROUP_INDEX_DEFAULT;
248 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
253 itemRectangle.x = X_GROUP_INDEX_DEFAULT_LABEL;
254 itemRectangle.y = yItemOffset;
255 itemRectangle.width = itemWidth;
256 itemRectangle.height = itemHeight;
258 RelativeLayout relativeLayout;
259 relativeLayout.Construct();
261 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
262 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
264 pLabel = new (std::nothrow) Label();
265 pLabel->Construct(itemRectangle, groupText);
266 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
267 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
268 pLabel->SetTextConfig(fontSize, style);
269 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
271 pItem->AddControl(*pLabel);
272 relativeLayout.SetMargin(*pLabel, 0, 0, 0, 0);
273 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
274 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
275 pItem->SetEnabled(false);
281 DeveloperOptionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
283 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
285 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
286 Rectangle itemRectangle;
288 Label* pLabel = null;
289 int fontSize = GetFontSize();
291 TableViewItem* pItem = new (std::nothrow) TableViewItem();
293 ItemTypeOneLine(itemRectangle);
295 if (groupIndex == ID_GROUP_DEVELOPER_MAIN)
297 itemText = ResourceManager::GetString(L"IDS_ST_BODY_USB_DEBUGGING");
298 itemRectangle.width -= W_RESIZE_LABEL_GAP;
301 RelativeLayout relativeLayout;
302 relativeLayout.Construct();
304 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
305 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
307 pLabel = new (std::nothrow) Label();
308 pLabel->Construct(itemRectangle, itemText);
309 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
310 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_BOLD);
311 pLabel->SetTextColor(COLOR_MAIN_TEXT);
313 pItem->AddControl(*pLabel);
314 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
315 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
316 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
322 DeveloperOptionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
324 AppLogDebug("ENTER");
333 DeveloperOptionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
335 AppLogDebug("ENTER");
344 DeveloperOptionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
346 SceneManager* pSceneManager = SceneManager::GetInstance();
347 AppAssert(pSceneManager);
349 bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
351 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
355 case ID_GROUP_DEVELOPER_MAIN:
357 if (itemIndex == ID_ITEM_DEVELOPER_MAIN_USB_DEBUGGING)
359 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
361 itemSelectStatus = !itemSelectStatus;
364 if (itemSelectStatus == true)
366 status = TABLE_VIEW_ITEM_STATUS_UNCHECKED;
367 tableView.SetItemChecked(groupIndex, itemIndex, false);
373 bool usbStatus = false;
374 if (SettingInfo::SetValue(SETTING_INFO_KEY_USB_DEBUGGING, usbStatus) == E_SUCCESS)
376 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_MAIN, ID_ITEM_DEVELOPER_MAIN_USB_DEBUGGING, usbStatus);
380 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_MAIN, ID_ITEM_DEVELOPER_MAIN_USB_DEBUGGING, true);
381 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
388 case ID_GROUP_DEVELOPER_CPU:
390 if (itemIndex == ID_ITEM_DEVELOPER_CPU_USAGE)
392 // TODO: Show CPU usage on/off.
397 case ID_GROUP_DEVELOPER_CPU_RENDERING:
399 if (itemIndex == ID_ITEM_DEVELOPER_CPU_RENDERING)
401 // TODO: Show CPU rendering on/off
406 case ID_GROUP_DEVELOPER_LIMIT_PROCESS:
408 if (itemIndex == ID_ITEM_DEVELOPER_LIMIT_PROCESS)
410 // TODO: Limit background process.
421 DeveloperOptionForm::GetDefaultGroupItemHeight(void)
423 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
427 DeveloperOptionForm::GetDefaultItemHeight(void)
429 return H_GROUP_ITEM_DEFAULT;
433 DeveloperOptionForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
438 DeveloperOptionForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
443 DeveloperOptionForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
448 DeveloperOptionForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
453 DeveloperOptionForm::CreateAlertPopup(void)
456 Label* pLabel = null;
457 Button* pLhsButton = null;
458 Button* pRhslButton = null;
460 Rectangle clientRect = GetClientAreaBounds();
461 Rectangle itemRectLabel;
462 Rectangle itemRectLhsButton;
463 Rectangle itemRectRhsButton;
466 clientRect.y = Y_ALERT_POPUP_CLIENT_RECT_DEFAULT;
467 clientRect.width = W_ALERT_POPUP_CLIENT_RECT_DEFAULT;
468 clientRect.height = H_ALERT_POPUP_CLIENT_RECT_DEFAULT;
471 itemRectLabel.y = Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
472 itemRectLabel.width = W_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
473 itemRectLabel.height = H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
475 itemRectLhsButton.x = X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
476 itemRectLhsButton.y = Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
477 itemRectLhsButton.width = W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
478 itemRectLhsButton.height = H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
480 itemRectRhsButton = itemRectLhsButton;
481 itemRectRhsButton.x = itemRectLhsButton.x + itemRectLhsButton.width + X_ALERT_POPUP_ITEM_RECT_RHS_BUTTON_RESIZE;
483 Dimension bounds = Dimension(clientRect.width, clientRect.height);
485 __usbDebuggingPopup = new (std::nothrow) Popup();
486 __usbDebuggingPopup->Construct(true, bounds);
487 __usbDebuggingPopup->SetTitleText(ResourceManager::GetString(L"IDS_ST_HEADER_ALLOW_USB_DEBUGGING_Q_ABB"));
488 __usbDebuggingPopup->SetTitleTextColor(COLOR_SUB_TEXT);
490 pLabel = new (std::nothrow) Label();
491 pLabel->Construct(itemRectLabel, ResourceManager::GetString(L"IDS_ST_BODY_USB_DEBUGGING_IS_INTENDED_FOR_DEVELOPMENT_PURPOSES_ONLY_MSG"));
492 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
493 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
494 pLabel->SetTextConfig(ALERT_POPUP_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
496 __usbDebuggingPopup->AddControl(*pLabel);
498 buttonText = ResourceManager::GetString(L"IDS_ST_BUTTON_OK");
499 pLhsButton = new (std::nothrow) Button();
500 pLhsButton->Construct(itemRectLhsButton, buttonText);
501 pLhsButton->SetActionId(IDA_USB_DEBUGGING_POPUP_OK);
503 __usbDebuggingPopup->AddControl(*pLhsButton);
505 buttonText = ResourceManager::GetString(L"IDS_ST_BODY_CANCEL");
507 pRhslButton = new (std::nothrow) Button();
508 pRhslButton->Construct(itemRectRhsButton, buttonText);
509 pRhslButton->SetActionId(IDA_USB_DEBUGGING_POPUP_CANCEL);
511 __usbDebuggingPopup->AddControl(*pRhslButton);
513 pLhsButton->AddActionEventListener(*this);
514 pRhslButton->AddActionEventListener(*this);
520 DeveloperOptionForm::ShowAlertPopup(void)
522 __usbDebuggingPopup->SetShowState(true);
523 __usbDebuggingPopup->Show();
527 DeveloperOptionForm::HideAlertPopup(void)
529 __usbDebuggingPopup->SetShowState(false);
530 __usbDebuggingPopup->Invalidate(true);
534 DeveloperOptionForm::OnActionPerformed(const Control& source, int actionId)
536 result r = E_FAILURE;
540 case IDA_USB_DEBUGGING_POPUP_OK:
542 r = SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_USB_DEBUGGING, true);
546 case E_UNSUPPORTED_OPERATION:
549 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
555 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_MAIN, ID_ITEM_DEVELOPER_MAIN_USB_DEBUGGING, true);
563 AppLogDebug("Set UsbDebugging result [%s] ", GetErrorMessage(r));
568 case IDA_USB_DEBUGGING_POPUP_CANCEL:
577 __pTableView->UpdateTableView();