NABI issues fixed: 41292, 41263, 41256, 41241, 41231, 41183, 41160, 41515, 41363...
[apps/osp/Contacts.git] / src / CtContactListPanel.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        CtContactListPanel.cpp
19  * @brief       This is the implementation file for the ContactListPanel class.
20  */
21
22 #include <FSocial.h>
23 #include "CtAccountListItemProvider.h"
24 #include "CtContactListItem.h"
25 #include "CtContactListPanel.h"
26 #include "CtContactListPresentationModel.h"
27 #include "CtContactsApp.h"
28 #include "CtMainForm.h"
29 #include "CtResourceManager.h"
30 #include "CtSceneRegister.h"
31 #include "CtSearchListEventListener.h"
32 #include "CtSearchListItem.h"
33 #include "CtTypes.h"
34
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Scenes;
42 using namespace Tizen::Social;
43
44
45 static const int IDA_FOOTER_CREATE = 1;
46 static const int IDA_MORE_DELETE = 2;
47 static const int IDA_MORE_SETTING = 3;
48 static const int IDA_HEADER_CONTACTS = 10;
49 static const int IDA_HEADER_GROUPS = 11;
50 static const int IDA_HEADER_FAVORITES = 12;
51 static const int IDA_POPUP_DELETE_OK = 30;
52 static const int IDA_POPUP_DELETE_CANCEL = 31;
53 static const int IDA_POPUP_VIEW_OK = 32;
54 static const int IDA_POPUP_VIEW_CANCEL = 33;
55 static const int IDA_POPUP_CONTACT_VALUE_CLOSE = 34;
56 static const int IDA_LIST_ELEMENT_DELETE = 40;
57 static const int IDA_LIST_ELEMENT_CALL = 41;
58 static const int IDA_LIST_ELEMENT_MESSAGE = 42;
59 static const int IDA_LIST_ELEMENT_VIDEO_CALL = 43;
60
61 static const int W_POPUP_ITEM_GAP = 20;
62 static const int H_ITEM = 112;
63 static const int X_EMPTY_IMAGE = 220;
64 static const int Y_EMPTY_IMAGE = 300;
65 static const int W_EMPTY_IMAGE = 280;
66 static const int H_EMPTY_IMAGE = 280;
67 static const int Y_EMPTY_COMMENT = 618;
68 static const int H_EMPTY_COMMENT = 38;
69 static const int H_GROUP_ITEM = 76;
70 static const int W_INITIAL_PANEL = 10;
71 static const int H_INITIAL_PANEL = 10;
72 static const int H_SEARCHBAR = 86;
73 static const int W_DELETE_POPUP = 688;
74 static const int H_DELETE_POPUP = 230;
75 static const int W_DELETE_LABEL = 656;
76 static const int H_DELETE_LABEL = 80;
77 static const int X_DELETE_LABEL = 16;
78 static const int Y_DELETE_LABEL = 32;
79 static const int Y_DELETE_BUTTON = 132;
80 static const int H_DELETE_BUTTON = 74;
81 static const int W_DELETE_BUTTON = 318;
82 static const int W_ACCOUNT_POPUP = 600;
83 static const int H_ACCOUNT_POPUP = 700;
84 static const int H_ACCOUNT_POPUP_BUTTON = 80;
85 static const int W_CONTACT_VALUE_POPUP = 688;
86 static const int H_CONTACT_VALUE_POPUP = 532;
87 static const int H_CONTACT_VALUE_POPUP_LIST_VIEW = 338;
88 static const int H_CLOSE_BUTTON = 74;
89 static const int Y_CLOSE_BUTTON = 358;
90 static const int W_CLOSE_BUTTON = 394;
91 static const int X_MORE = 55;
92
93 static const int FONT_SIZE_EMPTY_COMMENT = 32;
94 static const int FONT_SIZE_DELETE_CONFIRM = 42;
95 static const int FONT_SIZE_DELETE_BUTTON = 36;
96
97 static const unsigned int COLOR_EMPTY_COMMENT = Color32<102, 102, 102>::Value;
98 static const unsigned int COLOR_DELETE_BUTTON_NORMAL = Color32<213, 82, 82>::Value;
99 static const unsigned int COLOR_DELETE_BUTTON_PRESSED = Color32<194, 71, 71>::Value;
100 static const unsigned int COLOR_DELETE_BUTTON_TEXT = Color32<248, 246, 239>::Value;
101 static const unsigned int COLOR_DELETE_ELEMENT_NORMAL = Color32<208, 82, 82>::Value;
102 static const unsigned int COLOR_DELETE_ELEMENT_PRESSED = Color32<194, 71, 71>::Value;
103 static const unsigned int COLOR_DELETE_ELEMENT_TEXT = Color32<248, 246, 239>::Value;
104
105 static const int LIST_VIEW_GROUP_INDEX_SHIFT = 16;
106 static const int LIST_VIEW_MASK = 0xFFFF;
107
108 static const wchar_t* IDB_NO_CONTENTS = L"00_Nocontents_text.png";
109
110 static const wchar_t* INPUT_KEY_MESSAGE_TYPE = L"http://tizen.org/appcontrol/data/message/type";
111 static const wchar_t* INPUT_KEY_CALL_TYPE = L"http://tizen.org/appcontrol/data/call/type";
112 static const wchar_t* INPUT_KEY_MESSAGE_TO = L"http://tizen.org/appcontrol/data/to";
113 static const wchar_t* INPUT_TYPE_VIDEO = L"video";
114 static const wchar_t* INPUT_TYPE_VOICE = L"voice";
115 static const wchar_t* INPUT_TYPE_SMS = L"sms";
116 static const wchar_t* INPUT_URI_TEL = L"tel:";
117
118
119 ContactListPanel::ContactListPanel(void)
120 : __pAppControl(null)
121 , __pArgList(null)
122 , __pListView(null)
123 , __pSearchListView(null)
124 , __pAccountPopup(null)
125 , __pDeletePopup(null)
126 , __pMultipleContactValuePopup(null)
127 , __pSearchBar(null)
128 , __pEmptyImageLabel(null)
129 , __pEmptyCommentLabel(null)
130 , __pOptionMenu(null)
131 , __changedSceneId(IDSCN_CONTACT_LIST)
132 , __pAccountListEvent(null)
133 , __pPresentationModel(null)
134 , __pContactValueListEvent(null)
135 , __pSearchListEvent(null)
136 , __isKeypadOpened(false)
137 , __sweptItemIndex(0)
138 , __selectedIndex(-1)
139 {
140 }
141
142 ContactListPanel::~ContactListPanel(void)
143 {
144 }
145
146 void
147 ContactListPanel::Initialize(void)
148 {
149         Construct(Rectangle(0, 0, W_INITIAL_PANEL, H_INITIAL_PANEL));
150 }
151
152 result
153 ContactListPanel::OnInitializing(void)
154 {
155         const Form* pForm = dynamic_cast<Form*>(GetParent());
156         AppAssert(pForm);
157
158         Rectangle clientBounds = pForm->GetClientAreaBounds();
159         SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height));
160
161         __pPresentationModel = ContactListPresentationModel::GetInstance();
162
163         __pListView = new (std::nothrow) GroupedListView();
164         __pListView->Construct(Rectangle(0, H_SEARCHBAR, clientBounds.width, clientBounds.height - H_SEARCHBAR), GROUPED_LIST_VIEW_STYLE_INDEXED, true, true);
165         __pListView->SetItemProvider(*this);
166         __pListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_PB_BODY_NO_CONTACTS"));
167         __pListView->AddFastScrollListener(*this);
168         __pListView->AddGroupedListViewItemEventListener(*this);
169         __pListView->AddTouchEventListener(*this);
170
171         AddControl(__pListView);
172
173         __pSearchBar = new (std::nothrow) SearchBar();
174         __pSearchBar->Construct(Rectangle(0, 0, clientBounds.width, H_SEARCHBAR));
175         __pSearchBar->SetGuideText(ResourceManager::GetString(L"IDS_COM_BODY_SEARCH"));
176         __pSearchBar->AddSearchBarEventListener(*this);
177         __pSearchBar->AddFocusEventListener(*this);
178         __pSearchBar->AddTextEventListener(*this);
179         __pSearchBar->AddKeypadEventListener(*this);
180         __pSearchBar->SetContentAreaSize(Dimension(0, 0));
181
182         __pSearchListEvent = new (std::nothrow) SearchListEventListener(LIST_ANNEX_STYLE_NORMAL, __pPresentationModel);
183
184         AddControl(__pSearchBar);
185
186         __pSearchListView = new (std::nothrow) GroupedListView();
187         __pSearchListView->Construct(Rectangle(0, H_SEARCHBAR, clientBounds.width, clientBounds.height - H_SEARCHBAR), GROUPED_LIST_VIEW_STYLE_INDEXED, true, false);
188         __pSearchListView->SetItemProvider(*__pSearchListEvent);
189         __pSearchListView->AddGroupedListViewItemEventListener(*this);
190         __pSearchListView->AddTouchEventListener(*this);
191         __pSearchListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_PB_BODY_NO_CONTACTS"));
192         __pSearchListView->SetShowState(false);
193         AddControl(__pSearchListView);
194
195         __pEmptyImageLabel = new (std::nothrow) Label();
196         __pEmptyImageLabel->Construct(Rectangle(X_EMPTY_IMAGE, Y_EMPTY_IMAGE, W_EMPTY_IMAGE, H_EMPTY_IMAGE), L"");
197         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
198         if (pBitmap != null)
199         {
200                 __pEmptyImageLabel->SetBackgroundBitmap(*pBitmap);
201                 delete pBitmap;
202         }
203         __pEmptyImageLabel->SetShowState(false);
204
205         AddControl(__pEmptyImageLabel);
206
207         __pEmptyCommentLabel = new (std::nothrow) Label();
208         __pEmptyCommentLabel->Construct(Rectangle(0, Y_EMPTY_COMMENT, clientBounds.width, H_EMPTY_COMMENT),
209                                                                                                                                 ResourceManager::GetString(L"IDS_PB_BODY_NO_CONTACTS"));
210         __pEmptyCommentLabel->SetTextConfig(FONT_SIZE_EMPTY_COMMENT, LABEL_TEXT_STYLE_NORMAL);
211         __pEmptyCommentLabel->SetTextColor(Color(COLOR_EMPTY_COMMENT));
212         __pEmptyCommentLabel->SetShowState(false);
213
214         AddControl(__pEmptyCommentLabel);
215
216         __pOptionMenu = new (std::nothrow) OptionMenu();
217         __pOptionMenu->Construct();
218         __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_SK_DELETE"), IDA_MORE_DELETE);
219         __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_SETTINGS"), IDA_MORE_SETTING);
220         __pOptionMenu->AddActionEventListener(*this);
221         __pOptionMenu->SetShowState(false);
222         return E_SUCCESS;
223 }
224
225 result
226 ContactListPanel::OnTerminating(void)
227 {
228         result r = E_SUCCESS;
229
230         if (__pPresentationModel != null)
231         {
232                 __pPresentationModel->RemoveContactChangeListener(*this);
233         }
234
235         if (__pArgList != null)
236         {
237                 __pArgList->RemoveAll(true);
238                 delete __pArgList;
239         }
240
241         delete __pAppControl;
242         delete __pDeletePopup;
243         delete __pAccountPopup;
244         delete __pSearchListEvent;
245         delete __pAccountListEvent;
246         delete __pOptionMenu;
247         delete __pMultipleContactValuePopup;
248
249         return r;
250 }
251
252 void
253 ContactListPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
254 {
255         SceneManager* pSceneManager = SceneManager::GetInstance();
256         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
257         Form* pForm = dynamic_cast<Form*>(GetParent());
258         AppAssert(pForm);
259
260         switch (actionId)
261         {
262         case IDA_HEADER_CONTACTS:
263                 {
264                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
265                 }
266                 break;
267         case IDA_HEADER_GROUPS:
268                 {
269                         pForm->SetFocus();
270
271                         if (__isKeypadOpened)
272                         {
273                                 __changedSceneId = IDSCN_GROUP_LIST;
274                         }
275                         else
276                         {
277                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_LIST));
278                         }
279                 }
280                 break;
281         case IDA_HEADER_FAVORITES:
282                 {
283                         pForm->SetFocus();
284
285                         if (__isKeypadOpened)
286                         {
287                                 __changedSceneId = IDSCN_FAVORITE_LIST;
288
289                                 if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
290                                 {
291                                         if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
292                                         {
293                                                 __changedSceneId = IDSCN_FAVORITE_LIST;
294                                         }
295                                         else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
296                                         {
297                                                 __changedSceneId = IDSCN_FAVORITE_LIST_EDITOR;
298                                         }
299                                 }
300                                 break;
301                         }
302
303                         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
304                         {
305                                 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
306                                 {
307                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
308                                 }
309                                 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
310                                 {
311                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST_EDITOR));
312                                 }
313                         }
314                         else
315                         {
316                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
317                         }
318                 }
319                 break;
320         case IDA_FOOTER_CREATE:
321                 {
322                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
323                 }
324                 break;
325         case IDA_MORE_DELETE:
326                 {
327                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST_EDITOR));
328                 }
329                 break;
330         case IDA_MORE_SETTING:
331                 {
332                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SETTINGS, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
333                 }
334                 break;
335         case IDA_POPUP_DELETE_OK:
336                 {
337                         int groupIndex = (__sweptItemIndex >> LIST_VIEW_GROUP_INDEX_SHIFT) & LIST_VIEW_MASK;
338                         int itemIndex = __sweptItemIndex & LIST_VIEW_MASK;
339
340                         __pPresentationModel->RemoveContact(groupIndex, itemIndex);
341                         HideDeletePopup();
342                 }
343                 break;
344         case IDA_POPUP_DELETE_CANCEL:
345                 {
346                         HideDeletePopup();
347                 }
348                 break;
349         case IDA_POPUP_VIEW_OK:
350                 {
351
352                 }
353                 break;
354         case IDA_POPUP_VIEW_CANCEL:
355                 {
356                         HideAccountPopup();
357                 }
358                 break;
359         case IDA_POPUP_CONTACT_VALUE_CLOSE:
360                 {
361                         HideContactValuePopup();
362                 }
363                 break;
364         default:
365                 break;
366         }
367 }
368
369 void
370 ContactListPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
371                                                                    const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
372 {
373         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
374
375         const Form* pForm = dynamic_cast<Form*>(GetParent());
376         AppAssert(pForm);
377
378         Form *pEventForm = const_cast<Form*>(pForm);
379         pEventForm->SetFormMenuEventListener(this);
380
381         Header* pHeader = pForm->GetHeader();
382         pHeader->AddActionEventListener(*this);
383
384         Footer* pFooter = pForm->GetFooter();
385         pFooter->RemoveAllItems();
386         pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
387         pFooter->SetBackButton();
388         pFooter->AddActionEventListener(*this);
389         pFooter->RemoveMenuButton();
390
391         __pPresentationModel->InitializeContactList();
392
393         __pListView->SetFastScrollIndex(__pPresentationModel->GetAllKeys(), false);
394         __pListView->UpdateList();
395
396         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK || pContactsApp->GetOperationId() == OPERATION_ID_EDIT)
397         {
398                 if (__pPresentationModel->GetContactCount() == 0)
399                 {
400                         pFooter->RemoveMenuButton();
401                         __pSearchBar->SetShowState(false);
402                         __pListView->SetShowState(false);
403                         __pEmptyImageLabel->SetShowState(true);
404                         __pEmptyCommentLabel->SetShowState(true);
405                 }
406                 else
407                 {
408                         pFooter->SetMenuButton();
409                 }
410
411                 if (pArgs != null)
412                 {
413                         __pArgList = new (std::nothrow) ArrayList();
414                         __pArgList->Construct();
415
416                         for (int i = 0; i < pArgs->GetCount(); i++)
417                         {
418                                 __pArgList->Add(new (std::nothrow) String(*static_cast<String*>(pArgs->GetAt(i))));
419                         }
420                 }
421         }
422         else
423         {
424                 FooterItem footerItemCreate;
425                 footerItemCreate.Construct(IDA_FOOTER_CREATE);
426                 footerItemCreate.SetText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
427                 pFooter->AddItem(footerItemCreate);
428
429                 if (__pPresentationModel->GetContactCount() > 0)
430                 {
431                         pFooter->SetMenuButton();
432                         __pSearchBar->SetShowState(true);
433                         __pListView->SetShowState(true);
434                         __pEmptyImageLabel->SetShowState(false);
435                         __pEmptyCommentLabel->SetShowState(false);
436                 }
437                 else
438                 {
439                         pFooter->RemoveMenuButton();
440                         __pSearchBar->SetShowState(false);
441                         __pListView->SetShowState(false);
442                         __pEmptyImageLabel->SetShowState(true);
443                         __pEmptyCommentLabel->SetShowState(true);
444                 }
445                 pContactsApp->AddContactsAppChangeEventListener(*this);
446         }
447
448         __pPresentationModel->AddContactChangeListener(*this);
449
450         if (pArgs != null)
451         {
452                 pArgs->RemoveAll(true);
453                 delete pArgs;
454         }
455 }
456
457 void
458 ContactListPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
459                                                                         const Tizen::Ui::Scenes::SceneId& nextSceneId)
460 {
461         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
462
463         Form* pForm = dynamic_cast<Form*>(GetParent());
464         AppAssert(pForm);
465
466         Form *pEventForm = const_cast<Form*>(pForm);
467         pEventForm->SetFormMenuEventListener(null);
468
469         if (pForm->IsFooterVisible() == false)
470         {
471                 pForm->SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
472         }
473
474         Header* pHeader = pForm->GetHeader();
475         pHeader->RemoveActionEventListener(*this);
476
477         Footer* pFooter = pForm->GetFooter();
478         pFooter->RemoveActionEventListener(*this);
479
480         if (__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
481         {
482                 __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
483         }
484
485         __pPresentationModel->RemoveContactChangeListener(*this);
486         pContactsApp->RemoveContactsAppChangeEventListener(*this);
487
488         delete __pAppControl;
489         __pAppControl = null;
490 }
491
492 int
493 ContactListPanel::GetGroupCount(void)
494 {
495         return __pPresentationModel->GetKeyCount();
496 }
497
498 int
499 ContactListPanel::GetItemCount(int groupIndex)
500 {
501         return __pPresentationModel->GetContactCount(groupIndex);
502 }
503
504 Tizen::Ui::Controls::ListItemBase*
505 ContactListPanel::CreateItem(int groupIndex, int itemIndex, int itemWidth)
506 {
507         String name;
508         Bitmap* pThumbnail = null;
509
510         CustomItem* pItem = new (std::nothrow) CustomItem();
511         pItem->Construct(Dimension(itemWidth, H_ITEM), LIST_ANNEX_STYLE_NORMAL);
512
513         __pPresentationModel->GetContactItemInfoN(groupIndex, itemIndex, name, pThumbnail);
514
515         ContactListItem* pCustomElement = new (std::nothrow) ContactListItem(name, pThumbnail);
516         pItem->AddElement(Rectangle(0, 0, itemWidth, H_ITEM), 0, *(static_cast<ICustomElement *>(pCustomElement)));
517
518         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
519
520         if (pContactsApp->GetOperationId().IsEmpty() == false)
521         {
522                 return pItem;
523         }
524
525         bool isCallEnabled = true;
526         bool isMessageEnabled = true;
527         if (__pPresentationModel->GetDefaultPhoneNumber(groupIndex, itemIndex).IsEmpty())
528         {
529                 isCallEnabled = false;
530         }
531
532         if ((__pPresentationModel->GetDefaultPhoneNumber(groupIndex, itemIndex).IsEmpty()) && (__pPresentationModel->GetDefaultEmail(groupIndex, itemIndex).IsEmpty()))
533         {
534                 isMessageEnabled = false;
535         }
536
537
538         ListContextItem* pItemContext = new (std::nothrow) ListContextItem();
539         pItemContext->Construct();
540         pItemContext->AddElement(IDA_LIST_ELEMENT_CALL, ResourceManager::GetString(L"IDS_COM_BODY_CALL"), isCallEnabled);
541         pItemContext->AddElement(IDA_LIST_ELEMENT_MESSAGE, ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"), isMessageEnabled);
542 #if __SUPPORT_VIDEO_CALL
543         pItemContext->AddElement(IDA_LIST_ELEMENT_VIDEO_CALL, ResourceManager::GetString(L"IDS_COM_BODY_VIDEO_CALL"), isCallEnabled);
544 #endif
545         pItemContext->AddElement(IDA_LIST_ELEMENT_DELETE, ResourceManager::GetString(L"IDS_COM_SK_DELETE"));
546         pItemContext->SetElementBackgroundColor(IDA_LIST_ELEMENT_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, COLOR_DELETE_ELEMENT_NORMAL);
547         pItemContext->SetElementBackgroundColor(IDA_LIST_ELEMENT_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_PRESSED, COLOR_DELETE_ELEMENT_PRESSED);
548         pItemContext->SetElementTextColor(IDA_LIST_ELEMENT_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, COLOR_DELETE_ELEMENT_TEXT);
549
550         pItem->SetContextItem(pItemContext);
551
552         return pItem;
553 }
554
555 Tizen::Ui::Controls::GroupItem*
556 ContactListPanel::CreateGroupItem(int groupIndex, int itemWidth)
557 {
558         GroupItem* pItem = new (std::nothrow) GroupItem();
559         pItem->Construct(Dimension(itemWidth, H_GROUP_ITEM));
560         pItem->SetElement(__pPresentationModel->GetKey(groupIndex), null);
561
562         return pItem;
563 }
564
565 bool
566 ContactListPanel::DeleteItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
567 {
568         CustomItem* pCustomItem = static_cast<CustomItem *>(pItem);
569
570         pCustomItem->RemoveAllElements();
571
572         delete pItem;
573         pItem = null;
574
575         return true;
576 }
577
578 bool
579 ContactListPanel::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::GroupItem* pItem, int itemWidth)
580 {
581         delete pItem;
582         pItem = null;
583
584         return true;
585 }
586
587 void
588 ContactListPanel::OnContactsChanged(void)
589 {
590         Form* pForm = dynamic_cast<Form*>(GetParent());
591         AppAssert(pForm);
592
593         HideDeletePopup();
594
595         Footer* pFooter = pForm->GetFooter();
596
597         if (__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
598         {
599                 __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
600                 pForm->SetFocus();
601         }
602
603         __pPresentationModel->InitializeContactList();
604
605         if (__pPresentationModel->GetContactCount() > 0)
606         {
607                 int groupIndex;
608                 int itemIndex;
609
610                 pFooter->SetMenuButton();
611                 __pSearchBar->SetShowState(true);
612                 __pListView->SetShowState(true);
613                 __pEmptyImageLabel->SetShowState(false);
614                 __pEmptyCommentLabel->SetShowState(false);
615
616                 __pListView->GetTopDrawnItemIndex(groupIndex, itemIndex);
617                 __pListView->UpdateList();
618                 __pListView->SetFastScrollIndex(__pPresentationModel->GetAllKeys(), false);
619                 __pListView->Invalidate(true);
620                 __pListView->ScrollToItem(groupIndex, itemIndex);
621         }
622         else
623         {
624                 pFooter->RemoveMenuButton();
625                 __pSearchBar->SetShowState(false);
626                 __pListView->SetShowState(false);
627                 __pEmptyImageLabel->SetShowState(true);
628                 __pEmptyCommentLabel->SetShowState(true);
629         }
630 }
631
632 void
633 ContactListPanel::OnCategoriesChanged(void)
634 {
635 }
636
637 void
638 ContactListPanel::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, Tizen::Ui::Controls::SearchBarMode mode)
639 {
640         if (mode == SEARCH_BAR_MODE_NORMAL)
641         {
642                 __pListView->SetShowState(true);
643                 __pSearchListView->SetShowState(false);
644                 __pPresentationModel->ResetSearchedContactList();
645                 __pSearchListView->UpdateList();
646                 __pListView->UpdateList();
647         }
648         else
649         {
650                 //[TODO] to restore swept item.
651                 // need to be fixed with better idea..
652                 Rectangle bounds = __pListView->GetBounds();
653                 __pListView->SetBounds(bounds.x, bounds.y, bounds.width, bounds.height + 1);
654                 __pListView->Invalidate(true);
655                 __pListView->SetBounds(bounds);
656         }
657 }
658
659 void
660 ContactListPanel::OnGroupedListViewContextItemStateChanged(Tizen::Ui::Controls::GroupedListView& listView, int groupIndex, int itemIndex, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
661 {
662         int index = 0;
663
664         index |= groupIndex << LIST_VIEW_GROUP_INDEX_SHIFT;
665         index |= itemIndex;
666
667         __sweptItemIndex = index;
668
669         switch (elementId)
670         {
671         case IDA_LIST_ELEMENT_DELETE:
672                 {
673                         ShowDeletePopup();
674                 }
675                 break;
676         case IDA_LIST_ELEMENT_CALL:
677                 {
678                         String phoneNumber = __pPresentationModel->GetDefaultPhoneNumber(groupIndex, itemIndex);
679                         LaunchAppControl(PROVIDER_ID_PHONE, OPERATION_ID_CALL, phoneNumber, INPUT_TYPE_VOICE);
680                 }
681                 break;
682         case IDA_LIST_ELEMENT_MESSAGE:
683                 {
684                         if (!(__pPresentationModel->GetDefaultPhoneNumber(groupIndex, itemIndex).IsEmpty()))
685                         {
686                                 String phoneNumber = __pPresentationModel->GetDefaultPhoneNumber(groupIndex, itemIndex);
687                                 LaunchAppControl(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE, phoneNumber, INPUT_TYPE_SMS);
688                         }
689                         else if (!(__pPresentationModel->GetDefaultEmail(groupIndex, itemIndex).IsEmpty()))
690                         {
691                                 String emailId = __pPresentationModel->GetDefaultEmail(groupIndex, itemIndex);
692                                 LaunchAppControl(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE, emailId, null);
693                         }
694                 }
695                 break;
696         case IDA_LIST_ELEMENT_VIDEO_CALL:
697                 {
698                         String phoneNumber = __pPresentationModel->GetDefaultPhoneNumber(groupIndex, itemIndex);
699                         LaunchAppControl(PROVIDER_ID_PHONE, OPERATION_ID_CALL, phoneNumber, INPUT_TYPE_VIDEO);
700                 }
701                 break;
702         default:
703                 break;
704         }
705 }
706
707 void
708 ContactListPanel::OnGroupedListViewItemStateChanged(Tizen::Ui::Controls::GroupedListView& listView, int groupIndex, int itemIndex, int elementId, Tizen::Ui::Controls::ListItemStatus state)
709 {
710         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
711         
712         if (listView.Equals(*__pSearchListView) == true)
713         {
714                 __pPresentationModel->GetItemMainIndex(itemIndex, groupIndex, itemIndex);
715         }
716
717         __selectedIndex = 0;
718         __selectedIndex |= groupIndex << LIST_VIEW_GROUP_INDEX_SHIFT;
719         __selectedIndex |= itemIndex;
720
721         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
722         {
723                 IList* pList = null;
724                 HashMap* pReturnValue = new (std::nothrow) HashMap();
725                 pReturnValue->Construct();
726
727                 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
728                 {
729                         pList = __pPresentationModel->GetAllPhoneNumbersN(groupIndex, itemIndex);
730
731                         if (pList == null)
732                         {
733                                 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
734                         }
735                         else
736                         {
737                                 if (pList->GetCount() > 1)
738                                 {
739                                         __pContactValueListEvent = new (std::nothrow) ContactValueListItemProvider(pList);
740                                         ShowContactValuePopup(groupIndex, itemIndex);
741                                 }
742                                 else if (pList->GetCount() == 1)
743                                 {
744                                         AddContactValueOnList(pList, CONTACT_KEY_PHONE, 0, pReturnValue);
745
746                                         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
747                                         delete pList;
748                                 }
749                         }
750                 }
751                 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
752                 {
753                         pList = __pPresentationModel->GetAllEmailsN(groupIndex, itemIndex);
754
755                         if (pList == null)
756                         {
757                                 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
758                         }
759                         else
760                         {
761                                 if (pList->GetCount() > 1)
762                                 {
763                                         __pContactValueListEvent = new (std::nothrow) ContactValueListItemProvider(pList);
764                                         ShowContactValuePopup(groupIndex, itemIndex);
765                                 }
766                                 else if (pList->GetCount() == 1)
767                                 {
768                                         AddContactValueOnList(pList, CONTACT_KEY_EMAIL, 0, pReturnValue);
769
770                                         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
771                                         delete pList;
772                                 }
773                         }
774                 }
775                 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_ITEM_ID)
776                 {
777                         AppCtrlResult appCtrlResult = APP_CTRL_RESULT_SUCCEEDED;
778                         RecordId contactId = __pPresentationModel->GetContactId(groupIndex, itemIndex);
779                         if (contactId == INVALID_RECORD_ID)
780                         {
781                                 appCtrlResult = APP_CTRL_RESULT_FAILED;
782                         }
783                         else
784                         {
785                                 String contactId;
786                                 ArrayList* pValueList = new (std::nothrow) ArrayList();
787                                 pValueList->Construct();
788
789                                 contactId.Append(__pPresentationModel->GetContactId(groupIndex, itemIndex));
790                                 pValueList->Add(new (std::nothrow) String(contactId));
791
792                                 pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), pValueList);
793                         }
794
795                         ReturnValues(pContactsApp->GetRequestId(), appCtrlResult, pReturnValue);
796                 }
797                 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_VCARD)
798                 {
799                         AppCtrlResult appCtrlResult = APP_CTRL_RESULT_SUCCEEDED;
800                         String vCardPath = __pPresentationModel->ExportToVcard(groupIndex, itemIndex);
801
802                         if (vCardPath.IsEmpty())
803                         {
804                                 appCtrlResult = APP_CTRL_RESULT_FAILED;
805                         }
806                         else
807                         {
808                                 pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_PATH), new (std::nothrow) String(vCardPath));
809                         }
810
811                         ReturnValues(pContactsApp->GetRequestId(), appCtrlResult, pReturnValue);
812                 }
813
814                 delete pReturnValue;
815         }
816         else if (pContactsApp->GetOperationId() == OPERATION_ID_EDIT)
817         {
818                 ArrayList* pArgList = null;
819                 SceneManager* pSceneManager = SceneManager::GetInstance();
820
821                 if (__pArgList != null)
822                 {
823                         pArgList = new (std::nothrow) ArrayList();
824                         pArgList->Construct();
825
826                         for (int i = 0; i < __pArgList->GetCount(); i++)
827                         {
828                                 pArgList->Add(new (std::nothrow) String(*static_cast<String*>(__pArgList->GetAt(i))));
829                         }
830
831                         String* pContactId = new (std::nothrow) String(RETURN_TYPE_ITEM_ID);
832                         pContactId->Append(DELIMITER);
833                         pContactId->Append(__pPresentationModel->GetContactId(groupIndex, itemIndex));
834                         pArgList->InsertAt(pContactId, 0);
835
836                         __pArgList->RemoveAll(true);
837                 }
838
839                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgList);
840         }
841         else
842         {
843                 ArrayList* pContactId = new (std::nothrow) ArrayList();
844                 pContactId->Construct();
845
846                 pContactId->Add(*(new (std::nothrow) Integer(__pPresentationModel->GetContactId(groupIndex, itemIndex))));
847                 SceneManager* pSceneManager = SceneManager::GetInstance();
848
849                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_DETAILS, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pContactId);
850         }
851 }
852
853 void
854 ContactListPanel::OnGroupedListViewItemSwept(Tizen::Ui::Controls::GroupedListView& listView, int groupIndex, int itemIndex, Tizen::Ui::Controls::SweepDirection direction)
855 {
856 }
857
858 void
859 ContactListPanel::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
860 {
861
862 }
863
864 void
865 ContactListPanel::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
866 {
867         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
868
869         IList* pList = null;
870         int groupIndex = (__selectedIndex >> LIST_VIEW_GROUP_INDEX_SHIFT) & LIST_VIEW_MASK;
871         int itemIndex = __selectedIndex & LIST_VIEW_MASK;
872         AppCtrlResult appCtrlResult = APP_CTRL_RESULT_SUCCEEDED;
873
874         HashMap* pReturnValue = new (std::nothrow) HashMap();
875         pReturnValue->Construct();
876
877         if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
878         {
879                 pList = __pPresentationModel->GetAllPhoneNumbersN(groupIndex, itemIndex);
880                 if (pList == null)
881                 {
882                         appCtrlResult = APP_CTRL_RESULT_FAILED;
883                 }
884                 else
885                 {
886                         AddContactValueOnList(pList, CONTACT_KEY_PHONE, index, pReturnValue);
887                 }
888         }
889         else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
890         {
891
892                 pList = __pPresentationModel->GetAllEmailsN(groupIndex, itemIndex);
893                 if (pList == null)
894                 {
895                         appCtrlResult = APP_CTRL_RESULT_FAILED;
896                 }
897                 else
898                 {
899                         AddContactValueOnList(pList, CONTACT_KEY_EMAIL, index, pReturnValue);
900                 }
901         }
902         delete pList;
903
904         ReturnValues(pContactsApp->GetRequestId(), appCtrlResult, pReturnValue);
905 }
906
907 void
908 ContactListPanel::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
909 {
910
911 }
912
913 void
914 ContactListPanel::OnTextValueChanged(const Tizen::Ui::Control& source)
915 {
916         String searchText = __pSearchBar->GetText();
917         searchText.Trim();
918
919         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
920         if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
921         {
922                 __pPresentationModel->SetSearchText(searchText, SEARCH_TYPE_HAS_PHONE_ONLY);
923         }
924         else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
925         {
926                 __pPresentationModel->SetSearchText(searchText, SEARCH_TYPE_HAS_EMAIL_ONLY);
927         }
928         else
929         {
930                 __pPresentationModel->SetSearchText(searchText, SEARCH_TYPE_NORMAL);
931         }
932
933         if (searchText.GetLength() != 0)
934         {
935                 __pSearchListView->SetShowState(true);
936                 __pListView->SetShowState(false);
937         }
938         else
939         {
940                 __pSearchListView->SetShowState(false);
941                 __pListView->SetShowState(true);
942         }
943
944         __pSearchListView->UpdateList();
945 }
946
947 void
948 ContactListPanel::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
949 {
950 }
951
952 void
953 ContactListPanel::ShowDeletePopup(void)
954 {
955         if (__pDeletePopup == null)
956         {
957                 __pDeletePopup = new (std::nothrow) Popup();
958                 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
959
960                 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
961
962                 Label* pLabel = new (std::nothrow) Label();
963                 pLabel->Construct(Rectangle(X_DELETE_LABEL, Y_DELETE_LABEL, W_DELETE_LABEL, H_DELETE_LABEL), ResourceManager::GetString(L"IDS_COM_POP_DELETE_Q"));
964                 pLabel->SetTextConfig(FONT_SIZE_DELETE_CONFIRM, LABEL_TEXT_STYLE_NORMAL);
965                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
966                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
967
968                 Button* pDeleteButton = new (std::nothrow) Button();
969                 pDeleteButton->Construct(Rectangle(X_DELETE_LABEL, Y_DELETE_BUTTON, W_DELETE_BUTTON, H_DELETE_BUTTON), ResourceManager::GetString(L"IDS_COM_SK_DELETE"));
970                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
971                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
972                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
973                 pDeleteButton->SetTextSize(FONT_SIZE_DELETE_BUTTON);
974                 pDeleteButton->SetActionId(IDA_POPUP_DELETE_OK);
975                 pDeleteButton->AddActionEventListener(*this);
976
977                 Button* pCancelButton = new (std::nothrow) Button();
978                 pCancelButton->Construct(Rectangle(X_DELETE_LABEL + W_DELETE_BUTTON + W_POPUP_ITEM_GAP, Y_DELETE_BUTTON, W_DELETE_BUTTON, H_DELETE_BUTTON), ResourceManager::GetString(L"IDS_PB_SK_CANCEL"));
979                 pCancelButton->SetTextSize(FONT_SIZE_DELETE_BUTTON);
980                 pCancelButton->SetActionId(IDA_POPUP_DELETE_CANCEL);
981                 pCancelButton->AddActionEventListener(*this);
982
983                 __pDeletePopup->AddControl(pLabel);
984                 __pDeletePopup->AddControl(pDeleteButton);
985                 __pDeletePopup->AddControl(pCancelButton);
986         }
987
988         __pDeletePopup->SetShowState(true);
989         __pDeletePopup->Show();
990 }
991
992 void
993 ContactListPanel::HideDeletePopup(void)
994 {
995         delete __pDeletePopup;
996         __pDeletePopup = null;
997
998         Invalidate(true);
999 }
1000
1001 void
1002 ContactListPanel::ShowAccountPopup(void)
1003 {
1004         if (__pAccountListEvent != null)
1005         {
1006                 delete __pAccountListEvent;
1007                 __pAccountListEvent = null;
1008         }
1009
1010         if (__pAccountPopup != null)
1011         {
1012                 delete __pAccountPopup;
1013                 __pAccountPopup = null;
1014         }
1015
1016         if (__pAccountPopup == null)
1017         {
1018                 __pAccountPopup = new (std::nothrow) Popup();
1019                 __pAccountPopup->Construct(true, Dimension(W_ACCOUNT_POPUP, H_ACCOUNT_POPUP));
1020                 __pAccountPopup->SetTitleText(ResourceManager::GetString(L"IDS_PB_OPT_VIEW"));
1021
1022                 Rectangle popupClientBounds = __pAccountPopup->GetClientAreaBounds();
1023
1024                 ListView* pAccountListView = new (std::nothrow) ListView();
1025                 pAccountListView->Construct(Rectangle(0, 0, popupClientBounds.width, popupClientBounds.height - H_ACCOUNT_POPUP_BUTTON));
1026
1027                 __pAccountListEvent = new (std::nothrow) AccountListItemProvider(pAccountListView, __pPresentationModel);
1028
1029                 pAccountListView->SetItemProvider(*__pAccountListEvent);
1030
1031                 __pAccountPopup->AddControl(pAccountListView);
1032
1033                 Button* pViewButton = new (std::nothrow) Button();
1034                 pViewButton->Construct(Rectangle(0, popupClientBounds.height - H_ACCOUNT_POPUP_BUTTON, popupClientBounds.width / 2 - W_POPUP_ITEM_GAP, H_ACCOUNT_POPUP_BUTTON),
1035                                                                                                         ResourceManager::GetString(L"IDS_PB_OPT_VIEW"));
1036                 pViewButton->SetActionId(IDA_POPUP_VIEW_OK);
1037                 pViewButton->AddActionEventListener(*this);
1038
1039                 Button* pCancelButton = new (std::nothrow) Button();
1040                 pCancelButton->Construct(Rectangle(popupClientBounds.width / 2 + W_POPUP_ITEM_GAP, popupClientBounds.height - H_ACCOUNT_POPUP_BUTTON,
1041                                                                                                         popupClientBounds.width / 2 - W_POPUP_ITEM_GAP, H_ACCOUNT_POPUP_BUTTON), ResourceManager::GetString(L"IDS_PB_SK_CANCEL"));
1042                 pCancelButton->SetActionId(IDA_POPUP_VIEW_CANCEL);
1043                 pCancelButton->AddActionEventListener(*this);
1044
1045                 __pAccountPopup->AddControl(pViewButton);
1046                 __pAccountPopup->AddControl(pCancelButton);
1047         }
1048
1049         __pAccountPopup->SetShowState(true);
1050         __pAccountPopup->Show();
1051 }
1052
1053 void
1054 ContactListPanel::HideAccountPopup(void)
1055 {
1056         delete __pAccountPopup;
1057         __pAccountPopup = null;
1058
1059         Invalidate(true);
1060 }
1061
1062 void
1063 ContactListPanel::OnFastScrollIndexSelected (Tizen::Ui::Control& source, Tizen::Base::String& index)
1064 {
1065         __pListView->ScrollToItem(__pPresentationModel->GetKeyIndex(index), -1);
1066         __pListView->Invalidate(false);
1067 }
1068
1069 void
1070 ContactListPanel::OnFocusGained(const Tizen::Ui::Control& source)
1071 {
1072         if (source.Equals(*__pSearchBar))
1073         {
1074                 if (__pListView->GetShowState() == true)
1075                 {
1076                         __pListView->UpdateList();
1077                 }
1078         }
1079 }
1080
1081 void
1082 ContactListPanel::OnFocusLost(const Tizen::Ui::Control& source)
1083 {
1084 }
1085
1086 void
1087 ContactListPanel::ShowContactValuePopup(int groupIndex, int itemIndex)
1088 {
1089         delete __pMultipleContactValuePopup;
1090         __pMultipleContactValuePopup = new (std::nothrow) Popup();
1091         __pMultipleContactValuePopup->Construct(true, Dimension(W_CONTACT_VALUE_POPUP, H_CONTACT_VALUE_POPUP));
1092         __pMultipleContactValuePopup->SetTitleText(__pPresentationModel->GetName(groupIndex, itemIndex));
1093
1094         Rectangle popupClientBounds = __pMultipleContactValuePopup->GetClientAreaBounds();
1095
1096         ListView* pListView = new (std::nothrow) ListView();
1097         pListView->Construct(Rectangle(0, 0, popupClientBounds.width, H_CONTACT_VALUE_POPUP_LIST_VIEW));
1098         pListView->SetItemProvider(*__pContactValueListEvent);
1099         pListView->AddListViewItemEventListener(*this);
1100
1101         __pMultipleContactValuePopup->AddControl(pListView);
1102
1103         Button* pCancelButton = new (std::nothrow) Button();
1104         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"));
1105         pCancelButton->SetActionId(IDA_POPUP_CONTACT_VALUE_CLOSE);
1106         pCancelButton->AddActionEventListener(*this);
1107
1108         __pMultipleContactValuePopup->AddControl(pCancelButton);
1109         __pMultipleContactValuePopup->SetShowState(true);
1110         __pMultipleContactValuePopup->Show();
1111 }
1112
1113 void
1114 ContactListPanel::HideContactValuePopup(void)
1115 {
1116         __pMultipleContactValuePopup->SetShowState(false);
1117
1118         delete __pContactValueListEvent;
1119         __pContactValueListEvent = null;
1120
1121         Invalidate(true);
1122 }
1123
1124 void
1125 ContactListPanel::ReturnValues(RequestId requestId, Tizen::App::AppCtrlResult appCtrlResult, const Tizen::Base::Collection::IMap* pReturnValue)
1126 {
1127         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
1128         result r = pAppManager->SendAppControlResult(requestId, appCtrlResult, pReturnValue);
1129         AppLogDebug("[%s] The return result from SendAppControlResult(), AppCtrlResult value : %d.", GetErrorMessage(r), appCtrlResult);
1130
1131         UiApp::GetInstance()->Terminate();
1132 }
1133
1134 void
1135 ContactListPanel::AddContactValueOnList(const Tizen::Base::Collection::IList* pList, const Tizen::Base::String& keyType, int index, Tizen::Base::Collection::HashMap* pReturnValue)
1136 {
1137         int blankIndex = 0;
1138
1139         String value(*(static_cast<const String *>(pList->GetAt(index))));
1140         value.LastIndexOf(CHARACTER_SPACE, value.GetLength()-1, blankIndex);
1141         value.Remove(0, blankIndex + 1);
1142
1143         ArrayList* pValueList = new (std::nothrow) ArrayList();
1144         pValueList->Construct();
1145         pValueList->Add(new (std::nothrow) String(value));
1146
1147         pReturnValue->Add(new (std::nothrow) String(keyType), pValueList);
1148 }
1149
1150 result
1151 ContactListPanel::LaunchAppControl(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, const Tizen::Base::String& argument, const Tizen::Base::String& type)
1152 {
1153         result r = E_SUCCESS;
1154
1155         if (__pAppControl != null)
1156         {
1157                 return E_FAILURE;
1158         }
1159
1160         String uri;
1161         HashMap extraData;
1162         extraData.Construct();
1163
1164         if (appId.Equals(String(PROVIDER_ID_PHONE)))
1165         {
1166                 uri.Append(INPUT_URI_TEL);
1167                 uri.Append(argument);
1168                 extraData.Add(new (std::nothrow) String(INPUT_KEY_CALL_TYPE), new (std::nothrow) String(type));
1169         }
1170         else if (appId.Equals(String(PROVIDER_ID_MESSAGE)))
1171         {
1172                 extraData.Add(new (std::nothrow) String(INPUT_KEY_MESSAGE_TO), new (std::nothrow) String(argument));
1173                 extraData.Add(new (std::nothrow) String(INPUT_KEY_MESSAGE_TYPE), new (std::nothrow) String(type));
1174         }
1175
1176         __pAppControl = AppManager::FindAppControlN(appId, operationId);
1177         if (__pAppControl != null)
1178         {
1179                 r = __pAppControl->Start(&uri, null, &extraData, null);
1180                 if (IsFailed(r))
1181                 {
1182                         AppLogDebug("[%s] Unable to launch app control", GetErrorMessage(r));
1183                 }
1184         }
1185
1186         extraData.RemoveAll(true);
1187
1188         return r;
1189 }
1190
1191 void
1192 ContactListPanel::OnKeypadWillOpen(Tizen::Ui::Control& source)
1193 {
1194 }
1195
1196 void
1197 ContactListPanel::OnKeypadOpened(Tizen::Ui::Control& source)
1198 {
1199         Form* pForm = dynamic_cast<Form*>(GetParent());
1200         AppAssert(pForm);
1201
1202         pForm->SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, false);
1203         __isKeypadOpened = true;
1204 }
1205
1206 void
1207 ContactListPanel::OnKeypadClosed(Tizen::Ui::Control& source)
1208 {
1209         Form* pForm = dynamic_cast<Form*>(GetParent());
1210         AppAssert(pForm);
1211
1212         pForm->SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
1213         pForm->Invalidate(true);
1214
1215         __isKeypadOpened = false;
1216
1217         if (__changedSceneId.Equals(IDSCN_CONTACT_LIST, true) == false)
1218         {
1219                 SceneManager* pSceneManager = SceneManager::GetInstance();
1220                 pSceneManager->GoForward(ForwardSceneTransition(__changedSceneId));
1221
1222                 __changedSceneId = IDSCN_CONTACT_LIST;
1223         }
1224 }
1225
1226 void
1227 ContactListPanel::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
1228 {
1229         if (keypadAction == KEYPAD_ACTION_SEARCH)
1230         {
1231                 __pSearchBar->HideKeypad();
1232         }
1233 }
1234
1235 void
1236 ContactListPanel::OnFormMenuRequested(Tizen::Ui::Controls::Form& source)
1237 {
1238         if(__pPresentationModel->GetContactCount() > 0)
1239         {
1240                 __pOptionMenu->SetShowState(true);
1241                 __pOptionMenu->Show();
1242         }
1243 }
1244
1245 void
1246 ContactListPanel::OnForeground(void)
1247 {
1248         delete __pAppControl;
1249         __pAppControl = null;
1250 }
1251
1252 void
1253 ContactListPanel::OnBackground(void)
1254 {
1255 }
1256
1257 void
1258 ContactListPanel::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo & touchInfo)
1259 {
1260         if (source.Equals(*__pListView))
1261         {
1262                 __pListView->SetFocus();
1263         }
1264 }
1265
1266 void
1267 ContactListPanel::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
1268 {
1269 }
1270
1271 void
1272 ContactListPanel::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
1273 {
1274 }
1275
1276 void
1277 ContactListPanel::OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
1278 {
1279 }
1280
1281 void
1282 ContactListPanel::OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
1283 {
1284 }