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