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 StBluetoothDetailForm.cpp
19 * @brief This is the implementation file for BluetoothDetailForm class.
22 #include "StBluetoothDetailForm.h"
23 #include "StResourceManager.h"
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
33 static const int ID_BLUETOOTH_DETAIL_GROUP_COUNT_DEFAULT = 1;
34 static const int ID_BLUETOOTH_DETAIL_ITEM_COUNT_DEFAULT = 2;
35 static const int ID_BLUETOOTH_DETAIL_INITIALIZE_VALUE = -1;
37 static const RequestId ID_BLUETOOTH_DETAIL_USER_PENDING_EVNET_GOBACKWARD = 100;
39 enum BluetoothDetailStatusGroupItem
41 BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_BASE,
42 BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_DEVICE_NAME = BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_BASE,
43 BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_UNPAIR,
44 BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_TOTALCOUNT,
45 BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_MAX
48 BluetoothDetailForm::BluetoothDetailForm(void)
49 : __pPendingEventReceivedForm(null)
50 , __pairedDeviceIndex(ID_BLUETOOTH_DETAIL_INITIALIZE_VALUE)
51 , __isTerminate(false)
55 BluetoothDetailForm::~BluetoothDetailForm(void)
60 BluetoothDetailForm::CreateFooter(void)
62 Footer* pFooter = GetFooter();
65 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
66 pFooter->SetBackButton();
67 pFooter->AddActionEventListener(*this);
69 SetFormBackEventListener(this);
73 BluetoothDetailForm::OnInitializing(void)
75 CreateHeader(ResourceManager::GetString(L"IDS_BT_BODY_DETAILS"));
78 SetUserPendingEventReceivedForm(this);
83 BluetoothDetailForm::OnTerminating(void)
85 __pPendingEventReceivedForm = null;
86 __pBluetoothPresentationModelInstance = null;
89 SetFormBackEventListener(null);
94 BluetoothDetailForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
98 AppLogDebug("pArgs is null");
103 String* pPairedDeviceIndex = static_cast<String*>(pArgs->GetAt(0));
104 if (pPairedDeviceIndex == null)
106 AppLogDebug("pPairedDeviceIndex is null");
107 __isTerminate = true;
111 result r = Integer::Parse(*pPairedDeviceIndex, __pairedDeviceIndex);
113 || (__pairedDeviceIndex < 0))
115 AppLogDebug("Integer::Parse fail[%s] __pairedDeviceIndex[%d]", GetErrorMessage(r), __pairedDeviceIndex);
116 __isTerminate = true;
120 r = BluetoothPresentationModelInit();
123 AppLogDebug("BluetoothPresentationModelInit fail [%s]", GetErrorMessage(r));
124 __isTerminate = true;
135 BluetoothDetailForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
140 BluetoothDetailForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
142 SceneManager* pSceneManager = SceneManager::GetInstance();
143 AppAssert(pSceneManager);
145 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
149 BluetoothDetailForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
151 SceneManager* pSceneManager = SceneManager::GetInstance();
152 AppAssert(pSceneManager);
154 if (requestId == ID_BLUETOOTH_DETAIL_USER_PENDING_EVNET_GOBACKWARD)
156 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
161 BluetoothDetailForm::GetGroupCount(void)
163 return ID_BLUETOOTH_DETAIL_GROUP_COUNT_DEFAULT;
167 BluetoothDetailForm::GetItemCount(int groupIndex)
169 return ID_BLUETOOTH_DETAIL_ITEM_COUNT_DEFAULT;
173 BluetoothDetailForm::CreateGroupItem(int groupIndex, int itemWidth)
175 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
176 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
177 Rectangle itemRectangle;
180 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
182 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
183 itemRectangle.y = Y_GROUP_ITEM_DEFAULT_LABEL;
184 itemRectangle.width = itemWidth;
185 itemRectangle.height = itemHeight;
187 RelativeLayout relativeLayout;
188 relativeLayout.Construct();
190 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
192 Label* pLabel = new (std::nothrow) Label();
195 AppLogDebug("pLabel is null");
198 result r = pLabel->Construct(itemRectangle, groupText);
201 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
206 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
207 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
208 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
209 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
210 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
212 pItem->AddControl(pLabel);
213 pItem->SetEnabled(false);
214 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
215 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
216 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
222 BluetoothDetailForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
224 bool isItemSubText = false;
225 int itemHeight = H_GROUP_ITEM_DEFAULT;
226 Rectangle itemMainRectangle;
227 Rectangle itemSubRectangle;
230 int fontSize = GetFontSize();
232 TableViewItem* pItem = new (std::nothrow) TableViewItem();
235 AppLogDebug("pItem is null");
239 if ((groupIndex != BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_BASE)
240 || (__pBluetoothPresentationModelInstance == null))
242 if (__pBluetoothPresentationModelInstance == null)
244 AppLogDebug("__pBluetoothPresentationModelInstance is null");
248 AppLogDebug("Unknown groupIndex");
257 case BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_DEVICE_NAME:
259 itemMainText = ResourceManager::GetString(L"IDS_ST_HEADER_DEVICE_NAME_ABB");
260 itemSubText =__pBluetoothPresentationModelInstance->GetPairedDeviceNameAt(__pairedDeviceIndex);
261 isItemSubText = true;
262 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
263 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
267 case BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_UNPAIR:
269 itemMainText = ResourceManager::GetString(L"IDS_BT_BUTTON_UNPAIR");
270 ItemTypeOneLine(itemMainRectangle);
282 RelativeLayout relativeLayout;
283 relativeLayout.Construct();
285 result r = pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
288 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
292 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
294 Label* pLabel = new (std::nothrow) Label();
297 AppLogDebug("pLabel is null");
301 r = pLabel->Construct(itemMainRectangle, itemMainText);
304 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
309 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
310 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
311 pLabel->SetTextColor(COLOR_MAIN_TEXT);
313 pItem->AddControl(pLabel);
315 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
316 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
317 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
320 Label* pSecondLabel = new (std::nothrow) Label();
321 if (pSecondLabel == null)
323 AppLogDebug("pLabel is null");
327 r = pSecondLabel->Construct(itemSubRectangle, itemSubText);
330 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
335 pSecondLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
336 pSecondLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
337 pSecondLabel->SetTextColor(COLOR_SUB_TEXT);
339 pItem->AddControl(pSecondLabel);
340 relativeLayout.SetMargin(*pSecondLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
341 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
342 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
349 BluetoothDetailForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
358 BluetoothDetailForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
367 BluetoothDetailForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
369 SceneManager* pSceneManager = SceneManager::GetInstance();
370 AppAssert(pSceneManager);
372 if ((groupIndex != BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_BASE)
373 || (__pBluetoothPresentationModelInstance == null))
375 if (__pBluetoothPresentationModelInstance == null)
377 AppLogDebug("__pBluetoothPresentationModelInstance is null");
381 AppLogDebug("Unknown groupIndex");
387 if ((itemIndex != BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_UNPAIR)
388 || (__pairedDeviceIndex == ID_BLUETOOTH_DETAIL_INITIALIZE_VALUE))
390 if (__pairedDeviceIndex == ID_BLUETOOTH_DETAIL_INITIALIZE_VALUE)
392 AppLogDebug("__pairedDeviceIndex is unKnown");
393 SendToUserPendingEvent(ID_BLUETOOTH_DETAIL_USER_PENDING_EVNET_GOBACKWARD);
397 AppLogDebug("itemIndex is unKnown");
402 __pBluetoothPresentationModelInstance->UnpairToPairedBluetoothDeviceAt(__pairedDeviceIndex);
406 BluetoothDetailForm::BluetoothPresentationModelInit(void)
408 __pBluetoothPresentationModelInstance = BluetoothPresentationModel::GetInstance();
409 if (__pBluetoothPresentationModelInstance == null)
411 AppLogDebug("__pBluetoothPresentationModelInstance is null");
414 __pBluetoothPresentationModelInstance->SetEventListener(this);
420 BluetoothDetailForm::SetUserPendingEventReceivedForm(Tizen::Ui::Controls::Form* pEventReveivedForm)
422 __pPendingEventReceivedForm = pEventReveivedForm;
426 BluetoothDetailForm::SendToUserPendingEvent(RequestId requestId)
428 __pPendingEventReceivedForm->SendUserEvent(requestId, null);
432 BluetoothDetailForm::GetDefaultGroupItemHeight(void)
434 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
438 BluetoothDetailForm::GetDefaultItemHeight(void)
440 return H_GROUP_ITEM_DEFAULT;
444 BluetoothDetailForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
449 BluetoothDetailForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
454 BluetoothDetailForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
459 BluetoothDetailForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
464 BluetoothDetailForm::OnBluetoothPresentationModelEventCompletedN(BluetoothPresentationModelEvent bluetoothEvent, result r, Tizen::Net::Bluetooth::BluetoothDevice* pDevice)
466 if (bluetoothEvent == BLUETOOTH_PRESENTATION_MODEL_EVENT_UNPAIRED)
468 SendToUserPendingEvent(ID_BLUETOOTH_DETAIL_USER_PENDING_EVNET_GOBACKWARD);
472 AppLogDebug("BluetoothPresentationModelEvent is unknown");