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