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 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_USB_DEBUGGING = 0;
37 static const int ID_GROUP_DEVELOPER_MAIN_ITEM_COUNT = 1;
38 static const int ID_ITEM_DEVELOPER_USB_DEBUGGING = 0;
40 static const int ID_GROUP_DEVELOPER_GPU_RENDERING = 1;
41 static const int ID_GROUP_DEVELOPER_GPU_RENDERING_ITEM_COUNT = 1;
42 static const int ID_ITEM_DEVELOPER_GPU_RENDERING = 0;
44 static const int ID_GROUP_DEVELOPER_GPU_RENDERING_HELP = 2;
45 static const int ID_GROUP_DEVELOPER_GPU_RENDERING_HELP_ITEM_COUNT = 0;
47 static const int ID_GROUP_DEVELOPER_CPU = 3;
48 static const int ID_GROUP_DEVELOPER_CPU_ITEM_COUNT = 0;
49 static const int ID_ITEM_DEVELOPER_CPU_USAGE = 0;
51 static const int ID_GROUP_DEVELOPER_CPU_RENDERING = 4;
52 static const int ID_GROUP_DEVELOPER_CPU_RENDERING_ITEM_COUNT = 1;
53 static const int ID_ITEM_DEVELOPER_CPU_RENDERING = 0;
55 static const int ID_GROUP_DEVELOPER_LIMIT_PROCESS = 5;
56 static const int ID_GROUP_DEVELOPER_LIMIT_PROCESS_ITEM_COUNT = 1;
57 static const int ID_ITEM_DEVELOPER_LIMIT_PROCESS = 0;
59 static const int IDA_USB_DEBUGGING_POPUP_OK = 100;
60 static const int IDA_USB_DEBUGGING_POPUP_CANCEL = 200;
62 static const int ID_GROUP_COUNT = 3;
63 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_DEVELOPER_GPU_RENDERING_ITEM_COUNT;
64 static const int H_HELP_TEXT_GAP = 3;
65 static const int W_RESIZE_LABEL_GAP = 170;
67 static const int Y_ALERT_POPUP_CLIENT_RECT_DEFAULT = 160;
68 static const int Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 20;
69 static const int H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 340;
70 static const int W_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 690;
71 static const int X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 30;
72 static const int Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 410;
73 static const int W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 310;
74 static const int H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 80;
75 static const int X_ALERT_POPUP_ITEM_RECT_RHS_BUTTON_RESIZE = 20;
76 static const int ALERT_POPUP_LABEL_FONT_SIZE = 40;
78 static const int W_ALERT_POPUP_CLIENT_RECT_DEFAULT = 700;
79 static const int H_ALERT_POPUP_CLIENT_RECT_DEFAULT = 600;
81 static const int H_FONT_GAP = 20;
83 DeveloperOptionForm::DeveloperOptionForm(void)
84 : __isAppControlRequest(false)
85 , __usbDebuggingPopup(null)
89 DeveloperOptionForm::~DeveloperOptionForm(void)
94 DeveloperOptionForm::CreateFooter(void)
96 Footer* pFooter = GetFooter();
99 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
100 pFooter->SetBackButton();
101 pFooter->AddActionEventListener(*this);
103 SetFormBackEventListener(this);
107 DeveloperOptionForm::OnInitializing(void)
109 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_DEVELOPER_OPTIONS"));
112 AppLogDebug("ENTER");
118 DeveloperOptionForm::OnTerminating(void)
120 delete __usbDebuggingPopup;
121 __usbDebuggingPopup = null;
124 SetFormBackEventListener(null);
129 DeveloperOptionForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
131 result r = E_FAILURE;
133 bool itemStatus= false;
137 String categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
139 if (categoryCheck == L"category:USB")
141 __isAppControlRequest = true;
145 __pTableView->UpdateTableView();
147 if ((r = SettingInfo::GetValue(SETTING_INFO_KEY_USB_DEBUGGING, itemStatus)) == E_SUCCESS)
149 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_USB_DEBUGGING, ID_ITEM_DEVELOPER_USB_DEBUGGING, itemStatus);
153 AppLogDebug("result Read usbDebugging [%s] value[%d]", GetErrorMessage(r), itemStatus);
158 if ((r = SettingInfo::GetValue(SETTING_INFO_KEY_FORCE_GPU_RENDERING, itemStatus)) == E_SUCCESS)
160 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_GPU_RENDERING, ID_ITEM_DEVELOPER_GPU_RENDERING, itemStatus);
164 AppLogDebug("result Read GPU Rendering [%s] value[%d]", GetErrorMessage(r), itemStatus);
169 DeveloperOptionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
174 DeveloperOptionForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
176 SceneManager* pSceneManager = SceneManager::GetInstance();
177 AppAssert(pSceneManager);
179 if (__isAppControlRequest == true)
181 UiApp* pApp = UiApp::GetInstance();
187 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
192 DeveloperOptionForm::GetGroupCount(void)
194 AppLogDebug("ENTER");
195 return ID_GROUP_COUNT;
199 DeveloperOptionForm::GetItemCount(int groupIndex)
205 case ID_GROUP_DEVELOPER_USB_DEBUGGING:
207 case ID_GROUP_DEVELOPER_GPU_RENDERING:
209 itemCount = ID_GROUP_MAX_ITEM_COUNT;
217 AppLogDebug("GetItemCount %d", itemCount);
222 DeveloperOptionForm::CreateGroupItem(int groupIndex, int itemWidth)
224 AppLogDebug("ENTER");
226 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
227 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
228 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
229 Rectangle itemMainRectangle;
231 Label* pLabel = null;
232 int fontSize = GetFontSize();
234 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
238 case ID_GROUP_DEVELOPER_GPU_RENDERING_HELP:
240 style = LABEL_TEXT_STYLE_NORMAL;
241 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
242 groupText = ResourceManager::GetString(L"IDS_ST_BODY_USE_2D_HARDWARE_ACCELERATION_IN_APPLICATIONS_ABB");
243 itemHeight = GetHeightForStringArea(groupText, itemWidth, fontSize) + H_FONT_GAP;
247 case ID_GROUP_DEVELOPER_USB_DEBUGGING:
249 yItemOffset = Y_GROUP_INDEX_DEFAULT;
250 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
254 case ID_GROUP_DEVELOPER_CPU:
256 style = LABEL_TEXT_STYLE_NORMAL;
257 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
258 groupText = ResourceManager::GetString(L"IDS_ST_BODY_DEBUGGING_MODE_LAUNCHES_WHEN_USB_IS_CONNECTED");
259 itemHeight = GetHeightForStringArea(groupText, itemWidth, fontSize);
263 case ID_GROUP_DEVELOPER_CPU_RENDERING:
265 style = LABEL_TEXT_STYLE_NORMAL;
266 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
267 itemHeight = ((H_GROUP_INDEX_HELP_TEXT * LINE_COUNT_2) + H_GROUP_INDEX_NO_TITLE_TEXT_GAP);
271 case ID_GROUP_DEVELOPER_LIMIT_PROCESS:
273 style = LABEL_TEXT_STYLE_NORMAL;
274 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
275 itemHeight = ((H_GROUP_INDEX_HELP_TEXT * LINE_COUNT_2) + H_GROUP_INDEX_NO_TITLE_TEXT_GAP);
281 yItemOffset = Y_GROUP_INDEX_DEFAULT;
282 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
287 itemMainRectangle.x = X_GROUP_INDEX_DEFAULT_LABEL;
288 itemMainRectangle.y = yItemOffset;
289 itemMainRectangle.width = itemWidth;
290 itemMainRectangle.height = itemHeight;
292 RelativeLayout relativeLayout;
293 relativeLayout.Construct();
295 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
296 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
298 pLabel = new (std::nothrow) Label();
299 pLabel->Construct(itemMainRectangle, groupText);
300 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
301 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
302 pLabel->SetTextConfig(fontSize, style);
303 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
305 pItem->AddControl(pLabel);
306 relativeLayout.SetMargin(*pLabel, 0, 0, 0, 0);
307 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
308 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
309 pItem->SetEnabled(false);
315 DeveloperOptionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
317 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
319 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
320 Rectangle itemMainRectangle;
322 Label* pLabel = null;
323 int fontSize = GetFontSize();
325 TableViewItem* pItem = new (std::nothrow) TableViewItem();
327 ItemTypeOneLine(itemMainRectangle);
331 case ID_GROUP_DEVELOPER_USB_DEBUGGING:
333 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_USB_DEBUGGING");
334 itemMainRectangle.width -= W_RESIZE_LABEL_GAP;
338 case ID_GROUP_DEVELOPER_GPU_RENDERING:
340 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FORCE_GPU_RENDERING_ABB");
341 itemMainRectangle.width -= W_RESIZE_LABEL_GAP;
349 RelativeLayout relativeLayout;
350 relativeLayout.Construct();
352 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
353 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
355 pLabel = new (std::nothrow) Label();
356 pLabel->Construct(itemMainRectangle, itemMainText);
357 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
358 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
359 pLabel->SetTextColor(COLOR_MAIN_TEXT);
361 pItem->AddControl(pLabel);
362 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
363 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
364 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
370 DeveloperOptionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
372 AppLogDebug("ENTER");
381 DeveloperOptionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
383 AppLogDebug("ENTER");
392 DeveloperOptionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
394 SceneManager* pSceneManager = SceneManager::GetInstance();
395 AppAssert(pSceneManager);
397 bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
399 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
403 case ID_GROUP_DEVELOPER_USB_DEBUGGING:
405 if (itemIndex == ID_ITEM_DEVELOPER_USB_DEBUGGING)
407 result r = E_FAILURE;
408 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
410 itemSelectStatus = !itemSelectStatus;
413 if (itemSelectStatus)
420 if ((r = SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_USB_DEBUGGING, itemSelectStatus)) == E_SUCCESS)
422 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_USB_DEBUGGING, ID_ITEM_DEVELOPER_USB_DEBUGGING, itemSelectStatus);
426 AppLogDebug("result[%s]", GetErrorMessage(r));
427 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_USB_DEBUGGING, ID_ITEM_DEVELOPER_USB_DEBUGGING, true);
428 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
435 case ID_GROUP_DEVELOPER_GPU_RENDERING:
437 result r = E_FAILURE;
438 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
440 itemSelectStatus = !itemSelectStatus;
443 if ((r = SettingInfo::SetValue(SETTING_INFO_KEY_FORCE_GPU_RENDERING, itemSelectStatus)) == E_SUCCESS)
445 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_GPU_RENDERING, ID_ITEM_DEVELOPER_GPU_RENDERING, itemSelectStatus);
449 AppLogDebug("rendering result[%s]", GetErrorMessage(r));
450 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_GPU_RENDERING, ID_ITEM_DEVELOPER_GPU_RENDERING, false);
455 case ID_GROUP_DEVELOPER_CPU:
457 if (itemIndex == ID_ITEM_DEVELOPER_CPU_USAGE)
459 // TODO: Show CPU usage on/off.
464 case ID_GROUP_DEVELOPER_CPU_RENDERING:
466 if (itemIndex == ID_ITEM_DEVELOPER_CPU_RENDERING)
468 // TODO: Show CPU rendering on/off
473 case ID_GROUP_DEVELOPER_LIMIT_PROCESS:
475 if (itemIndex == ID_ITEM_DEVELOPER_LIMIT_PROCESS)
477 // TODO: Limit background process.
488 DeveloperOptionForm::GetDefaultGroupItemHeight(void)
490 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
494 DeveloperOptionForm::GetDefaultItemHeight(void)
496 return H_GROUP_ITEM_DEFAULT;
500 DeveloperOptionForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
505 DeveloperOptionForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
510 DeveloperOptionForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
515 DeveloperOptionForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
520 DeveloperOptionForm::CreateAlertPopup(void)
523 Label* pLabel = null;
524 Button* pLhsButton = null;
525 Button* pRhslButton = null;
527 Rectangle clientRect = GetClientAreaBounds();
528 Rectangle itemRectLabel;
529 Rectangle itemRectLhsButton;
530 Rectangle itemRectRhsButton;
533 clientRect.y = Y_ALERT_POPUP_CLIENT_RECT_DEFAULT;
534 clientRect.width = W_ALERT_POPUP_CLIENT_RECT_DEFAULT;
535 clientRect.height = H_ALERT_POPUP_CLIENT_RECT_DEFAULT;
537 itemRectLabel.x = Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
538 itemRectLabel.y = Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT + itemRectLabel.x;
539 itemRectLabel.width = W_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
540 itemRectLabel.height = H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
542 itemRectLhsButton.x = X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
543 itemRectLhsButton.y = Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
544 itemRectLhsButton.width = W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
545 itemRectLhsButton.height = H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
547 itemRectRhsButton = itemRectLhsButton;
548 itemRectRhsButton.x = itemRectLhsButton.x + itemRectLhsButton.width + X_ALERT_POPUP_ITEM_RECT_RHS_BUTTON_RESIZE;
550 Dimension bounds = Dimension(clientRect.width, clientRect.height);
552 __usbDebuggingPopup = new (std::nothrow) Popup();
553 __usbDebuggingPopup->Construct(true, bounds);
554 __usbDebuggingPopup->SetTitleText(ResourceManager::GetString(L"IDS_ST_HEADER_ALLOW_USB_DEBUGGING_Q_ABB"));
555 __usbDebuggingPopup->SetTitleTextColor(COLOR_SUB_TEXT);
557 pLabel = new (std::nothrow) Label();
558 pLabel->Construct(itemRectLabel, ResourceManager::GetString(L"IDS_ST_BODY_USB_DEBUGGING_IS_INTENDED_FOR_DEVELOPMENT_PURPOSES_ONLY_MSG"));
559 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
560 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
561 pLabel->SetTextConfig(ALERT_POPUP_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
563 __usbDebuggingPopup->AddControl(pLabel);
565 buttonText = ResourceManager::GetString(L"IDS_ST_BUTTON_OK");
566 pLhsButton = new (std::nothrow) Button();
567 pLhsButton->Construct(itemRectLhsButton, buttonText);
568 pLhsButton->SetActionId(IDA_USB_DEBUGGING_POPUP_OK);
570 __usbDebuggingPopup->AddControl(pLhsButton);
572 buttonText = ResourceManager::GetString(L"IDS_ST_BODY_CANCEL");
574 pRhslButton = new (std::nothrow) Button();
575 pRhslButton->Construct(itemRectRhsButton, buttonText);
576 pRhslButton->SetActionId(IDA_USB_DEBUGGING_POPUP_CANCEL);
578 __usbDebuggingPopup->AddControl(pRhslButton);
580 pLhsButton->AddActionEventListener(*this);
581 pRhslButton->AddActionEventListener(*this);
587 DeveloperOptionForm::ShowAlertPopup(void)
589 __usbDebuggingPopup->SetShowState(true);
590 __usbDebuggingPopup->Show();
594 DeveloperOptionForm::HideAlertPopup(void)
596 __usbDebuggingPopup->SetShowState(false);
597 __usbDebuggingPopup->Invalidate(true);
601 DeveloperOptionForm::OnActionPerformed(const Control& source, int actionId)
603 result r = E_FAILURE;
607 case IDA_USB_DEBUGGING_POPUP_OK:
609 r = SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_USB_DEBUGGING, true);
613 case E_UNSUPPORTED_OPERATION:
616 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
622 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_USB_DEBUGGING, ID_ITEM_DEVELOPER_USB_DEBUGGING, true);
630 AppLogDebug("Set UsbDebugging result [%s] ", GetErrorMessage(r));
634 case IDA_USB_DEBUGGING_POPUP_CANCEL:
636 __pTableView->SetItemChecked(ID_GROUP_DEVELOPER_USB_DEBUGGING, ID_ITEM_DEVELOPER_USB_DEBUGGING, false);
644 __pTableView->UpdateTableView();