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->AddActionEventListener(*this);
68 SetFormBackEventListener(this);
72 BluetoothDetailForm::OnInitializing(void)
74 CreateHeader(ResourceManager::GetString(L"IDS_BT_BODY_DETAILS"));
76 SetUserPendingEventReceivedForm(this);
81 BluetoothDetailForm::OnTerminating(void)
83 __pPendingEventReceivedForm = null;
84 __pBluetoothPresentationModelInstance = null;
87 SetFormBackEventListener(null);
92 BluetoothDetailForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
96 AppLogDebug("pArgs is null");
101 String* pPairedDeviceIndex = static_cast<String*>(pArgs->GetAt(0));
102 if (pPairedDeviceIndex == null)
104 AppLogDebug("pPairedDeviceIndex is null");
105 __isTerminate = true;
109 result r = Integer::Parse(*pPairedDeviceIndex, __pairedDeviceIndex);
111 || (__pairedDeviceIndex < 0))
113 AppLogDebug("Integer::Parse fail[%s] __pairedDeviceIndex[%d]", GetErrorMessage(r), __pairedDeviceIndex);
114 __isTerminate = true;
118 r = BluetoothPresentationModelInit();
121 AppLogDebug("BluetoothPresentationModelInit fail [%s]", GetErrorMessage(r));
122 __isTerminate = true;
133 BluetoothDetailForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
138 BluetoothDetailForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
140 SceneManager* pSceneManager = SceneManager::GetInstance();
141 AppAssert(pSceneManager);
143 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
147 BluetoothDetailForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
149 SceneManager* pSceneManager = SceneManager::GetInstance();
150 AppAssert(pSceneManager);
152 if (requestId == ID_BLUETOOTH_DETAIL_USER_PENDING_EVNET_GOBACKWARD)
154 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
159 BluetoothDetailForm::GetGroupCount(void)
161 return ID_BLUETOOTH_DETAIL_GROUP_COUNT_DEFAULT;
165 BluetoothDetailForm::GetItemCount(int groupIndex)
167 return ID_BLUETOOTH_DETAIL_ITEM_COUNT_DEFAULT;
171 BluetoothDetailForm::CreateGroupItem(int groupIndex, int itemWidth)
173 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
174 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
175 Rectangle itemRectangle;
178 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
180 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
181 itemRectangle.y = Y_GROUP_ITEM_DEFAULT_LABEL;
182 itemRectangle.width = itemWidth;
183 itemRectangle.height = itemHeight;
185 RelativeLayout relativeLayout;
186 relativeLayout.Construct();
188 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
190 Label* pLabel = new (std::nothrow) Label();
193 AppLogDebug("pLabel is null");
196 result r = pLabel->Construct(itemRectangle, groupText);
199 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
204 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
205 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
206 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
207 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
208 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
210 pItem->AddControl(pLabel);
211 pItem->SetEnabled(false);
212 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
213 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
214 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
220 BluetoothDetailForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
222 bool isItemSubText = false;
223 int itemHeight = H_GROUP_ITEM_DEFAULT;
224 Rectangle itemMainRectangle;
225 Rectangle itemSubRectangle;
228 int fontSize = GetFontSize();
230 TableViewItem* pItem = new (std::nothrow) TableViewItem();
233 AppLogDebug("pItem is null");
237 if ((groupIndex != BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_BASE)
238 || (__pBluetoothPresentationModelInstance == null))
240 if (__pBluetoothPresentationModelInstance == null)
242 AppLogDebug("__pBluetoothPresentationModelInstance is null");
246 AppLogDebug("Unknown groupIndex");
255 case BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_DEVICE_NAME:
257 itemMainText = ResourceManager::GetString(L"IDS_ST_HEADER_DEVICE_NAME_ABB");
258 itemSubText =__pBluetoothPresentationModelInstance->GetPairedDeviceNameAt(__pairedDeviceIndex);
259 isItemSubText = true;
260 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
261 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
265 case BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_UNPAIR:
267 itemMainText = ResourceManager::GetString(L"IDS_BT_BUTTON_UNPAIR");
268 ItemTypeOneLine(itemMainRectangle);
280 RelativeLayout relativeLayout;
281 relativeLayout.Construct();
283 result r = pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
286 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
290 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
292 Label* pLabel = new (std::nothrow) Label();
295 AppLogDebug("pLabel is null");
299 r = pLabel->Construct(itemMainRectangle, itemMainText);
302 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
307 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
308 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
309 pLabel->SetTextColor(COLOR_MAIN_TEXT);
311 pItem->AddControl(pLabel);
313 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
314 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
315 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
318 Label* pSecondLabel = new (std::nothrow) Label();
319 if (pSecondLabel == null)
321 AppLogDebug("pLabel is null");
325 r = pSecondLabel->Construct(itemSubRectangle, itemSubText);
328 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
333 pSecondLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
334 pSecondLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
335 pSecondLabel->SetTextColor(COLOR_SUB_TEXT);
337 pItem->AddControl(pSecondLabel);
338 relativeLayout.SetMargin(*pSecondLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
339 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
340 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
347 BluetoothDetailForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
356 BluetoothDetailForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
365 BluetoothDetailForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
367 SceneManager* pSceneManager = SceneManager::GetInstance();
368 AppAssert(pSceneManager);
370 if ((groupIndex != BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_BASE)
371 || (__pBluetoothPresentationModelInstance == null))
373 if (__pBluetoothPresentationModelInstance == null)
375 AppLogDebug("__pBluetoothPresentationModelInstance is null");
379 AppLogDebug("Unknown groupIndex");
385 if ((itemIndex != BLUETOOTH_DETAIL_STATUS_GROUP_ITEM_UNPAIR)
386 || (__pairedDeviceIndex == ID_BLUETOOTH_DETAIL_INITIALIZE_VALUE))
388 if (__pairedDeviceIndex == ID_BLUETOOTH_DETAIL_INITIALIZE_VALUE)
390 AppLogDebug("__pairedDeviceIndex is unKnown");
391 SendToUserPendingEvent(ID_BLUETOOTH_DETAIL_USER_PENDING_EVNET_GOBACKWARD);
395 AppLogDebug("itemIndex is unKnown");
400 __pBluetoothPresentationModelInstance->UnpairToPairedBluetoothDeviceAt(__pairedDeviceIndex);
404 BluetoothDetailForm::BluetoothPresentationModelInit(void)
406 __pBluetoothPresentationModelInstance = BluetoothPresentationModel::GetInstance();
407 if (__pBluetoothPresentationModelInstance == null)
409 AppLogDebug("__pBluetoothPresentationModelInstance is null");
412 __pBluetoothPresentationModelInstance->SetEventListener(this);
418 BluetoothDetailForm::SetUserPendingEventReceivedForm(Tizen::Ui::Controls::Form* pEventReveivedForm)
420 __pPendingEventReceivedForm = pEventReveivedForm;
424 BluetoothDetailForm::SendToUserPendingEvent(RequestId requestId)
426 __pPendingEventReceivedForm->SendUserEvent(requestId, null);
430 BluetoothDetailForm::GetDefaultGroupItemHeight(void)
432 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
436 BluetoothDetailForm::GetDefaultItemHeight(void)
438 return H_GROUP_ITEM_DEFAULT;
442 BluetoothDetailForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
447 BluetoothDetailForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
452 BluetoothDetailForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
457 BluetoothDetailForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
462 BluetoothDetailForm::OnBluetoothPresentationModelEventCompletedN(BluetoothPresentationModelEvent bluetoothEvent, result r, Tizen::Net::Bluetooth::BluetoothDevice* pDevice)
464 if (bluetoothEvent == BLUETOOTH_PRESENTATION_MODEL_EVENT_UNPAIRED)
466 SendToUserPendingEvent(ID_BLUETOOTH_DETAIL_USER_PENDING_EVNET_GOBACKWARD);
470 AppLogDebug("BluetoothPresentationModelEvent is unknown");