Applied latest source code
[apps/native/preloaded/Settings.git] / src / StWifiDirectConnectionForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                StWifiDirectConnectionForm.cpp
19  * @brief               This is the implementation file for WifiDirectConnectionForm class.
20  */
21
22 #include "StResourceManager.h"
23 #include "StTypes.h"
24 #include "StWifiDirectConnectionForm.h"
25
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Runtime;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Net::Wifi;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
35
36 #define WIFI_DIRECT_CONNECTION_DEBUG_CODE
37
38 static const int Y_ITEM_COUNT_DISPLAY = 968;
39 static const int DURATION = 500;
40 static const int FRAME_COUNT = 30;
41
42 static const int X_SEARCH_ICON = 630;
43 static const int Y_SEARCH_ICON = 10;
44 static const int W_SEARCH_ICON = 62;
45 static const int H_SEARCH_ICON = 62;
46
47 static const int ID_WIFI_DIRECT_CONNECTION_COUNT_DEFAULT = 1;
48 static const int ID_WIFI_DIRECT_CONNECTION_ITEM_COUNT_TEXT_LENGTH = 5;
49 static const int ID_WIFI_DIRECT_CONNECTION_BALLOON_POPUP_TIMER_EXPIRED_TIME = 2000;
50 static const int ID_WIFI_DIRECT_IN_PROGRESS_REPEAT_COUNT = 1000;
51
52 static const int IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE = 100;
53 static const int IDA_WIFI_DIRECT_CONNECTION_FOOTER_SCAN = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 1;
54 static const int IDA_WIFI_DIRECT_CONNECTION_FOOTER_STOP = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 2;
55 static const int IDA_WIFI_DIRECT_CONNECTION_CONNECT = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 3;
56 static const int IDA_WIFI_DIRECT_CONNECTION_SELECTED_GROUP_ITEM = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 4;
57 static const int IDA_WIFI_DIRECT_CONNECTION_SELECT_ALL_GROUP_ITEM = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 4;
58 static const int IDA_WIFI_DIRECT_CONNECTION_UNSELECT_ALL_GROUP_ITEM = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 5;
59
60 static const int ID_WIFI_DIRECT_FOOTER_SCAN = 0;
61 static const int ID_WIFI_DIRECT_FOOTER_CONNECT = 1;
62
63 WifiDirectConnectionForm::WifiDirectConnectionForm(void)
64         : __pWifiDirectManagerInstance(null)
65         , __pLabelItemCount(null)
66         , __pCheckButton(null)
67         , __pAnimationFrameList(null)
68         , __pAnimation(null)
69         , __groupScanDeviceListInfoCount(0)
70 {
71         __balloonPopuptimer.Construct(*this);
72 }
73
74 WifiDirectConnectionForm::~WifiDirectConnectionForm(void)
75 {
76 }
77
78 void
79 WifiDirectConnectionForm::CreateFooter(void)
80 {
81         Footer* pFooter = GetFooter();
82         AppAssert(pFooter);
83
84         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
85
86         FooterItem footerScan;
87         footerScan.Construct(IDA_WIFI_DIRECT_CONNECTION_FOOTER_SCAN);
88         footerScan.SetText(ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
89
90         FooterItem footerConnect;
91         footerConnect.Construct(IDA_WIFI_DIRECT_CONNECTION_CONNECT);
92         footerConnect.SetText(ResourceManager::GetString(L"IDS_WIFI_BODY_CONNECT"));
93
94         pFooter->AddItem(footerScan);
95         pFooter->AddItem(footerConnect);
96         pFooter->AddActionEventListener(*this);
97         pFooter->SetItemEnabled(ID_WIFI_DIRECT_FOOTER_CONNECT, false);
98
99         SetFormBackEventListener(this);
100 }
101
102 void
103 WifiDirectConnectionForm::DisableFooter(unsigned int itemIndex)
104 {
105         Footer* pFooter = GetFooter();
106         AppAssert(pFooter);
107
108         pFooter->SetItemEnabled(itemIndex, false);
109         pFooter->Invalidate(true);
110 }
111
112 void
113 WifiDirectConnectionForm::EnableFooter(unsigned int itemIndex)
114 {
115         Footer* pFooter = GetFooter();
116         AppAssert(pFooter);
117
118         pFooter->SetItemEnabled(itemIndex, true);
119         pFooter->Invalidate(true);
120 }
121
122 void
123 WifiDirectConnectionForm::SetFooterText(const int actionId, Tizen::Base::String itemText)
124 {
125         Footer* pFooter = GetFooter();
126         AppAssert(pFooter);
127
128         FooterItem footerItem;
129         footerItem.Construct(actionId);
130         footerItem.SetText(itemText);
131
132         pFooter->RemoveItemAt(0);
133         pFooter->InsertItemAt(0, footerItem);
134 }
135
136 void
137 WifiDirectConnectionForm::CreateGroupText(void)
138 {
139         Label* pLabel;
140         Rectangle itemRectLabel = GetClientAreaBounds();
141
142         itemRectLabel.y = Y_GROUP_DEFAULT;
143         itemRectLabel.height = H_GROUP_INDEX_DEFAULT;
144
145         String itemLabelText = ResourceManager::GetString(L"IDS_ST_HEADER_AVAILABLE_DEVICES");
146
147         pLabel = new (std::nothrow) Label();
148         pLabel->Construct(itemRectLabel, itemLabelText);
149         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
150         pLabel->SetTextConfig(FONT_SIZE_MAIN_TEXT, LABEL_TEXT_STYLE_BOLD);
151         pLabel->SetTextColor(COLOR_MAIN_TEXT);
152
153         AddControl(pLabel);
154 }
155
156 void
157 WifiDirectConnectionForm::CreateTableView(void)
158 {
159         Rectangle bounds = GetClientAreaBounds();
160         Rectangle itemRectSelect;
161         Rectangle itemSelectCount;
162         String itemText = ResourceManager::GetString(L"IDS_ST_BODY_SELECT_ALL");
163         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
164
165         bounds.x = X_GROUP_DEFAULT;
166         bounds.y = H_GROUP_ITEM_DEFAULT;
167         bounds.width -= (bounds.x * WIDTH_GAP);
168
169         itemRectSelect = itemSelectCount = bounds;
170
171         itemRectSelect.y = H_GROUP_INDEX_DEFAULT;
172         itemRectSelect.height = H_GROUP_ITEM_DEFAULT;
173         bounds.y = itemRectSelect.y + itemRectSelect.height;
174         bounds.height -= bounds.y;
175
176         __pCheckButton = new (std::nothrow) CheckButton();
177         __pCheckButton->Construct(itemRectSelect, CHECK_BUTTON_STYLE_MARK,
178                                                                         BACKGROUND_STYLE_DEFAULT, false, itemText, GROUP_STYLE_NONE);
179         __pCheckButton->SetActionId(IDA_WIFI_DIRECT_CONNECTION_SELECT_ALL_GROUP_ITEM,
180                                                                 IDA_WIFI_DIRECT_CONNECTION_UNSELECT_ALL_GROUP_ITEM, IDA_WIFI_DIRECT_CONNECTION_SELECTED_GROUP_ITEM);
181
182         AddControl(__pCheckButton);
183
184         __pCheckButton->AddActionEventListener(*this);
185         __pCheckButton->SetColor(CHECK_BUTTON_STATUS_NORMAL, COLOR_BG_CHECKBOX);
186
187         __pTableView = new (std::nothrow) GroupedTableView();
188         __pTableView->Construct(bounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FIXED);
189         __pTableView->SetItemProvider(this);
190
191         AddControl(__pTableView);
192
193         __pTableView->AddGroupedTableViewItemEventListener(*this);
194
195         itemSelectCount.y = Y_ITEM_COUNT_DISPLAY;
196         itemSelectCount.height = H_GROUP_INDEX_NO_TITLE_DEFAULT;
197
198         __pLabelItemCount = new (std::nothrow) Label();
199         __pLabelItemCount->Construct(itemSelectCount, itemSelectedText);
200         __pLabelItemCount->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
201         __pLabelItemCount->SetTextConfig(FONT_SIZE_MAIN_TEXT, LABEL_TEXT_STYLE_BOLD);
202         __pLabelItemCount->SetTextColor(COLOR_MAIN_TEXT);
203         __pLabelItemCount->SetBackgroundColor(COLOR_BG_CHECKBOX);
204         __pLabelItemCount->SetShowState(false);
205
206         AddControl(__pLabelItemCount);
207         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
208         if (pRelativeLayout != null)
209         {
210                 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
211                 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
212                 delete pRelativeLayout;
213         }
214 }
215
216 void
217 WifiDirectConnectionForm::CreateInPorgressAnimationFrame(void)
218 {
219         int count = 0;
220         long duration = DURATION / FRAME_COUNT;
221
222         Bitmap* pBitmap = null;
223         AnimationFrame* pAniFrame = null;
224
225         __pAnimationFrameList = new (std::nothrow) ArrayList(SingleObjectDeleter);
226         __pAnimationFrameList->Construct();
227
228         for (count = 0; count < FRAME_COUNT; count++)
229         {
230                 String searchIconFilePath;
231                 searchIconFilePath.Format(searchIconFilePath.GetLength(), IDB_SEARCH_ICON_SIZE_LAGER_IMAGE_PATH_FORMAT, count);
232                 pBitmap = ResourceManager::GetBitmapN(searchIconFilePath);
233                 if (pBitmap == null)
234                 {
235                         AppLogDebug("GetBitmapN fail");
236                         continue;
237                 }
238                 pAniFrame = new (std::nothrow) AnimationFrame(*pBitmap, duration);
239                 __pAnimationFrameList->Add(*pAniFrame);
240                 delete pBitmap;
241         }
242 }
243
244 void
245 WifiDirectConnectionForm::DestoryInPorgressAnimationFrame(void)
246 {
247         if (__pAnimationFrameList != null)
248         {
249                 delete __pAnimationFrameList;
250                 __pAnimationFrameList = null;
251         }
252 }
253
254 void
255 WifiDirectConnectionForm::SetHandlerInProgressAnimation(void)
256 {
257         Rectangle itemRectLabel = Rectangle(X_SEARCH_ICON, Y_SEARCH_ICON, W_SEARCH_ICON, H_SEARCH_ICON);
258
259         __pAnimation = new (std::nothrow) Animation();
260         result r = __pAnimation->Construct(itemRectLabel, *__pAnimationFrameList);
261         if (IsFailed(r))
262         {
263                 AppLogDebug("__pAnimation->Construct failed(%s)", GetErrorMessage(r));
264                 delete __pAnimation;
265                 return;
266         }
267         __pAnimation->SetRepeatCount(ID_WIFI_DIRECT_CONNECTION_COUNT_DEFAULT);
268
269         __pAnimation->AddAnimationEventListener(*this);
270         __pAnimation->SetShowState(false);
271
272         AddControl(__pAnimation);
273 }
274
275 void
276 WifiDirectConnectionForm::RemoveHandlerInProgressAnimation(void)
277 {
278         if (__pAnimation != null)
279         {
280                 __pAnimation = null;
281         }
282 }
283
284 void
285 WifiDirectConnectionForm::PlayInPorgressAnimation(void)
286 {
287         if (__pAnimation != null)
288         {
289                 __pAnimation->SetRepeatCount(ID_WIFI_DIRECT_IN_PROGRESS_REPEAT_COUNT);
290                 __pAnimation->SetShowState(true);
291                 __pAnimation->Play();
292         }
293 }
294
295 void
296 WifiDirectConnectionForm::StopInPorgressAnimation(void)
297 {
298         if (__pAnimation != null)
299         {
300                 __pAnimation->Stop();
301                 __pAnimation->SetShowState(false);
302         }
303 }
304
305 result
306 WifiDirectConnectionForm::OnInitializing(void)
307 {
308         SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
309         CreateHeader(ResourceManager::GetString(L"IDS_WIFI_BUTTON_MULTI_CONNECT"));
310         CreateFooter();
311         CreateGroupText();
312
313         CreateInPorgressAnimationFrame();
314         SetHandlerInProgressAnimation();
315         CreateTableView();
316
317         __pWifiDirectManagerInstance = GetWifiDirectManagerInstance();
318         result r = E_SUCCESS;
319
320         if ((__pWifiDirectManagerInstance == null)
321                 || IsFailed(GetLastResult()))
322         {
323                 if (__pWifiDirectManagerInstance == null)
324                 {
325                         r = E_FAILURE;
326                 }
327                 return r;
328         }
329
330         if (__pWifiDirectManagerInstance->IsActivated())
331         {
332                 DisableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
333                 TableViewItemInit();
334                 ReAdjustScanDeviceListInfoCount();
335         }
336         else
337         {
338                 AppLogDebug("WifiDirect is state of Deactivated");
339                 return E_FAILURE;
340         }
341
342         return r;
343 }
344
345 result
346 WifiDirectConnectionForm::OnTerminating(void)
347 {
348         __pTableView = null;
349         __pLabelItemCount = null;
350         __pCheckButton = null;
351         __pWifiDirectManagerInstance = null;
352
353         RemoveHandlerInProgressAnimation();
354         DestoryInPorgressAnimationFrame();
355
356         SetFormBackEventListener(null);
357         return E_SUCCESS;
358 }
359
360 void
361 WifiDirectConnectionForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
362 {
363         __pTableView->UpdateTableView();
364 }
365
366 void
367 WifiDirectConnectionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
368 {
369 }
370
371 void
372 WifiDirectConnectionForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
373 {
374         SceneManager* pSceneManager = SceneManager::GetInstance();
375         AppAssert(pSceneManager);
376
377         if ((__pWifiDirectManagerInstance != null)
378                 && (__pWifiDirectManagerInstance->IsScanInProgress()))
379         {
380                 __pWifiDirectManagerInstance->CancelRemoteDeviceScan();
381         }
382
383         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
384 }
385
386 int
387 WifiDirectConnectionForm::GetGroupCount(void)
388 {
389         return ID_WIFI_DIRECT_CONNECTION_COUNT_DEFAULT;
390 }
391
392 int
393 WifiDirectConnectionForm::GetItemCount(int groupIndex)
394 {
395         return __groupScanDeviceListInfoCount;
396 }
397
398 TableViewGroupItem*
399 WifiDirectConnectionForm::CreateGroupItem(int groupIndex, int itemWidth)
400 {
401         return null;
402 }
403
404 TableViewItem*
405 WifiDirectConnectionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
406 {
407         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
408         Rectangle itemIconLabelRect;
409         Rectangle itemIconRect;
410         String itemText;
411         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_MOBILE_AP);
412         Label* pLabel = null;
413         int fontSize = GetFontSize();
414
415         TableViewItem* pItem = new (std::nothrow) TableViewItem();
416
417         WifiDirectDeviceInfo* pScanRemoteDevice = __pWifiDirectManagerInstance->GetScanDeviceListInfoAt(itemIndex);
418         if (pScanRemoteDevice != null)
419         {
420                 itemText = pScanRemoteDevice->GetDeviceName();
421                 if (itemText.IsEmpty() == true)
422                 {
423                         delete pItem;
424                         return null;
425                 }
426         }
427         else
428         {
429                 delete pItem;
430                 return null;
431         }
432
433         RelativeLayout relativeLayout;
434         relativeLayout.Construct();
435
436         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
437         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
438
439         ItemTypeIconAndOneLine(itemIconRect, itemIconLabelRect);
440
441         pLabel = new (std::nothrow) Label();
442         pLabel->Construct(itemIconRect, L"");
443         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
444         pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
445         pLabel->SetBackgroundBitmap(*pBitmap);
446
447         pItem->AddControl(pLabel);
448
449         pLabel = new (std::nothrow) Label();
450         pLabel->Construct(itemIconLabelRect, itemText);
451         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
452         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_BOLD);
453         pLabel->SetTextColor(COLOR_MAIN_TEXT);
454
455         pItem->AddControl(pLabel);
456         relativeLayout.SetMargin(*pLabel, itemIconLabelRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
457         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
458         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
459
460         return pItem;
461 }
462
463 bool
464 WifiDirectConnectionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
465 {
466         delete pItem;
467         pItem = null;   
468
469         return true;
470 }
471
472 bool
473 WifiDirectConnectionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
474 {
475         delete pItem;
476         pItem = null;
477
478         return true;
479 }
480
481 void
482 WifiDirectConnectionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
483 {
484         int itemCount = 0;
485         int count = 0;
486         unsigned int checkedItemCount = 0;
487         int localGroup = 0;
488         int localItem = 0;
489
490         if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
491         {
492                 tableView.SetItemChecked(groupIndex, itemIndex, true);
493         }
494         else if (status == TABLE_VIEW_ITEM_STATUS_UNCHECKED)
495         {
496                 tableView.SetItemChecked(groupIndex, itemIndex, false);
497         }
498         else
499         {
500                 return;
501         }
502
503         itemCount = tableView.GetItemCountAt(0);
504         for (count = 0; count < itemCount; count++)
505         {
506                 localGroup = 0;
507                 localItem = count;
508
509                 if (__pTableView->IsItemChecked(groupIndex, itemIndex))
510                 {
511                         checkedItemCount++;
512                 }
513         }
514
515         if (checkedItemCount != 0)
516         {
517                 EnableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
518                 ShowBalloonPopup(checkedItemCount);
519         }
520         else
521         {
522                 DisableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
523         }
524 }
525
526 void
527 WifiDirectConnectionForm::OnActionPerformed(const Control& source, int actionId)
528 {
529         result r = E_SUCCESS;
530         Footer* pFooter = GetFooter();
531         AppAssert(pFooter);
532
533         switch (actionId)
534         {
535         case IDA_WIFI_DIRECT_CONNECTION_CONNECT:
536                 {
537                         SceneManager* pSceneManager = SceneManager::GetInstance();
538                         AppAssert(pSceneManager);
539
540                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
541                 }
542                 break;
543
544         case IDA_WIFI_DIRECT_CONNECTION_SELECT_ALL_GROUP_ITEM:
545                 {
546                         SelectAllGroupItem();
547                         EnableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
548                 }
549                 break;
550
551         case IDA_WIFI_DIRECT_CONNECTION_FOOTER_SCAN:
552                 {
553                         DisableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
554                         DisableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
555                         r = __pWifiDirectManagerInstance->RemoteDeviceScan();
556                         if (!IsFailed(r))
557                         {
558                                 SetFooterText(IDA_WIFI_DIRECT_CONNECTION_FOOTER_STOP, ResourceManager::GetString(L"IDS_COM_BODY_STOP"));
559                                 ReAdjustScanDeviceListInfoCount();
560                                 PlayInPorgressAnimation();
561                                 UpdateTableView();
562                         }
563                         EnableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
564                 }
565                 break;
566
567         case IDA_WIFI_DIRECT_CONNECTION_FOOTER_STOP:
568                 {
569                         DisableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
570                         __pWifiDirectManagerInstance->CancelRemoteDeviceScan();
571                         StopInPorgressAnimation();
572                         SetFooterText(IDA_WIFI_DIRECT_CONNECTION_FOOTER_SCAN, ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
573                         EnableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
574                 }
575                 break;
576
577         case IDA_WIFI_DIRECT_CONNECTION_UNSELECT_ALL_GROUP_ITEM:
578                 {
579                         UnSelectAllGroupItem();
580                         DisableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
581                 }
582                 break;
583
584         default:
585                 break;
586         }
587 }
588
589 void
590 WifiDirectConnectionForm::TableViewItemInit(void)
591 {
592         __groupScanDeviceListInfoCount = 0;
593 }
594
595 void
596 WifiDirectConnectionForm::ReAdjustScanDeviceListInfoCount(void)
597 {
598         if ((__pWifiDirectManagerInstance == null)
599                 || (__pTableView == null))
600         {
601                 AppLogDebug("__pWifiDirectManagerInstance or __pTableView is null");
602                 return;
603         }
604
605         unsigned int itemCount = __pWifiDirectManagerInstance->GetScanDeviceListInfoCount();
606         if (itemCount != 0)
607         {
608                 __groupScanDeviceListInfoCount = itemCount;
609         }
610 }
611
612 void
613 WifiDirectConnectionForm::UpdateTableView(void)
614 {
615         if (__pTableView == null)
616         {
617                 AppLogDebug("__pTableView is null");
618                 return;
619         }
620         __pTableView->UpdateTableView();
621 }
622
623 void
624 WifiDirectConnectionForm::OnWifiDirectManagerEventCompleted(WifiDirectManagerEvent requestEvent, result r)
625 {
626         if (__pWifiDirectManagerInstance == null)
627         {
628                 return;
629         }
630
631         switch (requestEvent)
632         {
633         case WIFI_DIRECT_MANAGER_EVENT_SCAN_COMPLETED_N:
634                 {
635                         DisableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
636                         SetFooterText(IDA_WIFI_DIRECT_CONNECTION_FOOTER_SCAN, ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
637                         EnableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
638                         StopInPorgressAnimation();
639                         ReAdjustScanDeviceListInfoCount();
640                         UpdateTableView();
641                 }
642                 break;
643
644         default:
645                 {
646                         SceneManager* pSceneManager = SceneManager::GetInstance();
647                         AppAssert(pSceneManager);
648
649                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
650                         AppLogDebug("Requested Event : [%d], Result : [%d]", requestEvent, r);
651                 }
652                 break;
653         }
654 }
655
656 WifiDirectManager*
657 WifiDirectConnectionForm::GetWifiDirectManagerInstance(void)
658 {
659         if (WifiDirectManager::GetInstance() == null)
660         {
661                 return null;
662         }
663
664         WifiDirectManager::GetInstance()->RemoveIWifiDirectManagerEventListener();
665         WifiDirectManager::GetInstance()->SetIWifiDirectManagerEventListener(*this);
666
667         return WifiDirectManager::GetInstance();
668 }
669
670 void
671 WifiDirectConnectionForm::ShowBalloonPopup(unsigned int itemCount)
672 {
673         String itemCountText;
674         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
675
676         if (__pLabelItemCount == null)
677         {
678                 AppLogDebug("__pLabelItemCount is null");
679                 return;
680         }
681
682         itemCountText.Format(ID_WIFI_DIRECT_CONNECTION_ITEM_COUNT_TEXT_LENGTH, L" (%d)", itemCount);
683         itemSelectedText.Insert(itemCountText, itemSelectedText.GetLength());
684
685         __pLabelItemCount->SetText(itemSelectedText);
686         __pLabelItemCount->SetShowState(true);
687         __pLabelItemCount->Invalidate(true);
688
689         __balloonPopuptimer.Start(ID_WIFI_DIRECT_CONNECTION_BALLOON_POPUP_TIMER_EXPIRED_TIME);
690 }
691
692 void
693 WifiDirectConnectionForm::SelectAllGroupItem(void)
694 {
695         int groupItemCount = 0;
696         int loopCount = 0;
697         int checkedItemCount = 0;
698         int localGroup = 0;
699         int localItem = 0;
700
701         if (__pTableView == null)
702         {
703                 AppLogDebug("__pTableView is null ");
704                 return;
705         }
706
707         groupItemCount = __pTableView->GetItemCountAt(0);
708         __pTableView->UpdateTableView();
709
710         for (loopCount = 0; loopCount < groupItemCount; loopCount++)
711         {
712                 localGroup = 0;
713                 localItem = loopCount;
714                 __pTableView->SetItemChecked(localGroup, localItem, true);
715
716                 if (__pTableView->IsItemChecked(localGroup, localItem))
717                 {
718                         checkedItemCount++;
719                 }
720         }
721
722         EnableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
723         ShowBalloonPopup(checkedItemCount);
724 }
725
726 void
727 WifiDirectConnectionForm::UnSelectAllGroupItem(void)
728 {
729         int GroupItemCount = 0;
730         int loopCount = 0;
731         int localGroup = 0;
732         int localItem = 0;
733
734         if ((__pTableView == null)
735                 || (__pCheckButton == null))
736         {
737                 AppLogDebug("__pTableView or __pCheckButton is null ");
738                 return;
739         }
740
741         GroupItemCount = __pTableView->GetItemCountAt(0);
742
743         __pTableView->UpdateTableView();
744         __pCheckButton->SetSelected(false);
745
746         for (loopCount = 0; loopCount < GroupItemCount; loopCount++)
747         {
748                 localGroup = 0;
749                 localItem = loopCount;
750
751                 __pTableView->SetItemChecked(localGroup, localItem, false);
752         }
753 }
754
755 void
756 WifiDirectConnectionForm::OnTimerExpired(Timer& timer)
757 {
758         if (__pLabelItemCount != null)
759         {
760                 __pLabelItemCount->SetShowState(false);
761                 __pLabelItemCount->Invalidate(true);
762         }
763 }
764
765 int
766 WifiDirectConnectionForm::GetDefaultGroupItemHeight(void)
767 {
768         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
769 }
770
771 int
772 WifiDirectConnectionForm::GetDefaultItemHeight(void)
773 {
774         return H_GROUP_ITEM_DEFAULT;
775 }
776
777 void
778 WifiDirectConnectionForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
779 {
780 }
781
782 void
783 WifiDirectConnectionForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
784 {
785 }
786
787 void
788 WifiDirectConnectionForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
789 {
790 }
791
792 void
793 WifiDirectConnectionForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
794 {
795 }