44cd1203cd176e721853c5bda48e3bbaa8440ef9
[apps/osp/Contacts.git] / src / CtFavoriteListEditorPanel.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        CtFavoriteListEditorPanel.cpp
19  * @brief       This is the implementation file for the FavoriteListEditorPanel class.
20  */
21
22 #include "CtContactsApp.h"
23 #include "CtFavoriteListEditorPanel.h"
24 #include "CtFavoriteListPresentationModel.h"
25 #include "CtMainForm.h"
26 #include "CtResourceManager.h"
27 #include "CtSceneRegister.h"
28 #include "CtTypes.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
36
37 static const int IDA_FOOTER_REMOVE_FAVORITE = 0;
38 static const int IDA_FOOTER_CANCEL = 1;
39 static const int IDA_FOOTER_DONE = 2;
40 static const int IDA_HEADER_CONTACTS = 10;
41 static const int IDA_HEADER_GROUPS = 11;
42 static const int IDA_HEADER_FAVORITES = 12;
43 static const int IDA_POPUP_CONTACT_VALUE_CLOSE = 20;
44
45 static const int W_INITAIL_PANEL = 10;
46 static const int H_INITIAL_PANEL = 10;
47 static const int W_ICONLISTVIEW_LEFT_MARGIN = 14;
48 static const int W_ICONLISTVIEW_RIGHT_MARGIN = 10;
49 static const int W_ICONLISTVIEW_ITEM = 216;
50 static const int H_ICONLISTVIEW_ITEM = 216;
51 static const int H_TEXT_BACKGROUND = 64;
52 static const int H_TEXT_SPACE = 96;
53 static const int W_ITEM_SPACE = 24;
54 static const int H_ITEM_SPACE = 24;
55 static const int W_CONTACT_VALUE_POPUP = 688;
56 static const int H_CONTACT_VALUE_POPUP = 532;
57 static const int H_CONTACT_VALUE_POPUP_LIST_VIEW = 338;
58 static const int Y_CLOSE_BUTTON = 358;
59 static const int W_CLOSE_BUTTON = 394;
60 static const int H_CLOSE_BUTTON = 74;
61 static const int X_EMPTY_IMAGE = 220;
62 static const int Y_EMPTY_IMAGE = 300;
63 static const int W_EMPTY_IMAGE = 280;
64 static const int H_EMPTY_IMAGE = 280;
65 static const int Y_EMPTY_COMMENT = 618;
66 static const int H_EMPTY_COMMENT = 38;
67 static const int H_BOTTOM_LABEL = 48;
68 static const int W_NAME_TEXT_MARGIN = 10;
69
70 static const int FONT_SIZE_WITH_THUMBNAIL = 24;
71 static const int FONT_SIZE_EMPTY_COMMENT = 32;
72 static const int FONT_SIZE = 40;
73 static const int FONT_SIZE_BOTTOM_LABEL = 32;
74
75 static const wchar_t* IDB_NO_FAVORITES = L"00_Nocontents_picture.png";
76
77 static const unsigned int COLOR_ITEM_BACKGROUND = Color32<201, 201, 201>::Value;
78 static const unsigned int COLOR_ITEM_TEXT_BACKGROUND = Color32<0, 0, 0, 89>::Value;
79 static const unsigned int COLOR_TEXT_WITH_THUMBNAIL = Color32<249, 249, 249>::Value;
80 static const unsigned int COLOR_TEXT = Color32<255, 255, 255>::Value;
81 static const unsigned int COLOR_LINE = Color32<225, 225, 225, 26>::Value;
82 static const unsigned int COLOR_EMPTY_COMMENT = Color32<102, 102, 102>::Value;
83 static const unsigned int COLOR_BOTTOM_LABEL_BG = Color32<68, 68, 68>::Value;
84 static const unsigned int COLOR_BOTTOM_LABEL_FONT = Color32<255, 255, 255>::Value;
85
86 FavoriteListEditorPanel::FavoriteListEditorPanel(void)
87 : __pFavoriteListView(null)
88 , __pMultipleContactValuePopup(null)
89 , __pEmptyImageLabel(null)
90 , __pEmptyCommentLabel(null)
91 , __pBottomLabel(null)
92 , __pTempContactValueHashMap(null)
93 , __pPresentationModel(null)
94 , __pContactValueListProvider(null)
95 {
96 }
97
98 FavoriteListEditorPanel::~FavoriteListEditorPanel(void)
99 {
100 }
101
102 void
103 FavoriteListEditorPanel::Initialize(void)
104 {
105         Construct(Rectangle(0, 0, W_INITAIL_PANEL, H_INITIAL_PANEL));
106 }
107
108 result
109 FavoriteListEditorPanel::OnInitializing(void)
110 {
111         result r = E_SUCCESS;
112
113         const Form* pForm = dynamic_cast<Form*>(GetParent());
114         AppAssert(pForm);
115
116         Rectangle clientBounds = pForm->GetClientAreaBounds();
117         SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height));
118
119         __pPresentationModel = FavoriteListPresentationModel::GetInstance();
120
121         __pFavoriteListView = new (std::nothrow) IconListView();
122         __pFavoriteListView->Construct(Rectangle(0, 0, clientBounds.width, clientBounds.height - H_BOTTOM_LABEL), Dimension(W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM), ICON_LIST_VIEW_STYLE_MARK);
123         __pFavoriteListView->SetItemProvider(*this);
124         __pFavoriteListView->AddIconListViewItemEventListener(*this);
125         __pFavoriteListView->SetItemLayoutHorizontalAlignment(ALIGNMENT_LEFT);
126         __pFavoriteListView->SetItemLayoutVerticalAlignment(ALIGNMENT_TOP);
127         __pFavoriteListView->SetItemSpacing(W_ITEM_SPACE, H_ITEM_SPACE);
128         __pFavoriteListView->SetMargin(MARGIN_TYPE_LEFT, W_ICONLISTVIEW_LEFT_MARGIN);
129         __pFavoriteListView->SetMargin(MARGIN_TYPE_RIGHT, W_ICONLISTVIEW_RIGHT_MARGIN);
130         __pFavoriteListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT);
131         __pFavoriteListView->SetTouchAnimationEnabled(false);
132
133         AddControl(__pFavoriteListView);
134
135         __pEmptyImageLabel = new (std::nothrow) Label();
136         __pEmptyImageLabel->Construct(Rectangle(X_EMPTY_IMAGE, Y_EMPTY_IMAGE, W_EMPTY_IMAGE, H_EMPTY_IMAGE), L"");
137         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_NO_FAVORITES);
138         if (pBitmap != null)
139         {
140                 __pEmptyImageLabel->SetBackgroundBitmap(*pBitmap);
141                 delete pBitmap;
142         }
143         __pEmptyImageLabel->SetShowState(false);
144
145         AddControl(__pEmptyImageLabel);
146
147         __pEmptyCommentLabel = new (std::nothrow) Label();
148         __pEmptyCommentLabel->Construct(Rectangle(0, Y_EMPTY_COMMENT, clientBounds.width, H_EMPTY_COMMENT),
149                                                                                                                                 ResourceManager::GetString(L"IDS_PB_BODY_NO_FAVOURITES"));
150         __pEmptyCommentLabel->SetTextConfig(FONT_SIZE_EMPTY_COMMENT, LABEL_TEXT_STYLE_NORMAL);
151         __pEmptyCommentLabel->SetTextColor(Color(COLOR_EMPTY_COMMENT));
152         __pEmptyCommentLabel->SetShowState(false);
153
154         AddControl(__pEmptyCommentLabel);
155
156         __pBottomLabel = new (std::nothrow) Label();
157         __pBottomLabel->Construct(Rectangle(0, clientBounds.height - H_BOTTOM_LABEL, clientBounds.width, H_BOTTOM_LABEL),
158                                                                 ResourceManager::GetString(L"IDS_COM_POP_SELECTED") + INITIAL_SELECTED_COUNT);
159         __pBottomLabel->SetBackgroundColor(Color(COLOR_BOTTOM_LABEL_BG));
160         __pBottomLabel->SetTextColor(Color(COLOR_BOTTOM_LABEL_FONT));
161         __pBottomLabel->SetTextConfig(FONT_SIZE_BOTTOM_LABEL, LABEL_TEXT_STYLE_BOLD);
162         __pBottomLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
163         __pBottomLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
164         AddControl(__pBottomLabel);
165
166         __pTempContactValueHashMap = new (std::nothrow) HashMap();
167         __pTempContactValueHashMap->Construct();
168
169         return r;
170 }
171
172 result
173 FavoriteListEditorPanel::OnTerminating(void)
174 {
175         result r = E_SUCCESS;
176
177         if (__pPresentationModel != null)
178         {
179                 __pPresentationModel->RemoveContactChangeListener(*this);
180         }
181
182         if (__pTempContactValueHashMap != null)
183         {
184                 __pTempContactValueHashMap->RemoveAll(true);
185                 delete __pTempContactValueHashMap;
186         }
187
188         delete __pMultipleContactValuePopup;
189
190         return r;
191 }
192
193 void
194 FavoriteListEditorPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
195 {
196         SceneManager* pSceneManager = SceneManager::GetInstance();
197         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
198
199         switch (actionId)
200         {
201         case IDA_HEADER_CONTACTS:
202                 {
203                         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
204                         {
205                                 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
206                                 {
207                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
208                                 }
209                                 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
210                                 {
211                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST_EDITOR));
212                                 }
213                         }
214                         else
215                         {
216                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
217                         }
218                 }
219                 break;
220         case IDA_HEADER_GROUPS:
221                 {
222                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_LIST));
223                 }
224                 break;
225         case IDA_HEADER_FAVORITES:
226                 {
227                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
228                 }
229                 break;
230         case IDA_FOOTER_REMOVE_FAVORITE:
231                 {
232                         RemoveFavorites();
233                         pSceneManager->GoBackward(BackwardSceneTransition());
234                 }
235                 break;
236         case IDA_FOOTER_CANCEL:
237                 {
238                         pSceneManager->GoBackward(BackwardSceneTransition());
239                 }
240                 break;
241         case IDA_FOOTER_DONE:
242                 {
243                         ReturnMultipleValues();
244                 }
245                 break;
246         case IDA_POPUP_CONTACT_VALUE_CLOSE:
247                 {
248                         HideContactValuePopup();
249                 }
250                 break;
251         default:
252                 break;
253         }
254 }
255
256 void
257 FavoriteListEditorPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
258 {
259         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
260
261         const Form* pForm = dynamic_cast<Form*>(GetParent());
262         AppAssert(pForm);
263
264         Header* pHeader = pForm->GetHeader();
265         pHeader->AddActionEventListener(*this);
266
267         Footer* pFooter = pForm->GetFooter();
268         pFooter->RemoveAllItems();
269         pFooter->RemoveAllButtons();
270         pFooter->AddActionEventListener(*this);
271
272         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
273         {
274                 pFooter->SetBackButton();
275
276                 __pPresentationModel->InitializeFavoriteList(pContactsApp->GetReturnType());
277
278                 if (__pPresentationModel->GetFavoriteCount() > 0)
279                 {
280                         FooterItem footerItemDone;
281                         footerItemDone.Construct(IDA_FOOTER_DONE);
282                         footerItemDone.SetText(ResourceManager::GetString(L"IDS_COM_SK_DONE"));
283                         pFooter->AddItem(footerItemDone);
284
285                         bool isChecked = false;
286                         int favoriteCount = __pPresentationModel->GetFavoriteCount();
287                         for (int index = 0; index < favoriteCount; index++)
288                         {
289                                 if (__pFavoriteListView->IsItemChecked(index))
290                                 {
291                                         isChecked = true;
292                                         break;
293                                 }
294                         }
295
296                         if (isChecked == false)
297                         {
298                                 pFooter->SetItemEnabled(0, false);
299                         }
300                 }
301                 else
302                 {
303                         __pFavoriteListView->SetShowState(false);
304                         __pEmptyImageLabel->SetShowState(true);
305                         __pEmptyCommentLabel->SetShowState(true);
306                         __pBottomLabel->SetShowState(false);
307                 }
308         }
309         else
310         {
311                 for (int index = 0; index < __pPresentationModel->GetFavoriteCount(); index++)
312                 {
313                         __pFavoriteListView->SetItemChecked(index, false);
314                 }
315
316                 __pPresentationModel->InitializeFavoriteList();
317                 __pFavoriteListView->UpdateList();
318
319                 FooterItem footerItemRemove;
320                 footerItemRemove.Construct(IDA_FOOTER_REMOVE_FAVORITE);
321                 footerItemRemove.SetText(ResourceManager::GetString(L"IDS_COM_BODY_REMOVE"));
322                 pFooter->AddItem(footerItemRemove);
323                 pFooter->SetItemEnabled(0, false);
324
325                 FooterItem footerItemCancel;
326                 footerItemCancel.Construct(IDA_FOOTER_CANCEL);
327                 footerItemCancel.SetText(ResourceManager::GetString(L"IDS_PB_SK_CANCEL"));
328                 pFooter->AddItem(footerItemCancel);
329         }
330
331         UpdateBottomLabel();
332
333         __pPresentationModel->AddContactChangeListener(*this);
334
335         delete pArgs;
336 }
337
338 void
339 FavoriteListEditorPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
340 {
341         const Form* pForm = dynamic_cast<Form*>(GetParent());
342         AppAssert(pForm);
343
344         Header* pHeader = pForm->GetHeader();
345         pHeader->RemoveActionEventListener(*this);
346
347         Footer* pFooter = pForm->GetFooter();
348         pFooter->RemoveActionEventListener(*this);
349
350         __pPresentationModel->RemoveContactChangeListener(*this);
351 }
352
353 void
354 FavoriteListEditorPanel::OnContactsChanged(void)
355 {
356         const Form* pForm = dynamic_cast<Form*>(GetParent());
357         Footer* pFooter = pForm->GetFooter();
358
359         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
360
361         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
362         {
363                 int favoriteCount = __pPresentationModel->GetFavoriteCount();
364                 for (int index = 0; index < favoriteCount; index++)
365                 {
366                         __pFavoriteListView->SetItemChecked(index, false);
367                 }
368
369                 __pPresentationModel->InitializeFavoriteList(pContactsApp->GetReturnType());
370
371                 if (__pPresentationModel->GetFavoriteCount() > 0)
372                 {
373                         pFooter->SetItemEnabled(0, false);
374                         pFooter->Invalidate(true);
375
376                         __pFavoriteListView->SetShowState(true);
377                         __pEmptyImageLabel->SetShowState(false);
378                         __pEmptyCommentLabel->SetShowState(false);
379                         __pBottomLabel->SetShowState(true);
380                 }
381                 else
382                 {
383                         __pFavoriteListView->SetShowState(false);
384                         __pEmptyImageLabel->SetShowState(true);
385                         __pEmptyCommentLabel->SetShowState(true);
386                         __pBottomLabel->SetShowState(false);
387                 }
388         }
389         else
390         {
391                 for (int index = 0; index < __pPresentationModel->GetFavoriteCount(); index++)
392                 {
393                         __pFavoriteListView->SetItemChecked(index, false);
394                 }
395
396                 __pPresentationModel->InitializeFavoriteList();
397
398                 if (__pPresentationModel->GetFavoriteCount() > 0)
399                 {
400                         pFooter->SetItemEnabled(0, false);
401                         pFooter->Invalidate(true);
402
403                         __pFavoriteListView->SetShowState(true);
404                         __pEmptyImageLabel->SetShowState(false);
405                         __pEmptyCommentLabel->SetShowState(false);
406                         __pBottomLabel->SetShowState(true);
407                 }
408                 else
409                 {
410                         __pFavoriteListView->SetShowState(false);
411                         __pEmptyImageLabel->SetShowState(true);
412                         __pEmptyCommentLabel->SetShowState(true);
413                         __pBottomLabel->SetShowState(false);
414                 }
415         }
416
417         __pFavoriteListView->UpdateList();
418         //Invalidate(true);
419
420         UpdateBottomLabel();
421 }
422
423 void
424 FavoriteListEditorPanel::OnCategoriesChanged(void)
425 {
426 }
427
428 void
429 FavoriteListEditorPanel::OnIconListViewItemReordered(Tizen::Ui::Controls::IconListView &iconListView, int indexFrom, int indexTo)
430 {
431 }
432
433 void
434 FavoriteListEditorPanel::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView &iconListView, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
435 {
436         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
437
438         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
439         {
440                 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE ||
441                         pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
442                 {
443                         IList* pList = __pPresentationModel->GetMultiValuesN(pContactsApp->GetReturnType(), index);
444                         if (pList == null)
445                         {
446                                 HashMap* pReturnValue = new (std::nothrow) HashMap();
447                                 pReturnValue->Construct();
448
449                                 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
450
451                                 return;
452                         }
453
454                         if (iconListView.IsItemChecked(index) == true)
455                         {
456                                 if (pList->GetCount() > 1)
457                                 {
458                                         iconListView.SetItemChecked(index, false);
459                                         __pContactValueListProvider = new (std::nothrow) ContactValueListItemProvider(pList);
460                                         ShowContactValuePopup(index);
461                                 }
462                                 else if (pList->GetCount() == 1)
463                                 {
464                                         String* pReturnValue = static_cast<String*>(pList->GetAt(0));
465                                         int blankIndex = 0;
466                                         pReturnValue->IndexOf(CHARACTER_SPACE, 0, blankIndex);
467                                         pReturnValue->Remove(0, blankIndex + 1);
468                                         __pTempContactValueHashMap->Add(*(new (std::nothrow) Integer(index)), *(new (std::nothrow) String(*pReturnValue)));
469                                         delete pList;
470                                 }
471
472                         }
473                         else
474                         {
475                                 __pTempContactValueHashMap->Remove(Integer(index), true);
476                         }
477                 }
478         }
479
480         UpdateBottomLabel();
481 }
482
483 void
484 FavoriteListEditorPanel::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
485 {
486 }
487
488 void
489 FavoriteListEditorPanel::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
490 {
491         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
492
493         int selectedIndex = -1;
494         Integer::Parse(listView.GetName(), selectedIndex);
495
496         IList* pList = __pPresentationModel->GetMultiValuesN(pContactsApp->GetReturnType(), selectedIndex);
497         if (pList == null)
498         {
499                 HashMap* pReturnValue = new (std::nothrow) HashMap();
500                 pReturnValue->Construct();
501
502                 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
503
504                 return;
505         }
506
507         String* pReturnValueInfo = static_cast<String*>(pList->GetAt(index));
508         int blankIndex = 0;
509         pReturnValueInfo->IndexOf(CHARACTER_SPACE, 0, blankIndex);
510         pReturnValueInfo->Remove(0, blankIndex + 1);
511         __pTempContactValueHashMap->Add(*(new (std::nothrow) Integer(selectedIndex)), *(new (std::nothrow) String(*pReturnValueInfo)));
512
513         delete pList;
514
515         __pFavoriteListView->SetItemChecked(selectedIndex, true);
516         HideContactValuePopup();
517         UpdateBottomLabel();
518 }
519
520 void
521 FavoriteListEditorPanel::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
522 {
523 }
524
525 Tizen::Ui::Controls::IconListViewItem*
526 FavoriteListEditorPanel::CreateItem(int index)
527 {
528         Bitmap* pThumbnail = null;
529         String name;
530         Font textFont;
531         Color textColor;
532         int textHeight;
533         int textY;
534         TextHorizontalAlignment alignment = TEXT_ALIGNMENT_LEFT;
535
536         if (__pPresentationModel->GetFavoriteItemInfo(index, name, pThumbnail) != E_SUCCESS)
537         {
538                 return null;
539         }
540
541         Canvas* pCanvas = new (std::nothrow) Canvas();
542         pCanvas->Construct(Rectangle(0, 0, W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM));
543         pCanvas->Clear();
544
545         if (pThumbnail != null)
546         {
547                 textFont.Construct(FONT_STYLE_BOLD , FONT_SIZE_WITH_THUMBNAIL);
548                 textY = H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND;
549                 textHeight = H_TEXT_BACKGROUND;
550                 textColor = Color(COLOR_TEXT_WITH_THUMBNAIL);
551
552                 pCanvas->DrawBitmap(pCanvas->GetBounds(), *pThumbnail, Rectangle(0, 0, pThumbnail->GetWidth(), pThumbnail->GetHeight()));
553                 pCanvas->SetForegroundColor(Color(COLOR_LINE));
554                 pCanvas->DrawLine(Point(0, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND), Point(W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND));
555                 pCanvas->FillRectangle(Color(COLOR_ITEM_TEXT_BACKGROUND), Rectangle(0, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND, W_ICONLISTVIEW_ITEM, H_TEXT_BACKGROUND));
556         }
557         else
558         {
559                 textFont.Construct(FONT_STYLE_BOLD , FONT_SIZE);
560                 textY = (H_ICONLISTVIEW_ITEM / 2) - (H_TEXT_SPACE / 2);
561                 textHeight = H_TEXT_SPACE;
562                 textColor = Color(COLOR_TEXT);
563                 alignment = TEXT_ALIGNMENT_CENTER;
564
565                 pCanvas->FillRectangle(Color(COLOR_ITEM_BACKGROUND), pCanvas->GetBounds());
566         }
567
568         EnrichedText* pEnrichedTextName = new (std::nothrow) EnrichedText();
569         pEnrichedTextName->Construct(Dimension(W_ICONLISTVIEW_ITEM - (W_NAME_TEXT_MARGIN * 2), textHeight));
570         pEnrichedTextName->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
571         pEnrichedTextName->SetHorizontalAlignment(alignment);
572         pEnrichedTextName->SetTextWrapStyle(TEXT_WRAP_WORD_WRAP);
573         pEnrichedTextName->SetTextAbbreviationEnabled(true);
574
575         TextElement* pTextElementName = new (std::nothrow) TextElement();
576         pTextElementName->Construct(name);
577         pTextElementName->SetFont(textFont);
578         pTextElementName->SetTextColor(textColor);
579
580         pEnrichedTextName->Add(*pTextElementName);
581
582         pCanvas->DrawText(Point(W_NAME_TEXT_MARGIN, textY), *pEnrichedTextName);
583
584         Bitmap* pBitmapItem = new (std::nothrow) Bitmap();
585         pBitmapItem->Construct(*pCanvas, Rectangle(0, 0, W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM));
586
587         IconListViewItem* pFavoriteItem = new (std::nothrow) IconListViewItem();
588         pFavoriteItem->Construct(*pBitmapItem);
589
590         delete pThumbnail;
591         delete pCanvas;
592         delete pBitmapItem;
593         delete pEnrichedTextName;
594         delete pTextElementName;
595
596         return pFavoriteItem;
597 }
598
599 bool
600 FavoriteListEditorPanel::DeleteItem(int index, Tizen::Ui::Controls::IconListViewItem *pItem)
601 {
602         delete pItem;
603         pItem = null;
604
605         return true;
606 }
607
608 int
609 FavoriteListEditorPanel::GetItemCount(void)
610 {
611         return __pPresentationModel->GetFavoriteCount();
612 }
613
614 void
615 FavoriteListEditorPanel::RemoveFavorites(void)
616 {
617         for (int i = 0; i < __pPresentationModel->GetFavoriteCount(); i++)
618         {
619                 if (__pFavoriteListView->IsItemChecked(i))
620                 {
621                         __pPresentationModel->SetAsFavorite(__pPresentationModel->GetContactId(i), false);
622                 }
623         }
624 }
625
626 void
627 FavoriteListEditorPanel::ReturnValues(RequestId requestId, Tizen::App::AppCtrlResult appCtrlResult, const Tizen::Base::Collection::IMap* pReturnValue)
628 {
629         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
630
631         result r = pAppManager->SendAppControlResult(requestId, appCtrlResult, pReturnValue);
632         AppLogDebug("[%s] The return result from SendAppControlResult(), AppCtrlResult value : %d.", GetErrorMessage(r), appCtrlResult);
633
634         UiApp::GetInstance()->Terminate();
635 }
636
637 void
638 FavoriteListEditorPanel::ReturnMultipleValues(void)
639 {
640         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
641
642         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
643         {
644                 String keyType;
645                 ArrayList* pValueList = new (std::nothrow) ArrayList();
646                 pValueList->Construct();
647
648                 HashMap* pReturnValue = new (std::nothrow) HashMap();
649                 pReturnValue->Construct();
650
651                 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_ITEM_ID)
652                 {
653                         for (int index = 0; index < __pPresentationModel->GetFavoriteCount(); index++)
654                         {
655                                 if (__pFavoriteListView->IsItemChecked(index))
656                                 {
657                                         int contactId = __pPresentationModel->GetContactId(index);
658                                         pValueList->Add(new (std::nothrow) String(Integer::ToString(contactId)));
659                                 }
660                         }
661                         pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), pValueList);
662
663                         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
664
665                         return;
666                 }
667
668                 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
669                 {
670                         keyType.Append(CONTACT_KEY_PHONE);
671                 }
672                 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
673                 {
674                         keyType.Append(CONTACT_KEY_EMAIL);
675                 }
676                 else
677                 {
678                         delete pValueList;
679
680                         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
681
682                         return;
683                 }
684
685                 IMapEnumerator* pMapEnum = __pTempContactValueHashMap->GetMapEnumeratorN();
686                 while (pMapEnum->MoveNext() == E_SUCCESS)
687                 {
688                         String* pValue = static_cast<String*> (pMapEnum->GetValue());
689                         pValueList->Add(new (std::nothrow) String(*pValue));
690                 }
691                 delete pMapEnum;
692
693                 pReturnValue->Add(new (std::nothrow) String(keyType), pValueList);
694
695                 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
696         }
697 }
698
699 void
700 FavoriteListEditorPanel::ShowContactValuePopup(int index)
701 {
702         String name;
703         Bitmap* pEmpty = null;
704
705         delete __pMultipleContactValuePopup;
706         __pMultipleContactValuePopup = new (std::nothrow) Popup();
707         __pMultipleContactValuePopup->Construct(true, Dimension(W_CONTACT_VALUE_POPUP, H_CONTACT_VALUE_POPUP));
708         __pPresentationModel->GetFavoriteItemInfo(index, name, pEmpty);
709         __pMultipleContactValuePopup->SetTitleText(name);
710
711         Rectangle popupClientBounds = __pMultipleContactValuePopup->GetClientAreaBounds();
712
713         ListView* pListView = new (std::nothrow) ListView();
714         pListView->Construct(Rectangle(0, 0, popupClientBounds.width, H_CONTACT_VALUE_POPUP_LIST_VIEW));
715         pListView->SetItemProvider(*__pContactValueListProvider);
716         pListView->AddListViewItemEventListener(*this);
717         pListView->SetName(String(Integer::ToString(index)));
718
719         __pMultipleContactValuePopup->AddControl(pListView);
720
721         Button* pCancelButton = new (std::nothrow) Button();
722         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"));
723         pCancelButton->SetActionId(IDA_POPUP_CONTACT_VALUE_CLOSE);
724         pCancelButton->AddActionEventListener(*this);
725
726         __pMultipleContactValuePopup->AddControl(pCancelButton);
727         __pMultipleContactValuePopup->SetShowState(true);
728         __pMultipleContactValuePopup->Show();
729 }
730
731 void
732 FavoriteListEditorPanel::HideContactValuePopup(void)
733 {
734         __pMultipleContactValuePopup->SetShowState(false);
735
736         delete __pContactValueListProvider;
737         __pContactValueListProvider = null;
738
739         Invalidate(true);
740 }
741
742 void
743 FavoriteListEditorPanel::UpdateBottomLabel(void)
744 {
745         int selectedCount = 0;
746         int favoriteCount = __pPresentationModel->GetFavoriteCount();
747         for (int index = 0; index < favoriteCount; index++)
748         {
749                 if (__pFavoriteListView->IsItemChecked(index))
750                 {
751                         selectedCount++;
752                 }
753         }
754
755         String string = ResourceManager::GetString(L"IDS_COM_POP_SELECTED");
756         string.Append(L" (");
757         string.Append(selectedCount);
758         string.Append(L")");
759         __pBottomLabel->SetText(string);
760         Form* pForm = dynamic_cast<Form*>(GetParent());
761         AppAssert(pForm);
762
763         Footer* pFooter = pForm->GetFooter();
764
765         if (selectedCount > 0)
766         {
767                 __pBottomLabel->SetShowState(true);
768                 __pFavoriteListView->SetSize(__pFavoriteListView->GetSize().width, pForm->GetClientAreaBounds().height - H_BOTTOM_LABEL);
769                 pFooter->SetItemEnabled(0, true);
770         }
771         else
772         {
773                 __pBottomLabel->SetShowState(false);
774                 __pFavoriteListView->SetSize(__pFavoriteListView->GetSize().width, pForm->GetClientAreaBounds().height);
775                 pFooter->SetItemEnabled(0, false);
776         }
777         __pBottomLabel->Invalidate(true);
778         pFooter->Invalidate(true);
779 }