2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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 StWifiDirectForm.cpp
19 * @brief This is the implementation file for WifiDirectForm class.
22 #include "StResourceManager.h"
23 #include "StSettingScenesList.h"
25 #include "StWifiDirectForm.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::Net::Wifi;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
37 #define WIFI_DIRECT_DEBUG_CODE
38 #define WIFI_DIRECT_BUG_REPORT
40 static const int DURATION = 500;
41 static const int FRAME_COUNT = 30;
42 static const int ID_WIFI_DIRECT_IN_PROGRESS_ANIMATION_DEFAULT = -1;
43 static const int ID_WIFI_DIRECT_IN_PROGRESS_REPEAT_COUNT = 1000;
44 static const int X_IN_PROGRESS_ANIMATION = 620;
45 static const int Y_IN_PROGRESS_ANIMATION = 31;
46 static const int W_IN_PROGRESS_ANIMATION = 62;
47 static const int H_IN_PROGRESS_ANIMATION = 62;
49 static const int ID_WIFIDIRECT_COUNT_DEFAULT = 1;
50 static const int ID_FOOTER_ITEM_INDEX_1 = 0;
52 static const int W_WIFI_DIRECT_MULTI_CONNECT_ITEM = (W_GROUP_DEFAULT - (X_GROUP_DEFAULT * WIDTH_GAP * WIDTH_GAP));
54 static const int IDA_WIFI_DIRECT_ACTION_ID_BASE = 100;
55 static const int IDA_WIFI_DIRECT_FOOTER_SCAN = IDA_WIFI_DIRECT_ACTION_ID_BASE + 1;
56 static const int IDA_WIFI_DIRECT_FOOTER_CANCEL = IDA_WIFI_DIRECT_ACTION_ID_BASE + 2;
57 static const int IDA_WIFI_DIRECT_MULTI_CONNECT = IDA_WIFI_DIRECT_ACTION_ID_BASE + 3;
58 static const int IDA_WIFI_DIRECT_DISCONNECT = IDA_WIFI_DIRECT_ACTION_ID_BASE + 4;
59 static const int IDA_WIFI_DIRECT_CANCEL_CONNECT = IDA_WIFI_DIRECT_ACTION_ID_BASE + 5;
60 static const int IDA_WIFI_DIRECT_DISCONNECT_ALL = IDA_WIFI_DIRECT_ACTION_ID_BASE + 6;
62 static const int WIFI_DIRECT_DEFAULT_COUNT = 1;
64 enum WifiDirectGroupIndex
66 WIFI_DIRECT_GROUP_INDEX_BASE,
67 WIFI_DIRECT_GROUP_INDEX_0 = WIFI_DIRECT_GROUP_INDEX_BASE,
68 WIFI_DIRECT_GROUP_INDEX_1,
69 WIFI_DIRECT_GROUP_INDEX_2,
70 WIFI_DIRECT_GROUP_INDEX_3,
71 WIFI_DIRECT_GROUP_INDEX_4,
72 WIFI_DIRECT_GROUP_INDEX_5,
73 WIFI_DIRECT_GROUP_INDEX_6,
74 WIFI_DIRECT_GROUP_INDEX_7,
75 WIFI_DIRECT_GROUP_INDEX_MAX
80 WIFI_DIRECT_GROUP_ITEM_BASE,
81 WIFI_DIRECT_GROUP_ITEM_NONE = WIFI_DIRECT_GROUP_ITEM_BASE,
82 WIFI_DIRECT_GROUP_TURN_ON_OFF_CONTROL_ITEM,
83 WIFI_DIRECT_GROUP_CONNECTED_DEVICES_ITEM,
84 WIFI_DIRECT_GROUP_AVAILABLE_DEVICES_ITEM,
85 WIFI_DIRECT_GROUP_MULTI_CONNECT_ITEM,
86 WIFI_DIRECT_GROUP_BUSY_DEVICES_ITEM,
87 WIFI_DIRECT_GROUP_ABOUT_WIFIDIRECT_ITEM,
88 WIFI_DIRECT_GROUP_ITEM_TOTOAL_COUNT,
89 WIFI_DIRECT_GROUP_ITEM_MAX
92 WifiDirectForm::WifiDirectForm(void)
93 : __pWifiDirectManagerInstance(null)
94 , __localDeviceName(L"")
95 , __localDeviceMemberType(WIFI_DIRECT_GROUP_MEMBER_TYPE_NONE)
96 , __pAnimationFrameList(null)
98 , __isAppControlRequest(false)
100 __positionInProgressAnimation.groupIndex = 0;
101 __positionInProgressAnimation.itemIndex = 0;
104 WifiDirectForm::~WifiDirectForm(void)
109 WifiDirectForm::CreateFooter(void)
111 Footer* pFooter = GetFooter();
114 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
116 FooterItem footerScan;
117 footerScan.Construct(IDA_WIFI_DIRECT_FOOTER_SCAN);
118 footerScan.SetText(ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
120 pFooter->AddItem(footerScan);
121 pFooter->SetBackButton();
122 pFooter->AddActionEventListener(*this);
123 pFooter->SetItemEnabled(ID_FOOTER_ITEM_INDEX_1, false);
125 SetFormBackEventListener(this);
129 WifiDirectForm::DisableScanFooter(void)
131 Footer* pFooter = GetFooter();
134 pFooter->SetItemEnabled(0, false);
135 pFooter->Invalidate(true);
139 WifiDirectForm::EnableScanFooter(void)
141 Footer* pFooter = GetFooter();
144 pFooter->SetItemEnabled(0, true);
145 pFooter->Invalidate(true);
149 WifiDirectForm::SetFooterText(const int actionId, Tizen::Base::String itemText)
151 Footer* pFooter = GetFooter();
154 FooterItem footerItem;
155 footerItem.Construct(actionId);
156 footerItem.SetText(itemText);
158 pFooter->RemoveItemAt(0);
159 pFooter->InsertItemAt(0, footerItem);
163 WifiDirectForm::OnInitializing(void)
165 CreateHeader(ResourceManager::GetString(L"IDS_ST_HEADER_WI_FI_DIRECT"));
170 result r = InitWifiDirectManagerInstance();
174 SetLocalDeviceName();
175 ReAdjustGroupItemToIndex();
176 __pWifiDirectManagerInstance->QueryAllGroupMemberInfoList();
177 CreateInPorgressAnimationFrame();
184 WifiDirectForm::OnTerminating(void)
186 DestoryInPorgressAnimationFrame();
187 __pWifiDirectManagerInstance = null;
191 SetFormBackEventListener(null);
196 WifiDirectForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
198 __pTableView->UpdateTableView();
199 if (previousSceneId.Equals(String(IDSCN_WIFI_DIRECT_CONNECTION)))
201 InitWifiDirectManagerInstance();
203 ReAdjustGroupItemToIndex();
206 else if (pArgs != null)
208 String categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
210 if (categoryCheck == L"category:WifiDirect")
212 __isAppControlRequest = true;
219 WifiDirectForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
224 WifiDirectForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
226 SceneManager* pSceneManager = SceneManager::GetInstance();
227 AppAssert(pSceneManager);
229 if (__isAppControlRequest == true)
231 UiApp* pApp = UiApp::GetInstance();
238 if (__pWifiDirectManagerInstance)
240 __pWifiDirectManagerInstance->CancelRemoteDeviceScan();
242 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
247 WifiDirectForm::OnWifiDirectManagerEventCompleted(WifiDirectManagerEvent requestEvent, result r)
249 result returnResult = r;
250 static bool isUpdateTableview = false;
252 if (__pWifiDirectManagerInstance == null)
257 switch (requestEvent)
259 case WIFI_DIRECT_MANAGER_EVENT_DEVICE_ACTIVATED:
261 if (!IsFailed(returnResult))
263 returnResult = __pWifiDirectManagerInstance->RemoteDeviceScan();
264 if (!IsFailed(returnResult))
266 SetFooterText(IDA_WIFI_DIRECT_FOOTER_CANCEL, ResourceManager::GetString(L"IDS_COM_BODY_STOP"));
267 ReAdjustGroupItemToIndex(true);
272 AppLogDebug("Error Message = [%ls]", GetErrorMessage(returnResult));
273 __pWifiDirectManagerInstance->Deactivate();
280 case WIFI_DIRECT_MANAGER_EVENT_DEVICE_DEACTIVATED:
282 if (!IsFailed(returnResult))
284 SetFooterText(IDA_WIFI_DIRECT_FOOTER_SCAN, ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
286 ReAdjustGroupItemToIndex();
291 AppLogDebug("Error Message = [%ls]", GetErrorMessage(returnResult));
296 case WIFI_DIRECT_MANAGER_EVENT_SCAN_COMPLETED_N:
299 SetFooterText(IDA_WIFI_DIRECT_FOOTER_SCAN, ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
301 ReAdjustGroupItemToIndex(true);
306 case WIFI_DIRECT_MANAGER_EVENT_ASSOCIATION_COMPLETED:
308 case WIFI_DIRECT_MANAGER_EVENT_GROUP_CREATED_N:
310 if ((!IsFailed(returnResult))
311 || (returnResult == E_OPERATION_CANCELED))
313 SetFooterText(IDA_WIFI_DIRECT_FOOTER_SCAN, ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
315 ReAdjustGroupItemToIndex();
318 returnResult = E_SUCCESS;
322 AppLogDebug("Error Message = [%s]", GetErrorMessage(returnResult));
323 __pWifiDirectManagerInstance->Deactivate();
328 case WIFI_DIRECT_EVENT_CANCELCREATEGROUP:
330 AppLogDebug("WIFI_DIRECT_EVENT_CANCELCREATEGROUP");
334 case WIFI_DIRECT_MANAGER_EVENT_ASSOCITION_TERMINATED:
336 case WIFI_DIRECT_MAMAGER_EVENT_GROUP_DESTRORYED:
338 returnResult = __pWifiDirectManagerInstance->RemoteDeviceScan();
339 if (!IsFailed(returnResult))
341 SetFooterText(IDA_WIFI_DIRECT_FOOTER_CANCEL, ResourceManager::GetString(L"IDS_COM_BODY_STOP"));
342 ReAdjustGroupItemToIndex(true);
346 ReAdjustGroupItemToIndex();
353 case WIFI_DIRECT_MANAGER_EVENT_CLIENT_ASSOCIATED:
355 if (!IsFailed(returnResult))
357 ReAdjustGroupItemToIndex();
362 AppLogDebug("Error Message = [%ls]", GetErrorMessage(returnResult));
363 __pWifiDirectManagerInstance->Deactivate();
368 case WIFI_DIRECT_MANAGER_EVENT_CLIENT_DISASSOCIATED:
370 if (!IsFailed(returnResult))
372 ReAdjustGroupItemToIndex();
377 AppLogDebug("Error Message = [%ls]", GetErrorMessage(returnResult));
378 __pWifiDirectManagerInstance->Deactivate();
383 case WIFI_DIRECT_EVENT_CANCELSCAN:
385 AppLogDebug("WIFI_DIRECT_EVENT_CANCELSCAN");
389 case WIFI_DIRECT_MANAGER_EVENT_GROUP_OWNER_INFO_RECEIVED:
391 AppLogDebug("WIFI_DIRECT_MANAGER_EVENT_GROUP_OWNER_INFO_RECEIVED");
395 case WIFI_DIRECT_MANAGER_EVENT_REQUESTED_ALL_GROUP_MEMBER_INFO_RECEIVED_N:
397 ReAdjustGroupItemToIndex();
398 if (isUpdateTableview)
402 isUpdateTableview = false;
406 case WIFI_DIRECT_MANAGER_EVENT_ALL_GROUP_MEMBER_INFO_RECEIVED_N:
408 AppLogDebug("WIFI_DIRECT_MANAGER_EVENT_ALL_GROUP_MEMBER_INFO_RECEIVED_N");
416 AppLogDebug("EXIT[requestEvent:%d]", requestEvent);
417 #ifdef WIFI_DIRECT_DEBUG_CODE
418 if (IsFailed(returnResult))
420 String resultError = GetErrorMessage(returnResult);
421 ShowMessageBox(L"WIFI_DIRECT_DEBUG_CODE", resultError);
427 WifiDirectForm::GetGroupCount(void)
429 AppLogDebug("__groupIndex[GROUP_TOTAL_COUNT]=%d", __groupIndex[GROUP_TOTAL_COUNT]);
430 return __groupIndex[GROUP_TOTAL_COUNT];
434 WifiDirectForm::GetItemCount(int groupIndex)
440 case WIFI_DIRECT_GROUP_INDEX_0:
442 itemCount = __groupItemCount[WIFI_DIRECT_GROUP_INDEX_0];
446 case WIFI_DIRECT_GROUP_INDEX_1:
448 itemCount = __groupItemCount[WIFI_DIRECT_GROUP_INDEX_1];
452 case WIFI_DIRECT_GROUP_INDEX_2:
454 itemCount = __groupItemCount[WIFI_DIRECT_GROUP_INDEX_2];
458 case WIFI_DIRECT_GROUP_INDEX_3:
460 itemCount = __groupItemCount[WIFI_DIRECT_GROUP_INDEX_3];
464 case WIFI_DIRECT_GROUP_INDEX_4:
466 itemCount = __groupItemCount[WIFI_DIRECT_GROUP_INDEX_4];
470 case WIFI_DIRECT_GROUP_INDEX_5:
472 itemCount = __groupItemCount[WIFI_DIRECT_GROUP_INDEX_5];
480 AppLogDebug("[groupIndex:%d]GetItemCount %d", groupIndex, itemCount);
485 WifiDirectForm::CreateGroupItem(int groupIndex, int itemWidth)
487 int itemHeight = H_GROUP_INDEX_DEFAULT;
488 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
489 Rectangle itemRectangle;
491 Label* pLabel = null;
493 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
499 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
500 itemRectangle.y = H_GROUP_INDEX_TITLE_TEXT;
501 itemRectangle.width = itemWidth;
502 itemRectangle.height = H_GROUP_INDEX_DEFAULT - H_GROUP_INDEX_TITLE_TEXT;
504 switch (__groupIndex[groupIndex])
506 case WIFI_DIRECT_GROUP_TURN_ON_OFF_CONTROL_ITEM:
508 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
509 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
510 itemRectangle.y = Y_GROUP_ITEM_DEFAULT_LABEL;
511 itemRectangle.width = itemWidth;
512 itemRectangle.height = itemHeight;
516 case WIFI_DIRECT_GROUP_BUSY_DEVICES_ITEM:
518 groupText = ResourceManager::GetString(L"IDS_ST_HEADER_BUSY_DEVICES");
522 case WIFI_DIRECT_GROUP_AVAILABLE_DEVICES_ITEM:
524 int itemCount = __pWifiDirectManagerInstance->GetScanDeviceListInfoCount();
527 groupText = ResourceManager::GetString(L"IDS_ST_HEADER_AVAILABLE_DEVICES");
531 groupText = ResourceManager::GetString(L"IDS_WIFI_BODY_WI_FI_DIRECT_DEVICES");
536 case WIFI_DIRECT_GROUP_CONNECTED_DEVICES_ITEM:
538 groupText = ResourceManager::GetString(L"IDS_ST_HEADER_CONNECTED_DEVICES");
546 RelativeLayout relativeLayout;
547 relativeLayout.Construct();
549 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
550 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
552 pLabel = new (std::nothrow) Label();
553 pLabel->Construct(itemRectangle, groupText);
554 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
555 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
556 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
557 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
559 pItem->AddControl(*pLabel);
560 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
561 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
562 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
563 pItem->SetEnabled(false);
569 WifiDirectForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
571 bool isTwoLineItemText = false;
572 bool isCreateButtonControl = false;
573 bool isCreateIcon = false;
574 bool isCreaetInProgressAnimation = false;
575 int buttonActionId = IDA_WIFI_DIRECT_ACTION_ID_BASE;
576 int itemHeight = H_GROUP_ITEM_DEFAULT;
577 Rectangle itemIconRect;
578 Rectangle itemRectangle;
579 Rectangle itemRectSecondLabel;
580 Rectangle itemInPorgressAnimationRect;
582 String itemTextTwoLine;
583 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
584 Label* pLabel = null;
585 Label* pSecondLabel = null;
586 Bitmap* pBitmap = null;
587 int fontSize = GetFontSize();
589 TableViewItem* pItem = new (std::nothrow) TableViewItem();
591 || (__pTableView == null )
592 || (__pWifiDirectManagerInstance == null))
598 itemHeight = H_GROUP_ITEM_DEFAULT;
599 ItemTypeOneLine(itemRectangle);
601 switch (__groupIndex[groupIndex])
603 case WIFI_DIRECT_GROUP_TURN_ON_OFF_CONTROL_ITEM:
605 int lastEvent = __pWifiDirectManagerInstance->GetLastEventToPerform();
606 if (lastEvent == WIFI_DIRECT_MANAGER_EVENT_DEVICE_ACTIVATING)
608 itemText = ResourceManager::GetString(L"IDS_COM_POP_ACTIVATING");
609 style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
611 else if (lastEvent == WIFI_DIRECT_MANAGER_EVENT_DEVICE_DEACTIVATING)
613 itemText = ResourceManager::GetString(L"IDS_ST_POP_DEACTIVATING_ING");
614 style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
618 if (__pWifiDirectManagerInstance->IsActivated())
620 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
623 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
624 itemText = ResourceManager::GetString(L"IDS_ST_HEADER_WI_FI_DIRECT");
627 isTwoLineItemText = true;
628 itemTextTwoLine = GetLocalDeviceName();
629 ItemTypeTwoLine(itemRectangle, itemRectSecondLabel, fontSize);
630 itemHeight = (itemRectangle.height + itemRectSecondLabel.height);
634 case WIFI_DIRECT_GROUP_CONNECTED_DEVICES_ITEM:
636 WifiDirectDeviceInfo* pConnectDevice = __pWifiDirectManagerInstance->GetGroupMemberListInfoAt(itemIndex);
637 if (pConnectDevice != null)
639 itemText = pConnectDevice->GetDeviceName();
640 pBitmap = ResourceManager::GetBitmapN(IDB_ABOUT_PHONE);
648 isTwoLineItemText = true;
651 ItemTypeIconAndTwoLine(itemIconRect, itemRectangle, itemRectSecondLabel, fontSize);
652 itemHeight = (itemRectangle.height + itemRectSecondLabel.height);
654 itemTextTwoLine = ResourceManager::GetString(L"IDS_WIFI_BODY_CONNECTED");
658 case WIFI_DIRECT_GROUP_AVAILABLE_DEVICES_ITEM:
660 itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_NO_DEVICES_FOUND");
662 WifiDirectDeviceInfo* pScanRemoteDevice = __pWifiDirectManagerInstance->GetScanDeviceListInfoAt(itemIndex);
663 if (pScanRemoteDevice != null)
665 itemText = pScanRemoteDevice->GetDeviceName();
666 if (itemText.IsEmpty() == false)
668 int localDeviceLastEvent = __pWifiDirectManagerInstance->GetLastEventToPerform();
670 if ((localDeviceLastEvent == WIFI_DIRECT_MANAGER_EVENT_GROUP_CREATING)
671 || ( localDeviceLastEvent == WIFI_DIRECT_MANAGER_EVENT_ASSOCIATING))
673 itemTextTwoLine = ResourceManager::GetString(L"IDS_ST_BODY_TAP_TO_CONNECT_ABB");
675 TableViewIndex positionInPorgressAnimation = GetPositionInProgressAnimation();
676 if ((positionInPorgressAnimation.groupIndex == groupIndex)
677 && (positionInPorgressAnimation.itemIndex == itemIndex))
679 isCreaetInProgressAnimation = true;
680 itemInPorgressAnimationRect = Rectangle(X_IN_PROGRESS_ANIMATION, Y_IN_PROGRESS_ANIMATION
681 , W_IN_PROGRESS_ANIMATION, H_IN_PROGRESS_ANIMATION);
683 itemTextTwoLine = ResourceManager::GetString(L"IDS_WIFI_BODY_CONNECTING_ING");
688 itemTextTwoLine = ResourceManager::GetString(L"IDS_ST_BODY_TAP_TO_CONNECT_ABB");
692 isTwoLineItemText = true;
694 ItemTypeIconAndTwoLine(itemIconRect, itemRectangle, itemRectSecondLabel, fontSize);
695 itemHeight = (itemRectangle.height + itemRectSecondLabel.height);
696 pBitmap = ResourceManager::GetBitmapN(IDB_ABOUT_PHONE);
702 case WIFI_DIRECT_GROUP_MULTI_CONNECT_ITEM:
704 int localDeviceMemberType = GetLocalDeviceMemberType();
705 int localDeviceLastEvent = __pWifiDirectManagerInstance->GetLastEventToPerform();
707 if (localDeviceMemberType != WIFI_DIRECT_GROUP_MEMBER_TYPE_NONE)
709 int connectedDeviceCount = __pWifiDirectManagerInstance->GetGroupMemberInfoListCount();
710 if (connectedDeviceCount > ID_WIFIDIRECT_COUNT_DEFAULT)
712 itemText = ResourceManager::GetString(L"IDS_WIFI_BUTTON_DISCONNECT_ALL");
713 buttonActionId = IDA_WIFI_DIRECT_DISCONNECT_ALL;
717 itemText = ResourceManager::GetString(L"IDS_WIFI_SK_DISCONNECT");
718 buttonActionId = IDA_WIFI_DIRECT_DISCONNECT;
721 else if ((localDeviceLastEvent == WIFI_DIRECT_MANAGER_EVENT_ASSOCIATING)
722 || (localDeviceLastEvent == WIFI_DIRECT_MANAGER_EVENT_GROUP_CREATING))
724 itemText = ResourceManager::GetString(L"IDS_WIFI_SK2_CANCEL_CONNECTION");
725 buttonActionId = IDA_WIFI_DIRECT_CANCEL_CONNECT;
729 itemText = ResourceManager::GetString(L"IDS_WIFI_BUTTON_MULTI_CONNECT");
730 buttonActionId = IDA_WIFI_DIRECT_MULTI_CONNECT;
733 itemHeight = H_GROUP_ITEM_DEFAULT_BUTTON;
735 itemRectangle = Rectangle(X_GROUP_DEFAULT, Y_GROUP_DEFAULT
736 , W_WIFI_DIRECT_MULTI_CONNECT_ITEM, H_GROUP_ITEM_DEFAULT_BUTTON);
738 isCreateButtonControl = true;
742 case WIFI_DIRECT_GROUP_BUSY_DEVICES_ITEM:
744 WifiDirectDeviceInfo* pBusyDevice = __pWifiDirectManagerInstance->GetBusyDeviceListInfoAt(itemIndex);
745 if (pBusyDevice != null)
747 itemText = pBusyDevice->GetDeviceName();
748 pBitmap = ResourceManager::GetBitmapN(IDB_ABOUT_PHONE);
756 isTwoLineItemText = true;
759 itemHeight = H_GROUP_ITEM_TWO_LINE_DEFAULT;
760 ItemTypeIconAndTwoLine(itemIconRect, itemRectangle, itemRectSecondLabel, fontSize);
761 itemHeight = (itemRectangle.height + itemRectSecondLabel.height);
765 case WIFI_DIRECT_GROUP_ABOUT_WIFIDIRECT_ITEM:
767 itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_ABOUT_WI_FI_DIRECT_ABB");
779 RelativeLayout relativeLayout;
780 relativeLayout.Construct();
782 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
783 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
785 if (isCreateButtonControl)
787 Button* pButton = new (std::nothrow) Button();
788 pButton->Construct(itemRectangle, itemText);
789 pButton->SetActionId(buttonActionId);
790 pButton->AddActionEventListener(*this);
792 pItem->AddControl(*pButton);
798 pLabel = new (std::nothrow) Label();
799 pLabel->Construct(itemIconRect, L"");
800 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
801 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
802 pLabel->SetBackgroundBitmap(*pBitmap);
804 pItem->AddControl(*pLabel);
809 pLabel = new (std::nothrow) Label();
810 pLabel->Construct(itemRectangle, itemText);
811 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
812 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
813 pLabel->SetTextColor(COLOR_MAIN_TEXT);
815 pItem->AddControl(*pLabel);
816 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
817 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
818 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
820 if (isTwoLineItemText)
822 pSecondLabel = new (std::nothrow) Label();
823 pSecondLabel->Construct(itemRectSecondLabel, itemTextTwoLine);
824 pSecondLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
825 pSecondLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
826 pSecondLabel->SetTextColor(COLOR_SUB_TEXT);
828 pItem->AddControl(*pSecondLabel);
829 relativeLayout.SetMargin(*pLabel, itemRectSecondLabel.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
830 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
831 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
834 if (isCreaetInProgressAnimation)
836 Animation* pAnimation = new (std::nothrow) Animation();
837 if (pAnimation->Construct(itemInPorgressAnimationRect, *__pAnimationFrameList) == E_SUCCESS)
839 pAnimation->SetRepeatCount(WIFI_DIRECT_DEFAULT_COUNT);
841 pItem->AddControl(*pAnimation);
843 SetHandlerInProgressAnimation(pAnimation);
849 if (__groupIndex[groupIndex] == WIFI_DIRECT_GROUP_ABOUT_WIFIDIRECT_ITEM)
851 PlayInPorgressAnimation();
858 WifiDirectForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
867 WifiDirectForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
869 TableViewIndex positionInProgressAnimation = GetPositionInProgressAnimation();
870 if ((positionInProgressAnimation.groupIndex == groupIndex)
871 && (positionInProgressAnimation.itemIndex == itemIndex))
873 StopInPorgressAnimation();
874 RemoveHandlerInProgressAnimation(groupIndex, itemIndex);
884 WifiDirectForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
886 result returnResult = E_SUCCESS;
887 SceneManager* pSceneManager = SceneManager::GetInstance();
888 AppAssert(pSceneManager);
890 if (__pWifiDirectManagerInstance == null)
894 __pWifiDirectManagerInstance->CancelRemoteDeviceScan();
896 switch (__groupIndex[groupIndex])
898 case WIFI_DIRECT_GROUP_TURN_ON_OFF_CONTROL_ITEM:
900 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
902 if (tableView.IsItemChecked(groupIndex, itemIndex) == true)
904 tableView.SetItemChecked(groupIndex, itemIndex, false);
905 status = TABLE_VIEW_ITEM_STATUS_UNCHECKED;
909 tableView.SetItemChecked(groupIndex, itemIndex, true);
910 status = TABLE_VIEW_ITEM_STATUS_CHECKED;
914 if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
916 returnResult = __pWifiDirectManagerInstance->Activate();
917 if (!IsFailed(returnResult))
920 ModifyTableViewItem(groupIndex, itemIndex);
925 returnResult = __pWifiDirectManagerInstance->Deactivate();
926 if (!IsFailed(returnResult))
929 ModifyTableViewItem(groupIndex, itemIndex);
935 case WIFI_DIRECT_GROUP_AVAILABLE_DEVICES_ITEM:
937 WifiDirectDeviceInfo* pRemoteDeviceInfo = __pWifiDirectManagerInstance->GetScanDeviceListInfoAt(itemIndex);
938 if (pRemoteDeviceInfo == null)
940 returnResult = GetLastResult();
944 returnResult = __pWifiDirectManagerInstance->ConnectTo(*pRemoteDeviceInfo);
945 if (!IsFailed(returnResult))
948 SetPositionInProgressAnimation(groupIndex, itemIndex);
950 #ifdef WIFI_DIRECT_BUG_REPORT
951 AppLogDebug("WIFI_DIRECT_BUG_REPORT[Call RefreshItem method, operate createitem before delete item");
954 ModifyTableViewItem(itemTag.groupIndex, itemTag.itemIndex);
955 int groupIndex = GetGroupItemToIndex(WIFI_DIRECT_GROUP_MULTI_CONNECT_ITEM);
956 ModifyTableViewItem(groupIndex, 0);
963 case WIFI_DIRECT_GROUP_ABOUT_WIFIDIRECT_ITEM:
965 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WIFI_DIRECT_ABOUT, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
973 #ifdef WIFI_DIRECT_DEBUG_CODE
974 if (IsFailed(returnResult))
976 String resultError = GetErrorMessage(returnResult);
977 ShowMessageBox(L"WIFI_DIRECT_DEBUG_CODE", resultError);
983 WifiDirectForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
985 result returnResult = E_SUCCESS;
987 if (__pWifiDirectManagerInstance == null)
994 case IDA_WIFI_DIRECT_FOOTER_SCAN:
997 returnResult = __pWifiDirectManagerInstance->RemoteDeviceScan();
999 if (!IsFailed(returnResult))
1001 SetFooterText(IDA_WIFI_DIRECT_FOOTER_CANCEL, ResourceManager::GetString(L"IDS_COM_BODY_STOP"));
1002 ReAdjustGroupItemToIndex(true);
1007 __pWifiDirectManagerInstance->Deactivate();
1013 case IDA_WIFI_DIRECT_FOOTER_CANCEL:
1015 DisableScanFooter();
1016 returnResult = __pWifiDirectManagerInstance->CancelRemoteDeviceScan();
1021 case IDA_WIFI_DIRECT_DISCONNECT:
1023 returnResult = __pWifiDirectManagerInstance->DisconnectAll();
1027 case IDA_WIFI_DIRECT_CANCEL_CONNECT:
1029 returnResult = __pWifiDirectManagerInstance->CancelConnect();
1033 case IDA_WIFI_DIRECT_MULTI_CONNECT:
1035 SceneManager* pSceneManager = SceneManager::GetInstance();
1036 AppAssert(pSceneManager);
1038 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WIFI_DIRECT_CONNECTION, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
1042 case IDA_WIFI_DIRECT_DISCONNECT_ALL:
1044 returnResult = __pWifiDirectManagerInstance->DisconnectAll();
1052 #ifdef WIFI_DIRECT_DEBUG_CODE
1053 if (IsFailed(returnResult))
1055 String resultError = GetErrorMessage(returnResult);
1056 ShowMessageBox(L"WIFI_DIRECT_DEBUG_CODE", resultError);
1062 WifiDirectForm::InitWifiDirectManagerInstance(void)
1064 __pWifiDirectManagerInstance = WifiDirectManager::GetInstance();
1065 if (__pWifiDirectManagerInstance == null)
1070 __pWifiDirectManagerInstance->RemoveIWifiDirectManagerEventListener();
1071 __pWifiDirectManagerInstance->SetIWifiDirectManagerEventListener(*this);
1073 if (__pWifiDirectManagerInstance->IsActivated() == true)
1082 WifiDirectForm::CreateInPorgressAnimationFrame(void)
1085 long duration = DURATION / FRAME_COUNT;
1087 Bitmap* pBitmap = null;
1088 AnimationFrame* pAniFrame = null;
1090 __pAnimationFrameList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1091 __pAnimationFrameList->Construct();
1093 for (count = 0; count < FRAME_COUNT; count++)
1095 String searchIconFilePath;
1096 searchIconFilePath.Format(searchIconFilePath.GetLength(), IDB_SEARCH_ICON_SIZE_LAGER_IMAGE_PATH_FORMAT, count);
1097 pBitmap = ResourceManager::GetBitmapN(searchIconFilePath);
1098 if (pBitmap == null)
1100 AppLogDebug("GetBitmapN fail");
1103 pAniFrame = new (std::nothrow) AnimationFrame(*pBitmap, duration);
1104 __pAnimationFrameList->Add(*pAniFrame);
1110 WifiDirectForm::DestoryInPorgressAnimationFrame(void)
1112 if (__pAnimationFrameList != null)
1114 delete __pAnimationFrameList;
1115 __pAnimationFrameList = null;
1120 WifiDirectForm::SetHandlerInProgressAnimation(Tizen::Ui::Controls::Animation* pAnimation)
1122 if ((pAnimation != null)
1123 && (__pAnimation == null )
1124 && (__positionInProgressAnimation.groupIndex != ID_WIFI_DIRECT_IN_PROGRESS_ANIMATION_DEFAULT)
1125 && (__positionInProgressAnimation.itemIndex != ID_WIFI_DIRECT_IN_PROGRESS_ANIMATION_DEFAULT))
1127 __pAnimation = pAnimation;
1128 __pAnimation->AddAnimationEventListener(*this);
1133 WifiDirectForm::PlayInPorgressAnimation(void)
1135 if (__pAnimation != null)
1137 __pAnimation->SetRepeatCount(ID_WIFI_DIRECT_IN_PROGRESS_REPEAT_COUNT);
1138 __pAnimation->SetShowState(true);
1139 __pAnimation->Play();
1144 WifiDirectForm::StopInPorgressAnimation(void)
1146 if (__pAnimation != null)
1148 __pAnimation->Stop();
1149 __pAnimation->SetShowState(false);
1154 WifiDirectForm::GetPositionInProgressAnimation(void)
1156 return __positionInProgressAnimation;
1160 WifiDirectForm::SetPositionInProgressAnimation(int groupIndex, int itemIndex)
1162 if (__pAnimation == null)
1164 __positionInProgressAnimation.groupIndex = groupIndex;
1165 __positionInProgressAnimation.itemIndex = itemIndex;
1170 WifiDirectForm::RemoveHandlerInProgressAnimation(int groupIndex, int itemIndex)
1172 if ((__positionInProgressAnimation.groupIndex == groupIndex)
1173 && (__positionInProgressAnimation.itemIndex == itemIndex)
1174 && (__pAnimation != null))
1176 __positionInProgressAnimation.groupIndex = ID_WIFI_DIRECT_IN_PROGRESS_ANIMATION_DEFAULT;
1177 __positionInProgressAnimation.itemIndex = ID_WIFI_DIRECT_IN_PROGRESS_ANIMATION_DEFAULT;
1178 __pAnimation = null;
1183 WifiDirectForm::TableViewItemInit(void)
1185 __groupItemCount[WIFI_DIRECT_GROUP_INDEX_0] = ID_WIFIDIRECT_COUNT_DEFAULT;
1186 __groupItemCount[WIFI_DIRECT_GROUP_INDEX_1] = 0;
1187 __groupItemCount[WIFI_DIRECT_GROUP_INDEX_2] = 0;
1188 __groupItemCount[WIFI_DIRECT_GROUP_INDEX_3] = 0;
1189 __groupItemCount[WIFI_DIRECT_GROUP_INDEX_4] = ID_WIFIDIRECT_COUNT_DEFAULT;
1193 WifiDirectForm::ModifyTableViewItem(int groupIndex, int itemIndex)
1195 if (__pTableView == null)
1197 AppLogDebug("__pTableView is null");
1201 __pTableView->RefreshItem(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1205 WifiDirectForm::ShowMessageBox(const Tizen::Base::String& title, const Tizen::Base::String& text)
1207 MessageBox messageBox;
1208 int result = E_SUCCESS;
1210 messageBox.Construct(title, text, MSGBOX_STYLE_NONE, MESSAGEBOX_DISPLAY_TIME_2_SEC);
1211 messageBox.ShowAndWait(result);
1215 WifiDirectForm::GetLocalDeviceName(void)
1217 return __localDeviceName;
1221 WifiDirectForm::SetLocalDeviceName(void)
1223 if (__pWifiDirectManagerInstance == null)
1225 AppLogDebug("__pWifiDirectManagerInstance is null");
1229 __localDeviceName = __pWifiDirectManagerInstance->GetLocalDeviceName();
1233 WifiDirectForm::SetLocalDeviceMemberType(void)
1235 if (__pWifiDirectManagerInstance == null)
1237 AppLogDebug("__pWifiDirectManagerInstance is null");
1241 __localDeviceMemberType = __pWifiDirectManagerInstance->GetLocalDeviceGroupMemberType();
1244 Tizen::Net::Wifi::WifiDirectGroupMemberType
1245 WifiDirectForm::GetLocalDeviceMemberType(void)
1247 return __localDeviceMemberType;
1251 WifiDirectForm::ReAdjustGroupItemToIndex(bool insertDefaultItemIngroupIndexAvailable)
1253 if ((__pWifiDirectManagerInstance == null)
1254 || (__pTableView == null))
1256 AppLogDebug("__pWifiDirectManagerInstance or __pTableView is null");
1263 __groupItemCount[groupIndex] = ID_WIFIDIRECT_COUNT_DEFAULT;
1264 __groupIndex[groupIndex] = WIFI_DIRECT_GROUP_TURN_ON_OFF_CONTROL_ITEM;
1265 groupIndex = groupIndex + ID_WIFIDIRECT_COUNT_DEFAULT;
1267 itemCount = __pWifiDirectManagerInstance->GetGroupMemberInfoListCount();
1270 __groupItemCount[groupIndex] = itemCount;
1271 __groupIndex[groupIndex] = WIFI_DIRECT_GROUP_CONNECTED_DEVICES_ITEM;
1272 groupIndex = groupIndex + ID_WIFIDIRECT_COUNT_DEFAULT;
1275 itemCount = __pWifiDirectManagerInstance->GetScanDeviceListInfoCount();
1278 __groupItemCount[groupIndex] = itemCount;
1279 __groupIndex[groupIndex] = WIFI_DIRECT_GROUP_AVAILABLE_DEVICES_ITEM;
1280 groupIndex = groupIndex + ID_WIFIDIRECT_COUNT_DEFAULT;
1282 else if (insertDefaultItemIngroupIndexAvailable)
1284 __groupItemCount[groupIndex] = ID_WIFIDIRECT_COUNT_DEFAULT;
1285 __groupIndex[groupIndex] = WIFI_DIRECT_GROUP_AVAILABLE_DEVICES_ITEM;
1286 groupIndex = groupIndex + ID_WIFIDIRECT_COUNT_DEFAULT;
1289 itemCount = __pWifiDirectManagerInstance->GetBusyDeviceListInfoCount();
1292 __groupItemCount[groupIndex] = itemCount;
1293 __groupIndex[groupIndex] = WIFI_DIRECT_GROUP_BUSY_DEVICES_ITEM;
1294 groupIndex = groupIndex + ID_WIFIDIRECT_COUNT_DEFAULT;
1297 if ((__pWifiDirectManagerInstance->GetGroupMemberInfoListCount() != 0)
1298 || (__pWifiDirectManagerInstance->GetScanDeviceListInfoCount() > ID_WIFIDIRECT_COUNT_DEFAULT))
1300 __groupItemCount[groupIndex] = ID_WIFIDIRECT_COUNT_DEFAULT;
1301 __groupIndex[groupIndex] = WIFI_DIRECT_GROUP_MULTI_CONNECT_ITEM;
1302 groupIndex = groupIndex + ID_WIFIDIRECT_COUNT_DEFAULT;
1303 SetLocalDeviceMemberType();
1306 __groupItemCount[groupIndex] = ID_WIFIDIRECT_COUNT_DEFAULT;
1307 __groupIndex[groupIndex] = WIFI_DIRECT_GROUP_ABOUT_WIFIDIRECT_ITEM;
1308 groupIndex = groupIndex + ID_WIFIDIRECT_COUNT_DEFAULT;
1310 __groupIndex[GROUP_TOTAL_COUNT] = groupIndex;
1314 WifiDirectForm::GetGroupItemToIndex(int groupItem)
1316 for (int loopCount = 0; loopCount < __groupIndex[GROUP_TOTAL_COUNT]; loopCount++)
1318 if (__groupIndex[loopCount] == groupItem)
1323 AppLogDebug("GroupItem not found");
1328 WifiDirectForm::UpdateTableView(void)
1330 if (__pTableView == null)
1332 AppLogDebug("__pTableView is null");
1335 __pTableView->UpdateTableView();
1339 WifiDirectForm::GetDefaultGroupItemHeight(void)
1341 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
1345 WifiDirectForm::GetDefaultItemHeight(void)
1347 return H_GROUP_ITEM_DEFAULT;
1351 WifiDirectForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
1356 WifiDirectForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
1361 WifiDirectForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
1366 WifiDirectForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)