NABI_SE Issue Fix: 45902 45915 and internal issue fix
[apps/osp/Contacts.git] / src / CtFavoriteListPanel.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        CtFavoriteListPanel.cpp
19  * @brief       This is the implementation file for the FavoriteListPanel class.
20  */
21
22 #include <FApp.h>
23 #include "CtContactsApp.h"
24 #include "CtContactValueListItemProvider.h"
25 #include "CtFavoriteListPanel.h"
26 #include "CtFavoriteListPresentationModel.h"
27 #include "CtMainForm.h"
28 #include "CtResourceManager.h"
29 #include "CtSceneRegister.h"
30 #include "CtTypes.h"
31
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
39
40 static const int IDA_FOOTER_ADD_FAVORITE = 1;
41 static const int IDA_MORE_EDIT_FAVORITE = 2;
42 static const int IDA_HEADER_CONTACTS = 10;
43 static const int IDA_HEADER_GROUPS = 11;
44 static const int IDA_HEADER_FAVORITES = 12;
45 static const int IDA_POPUP_CONTACT_VALUE_CLOSE = 20;
46 static const int IDA_FAVORITE_QUICK_MENU = 21;
47 static const int IDA_CONTEXTMENU_CALL = 30;
48 static const int IDA_CONTEXTMENU_MESSAGE = 31;
49 static const int IDA_CONTEXTMENU_VIDEO_CALL = 32;
50 static const int IDA_CONTEXTMENU_REMOVE = 33;
51
52 static const wchar_t* IDB_NO_FAVORITES = L"00_Nocontents_picture.png";
53 static const wchar_t* IDB_QUICK_MENU = L"00_button_expand_closed_press.png";
54
55 static const int W_INITAIL_PANEL = 10;
56 static const int H_INITIAL_PANEL = 10;
57 static const int W_ICONLISTVIEW_ITEM = 239;
58 static const int H_ICONLISTVIEW_ITEM = 239;
59 static const int H_TEXT_BACKGROUND = 64;
60 static const int H_TEXT_SPACE = 96;
61 static const int W_CONTACT_VALUE_POPUP = 688;
62 static const int H_CONTACT_VALUE_POPUP = 532;
63 static const int H_CONTACT_VALUE_POPUP_LIST_VIEW = 338;
64 static const int Y_CLOSE_BUTTON = 358;
65 static const int W_CLOSE_BUTTON = 394;
66 static const int H_CLOSE_BUTTON = 74;
67 static const int W_QUICK_MENU_BUTTON = 74;
68 static const int X_EMPTY_IMAGE = 220;
69 static const int Y_EMPTY_IMAGE = 300;
70 static const int W_EMPTY_IMAGE = 280;
71 static const int H_EMPTY_IMAGE = 280;
72 static const int Y_EMPTY_COMMENT = 618;
73 static const int H_EMPTY_COMMENT = 38;
74 static const int W_ITEM_SPACE = 1;
75 static const int H_ITEM_SPACE = 1;
76 static const int W_NAME_TEXT_MARGIN = 10;
77
78 static const int FONT_SIZE_WITH_THUMBNAIL = 24;
79 static const int FONT_SIZE_EMPTY_COMMENT = 32;
80 static const int FONT_SIZE = 40;
81
82 static const unsigned int COLOR_ITEM_BACKGROUND = Color32<201, 201, 201>::Value;
83 static const unsigned int COLOR_ITEM_TEXT_BACKGROUND = Color32<0, 0, 0, 89>::Value;
84 static const unsigned int COLOR_TEXT_WITH_THUMBNAIL = Color32<249, 249, 249>::Value;
85 static const unsigned int COLOR_TEXT = Color32<255, 255, 255>::Value;
86 static const unsigned int COLOR_LINE = Color32<225, 225, 225, 26>::Value;
87 static const unsigned int COLOR_EMPTY_COMMENT = Color32<102, 102, 102>::Value;
88
89 static const wchar_t* INPUT_KEY_CALL_TYPE = L"http://tizen.org/appcontrol/data/call/type";
90 static const wchar_t* INPUT_KEY_MESSAGE_TYPE = L"http://tizen.org/appcontrol/data/message/type";
91 static const wchar_t* INPUT_KEY_MESSAGE_TO = L"http://tizen.org/appcontrol/data/to";
92 static const wchar_t* INPUT_TYPE_VIDEO = L"video";
93 static const wchar_t* INPUT_TYPE_VOICE = L"voice";
94 static const wchar_t* INPUT_TYPE_SMS = L"sms";
95 static const wchar_t* INPUT_URI_TEL = L"tel:";
96
97 FavoriteListPanel::FavoriteListPanel(void)
98 : __isAppControlLaunching(false)
99 , __scrolledDistance(0)
100 , __selectedItemIndex(0)
101 , __pAppControl(null)
102 , __pContextMenuAction(null)
103 , __pOptionMenu(null)
104 , __pFavoriteListView(null)
105 , __pMultipleContactValuePopup(null)
106 , __pEmptyImageLabel(null)
107 , __pEmptyCommentLabel(null)
108 , __pPresentationModel(null)
109 , __pContactValueListProvider(null)
110 {
111 }
112
113 FavoriteListPanel::~FavoriteListPanel(void)
114 {
115 }
116
117 void
118 FavoriteListPanel::Initialize(void)
119 {
120         Construct(Rectangle(0, 0, W_INITAIL_PANEL, H_INITIAL_PANEL));
121 }
122
123 result
124 FavoriteListPanel::OnInitializing(void)
125 {
126         result r = E_SUCCESS;
127
128         const Form* pForm = dynamic_cast<Form*>(GetParent());
129         AppAssert(pForm);
130
131         Rectangle clientBounds = pForm->GetClientAreaBounds();
132         SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height));
133
134         __pPresentationModel = FavoriteListPresentationModel::GetInstance();
135
136         __pFavoriteListView = new (std::nothrow) IconListView();
137         __pFavoriteListView->Construct(Rectangle(0, 0, clientBounds.width, clientBounds.height), Dimension(W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM));
138         __pFavoriteListView->SetItemProvider(*this);
139         __pFavoriteListView->AddIconListViewItemEventListener(*this);
140         __pFavoriteListView->AddScrollEventListener(*this);
141         __pFavoriteListView->SetItemLayoutHorizontalAlignment(ALIGNMENT_LEFT);
142         __pFavoriteListView->SetItemLayoutVerticalAlignment(ALIGNMENT_TOP);
143         __pFavoriteListView->SetItemSpacing(W_ITEM_SPACE, H_ITEM_SPACE);
144         __pFavoriteListView->SetMargin(MARGIN_TYPE_LEFT, 0);
145         __pFavoriteListView->SetMargin(MARGIN_TYPE_RIGHT, 0);
146         __pFavoriteListView->SetTouchAnimationEnabled(false);
147
148         AddControl(__pFavoriteListView);
149
150         __pEmptyImageLabel = new (std::nothrow) Label();
151         __pEmptyImageLabel->Construct(Rectangle(X_EMPTY_IMAGE, Y_EMPTY_IMAGE, W_EMPTY_IMAGE, H_EMPTY_IMAGE), L"");
152         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_NO_FAVORITES);
153         if (pBitmap != null)
154         {
155                 __pEmptyImageLabel->SetBackgroundBitmap(*pBitmap);
156                 delete pBitmap;
157         }
158         __pEmptyImageLabel->SetShowState(false);
159
160         AddControl(__pEmptyImageLabel);
161
162         __pEmptyCommentLabel = new (std::nothrow) Label();
163         __pEmptyCommentLabel->Construct(Rectangle(0, Y_EMPTY_COMMENT, clientBounds.width, H_EMPTY_COMMENT),
164                                                                                                                                 ResourceManager::GetString(L"IDS_PB_BODY_NO_FAVOURITES"));
165         __pEmptyCommentLabel->SetTextConfig(FONT_SIZE_EMPTY_COMMENT, LABEL_TEXT_STYLE_NORMAL);
166         __pEmptyCommentLabel->SetTextColor(Color(COLOR_EMPTY_COMMENT));
167         __pEmptyCommentLabel->SetShowState(false);
168
169         AddControl(__pEmptyCommentLabel);
170
171         __pOptionMenu = new (std::nothrow) OptionMenu();
172         __pOptionMenu->Construct();
173         __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_SK_EDIT"), IDA_MORE_EDIT_FAVORITE);
174         __pOptionMenu->AddActionEventListener(*this);
175         __pOptionMenu->SetShowState(false);
176
177         return r;
178 }
179
180 result
181 FavoriteListPanel::OnTerminating(void)
182 {
183         result r = E_SUCCESS;
184
185         if (__pPresentationModel != null)
186         {
187                 __pPresentationModel->RemoveContactChangeListener(*this);
188         }
189
190         delete __pAppControl;
191         delete __pContextMenuAction;
192         delete __pMultipleContactValuePopup;
193
194         return r;
195 }
196
197 void
198 FavoriteListPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
199 {
200         SceneManager* pSceneManager = SceneManager::GetInstance();
201         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
202
203         switch (actionId)
204         {
205         case IDA_HEADER_CONTACTS:
206                 {
207                         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
208                         {
209                                 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
210                                 {
211                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
212                                 }
213                                 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
214                                 {
215                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST_EDITOR));
216                                 }
217                         }
218                         else
219                         {
220                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
221                         }
222                 }
223                 break;
224         case IDA_HEADER_GROUPS:
225                 {
226                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_LIST));
227                 }
228                 break;
229         case IDA_HEADER_FAVORITES:
230                 {
231                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
232                 }
233                 break;
234         case IDA_FOOTER_ADD_FAVORITE:
235                 {
236                         ArrayList* pArgList = new (std::nothrow) ArrayList();
237                         pArgList->Construct();
238
239                         for (int i = 0; i < __pPresentationModel->GetFavoriteCount(); i++)
240                         {
241                                 pArgList->Add(*(new (std::nothrow) Integer(__pPresentationModel->GetContactId(i))));
242                         }
243
244                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_SELECTOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgList);
245                 }
246                 break;
247         case IDA_MORE_EDIT_FAVORITE:
248                 {
249                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST_EDITOR));
250                 }
251                 break;
252         case IDA_POPUP_CONTACT_VALUE_CLOSE:
253                 {
254                         HideContactValuePopup();
255                 }
256                 break;
257         case IDA_CONTEXTMENU_CALL:
258                 {
259                         String phoneNumber = __pPresentationModel->GetDefaultPhoneNumber(__selectedItemIndex);
260                         LaunchAppControl(PROVIDER_ID_PHONE, OPERATION_ID_CALL, phoneNumber, INPUT_TYPE_VOICE);
261                 }
262                 break;
263         case IDA_CONTEXTMENU_MESSAGE:
264         {
265                 if (!(__pPresentationModel->GetDefaultPhoneNumber(__selectedItemIndex).IsEmpty()))
266                 {
267                         String phoneNumber = __pPresentationModel->GetDefaultPhoneNumber(__selectedItemIndex);
268                         LaunchAppControl(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE, phoneNumber, INPUT_TYPE_SMS);
269                 }
270                 else if (!(__pPresentationModel->GetDefaultEmail(__selectedItemIndex).IsEmpty()))
271                 {
272                         String emailId = __pPresentationModel->GetDefaultEmail(__selectedItemIndex);
273                         LaunchAppControl(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE, emailId, null);
274                 }
275         }
276                 break;
277         case IDA_CONTEXTMENU_VIDEO_CALL:
278                 {
279                         String phoneNumber = __pPresentationModel->GetDefaultPhoneNumber(__selectedItemIndex);
280                         LaunchAppControl(PROVIDER_ID_PHONE, OPERATION_ID_CALL, phoneNumber, INPUT_TYPE_VIDEO);
281                 }
282                 break;
283         case IDA_CONTEXTMENU_REMOVE:
284                 {
285                         __pPresentationModel->SetAsFavorite(__pPresentationModel->GetContactId(__selectedItemIndex), false);
286                         __pPresentationModel->InitializeFavoriteList();
287
288                         const Form* pForm = dynamic_cast<Form*>(GetParent());
289                         AppAssert(pForm);
290                         Footer* pFooter = pForm->GetFooter();
291                         if (__pPresentationModel->GetContactCount() > __pPresentationModel->GetFavoriteCount())
292                         {
293                                 pFooter->SetItemEnabled(0, true);
294                                 pFooter->Invalidate(true);
295                         }
296
297                         if (__pPresentationModel->GetFavoriteCount() == 0)
298                         {
299                                 __pFavoriteListView->SetShowState(false);
300                                 __pEmptyImageLabel->SetShowState(true);
301                                 __pEmptyCommentLabel->SetShowState(true);
302                                 pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
303                         }
304
305                         __pFavoriteListView->UpdateList();
306                 }
307                 break;
308         default:
309                 break;
310         }
311 }
312
313 void
314 FavoriteListPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
315 {
316         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
317
318         if (previousSceneId.Equals(IDSCN_CONTACT_SELECTOR, true) && pArgs != null)
319         {
320                 Integer* pContactId = null;
321                 IEnumerator* pEnum = pArgs->GetEnumeratorN();
322
323                 while (pEnum->MoveNext() == E_SUCCESS)
324                 {
325                         pContactId = static_cast<Integer*>(pEnum->GetCurrent());
326                         if (pContactId != null)
327                         {
328                                 __pPresentationModel->SetAsFavorite(pContactId->ToInt(), true);
329                         }
330                 }
331                 delete pEnum;
332                 pArgs->RemoveAll(true);
333                 delete pArgs;
334         }
335
336         Form* pForm = dynamic_cast<Form*>(GetParent());
337         AppAssert(pForm);
338
339         Form *pEventForm = const_cast<Form*>(pForm);
340         pEventForm->SetFormMenuEventListener(this);
341
342         Header* pHeader = pForm->GetHeader();
343         pHeader->AddActionEventListener(*this);
344
345         Footer* pFooter = pForm->GetFooter();
346         pFooter->RemoveAllItems();
347         pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
348         pFooter->AddActionEventListener(*this);
349
350         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
351         {
352                 pEventForm->SetFormMenuEventListener(null);
353                 __pPresentationModel->InitializeFavoriteList(pContactsApp->GetReturnType());
354         }
355         else
356         {
357                 __pPresentationModel->InitializeFavoriteList();
358
359                 FooterItem footerItemAdd;
360                 footerItemAdd.Construct(IDA_FOOTER_ADD_FAVORITE);
361                 footerItemAdd.SetText(ResourceManager::GetString(L"IDS_PB_OPT_ADD_TO_FAVORITES"));
362                 pFooter->AddItem(footerItemAdd);
363                 if (__pPresentationModel->GetContactCount() <= __pPresentationModel->GetFavoriteCount())
364                 {
365                         pFooter->SetItemEnabled(0, false);
366                 }
367
368                 if (__pPresentationModel->GetFavoriteCount() > 0 )
369                 {
370                         pForm->SetFormMenuEventListener(this);
371                 }
372                 else
373                 {
374                         pForm->SetFormMenuEventListener(null);
375                 }
376
377                 pContactsApp->AddContactsAppChangeEventListener(*this);
378         }
379
380         if (__pPresentationModel->GetFavoriteCount() > 0)
381         {
382                 __pFavoriteListView->SetShowState(true);
383                 __pEmptyImageLabel->SetShowState(false);
384                 __pEmptyCommentLabel->SetShowState(false);
385
386                 __pFavoriteListView->UpdateList();
387         }
388         else
389         {
390                 __pFavoriteListView->SetShowState(false);
391                 __pEmptyImageLabel->SetShowState(true);
392                 __pEmptyCommentLabel->SetShowState(true);
393         }
394
395         __pPresentationModel->AddContactChangeListener(*this);
396 }
397
398 void
399 FavoriteListPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
400 {
401         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
402         pContactsApp->RemoveContactsAppChangeEventListener(*this);
403
404         const Form* pForm = dynamic_cast<Form*>(GetParent());
405         AppAssert(pForm);
406
407         Form *pEventForm = const_cast<Form*>(pForm);
408         pEventForm->SetFormMenuEventListener(null);
409
410         Header* pHeader = pForm->GetHeader();
411         pHeader->RemoveActionEventListener(*this);
412
413         Footer* pFooter = pForm->GetFooter();
414         pFooter->RemoveActionEventListener(*this);
415
416         __pPresentationModel->RemoveContactChangeListener(*this);
417
418         delete __pAppControl;
419         __pAppControl = null;
420 }
421
422 void
423 FavoriteListPanel::OnIconListViewItemReordered(Tizen::Ui::Controls::IconListView &iconListView, int indexFrom, int indexTo)
424 {
425 }
426
427 void
428 FavoriteListPanel::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView &iconListView, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
429 {
430         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
431
432         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
433         {
434                 HashMap* pReturnValue = new (std::nothrow) HashMap();
435                 pReturnValue->Construct();
436
437                 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_ITEM_ID)
438                 {
439                         String contactId;
440                         ArrayList* pValueList = new (std::nothrow) ArrayList();
441                         pValueList->Construct();
442
443                         contactId.Append(__pPresentationModel->GetContactId(index));
444                         pValueList->Add(new (std::nothrow) String(contactId));
445
446                         pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), pValueList);
447
448                         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
449
450                         return;
451                 }
452                 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_VCARD)
453                 {
454                         AppCtrlResult appCtrlResult = APP_CTRL_RESULT_SUCCEEDED;
455                         String vCardPath = __pPresentationModel->ExportToVcard(index);
456
457                         if (vCardPath.IsEmpty())
458                         {
459                                 appCtrlResult = APP_CTRL_RESULT_FAILED;
460                         }
461                         else
462                         {
463                                 pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_PATH), new (std::nothrow) String(vCardPath));
464                         }
465                         ReturnValues(pContactsApp->GetRequestId(), appCtrlResult, pReturnValue);
466
467                         return;
468                 }
469
470                 IList* pList = __pPresentationModel->GetMultiValuesN(pContactsApp->GetReturnType(), index);
471                 if (pList == null)
472                 {
473                         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
474
475                         return;
476                 }
477
478                 if (pList->GetCount() > 1)
479                 {
480                         __pContactValueListProvider = new (std::nothrow) ContactValueListItemProvider(pList);
481                         ShowContactValuePopup(index);
482                 }
483                 else if (pList->GetCount() == 1)
484                 {
485                         String keyType;
486
487                         if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
488                         {
489                                 keyType.Append(CONTACT_KEY_PHONE);
490                         }
491                         else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
492                         {
493                                 keyType.Append(CONTACT_KEY_EMAIL);
494                         }
495                         else
496                         {
497                                 return;
498                         }
499
500                         String* pReturnInfo = static_cast<String*>(pList->GetAt(0));
501                         int blankIndex = 0;
502                         ArrayList* pValueList = new (std::nothrow) ArrayList();
503                         pValueList->Construct();
504
505                         pReturnInfo->IndexOf(CHARACTER_SPACE, 0, blankIndex);
506                         pReturnInfo->Remove(0, blankIndex + 1);
507
508                         pValueList->Add(new (std::nothrow) String(*pReturnInfo));
509                         pReturnValue->Add(new (std::nothrow) String(keyType), pValueList);
510
511                         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
512                         delete pList;
513                 }
514
515                 delete pReturnValue;
516         }
517         else
518         {
519                 SceneManager* pSceneManager = SceneManager::GetInstance();
520
521                 ArrayList* pContactId = new (std::nothrow) ArrayList();
522                 pContactId->Construct();
523
524                 pContactId->Add(*(new (std::nothrow) Integer(__pPresentationModel->GetContactId(index))));
525                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_DETAILS, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pContactId);
526         }
527 }
528
529 void
530 FavoriteListPanel::OnIconListViewOverlayBitmapSelected(Tizen::Ui::Controls::IconListView& iconListView, int index, int overlayBitmapId)
531 {
532         if(__isAppControlLaunching == true)
533         {
534                 return;
535         }
536         if (__pContextMenuAction != null)
537         {
538                 delete __pContextMenuAction;
539         }
540
541         if (overlayBitmapId == IDA_FAVORITE_QUICK_MENU)
542         {
543                 const Form* pForm = dynamic_cast<Form*>(GetParent());
544                 AppAssert(pForm);
545
546                 Point itemPosition(W_ICONLISTVIEW_ITEM * (index % iconListView.GetItemCountPerAxis() + 1) - (W_QUICK_MENU_BUTTON / 2), pForm->GetClientAreaBounds().y + H_ICONLISTVIEW_ITEM * (index / iconListView.GetItemCountPerAxis() + 1) - __scrolledDistance);
547
548                 __pContextMenuAction = new (std::nothrow) ContextMenu();
549                 __pContextMenuAction->Construct(itemPosition, CONTEXT_MENU_STYLE_GRID, CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD);
550
551                 if (__pPresentationModel->GetDefaultPhoneNumber(index).IsEmpty() == false)
552                 {
553                         __pContextMenuAction->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_CALL"), IDA_CONTEXTMENU_CALL);
554 #if __SUPPORT_VIDEO_CALL
555                         __pContextMenuAction->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_VIDEO_CALL"), IDA_CONTEXTMENU_VIDEO_CALL);
556 #endif
557                 }
558                 if ((__pPresentationModel->GetDefaultPhoneNumber(index).IsEmpty() == false)||(__pPresentationModel->GetDefaultEmail(index).IsEmpty() == false))
559                 {
560                         __pContextMenuAction->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"), IDA_CONTEXTMENU_MESSAGE);
561                 }
562                 __pContextMenuAction->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_REMOVE"), IDA_CONTEXTMENU_REMOVE);
563                 __pContextMenuAction->AddActionEventListener(*this);
564                 __pContextMenuAction->SetFocusable(true);
565                 __pContextMenuAction->Show();
566                 __selectedItemIndex = index;
567         }
568 }
569
570 void
571 FavoriteListPanel::OnFormMenuRequested(Tizen::Ui::Controls::Form& source)
572 {
573         if(__pPresentationModel->GetFavoriteCount() > 0)
574         {
575                 __pOptionMenu->SetShowState(true);
576                 __pOptionMenu->Show();
577         }
578 }
579
580 Tizen::Ui::Controls::IconListViewItem*
581 FavoriteListPanel::CreateItem(int index)
582 {
583         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
584         Bitmap* pThumbnail = null;
585         Bitmap* pBitmapQuickMenu = null;
586         String name;
587         Font textFont;
588         Color textColor;
589         int textY;
590         int textHeight;
591         int textWidth = W_ICONLISTVIEW_ITEM - (W_NAME_TEXT_MARGIN * 2);
592         TextHorizontalAlignment alignment = TEXT_ALIGNMENT_LEFT;
593
594         if (__pPresentationModel->GetFavoriteItemInfo(index, name, pThumbnail) != E_SUCCESS)
595         {
596                 return null;
597         }
598
599         Canvas* pCanvas = new (std::nothrow) Canvas();
600         pCanvas->Construct(Rectangle(0, 0, W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM));
601         pCanvas->Clear();
602
603         if (pThumbnail != null)
604         {
605                 textFont.Construct(FONT_STYLE_BOLD , FONT_SIZE_WITH_THUMBNAIL);
606                 textY = H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND;
607                 textHeight = H_TEXT_BACKGROUND;
608                 textColor = Color(COLOR_TEXT_WITH_THUMBNAIL);
609
610                 if (pContactsApp->GetOperationId() != OPERATION_ID_PICK)
611                 {
612                         textWidth = W_ICONLISTVIEW_ITEM - W_QUICK_MENU_BUTTON - W_NAME_TEXT_MARGIN;
613                 }
614
615                 pCanvas->DrawBitmap(pCanvas->GetBounds(), *pThumbnail, Rectangle(0, 0, pThumbnail->GetWidth(), pThumbnail->GetHeight()));
616                 pCanvas->SetForegroundColor(Color(COLOR_LINE));
617                 pCanvas->DrawLine(Point(0, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND), Point(W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND));
618                 pCanvas->FillRectangle(Color(COLOR_ITEM_TEXT_BACKGROUND), Rectangle(0, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND, W_ICONLISTVIEW_ITEM, H_TEXT_BACKGROUND));
619         }
620         else
621         {
622                 textFont.Construct(FONT_STYLE_BOLD , FONT_SIZE);
623                 textY = (H_ICONLISTVIEW_ITEM / 2) - (H_TEXT_SPACE / 2);
624                 textHeight = H_TEXT_SPACE;
625                 textColor = Color(COLOR_TEXT);
626                 alignment = TEXT_ALIGNMENT_CENTER;
627
628                 pCanvas->FillRectangle(Color(COLOR_ITEM_BACKGROUND), pCanvas->GetBounds());
629         }
630
631         EnrichedText* pEnrichedTextName = new (std::nothrow) EnrichedText();
632         pEnrichedTextName->Construct(Dimension(textWidth, textHeight));
633         pEnrichedTextName->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
634         pEnrichedTextName->SetHorizontalAlignment(alignment);
635         pEnrichedTextName->SetTextWrapStyle(TEXT_WRAP_WORD_WRAP);
636         pEnrichedTextName->SetTextAbbreviationEnabled(true);
637
638         TextElement* pTextElementName = new (std::nothrow) TextElement();
639         pTextElementName->Construct(name);
640         pTextElementName->SetFont(textFont);
641         pTextElementName->SetTextColor(textColor);
642
643         pEnrichedTextName->Add(*pTextElementName);
644
645         pCanvas->DrawText(Point(W_NAME_TEXT_MARGIN, textY), *pEnrichedTextName);
646
647         Bitmap* pBitmapItem = new (std::nothrow) Bitmap();
648         pBitmapItem->Construct(*pCanvas, Rectangle(0, 0, W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM));
649
650         IconListViewItem* pFavoriteItem = new (std::nothrow) IconListViewItem();
651         pFavoriteItem->Construct(*pBitmapItem);
652
653         if (pContactsApp->GetOperationId() != OPERATION_ID_PICK)
654         {
655                 pBitmapQuickMenu = ResourceManager::GetBitmapN(IDB_QUICK_MENU);
656
657                 if (pBitmapQuickMenu != null)
658                 {
659                         pFavoriteItem->SetOverlayBitmap(IDA_FAVORITE_QUICK_MENU, pBitmapQuickMenu, ALIGNMENT_RIGHT, ALIGNMENT_BOTTOM);
660                 }
661         }
662
663         delete pThumbnail;
664         delete pBitmapQuickMenu;
665         delete pCanvas;
666         delete pBitmapItem;
667         delete pEnrichedTextName;
668         delete pTextElementName;
669
670         return pFavoriteItem;
671 }
672
673 bool
674 FavoriteListPanel::DeleteItem(int index, Tizen::Ui::Controls::IconListViewItem *pItem)
675 {
676         delete pItem;
677         pItem = null;
678
679         return true;
680 }
681
682 int
683 FavoriteListPanel::GetItemCount(void)
684 {
685         return __pPresentationModel->GetFavoriteCount();
686 }
687
688 void
689 FavoriteListPanel::OnContactsChanged(void)
690 {
691         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
692
693         HideContactValuePopup();
694         if (__pContextMenuAction != null)
695         {
696                 delete __pContextMenuAction;
697                 __pContextMenuAction = null;
698         }
699
700         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
701         {
702                 __pPresentationModel->InitializeFavoriteList(pContactsApp->GetReturnType());
703         }
704         else
705         {
706                 __pPresentationModel->InitializeFavoriteList();
707         }
708
709         Form* pForm = dynamic_cast<Form*>(GetParent());
710         AppAssert(pForm);
711
712         Footer* pFooter = pForm->GetFooter();
713
714         if (__pPresentationModel->GetContactCount() <= __pPresentationModel->GetFavoriteCount())
715         {
716                 pFooter->SetItemEnabled(0, false);
717                 pFooter->Invalidate(true);
718         }
719         else
720         {
721                 pFooter->SetItemEnabled(0, true);
722                 pFooter->Invalidate(true);
723         }
724
725         if (__pPresentationModel->GetFavoriteCount() > 0)
726         {
727                 pForm->SetFormMenuEventListener(this);
728         }
729         else
730         {
731                 pForm->SetFormMenuEventListener(null);
732         }
733
734         if (__pPresentationModel->GetFavoriteCount() > 0)
735         {
736                 __pFavoriteListView->SetShowState(true);
737                 __pEmptyImageLabel->SetShowState(false);
738                 __pEmptyCommentLabel->SetShowState(false);
739         }
740         else
741         {
742                 __pFavoriteListView->SetShowState(false);
743                 __pEmptyImageLabel->SetShowState(true);
744                 __pEmptyCommentLabel->SetShowState(true);
745         }
746         __pFavoriteListView->UpdateList();
747 }
748
749 void
750 FavoriteListPanel::OnCategoriesChanged(void)
751 {
752 }
753
754 void
755 FavoriteListPanel::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
756 {
757 }
758
759 void
760 FavoriteListPanel::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
761 {
762         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
763
764         HashMap* pReturnValue = new (std::nothrow) HashMap();
765         pReturnValue->Construct();
766
767         String keyType;
768         int selectedIndex = -1;
769         Integer::Parse(listView.GetName(), selectedIndex);
770
771         if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
772         {
773                 keyType.Append(CONTACT_KEY_PHONE);
774         }
775         else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
776         {
777                 keyType.Append(CONTACT_KEY_EMAIL);
778         }
779         else
780         {
781                 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
782
783                 return;
784         }
785
786         IList* pList = __pPresentationModel->GetMultiValuesN(pContactsApp->GetReturnType(), selectedIndex);
787         String* pReturnInfo = static_cast<String *>(pList->GetAt(index));
788         int blankIndex = 0;
789         ArrayList* pValueList = new (std::nothrow) ArrayList();
790         pValueList->Construct();
791
792         pReturnInfo->IndexOf(CHARACTER_SPACE, 0, blankIndex);
793         pReturnInfo->Remove(0, blankIndex + 1);
794         pValueList->Add(new (std::nothrow) String(*pReturnInfo));
795         pReturnValue->Add(new (std::nothrow) String(keyType), pValueList);
796
797         delete pList;
798
799         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
800 }
801
802 void
803 FavoriteListPanel::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
804 {
805 }
806
807 void
808 FavoriteListPanel::ReturnValues(RequestId requestId, Tizen::App::AppCtrlResult appCtrlResult, const Tizen::Base::Collection::IMap* pReturnValue)
809 {
810         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
811
812         result r = pAppManager->SendAppControlResult(requestId, appCtrlResult, pReturnValue);
813         AppLogDebug("[%s] The return result from SendAppControlResult(), AppCtrlResult value : %d.", GetErrorMessage(r), appCtrlResult);
814
815         UiApp::GetInstance()->Terminate();
816 }
817
818 void
819 FavoriteListPanel::ShowContactValuePopup(int index)
820 {
821         String name;
822         Bitmap* pEmpty = null;
823
824         delete __pMultipleContactValuePopup;
825         __pMultipleContactValuePopup = new (std::nothrow) Popup();
826         __pMultipleContactValuePopup->Construct(true, Dimension(W_CONTACT_VALUE_POPUP, H_CONTACT_VALUE_POPUP));
827         __pPresentationModel->GetFavoriteItemInfo(index, name, pEmpty);
828         __pMultipleContactValuePopup->SetTitleText(name);
829         __pMultipleContactValuePopup->SetPropagatedKeyEventListener(this);
830
831         Rectangle popupClientBounds = __pMultipleContactValuePopup->GetClientAreaBounds();
832
833         ListView* pListView = new (std::nothrow) ListView();
834         pListView->Construct(Rectangle(0, 0, popupClientBounds.width, H_CONTACT_VALUE_POPUP_LIST_VIEW));
835         pListView->SetItemProvider(*__pContactValueListProvider);
836         pListView->AddListViewItemEventListener(*this);
837         pListView->SetName(String(Integer::ToString(index)));
838
839         __pMultipleContactValuePopup->AddControl(pListView);
840
841         Button* pCancelButton = new (std::nothrow) Button();
842         pCancelButton->Construct(Rectangle((popupClientBounds.width - W_CLOSE_BUTTON) / 2, Y_CLOSE_BUTTON, W_CLOSE_BUTTON, H_CLOSE_BUTTON), ResourceManager::GetString(L"IDS_COM_POP_CLOSE"));
843         pCancelButton->SetActionId(IDA_POPUP_CONTACT_VALUE_CLOSE);
844         pCancelButton->AddActionEventListener(*this);
845
846         __pMultipleContactValuePopup->AddControl(pCancelButton);
847         __pMultipleContactValuePopup->SetShowState(true);
848         __pMultipleContactValuePopup->Show();
849 }
850
851 void
852 FavoriteListPanel::HideContactValuePopup(void)
853 {
854         if (__pMultipleContactValuePopup)
855         {
856                 __pMultipleContactValuePopup->SetShowState(false);
857                 Invalidate(true);
858         }
859 }
860
861 void
862 FavoriteListPanel::OnScrollEndReached (Tizen::Ui::Control &source, Tizen::Ui::Controls::ScrollEndEvent type)
863 {
864         if (type == SCROLL_END_EVENT_END_BOTTOM)
865         {
866                 if (type == SCROLL_END_EVENT_END_BOTTOM)
867                 {
868                         IconListView* iconListView = static_cast<IconListView*>(&source);
869
870                         int listViewHeight = iconListView->GetHeight();
871                         int ItemHeight = H_ICONLISTVIEW_ITEM;
872                         int noOfItems = __pPresentationModel->GetFavoriteCount();
873
874                         int NoOfRows = noOfItems/iconListView->GetItemCountPerAxis();
875                         if(noOfItems%iconListView->GetItemCountPerAxis() != 0)
876                         {
877                                 NoOfRows = NoOfRows + 1;
878                         }
879
880                         int TotalHeight = NoOfRows * ItemHeight;
881
882                         __scrolledDistance = TotalHeight - listViewHeight;
883                 }
884         }
885         else if (type == SCROLL_END_EVENT_END_TOP)
886         {
887                 __scrolledDistance = 0;
888         }
889 }
890
891 void
892 FavoriteListPanel::OnScrollPositionChanged (Tizen::Ui::Control &source, int scrollPos)
893 {
894         __scrolledDistance = scrollPos;
895 }
896
897 void
898 FavoriteListPanel::OnScrollStopped (Tizen::Ui::Control &source)
899 {
900 }
901
902 result
903 FavoriteListPanel::LaunchAppControl(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, const Tizen::Base::String& argument, const Tizen::Base::String& type)
904 {
905         result r = E_SUCCESS;
906
907         if (__pAppControl != null)
908         {
909                 return E_FAILURE;
910         }
911
912         String uri;
913         HashMap extraData;
914         extraData.Construct();
915
916         if (appId.Equals(String(PROVIDER_ID_PHONE)))
917         {
918                 uri.Append(INPUT_URI_TEL);
919                 uri.Append(argument);
920                 extraData.Add(new (std::nothrow) String(INPUT_KEY_CALL_TYPE), new (std::nothrow) String(type));
921         }
922         else if (appId.Equals(String(PROVIDER_ID_MESSAGE)))
923         {
924                 extraData.Add(new (std::nothrow) String(INPUT_KEY_MESSAGE_TO), new (std::nothrow) String(argument));
925                 extraData.Add(new (std::nothrow) String(INPUT_KEY_MESSAGE_TYPE), new (std::nothrow) String(INPUT_TYPE_SMS));
926         }
927
928         __pAppControl = AppManager::FindAppControlN(appId, operationId);
929         if (__pAppControl != null)
930         {
931                 r = __pAppControl->Start(&uri, null, &extraData, null);
932                 if (IsFailed(r))
933                 {
934                         AppLogDebug("[%s] Unable to launch app control", GetErrorMessage(r));
935                 }
936                 else
937                 {
938                         __isAppControlLaunching = true;
939                 }
940         }
941
942         extraData.RemoveAll(true);
943
944         return r;
945 }
946
947 void
948 FavoriteListPanel::OnForeground(void)
949 {
950         __pFavoriteListView->SetEnabled(true);
951         __pFavoriteListView->UpdateList();
952         
953         delete __pAppControl;
954         __pAppControl = null;
955
956         __isAppControlLaunching = false;
957 }
958
959 void
960 FavoriteListPanel::OnBackground(void)
961 {
962 }
963
964 bool
965 FavoriteListPanel::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
966 {
967         return false;
968 }
969
970 bool
971 FavoriteListPanel::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
972 {
973         if (keyEventInfo.GetKeyCode() == KEY_BACK)
974         {
975                 if (__pMultipleContactValuePopup && __pMultipleContactValuePopup->GetShowState() == true)
976                 {
977                         HideContactValuePopup();
978                         return true;
979                 }
980         }
981         return false;
982 }
983
984 bool
985 FavoriteListPanel::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
986 {
987         return false;
988 }
989
990 bool
991 FavoriteListPanel::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
992 {
993         return false;
994 }