2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file CtFavoriteListPanel.cpp
19 * @brief This is the implementation file for the FavoriteListPanel class.
23 #include "CtContactsApp.h"
24 #include "CtContactValueListItemProvider.h"
25 #include "CtFavoriteListPanel.h"
26 #include "CtFavoriteListPresentationModel.h"
27 #include "CtMainForm.h"
28 #include "CtResourceManager.h"
29 #include "CtSceneRegister.h"
31 #include "CtCommonUtil.h"
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
41 static const int IDA_FOOTER_ADD_FAVORITE = 1;
42 static const int IDA_MORE_EDIT_FAVORITE = 2;
43 static const int IDA_HEADER_CONTACTS = 10;
44 static const int IDA_HEADER_GROUPS = 11;
45 static const int IDA_HEADER_FAVORITES = 12;
46 static const int IDA_POPUP_CONTACT_VALUE_CLOSE = 20;
47 static const int IDA_FAVORITE_QUICK_MENU = 21;
48 static const int IDA_CONTEXTMENU_CALL = 30;
49 static const int IDA_CONTEXTMENU_MESSAGE = 31;
50 static const int IDA_CONTEXTMENU_VIDEO_CALL = 32;
51 static const int IDA_CONTEXTMENU_REMOVE = 33;
53 static const wchar_t* IDB_NO_FAVORITES = L"00_Nocontents_picture.png";
54 static const wchar_t* IDB_QUICK_MENU = L"00_button_expand_closed_press.png";
56 static const int W_INITAIL_PANEL = 10;
57 static const int H_INITIAL_PANEL = 10;
58 static const int W_ICONLISTVIEW_ITEM = 239;
59 static const int H_ICONLISTVIEW_ITEM = 239;
60 static const int H_TEXT_BACKGROUND = 64;
61 static const int H_TEXT_SPACE = 96;
62 static const int W_CONTACT_VALUE_POPUP = 688;
63 static const int H_CONTACT_VALUE_POPUP = 532;
64 static const int H_CONTACT_VALUE_POPUP_LIST_VIEW = 338;
65 static const int Y_CLOSE_BUTTON = 358;
66 static const int W_CLOSE_BUTTON = 394;
67 static const int H_CLOSE_BUTTON = 74;
68 static const int W_QUICK_MENU_BUTTON = 74;
69 static const int X_EMPTY_IMAGE = 220;
70 static const int Y_EMPTY_IMAGE = 300;
71 static const int W_EMPTY_IMAGE = 280;
72 static const int H_EMPTY_IMAGE = 280;
73 static const int Y_EMPTY_COMMENT = 618;
74 static const int H_EMPTY_COMMENT = 38;
75 static const int W_ITEM_SPACE = 1;
76 static const int H_ITEM_SPACE = 1;
77 static const int W_NAME_TEXT_MARGIN = 10;
79 static const int FONT_SIZE_WITH_THUMBNAIL = 24;
80 static const int FONT_SIZE_EMPTY_COMMENT = 32;
81 static const int FONT_SIZE = 40;
83 static const unsigned int COLOR_ITEM_BACKGROUND = Color32<201, 201, 201>::Value;
84 static const unsigned int COLOR_ITEM_TEXT_BACKGROUND = Color32<0, 0, 0, 89>::Value;
85 static const unsigned int COLOR_TEXT_WITH_THUMBNAIL = Color32<249, 249, 249>::Value;
86 static const unsigned int COLOR_TEXT = Color32<255, 255, 255>::Value;
87 static const unsigned int COLOR_LINE = Color32<225, 225, 225, 26>::Value;
88 static const unsigned int COLOR_EMPTY_COMMENT = Color32<102, 102, 102>::Value;
90 static const wchar_t* INPUT_KEY_CALL_TYPE = L"http://tizen.org/appcontrol/data/call/type";
91 static const wchar_t* INPUT_KEY_MESSAGE_TYPE = L"http://tizen.org/appcontrol/data/message/type";
92 static const wchar_t* INPUT_KEY_MESSAGE_TO = L"http://tizen.org/appcontrol/data/to";
93 static const wchar_t* INPUT_TYPE_VIDEO = L"video";
94 static const wchar_t* INPUT_TYPE_VOICE = L"voice";
95 static const wchar_t* INPUT_TYPE_SMS = L"sms";
96 static const wchar_t* INPUT_URI_TEL = L"tel:";
98 FavoriteListPanel::FavoriteListPanel(void)
99 : __isAppControlLaunching(false)
100 , __scrolledDistance(0)
101 , __selectedItemIndex(0)
102 , __pAppControl(null)
103 , __pContextMenuAction(null)
104 , __pOptionMenu(null)
105 , __pFavoriteListView(null)
106 , __pMultipleContactValuePopup(null)
107 , __pEmptyImageLabel(null)
108 , __pEmptyCommentLabel(null)
109 , __pPresentationModel(null)
110 , __pContactValueListProvider(null)
114 FavoriteListPanel::~FavoriteListPanel(void)
119 FavoriteListPanel::Initialize(void)
121 Construct(Rectangle(0, 0, W_INITAIL_PANEL, H_INITIAL_PANEL));
125 FavoriteListPanel::OnInitializing(void)
127 result r = E_SUCCESS;
129 const Form* pForm = dynamic_cast<Form*>(GetParent());
132 FloatRectangle clientBounds = ((MainForm*)pForm)->GetClientBounds();
133 SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height));
135 __pPresentationModel = FavoriteListPresentationModel::GetInstance();
137 __pFavoriteListView = new (std::nothrow) IconListView();
138 __pFavoriteListView->Construct(Rectangle(0, 0, clientBounds.width, clientBounds.height), Dimension(W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM));
139 __pFavoriteListView->SetItemProvider(*this);
140 __pFavoriteListView->AddIconListViewItemEventListener(*this);
141 __pFavoriteListView->AddScrollEventListener(*this);
142 __pFavoriteListView->SetItemLayoutHorizontalAlignment(ALIGNMENT_LEFT);
143 __pFavoriteListView->SetItemLayoutVerticalAlignment(ALIGNMENT_TOP);
144 __pFavoriteListView->SetItemSpacing(W_ITEM_SPACE, H_ITEM_SPACE);
145 __pFavoriteListView->SetMargin(MARGIN_TYPE_LEFT, 0);
146 __pFavoriteListView->SetMargin(MARGIN_TYPE_RIGHT, 0);
147 __pFavoriteListView->SetTouchAnimationEnabled(false);
149 AddControl(__pFavoriteListView);
151 __pEmptyImageLabel = new (std::nothrow) Label();
152 __pEmptyImageLabel->Construct(Rectangle(X_EMPTY_IMAGE, Y_EMPTY_IMAGE, W_EMPTY_IMAGE, H_EMPTY_IMAGE), L"");
153 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_NO_FAVORITES);
156 __pEmptyImageLabel->SetBackgroundBitmap(*pBitmap);
159 __pEmptyImageLabel->SetShowState(false);
161 AddControl(__pEmptyImageLabel);
163 __pEmptyCommentLabel = new (std::nothrow) Label();
164 __pEmptyCommentLabel->Construct(Rectangle(0, Y_EMPTY_COMMENT, clientBounds.width, H_EMPTY_COMMENT),
165 ResourceManager::GetString(L"IDS_PB_BODY_NO_FAVOURITES"));
166 __pEmptyCommentLabel->SetTextConfig(FONT_SIZE_EMPTY_COMMENT, LABEL_TEXT_STYLE_NORMAL);
167 __pEmptyCommentLabel->SetTextColor(Color(COLOR_EMPTY_COMMENT));
168 __pEmptyCommentLabel->SetShowState(false);
170 AddControl(__pEmptyCommentLabel);
172 __pOptionMenu = new (std::nothrow) OptionMenu();
173 __pOptionMenu->Construct();
174 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_SK_EDIT"), IDA_MORE_EDIT_FAVORITE);
175 __pOptionMenu->AddActionEventListener(*this);
176 __pOptionMenu->SetShowState(false);
182 FavoriteListPanel::OnTerminating(void)
184 result r = E_SUCCESS;
186 if (__pPresentationModel != null)
188 __pPresentationModel->RemoveContactChangeListener(*this);
191 delete __pAppControl;
192 delete __pContextMenuAction;
193 delete __pMultipleContactValuePopup;
199 FavoriteListPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
201 SceneManager* pSceneManager = SceneManager::GetInstance();
202 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
206 case IDA_HEADER_CONTACTS:
208 if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
210 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
212 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
214 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
216 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST_EDITOR));
221 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
225 case IDA_HEADER_GROUPS:
227 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_LIST));
230 case IDA_HEADER_FAVORITES:
232 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
235 case IDA_FOOTER_ADD_FAVORITE:
237 if (CommonUtil::isMemoryAvailable() == false)
239 CommonUtil::showMemoryFullMessageBox();
243 ArrayList* pArgList = new (std::nothrow) ArrayList();
244 pArgList->Construct();
246 for (int i = 0; i < __pPresentationModel->GetFavoriteCount(); i++)
248 pArgList->Add(*(new (std::nothrow) Integer(__pPresentationModel->GetContactId(i))));
251 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_SELECTOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgList);
254 case IDA_MORE_EDIT_FAVORITE:
256 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST_EDITOR));
259 case IDA_POPUP_CONTACT_VALUE_CLOSE:
261 HideContactValuePopup();
264 case IDA_CONTEXTMENU_CALL:
266 String phoneNumber = __pPresentationModel->GetDefaultPhoneNumber(__selectedItemIndex);
267 LaunchAppControl(PROVIDER_ID_PHONE, OPERATION_ID_CALL, phoneNumber, INPUT_TYPE_VOICE);
270 case IDA_CONTEXTMENU_MESSAGE:
272 if (!(__pPresentationModel->GetDefaultPhoneNumber(__selectedItemIndex).IsEmpty()))
274 String phoneNumber = __pPresentationModel->GetDefaultPhoneNumber(__selectedItemIndex);
275 LaunchAppControl(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE, phoneNumber, INPUT_TYPE_SMS);
277 else if (!(__pPresentationModel->GetDefaultEmail(__selectedItemIndex).IsEmpty()))
279 String emailId = __pPresentationModel->GetDefaultEmail(__selectedItemIndex);
280 LaunchAppControl(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE, emailId, null);
284 case IDA_CONTEXTMENU_VIDEO_CALL:
286 String phoneNumber = __pPresentationModel->GetDefaultPhoneNumber(__selectedItemIndex);
287 LaunchAppControl(PROVIDER_ID_PHONE, OPERATION_ID_CALL, phoneNumber, INPUT_TYPE_VIDEO);
290 case IDA_CONTEXTMENU_REMOVE:
292 __pPresentationModel->SetAsFavorite(__pPresentationModel->GetContactId(__selectedItemIndex), false);
293 __pPresentationModel->InitializeFavoriteList();
295 const Form* pForm = dynamic_cast<Form*>(GetParent());
297 Footer* pFooter = pForm->GetFooter();
298 if (__pPresentationModel->GetContactCount() > __pPresentationModel->GetFavoriteCount())
300 pFooter->SetItemEnabled(0, true);
301 pFooter->Invalidate(true);
304 if (__pPresentationModel->GetFavoriteCount() == 0)
306 __pFavoriteListView->SetShowState(false);
307 __pEmptyImageLabel->SetShowState(true);
308 __pEmptyCommentLabel->SetShowState(true);
309 pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
312 __pFavoriteListView->UpdateList();
321 FavoriteListPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
323 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
325 __isAppControlLaunching = false;
327 if (previousSceneId.Equals(IDSCN_CONTACT_SELECTOR, true) && pArgs != null)
329 Integer* pContactId = null;
330 IEnumerator* pEnum = pArgs->GetEnumeratorN();
332 while (pEnum->MoveNext() == E_SUCCESS)
334 pContactId = static_cast<Integer*>(pEnum->GetCurrent());
335 if (pContactId != null)
337 __pPresentationModel->SetAsFavorite(pContactId->ToInt(), true);
341 pArgs->RemoveAll(true);
345 Form* pForm = dynamic_cast<Form*>(GetParent());
348 Form *pEventForm = const_cast<Form*>(pForm);
349 pEventForm->SetFormMenuEventListener(this);
351 Header* pHeader = pForm->GetHeader();
352 pHeader->AddActionEventListener(*this);
354 Footer* pFooter = pForm->GetFooter();
355 pFooter->AddActionEventListener(*this);
357 FloatRectangle clientBounds = ((MainForm*)pForm)->GetClientBounds();
359 if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
361 pFooter->SetShowState(false);
363 SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height + pFooter->GetHeight()));
364 __pFavoriteListView->SetSize(__pFavoriteListView->GetWidthF(), clientBounds.height + pFooter->GetHeight());
368 pEventForm->SetFormMenuEventListener(null);
369 __pPresentationModel->InitializeFavoriteList(pContactsApp->GetReturnType());
373 __pPresentationModel->InitializeFavoriteList();
375 FooterItem footerItemAdd;
376 footerItemAdd.Construct(IDA_FOOTER_ADD_FAVORITE);
377 footerItemAdd.SetText(ResourceManager::GetString(L"IDS_PB_OPT_ADD_TO_FAVORITES"));
378 int count = pFooter->GetItemCount();
381 pFooter->AddItem(footerItemAdd);
385 pFooter->SetItemAt(0, footerItemAdd);
389 pFooter->SetItemAt(0, footerItemAdd);
390 pFooter->RemoveItemAt(1);
391 pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
394 if (__pPresentationModel->GetContactCount() <= __pPresentationModel->GetFavoriteCount())
396 pFooter->SetItemEnabled(0, false);
400 pFooter->SetItemEnabled(0, true);
403 if (__pPresentationModel->GetFavoriteCount() > 0 )
405 pForm->SetFormMenuEventListener(this);
409 pForm->SetFormMenuEventListener(null);
412 pContactsApp->AddContactsAppChangeEventListener(*this);
415 if (__pPresentationModel->GetFavoriteCount() > 0)
417 __pFavoriteListView->SetShowState(true);
418 __pEmptyImageLabel->SetShowState(false);
419 __pEmptyCommentLabel->SetShowState(false);
421 __pFavoriteListView->UpdateList();
425 __pFavoriteListView->SetShowState(false);
426 __pEmptyImageLabel->SetShowState(true);
427 __pEmptyCommentLabel->SetShowState(true);
430 __pPresentationModel->AddContactChangeListener(*this);
434 FavoriteListPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
436 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
437 pContactsApp->RemoveContactsAppChangeEventListener(*this);
439 const Form* pForm = dynamic_cast<Form*>(GetParent());
442 Form *pEventForm = const_cast<Form*>(pForm);
443 pEventForm->SetFormMenuEventListener(null);
445 Header* pHeader = pForm->GetHeader();
446 pHeader->RemoveActionEventListener(*this);
448 Footer* pFooter = pForm->GetFooter();
449 pFooter->RemoveActionEventListener(*this);
451 __pPresentationModel->RemoveContactChangeListener(*this);
453 delete __pAppControl;
454 __pAppControl = null;
458 FavoriteListPanel::OnIconListViewItemReordered(Tizen::Ui::Controls::IconListView &iconListView, int indexFrom, int indexTo)
463 FavoriteListPanel::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView &iconListView, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
465 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
467 if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
469 HashMap* pReturnValue = new (std::nothrow) HashMap();
470 pReturnValue->Construct();
472 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_ITEM_ID)
475 ArrayList* pValueList = new (std::nothrow) ArrayList();
476 pValueList->Construct();
478 contactId.Append(__pPresentationModel->GetContactId(index));
479 pValueList->Add(new (std::nothrow) String(contactId));
481 pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), pValueList);
483 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
487 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_VCARD)
489 AppCtrlResult appCtrlResult = APP_CTRL_RESULT_SUCCEEDED;
490 String vCardPath = __pPresentationModel->ExportToVcard(index);
492 if (vCardPath.IsEmpty())
494 appCtrlResult = APP_CTRL_RESULT_FAILED;
498 pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_PATH), new (std::nothrow) String(vCardPath));
500 ReturnValues(pContactsApp->GetRequestId(), appCtrlResult, pReturnValue);
505 IList* pList = __pPresentationModel->GetMultiValuesN(pContactsApp->GetReturnType(), index);
508 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
513 if (pList->GetCount() > 1)
515 __pContactValueListProvider = new (std::nothrow) ContactValueListItemProvider(pList);
516 ShowContactValuePopup(index);
518 else if (pList->GetCount() == 1)
522 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
524 keyType.Append(CONTACT_KEY_PHONE);
526 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
528 keyType.Append(CONTACT_KEY_EMAIL);
535 String* pReturnInfo = static_cast<String*>(pList->GetAt(0));
537 ArrayList* pValueList = new (std::nothrow) ArrayList();
538 pValueList->Construct();
540 pReturnInfo->IndexOf(CHARACTER_SPACE, 0, blankIndex);
541 pReturnInfo->Remove(0, blankIndex + 1);
543 pValueList->Add(new (std::nothrow) String(*pReturnInfo));
544 pReturnValue->Add(new (std::nothrow) String(keyType), pValueList);
546 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
554 if (__isAppControlLaunching == true)
559 SceneManager* pSceneManager = SceneManager::GetInstance();
561 ArrayList* pContactId = new (std::nothrow) ArrayList();
562 pContactId->Construct();
564 pContactId->Add(*(new (std::nothrow) Integer(__pPresentationModel->GetContactId(index))));
565 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_DETAILS, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pContactId);
570 FavoriteListPanel::OnIconListViewOverlayBitmapSelected(Tizen::Ui::Controls::IconListView& iconListView, int index, int overlayBitmapId)
572 if(__isAppControlLaunching == true)
576 if (__pContextMenuAction != null)
578 delete __pContextMenuAction;
581 if (overlayBitmapId == IDA_FAVORITE_QUICK_MENU)
583 const Form* pForm = dynamic_cast<Form*>(GetParent());
586 Point itemPosition(W_ICONLISTVIEW_ITEM * (index % iconListView.GetItemCountPerAxis() + 1) - (W_QUICK_MENU_BUTTON / 2), pForm->GetClientAreaBounds().y + H_ICONLISTVIEW_ITEM * (index / iconListView.GetItemCountPerAxis() + 1) - __scrolledDistance);
588 __pContextMenuAction = new (std::nothrow) ContextMenu();
589 __pContextMenuAction->Construct(itemPosition, CONTEXT_MENU_STYLE_GRID, CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD);
591 if (__pPresentationModel->GetDefaultPhoneNumber(index).IsEmpty() == false)
593 __pContextMenuAction->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_CALL"), IDA_CONTEXTMENU_CALL);
594 #if __SUPPORT_VIDEO_CALL
595 __pContextMenuAction->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_VIDEO_CALL"), IDA_CONTEXTMENU_VIDEO_CALL);
598 if ((__pPresentationModel->GetDefaultPhoneNumber(index).IsEmpty() == false)||(__pPresentationModel->GetDefaultEmail(index).IsEmpty() == false))
600 __pContextMenuAction->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"), IDA_CONTEXTMENU_MESSAGE);
602 __pContextMenuAction->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_REMOVE"), IDA_CONTEXTMENU_REMOVE);
603 __pContextMenuAction->AddActionEventListener(*this);
604 __pContextMenuAction->SetFocusable(true);
605 __pContextMenuAction->Show();
606 __selectedItemIndex = index;
611 FavoriteListPanel::OnFormMenuRequested(Tizen::Ui::Controls::Form& source)
613 if(__pPresentationModel->GetFavoriteCount() > 0)
615 __pOptionMenu->SetShowState(true);
616 __pOptionMenu->Show();
620 Tizen::Ui::Controls::IconListViewItem*
621 FavoriteListPanel::CreateItem(int index)
623 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
624 Bitmap* pThumbnail = null;
625 Bitmap* pBitmapQuickMenu = null;
631 int textWidth = W_ICONLISTVIEW_ITEM - (W_NAME_TEXT_MARGIN * 2);
632 TextHorizontalAlignment alignment = TEXT_ALIGNMENT_LEFT;
634 if (__pPresentationModel->GetFavoriteItemInfo(index, name, pThumbnail) != E_SUCCESS)
639 Canvas* pCanvas = new (std::nothrow) Canvas();
640 pCanvas->Construct(Rectangle(0, 0, W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM));
643 if (pThumbnail != null)
645 textFont.Construct(FONT_STYLE_BOLD , FONT_SIZE_WITH_THUMBNAIL);
646 textY = H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND;
647 textHeight = H_TEXT_BACKGROUND;
648 textColor = Color(COLOR_TEXT_WITH_THUMBNAIL);
650 if (pContactsApp->GetOperationId() != OPERATION_ID_PICK)
652 textWidth = W_ICONLISTVIEW_ITEM - W_QUICK_MENU_BUTTON - W_NAME_TEXT_MARGIN;
655 pCanvas->DrawBitmap(pCanvas->GetBounds(), *pThumbnail, Rectangle(0, 0, pThumbnail->GetWidth(), pThumbnail->GetHeight()));
656 pCanvas->SetForegroundColor(Color(COLOR_LINE));
657 pCanvas->DrawLine(Point(0, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND), Point(W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND));
658 pCanvas->FillRectangle(Color(COLOR_ITEM_TEXT_BACKGROUND), Rectangle(0, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND, W_ICONLISTVIEW_ITEM, H_TEXT_BACKGROUND));
662 textFont.Construct(FONT_STYLE_BOLD , FONT_SIZE);
663 textY = (H_ICONLISTVIEW_ITEM / 2) - (H_TEXT_SPACE / 2);
664 textHeight = H_TEXT_SPACE;
665 textColor = Color(COLOR_TEXT);
666 alignment = TEXT_ALIGNMENT_CENTER;
668 pCanvas->FillRectangle(Color(COLOR_ITEM_BACKGROUND), pCanvas->GetBounds());
671 EnrichedText* pEnrichedTextName = new (std::nothrow) EnrichedText();
672 pEnrichedTextName->Construct(Dimension(textWidth, textHeight));
673 pEnrichedTextName->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
674 pEnrichedTextName->SetHorizontalAlignment(alignment);
675 pEnrichedTextName->SetTextWrapStyle(TEXT_WRAP_WORD_WRAP);
676 pEnrichedTextName->SetTextAbbreviationEnabled(true);
678 TextElement* pTextElementName = new (std::nothrow) TextElement();
679 pTextElementName->Construct(name);
680 pTextElementName->SetFont(textFont);
681 pTextElementName->SetTextColor(textColor);
683 pEnrichedTextName->Add(*pTextElementName);
685 pCanvas->DrawText(Point(W_NAME_TEXT_MARGIN, textY), *pEnrichedTextName);
687 Bitmap* pBitmapItem = new (std::nothrow) Bitmap();
688 pBitmapItem->Construct(*pCanvas, Rectangle(0, 0, W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM));
690 IconListViewItem* pFavoriteItem = new (std::nothrow) IconListViewItem();
691 pFavoriteItem->Construct(*pBitmapItem);
693 if (pContactsApp->GetOperationId() != OPERATION_ID_PICK)
695 pBitmapQuickMenu = ResourceManager::GetBitmapN(IDB_QUICK_MENU);
697 if (pBitmapQuickMenu != null)
699 pFavoriteItem->SetOverlayBitmap(IDA_FAVORITE_QUICK_MENU, pBitmapQuickMenu, ALIGNMENT_RIGHT, ALIGNMENT_BOTTOM);
704 delete pBitmapQuickMenu;
707 delete pEnrichedTextName;
708 delete pTextElementName;
710 return pFavoriteItem;
714 FavoriteListPanel::DeleteItem(int index, Tizen::Ui::Controls::IconListViewItem *pItem)
723 FavoriteListPanel::GetItemCount(void)
725 return __pPresentationModel->GetFavoriteCount();
729 FavoriteListPanel::OnContactsChanged(void)
731 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
733 HideContactValuePopup();
734 if (__pContextMenuAction != null)
736 delete __pContextMenuAction;
737 __pContextMenuAction = null;
740 if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
742 __pPresentationModel->InitializeFavoriteList(pContactsApp->GetReturnType());
746 __pPresentationModel->InitializeFavoriteList();
749 Form* pForm = dynamic_cast<Form*>(GetParent());
752 Footer* pFooter = pForm->GetFooter();
754 if (__pPresentationModel->GetContactCount() <= __pPresentationModel->GetFavoriteCount())
756 pFooter->SetItemEnabled(0, false);
757 pFooter->Invalidate(true);
761 pFooter->SetItemEnabled(0, true);
762 pFooter->Invalidate(true);
765 if (__pPresentationModel->GetFavoriteCount() > 0)
767 pForm->SetFormMenuEventListener(this);
771 pForm->SetFormMenuEventListener(null);
774 if (__pPresentationModel->GetFavoriteCount() > 0)
776 __pFavoriteListView->SetShowState(true);
777 __pEmptyImageLabel->SetShowState(false);
778 __pEmptyCommentLabel->SetShowState(false);
782 __pFavoriteListView->SetShowState(false);
783 __pEmptyImageLabel->SetShowState(true);
784 __pEmptyCommentLabel->SetShowState(true);
786 __pFavoriteListView->UpdateList();
790 FavoriteListPanel::OnCategoriesChanged(void)
795 FavoriteListPanel::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
800 FavoriteListPanel::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
802 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
804 HashMap* pReturnValue = new (std::nothrow) HashMap();
805 pReturnValue->Construct();
808 int selectedIndex = -1;
809 Integer::Parse(listView.GetName(), selectedIndex);
811 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
813 keyType.Append(CONTACT_KEY_PHONE);
815 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
817 keyType.Append(CONTACT_KEY_EMAIL);
821 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
826 IList* pList = __pPresentationModel->GetMultiValuesN(pContactsApp->GetReturnType(), selectedIndex);
827 String* pReturnInfo = static_cast<String *>(pList->GetAt(index));
829 ArrayList* pValueList = new (std::nothrow) ArrayList();
830 pValueList->Construct();
832 pReturnInfo->IndexOf(CHARACTER_SPACE, 0, blankIndex);
833 pReturnInfo->Remove(0, blankIndex + 1);
834 pValueList->Add(new (std::nothrow) String(*pReturnInfo));
835 pReturnValue->Add(new (std::nothrow) String(keyType), pValueList);
839 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
843 FavoriteListPanel::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
848 FavoriteListPanel::ReturnValues(RequestId requestId, Tizen::App::AppCtrlResult appCtrlResult, const Tizen::Base::Collection::IMap* pReturnValue)
850 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
852 result r = pAppManager->SendAppControlResult(requestId, appCtrlResult, pReturnValue);
853 AppLogDebug("[%s] The return result from SendAppControlResult(), AppCtrlResult value : %d.", GetErrorMessage(r), appCtrlResult);
855 UiApp::GetInstance()->Terminate();
859 FavoriteListPanel::ShowContactValuePopup(int index)
862 Bitmap* pEmpty = null;
864 delete __pMultipleContactValuePopup;
865 __pMultipleContactValuePopup = new (std::nothrow) Popup();
866 __pMultipleContactValuePopup->Construct(true, Dimension(W_CONTACT_VALUE_POPUP, H_CONTACT_VALUE_POPUP));
867 __pPresentationModel->GetFavoriteItemInfo(index, name, pEmpty);
868 __pMultipleContactValuePopup->SetTitleText(name);
869 __pMultipleContactValuePopup->SetPropagatedKeyEventListener(this);
871 Rectangle popupClientBounds = __pMultipleContactValuePopup->GetClientAreaBounds();
873 ListView* pListView = new (std::nothrow) ListView();
874 pListView->Construct(Rectangle(0, 0, popupClientBounds.width, H_CONTACT_VALUE_POPUP_LIST_VIEW));
875 pListView->SetItemProvider(*__pContactValueListProvider);
876 pListView->AddListViewItemEventListener(*this);
877 pListView->SetName(String(Integer::ToString(index)));
879 __pMultipleContactValuePopup->AddControl(pListView);
881 Button* pCancelButton = new (std::nothrow) Button();
882 pCancelButton->Construct(Rectangle((popupClientBounds.width - W_CLOSE_BUTTON) / 2, Y_CLOSE_BUTTON, W_CLOSE_BUTTON, H_CLOSE_BUTTON), ResourceManager::GetString(L"IDS_COM_POP_CLOSE"));
883 pCancelButton->SetActionId(IDA_POPUP_CONTACT_VALUE_CLOSE);
884 pCancelButton->AddActionEventListener(*this);
886 __pMultipleContactValuePopup->AddControl(pCancelButton);
887 __pMultipleContactValuePopup->SetShowState(true);
888 __pMultipleContactValuePopup->Show();
892 FavoriteListPanel::HideContactValuePopup(void)
894 if (__pMultipleContactValuePopup)
896 __pMultipleContactValuePopup->SetShowState(false);
902 FavoriteListPanel::OnScrollEndReached (Tizen::Ui::Control &source, Tizen::Ui::Controls::ScrollEndEvent type)
904 if (type == SCROLL_END_EVENT_END_BOTTOM)
906 if (type == SCROLL_END_EVENT_END_BOTTOM)
908 IconListView* iconListView = static_cast<IconListView*>(&source);
910 int listViewHeight = iconListView->GetHeight();
911 int ItemHeight = H_ICONLISTVIEW_ITEM;
912 int noOfItems = __pPresentationModel->GetFavoriteCount();
914 int NoOfRows = noOfItems/iconListView->GetItemCountPerAxis();
915 if(noOfItems%iconListView->GetItemCountPerAxis() != 0)
917 NoOfRows = NoOfRows + 1;
920 int TotalHeight = NoOfRows * ItemHeight;
922 __scrolledDistance = TotalHeight - listViewHeight;
925 else if (type == SCROLL_END_EVENT_END_TOP)
927 __scrolledDistance = 0;
932 FavoriteListPanel::OnScrollPositionChanged (Tizen::Ui::Control &source, int scrollPos)
934 __scrolledDistance = scrollPos;
938 FavoriteListPanel::OnScrollStopped (Tizen::Ui::Control &source)
943 FavoriteListPanel::LaunchAppControl(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, const Tizen::Base::String& argument, const Tizen::Base::String& type)
945 result r = E_SUCCESS;
947 if (__pAppControl != null)
954 extraData.Construct();
956 if (appId.Equals(String(PROVIDER_ID_PHONE)))
958 uri.Append(INPUT_URI_TEL);
959 uri.Append(argument);
960 extraData.Add(new (std::nothrow) String(INPUT_KEY_CALL_TYPE), new (std::nothrow) String(type));
962 else if (appId.Equals(String(PROVIDER_ID_MESSAGE)))
964 extraData.Add(new (std::nothrow) String(INPUT_KEY_MESSAGE_TO), new (std::nothrow) String(argument));
965 extraData.Add(new (std::nothrow) String(INPUT_KEY_MESSAGE_TYPE), new (std::nothrow) String(INPUT_TYPE_SMS));
968 __pAppControl = AppManager::FindAppControlN(appId, operationId);
969 if (__pAppControl != null)
971 r = __pAppControl->Start(&uri, null, &extraData, null);
974 AppLogDebug("[%s] Unable to launch app control", GetErrorMessage(r));
978 __isAppControlLaunching = true;
982 extraData.RemoveAll(true);
988 FavoriteListPanel::OnForeground(void)
990 __pFavoriteListView->SetEnabled(true);
991 __pFavoriteListView->UpdateList();
993 delete __pAppControl;
994 __pAppControl = null;
996 __isAppControlLaunching = false;
1000 FavoriteListPanel::OnBackground(void)
1005 FavoriteListPanel::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
1011 FavoriteListPanel::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
1013 if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
1015 if (__pMultipleContactValuePopup && __pMultipleContactValuePopup->GetShowState() == true)
1017 HideContactValuePopup();
1025 FavoriteListPanel::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
1031 FavoriteListPanel::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)