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 StMoreConnectivityForm.cpp
19 * @brief This is the implementation file for MoreConnectivityForm class.
22 #include "StBluetoothForm.h"
23 #include "StMoreConnectivityForm.h"
24 #include "StNfcPresentationModel.h"
25 #include "StResourceManager.h"
26 #include "StSettingScenesList.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
37 static const int ID_GROUP_CONNECTIVITY_ITEM_COUNT = 2;
38 static const int ID_ITEM_CONNECTIVITY_BLUETOOTH = 0;
39 static const int ID_ITEM_CONNECTIVITY_NFC = 1;
40 static const int ID_ITEM_CONNECTIVITY_WIFI_DIRECT = 2;
42 static const int ID_GROUP_COUNT = 1;
43 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_CONNECTIVITY_ITEM_COUNT;
45 static const int BLUETOOTH_OFF_OPTION = 0;
47 MoreConnectivityForm::MoreConnectivityForm(void)
51 MoreConnectivityForm::~MoreConnectivityForm(void)
56 MoreConnectivityForm::CreateFooter(void)
58 Footer* pFooter = GetFooter();
61 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
62 pFooter->SetBackButton();
63 pFooter->AddActionEventListener(*this);
65 SetFormBackEventListener(this);
69 MoreConnectivityForm::OnInitializing(void)
71 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MORE_CONNECTIVITY_SETTINGS"));
80 MoreConnectivityForm::OnTerminating(void)
84 SetFormBackEventListener(null);
89 MoreConnectivityForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
91 if (__pTableView == null)
93 AppLogDebug("__pTableView is null");
97 __pTableView->UpdateTableView();
99 bool EnableStatus = false;
100 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_NFC, EnableStatus) == E_SUCCESS)
102 AppLogDebug("systeminfo::GetValue() success(%s)", GetErrorMessage(GetLastResult()));
104 if (EnableStatus == true)
106 __pTableView->SetItemChecked(0, 1, NfcPresentationModel::GetInstance()->IsNfcActivated());
110 __pTableView->SetItemChecked(0, 1, false);
115 __pTableView->SetItemChecked(0, 1, false);
120 MoreConnectivityForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
125 MoreConnectivityForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
127 SceneManager* pSceneManager = SceneManager::GetInstance();
128 AppAssert(pSceneManager);
130 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
134 MoreConnectivityForm::GetGroupCount(void)
136 AppLogDebug("ENTER");
137 return ID_GROUP_COUNT;
141 MoreConnectivityForm::GetItemCount(int groupIndex)
143 int itemCount = ID_GROUP_MAX_ITEM_COUNT;
145 AppLogDebug("GetItemCount %d", itemCount);
151 MoreConnectivityForm::CreateGroupItem(int groupIndex, int itemWidth)
153 AppLogDebug("ENTER");
155 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
156 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
157 Rectangle itemRectangle;
159 Label* pLabel = null;
161 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
163 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
164 itemRectangle.y = Y_GROUP_ITEM_DEFAULT_LABEL;
165 itemRectangle.width = itemWidth;
166 itemRectangle.height = itemHeight;
168 RelativeLayout relativeLayout;
169 relativeLayout.Construct();
171 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
172 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
174 pLabel = new (std::nothrow) Label();
175 pLabel->Construct(itemRectangle, groupText);
176 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
177 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
178 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
180 pItem->AddControl(pLabel);
181 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
182 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
183 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
184 pItem->SetEnabled(false);
190 MoreConnectivityForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
192 AppLogDebug("ENTER");
194 bool checkSecondText = false;
195 int itmeHeight = H_GROUP_ITEM_DEFAULT_LABEL;
196 int btEnableStatus = BLUETOOTH_OFF_OPTION;
197 Rectangle itemLabelRect;
198 Rectangle itemIconRect;
199 Rectangle itemIconLabelRect;
200 Rectangle itemSecondLineTextRect;
201 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
202 Bitmap* pBitmap = null;
204 String secondLineText;
205 bool EnableStatus = false;
206 Label* pLabel = null;
207 int fontSize = GetFontSize();
209 TableViewItem* pItem = new (std::nothrow) TableViewItem();
211 if (itemIndex == ID_ITEM_CONNECTIVITY_BLUETOOTH)
213 checkSecondText = true;
214 ItemTypeIconAndTwoLine(itemIconRect, itemIconLabelRect, itemSecondLineTextRect, fontSize);
215 itmeHeight = (itemIconLabelRect.height + itemSecondLineTextRect.height);
216 pBitmap = ResourceManager::GetBitmapN(IDB_BLUETOOTH);
218 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, EnableStatus) == E_SUCCESS)
220 AppLogDebug("systeminfo::GetValue() fail(%s)", GetErrorMessage(GetLastResult()));
222 if (EnableStatus == true)
224 btEnableStatus = BluetoothPresentationModel::GetInstance()->IsBluetoothActivated();
225 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_ON");
229 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
234 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
236 itemText = ResourceManager::GetString(L"IDS_ST_BODY_BLUETOOTH");
238 else if (itemIndex == ID_ITEM_CONNECTIVITY_NFC)
240 checkSecondText = true;
241 ItemTypeIconAndTwoLine(itemIconRect, itemIconLabelRect, itemSecondLineTextRect, fontSize);
242 itmeHeight = (itemIconLabelRect.height + itemSecondLineTextRect.height);
243 pBitmap = ResourceManager::GetBitmapN(IDB_NFC);
244 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
246 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_NFC, EnableStatus) == E_SUCCESS)
248 AppLogDebug("systeminfo::GetValue() success(%s)", GetErrorMessage(GetLastResult()));
250 if (EnableStatus == true)
252 if (NfcPresentationModel::GetInstance()->IsNfcActivated() == true)
254 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_ON");
258 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
263 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
268 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
270 itemText = ResourceManager::GetString(L"IDS_NFC_BODY_NFC");
274 itemText = ResourceManager::GetString(L"IDS_ST_HEADER_WI_FI_DIRECT");
275 ItemTypeIconAndOneLine(itemIconRect, itemIconLabelRect);
278 RelativeLayout relativeLayout;
279 relativeLayout.Construct();
281 pItem->Construct(relativeLayout, Dimension(itemWidth, itmeHeight), style);
282 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
286 pLabel = new (std::nothrow) Label();
287 pLabel->Construct(itemLabelRect, itemText);
288 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
290 pItem->AddControl(pLabel);
291 relativeLayout.SetMargin(*pLabel, itemLabelRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
292 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
293 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
297 pLabel = new (std::nothrow) Label();
298 pLabel->Construct(itemIconRect, L"");
299 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
300 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
301 pLabel->SetBackgroundBitmap(*pBitmap);
303 pItem->AddControl(pLabel);
305 pLabel = new (std::nothrow) Label();
306 pLabel->Construct(itemIconLabelRect, itemText);
307 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
308 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
309 pLabel->SetTextColor(COLOR_MAIN_TEXT);
311 pItem->AddControl(pLabel);
312 relativeLayout.SetMargin(*pLabel, itemIconLabelRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
313 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
314 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
316 if (checkSecondText == true)
318 pLabel = new (std::nothrow) Label();
319 pLabel->Construct(itemSecondLineTextRect, secondLineText);
320 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
321 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
322 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
323 pLabel->SetTextColor(COLOR_SUB_TEXT);
325 pItem->AddControl(pLabel);
326 relativeLayout.SetMargin(*pLabel, itemSecondLineTextRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
327 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
328 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
336 MoreConnectivityForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
338 AppLogDebug("ENTER");
347 MoreConnectivityForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
349 AppLogDebug("ENTER");
358 MoreConnectivityForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
360 bool EnableStatus = false;
361 SceneManager* pSceneManager = SceneManager::GetInstance();
362 AppAssert(pSceneManager);
364 AppLogDebug("Group[ %d ] Index [ %d ]", groupIndex, itemIndex);
368 case ID_ITEM_CONNECTIVITY_BLUETOOTH:
370 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, EnableStatus) != E_SUCCESS)
372 AppLogDebug("systeminfo::GetValue() fail(%s)", GetErrorMessage(GetLastResult()));
375 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_BLUETOOTH, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
379 case ID_ITEM_CONNECTIVITY_NFC:
381 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_NFC, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
385 case ID_ITEM_CONNECTIVITY_WIFI_DIRECT:
387 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WIFI_DIRECT, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
397 MoreConnectivityForm::GetDefaultGroupItemHeight(void)
399 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
403 MoreConnectivityForm::GetDefaultItemHeight(void)
405 return H_GROUP_ITEM_DEFAULT;
409 MoreConnectivityForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
414 MoreConnectivityForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
416 if ((groupIndex != 0)
419 AppLogDebug("UpdateItem is Error");
423 Label* pLabel = static_cast<Label*>(pItem->GetControl(2));
424 AppLogDebug("pLabel is %ls", pLabel->GetText().GetPointer());
425 if (__pTableView->IsItemChecked(groupIndex, itemIndex) == true)
427 pLabel->SetText(ResourceManager::GetString(L"IDS_ST_BODY_ON"));
431 pLabel->SetText(ResourceManager::GetString(L"IDS_ST_BODY_OFF"));
437 MoreConnectivityForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
442 MoreConnectivityForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)