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