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->AddActionEventListener(*this);
64 SetFormBackEventListener(this);
68 MoreConnectivityForm::OnInitializing(void)
70 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MORE_CONNECTIVITY_SETTINGS"));
78 MoreConnectivityForm::OnTerminating(void)
82 SetFormBackEventListener(null);
87 MoreConnectivityForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
89 if (__pTableView == null)
91 AppLogDebug("__pTableView is null");
95 __pTableView->UpdateTableView();
97 bool EnableStatus = false;
98 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_NFC, EnableStatus) == E_SUCCESS)
100 AppLogDebug("systeminfo::GetValue() success(%s)", GetErrorMessage(GetLastResult()));
102 if (EnableStatus == true)
104 __pTableView->SetItemChecked(0, 1, NfcPresentationModel::GetInstance()->IsNfcActivated());
108 __pTableView->SetItemChecked(0, 1, false);
113 __pTableView->SetItemChecked(0, 1, false);
118 MoreConnectivityForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
123 MoreConnectivityForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
125 SceneManager* pSceneManager = SceneManager::GetInstance();
126 AppAssert(pSceneManager);
128 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
132 MoreConnectivityForm::GetGroupCount(void)
134 AppLogDebug("ENTER");
135 return ID_GROUP_COUNT;
139 MoreConnectivityForm::GetItemCount(int groupIndex)
141 int itemCount = ID_GROUP_MAX_ITEM_COUNT;
143 AppLogDebug("GetItemCount %d", itemCount);
149 MoreConnectivityForm::CreateGroupItem(int groupIndex, int itemWidth)
151 AppLogDebug("ENTER");
153 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
154 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
155 Rectangle itemRectangle;
157 Label* pLabel = null;
159 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
161 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
162 itemRectangle.y = Y_GROUP_ITEM_DEFAULT_LABEL;
163 itemRectangle.width = itemWidth;
164 itemRectangle.height = itemHeight;
166 RelativeLayout relativeLayout;
167 relativeLayout.Construct();
169 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
170 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
172 pLabel = new (std::nothrow) Label();
173 pLabel->Construct(itemRectangle, groupText);
174 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
175 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
176 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
178 pItem->AddControl(pLabel);
179 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
180 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
181 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
182 pItem->SetEnabled(false);
188 MoreConnectivityForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
190 AppLogDebug("ENTER");
192 bool checkSecondText = false;
193 int itmeHeight = H_GROUP_ITEM_DEFAULT_LABEL;
194 int btEnableStatus = BLUETOOTH_OFF_OPTION;
195 Rectangle itemLabelRect;
196 Rectangle itemIconRect;
197 Rectangle itemIconLabelRect;
198 Rectangle itemSecondLineTextRect;
199 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
200 Bitmap* pBitmap = null;
202 String secondLineText;
203 bool EnableStatus = false;
204 Label* pLabel = null;
205 int fontSize = GetFontSize();
207 TableViewItem* pItem = new (std::nothrow) TableViewItem();
209 if (itemIndex == ID_ITEM_CONNECTIVITY_BLUETOOTH)
211 checkSecondText = true;
212 ItemTypeIconAndTwoLine(itemIconRect, itemIconLabelRect, itemSecondLineTextRect, fontSize);
213 itmeHeight = (itemIconLabelRect.height + itemSecondLineTextRect.height);
214 pBitmap = ResourceManager::GetBitmapN(IDB_BLUETOOTH);
216 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, EnableStatus) == E_SUCCESS)
218 AppLogDebug("systeminfo::GetValue() fail(%s)", GetErrorMessage(GetLastResult()));
220 if (EnableStatus == true)
222 btEnableStatus = BluetoothPresentationModel::GetInstance()->IsBluetoothActivated();
223 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_ON");
227 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
232 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
234 itemText = ResourceManager::GetString(L"IDS_ST_BODY_BLUETOOTH");
236 else if (itemIndex == ID_ITEM_CONNECTIVITY_NFC)
238 checkSecondText = true;
239 ItemTypeIconAndTwoLine(itemIconRect, itemIconLabelRect, itemSecondLineTextRect, fontSize);
240 itmeHeight = (itemIconLabelRect.height + itemSecondLineTextRect.height);
241 pBitmap = ResourceManager::GetBitmapN(IDB_NFC);
242 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
244 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_NFC, EnableStatus) == E_SUCCESS)
246 AppLogDebug("systeminfo::GetValue() success(%s)", GetErrorMessage(GetLastResult()));
248 if (EnableStatus == true)
250 if (NfcPresentationModel::GetInstance()->IsNfcActivated() == true)
252 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_ON");
256 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
261 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
266 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
268 itemText = ResourceManager::GetString(L"IDS_NFC_BODY_NFC");
272 itemText = ResourceManager::GetString(L"IDS_ST_HEADER_WI_FI_DIRECT");
273 ItemTypeIconAndOneLine(itemIconRect, itemIconLabelRect);
276 RelativeLayout relativeLayout;
277 relativeLayout.Construct();
279 pItem->Construct(relativeLayout, Dimension(itemWidth, itmeHeight), style);
280 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
284 pLabel = new (std::nothrow) Label();
285 pLabel->Construct(itemLabelRect, itemText);
286 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
288 pItem->AddControl(pLabel);
289 relativeLayout.SetMargin(*pLabel, itemLabelRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
290 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
291 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
295 pLabel = new (std::nothrow) Label();
296 pLabel->Construct(itemIconRect, L"");
297 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
298 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
299 pLabel->SetBackgroundBitmap(*pBitmap);
301 pItem->AddControl(pLabel);
303 pLabel = new (std::nothrow) Label();
304 pLabel->Construct(itemIconLabelRect, itemText);
305 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
306 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
307 pLabel->SetTextColor(COLOR_MAIN_TEXT);
309 pItem->AddControl(pLabel);
310 relativeLayout.SetMargin(*pLabel, itemIconLabelRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
311 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
312 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
314 if (checkSecondText == true)
316 pLabel = new (std::nothrow) Label();
317 pLabel->Construct(itemSecondLineTextRect, secondLineText);
318 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
319 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
320 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
321 pLabel->SetTextColor(COLOR_SUB_TEXT);
323 pItem->AddControl(pLabel);
324 relativeLayout.SetMargin(*pLabel, itemSecondLineTextRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
325 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
326 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
334 MoreConnectivityForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
336 AppLogDebug("ENTER");
345 MoreConnectivityForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
347 AppLogDebug("ENTER");
356 MoreConnectivityForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
358 bool EnableStatus = false;
359 SceneManager* pSceneManager = SceneManager::GetInstance();
360 AppAssert(pSceneManager);
362 AppLogDebug("Group[ %d ] Index [ %d ]", groupIndex, itemIndex);
366 case ID_ITEM_CONNECTIVITY_BLUETOOTH:
368 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, EnableStatus) != E_SUCCESS)
370 AppLogDebug("systeminfo::GetValue() fail(%s)", GetErrorMessage(GetLastResult()));
373 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_BLUETOOTH, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
377 case ID_ITEM_CONNECTIVITY_NFC:
379 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_NFC, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
383 case ID_ITEM_CONNECTIVITY_WIFI_DIRECT:
385 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WIFI_DIRECT, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
395 MoreConnectivityForm::GetDefaultGroupItemHeight(void)
397 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
401 MoreConnectivityForm::GetDefaultItemHeight(void)
403 return H_GROUP_ITEM_DEFAULT;
407 MoreConnectivityForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
412 MoreConnectivityForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
414 if ((groupIndex != 0)
417 AppLogDebug("UpdateItem is Error");
421 Label* pLabel = static_cast<Label*>(pItem->GetControl(2));
422 AppLogDebug("pLabel is %ls", pLabel->GetText().GetPointer());
423 if (__pTableView->IsItemChecked(groupIndex, itemIndex) == true)
425 pLabel->SetText(ResourceManager::GetString(L"IDS_ST_BODY_ON"));
429 pLabel->SetText(ResourceManager::GetString(L"IDS_ST_BODY_OFF"));
435 MoreConnectivityForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
440 MoreConnectivityForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)