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 CtSearchListEventListener.cpp
19 * @brief This is the implementation file for the SearchListEventListener class.
22 #include "CtContactListPresentationModel.h"
23 #include "CtContactsApp.h"
24 #include "CtResourceManager.h"
25 #include "CtSearchListEventListener.h"
26 #include "CtSearchListItem.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Ui::Controls;
32 static const int IDA_LIST_ELEMENT_DELETE = 40;
33 static const int IDA_LIST_ELEMENT_CALL = 41;
34 static const int IDA_LIST_ELEMENT_MESSAGE = 42;
35 static const int IDA_LIST_ELEMENT_VIDEO_CALL = 43;
38 static const unsigned int COLOR_DELETE_ELEMENT_NORMAL = Color32<208, 82, 82>::Value;
39 static const unsigned int COLOR_DELETE_ELEMENT_PRESSED = Color32<194, 71, 71>::Value;
40 static const unsigned int COLOR_DELETE_ELEMENT_TEXT = Color32<248, 246, 239>::Value;
42 static const int H_GROUP_ITEM = 76;
43 static const int H_ITEM = 112;
44 static const int X_LIST_ITEM_TEXT_MARGIN = 32;
46 SearchListEventListener::SearchListEventListener(ListAnnexStyle itemAnnexStyle, ContactListPresentationModel* pContactListPresentationModel)
47 : __pContactListPresentationModel(pContactListPresentationModel)
48 , __itemAnnexStyle(itemAnnexStyle)
49 , __showDeleteOption(true)
53 SearchListEventListener::~SearchListEventListener(void)
58 SearchListEventListener::GetGroupCount(void)
60 if (__pContactListPresentationModel->GetSearchedContactCount() != 0)
71 SearchListEventListener::GetItemCount(int groupIndex)
73 return __pContactListPresentationModel->GetSearchedContactCount();
76 Tizen::Ui::Controls::ListItemBase*
77 SearchListEventListener::CreateItem(int groupIndex, int itemIndex, int itemWidth)
81 Bitmap* pThumbnail = null;
82 CustomItem* pItem = null;
83 SearchListItem* pCustomElement = null;
84 int searchItemWidth = itemWidth;
85 int groupItemMainIndex = 0;
86 int ItemMainIndex = 0;
88 ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
90 if (__itemAnnexStyle == LIST_ANNEX_STYLE_MARK)
92 searchItemWidth -= (ListItemBase::GetAnnexWidth(LIST_ANNEX_STYLE_MARK) + X_LIST_ITEM_TEXT_MARGIN);
94 __pContactListPresentationModel->GetSearchedContactItemInfo(itemIndex, name, pThumbnail);
96 pItem = new (std::nothrow) CustomItem();
97 pItem->Construct(Dimension(itemWidth, H_ITEM + pContactsApp->GetFontHeightOffset()), __itemAnnexStyle);
99 pCustomElement = new (std::nothrow) SearchListItem(name, pThumbnail, __pContactListPresentationModel->GetSearchText());
101 pItem->AddElement(Rectangle(0, 0, searchItemWidth, H_ITEM + pContactsApp->GetFontHeightOffset()), 0, *(static_cast<ICustomElement *>(pCustomElement)));
104 if (pContactsApp->GetOperationId().IsEmpty() == false || __itemAnnexStyle == LIST_ANNEX_STYLE_MARK)
109 __pContactListPresentationModel->GetItemMainIndex(itemIndex, groupItemMainIndex, ItemMainIndex);
111 bool isCallEnabled = true;
112 bool isMessageEnabled = true;
113 if (__pContactListPresentationModel->GetDefaultPhoneNumber(groupItemMainIndex, ItemMainIndex).IsEmpty())
115 isCallEnabled = false;
118 if ((__pContactListPresentationModel->GetDefaultPhoneNumber(groupItemMainIndex, ItemMainIndex).IsEmpty()) && (__pContactListPresentationModel->GetDefaultEmail(groupItemMainIndex, ItemMainIndex).IsEmpty()))
120 isMessageEnabled = false;
123 ListContextItem* pItemContext = new (std::nothrow) ListContextItem();
124 pItemContext->Construct();
125 pItemContext->AddElement(IDA_LIST_ELEMENT_CALL, ResourceManager::GetString(L"IDS_COM_BODY_CALL"), isCallEnabled);
126 pItemContext->AddElement(IDA_LIST_ELEMENT_MESSAGE, ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"), isMessageEnabled);
127 #if __SUPPORT_VIDEO_CALL
128 pItemContext->AddElement(IDA_LIST_ELEMENT_VIDEO_CALL, ResourceManager::GetString(L"IDS_COM_BODY_VIDEO_CALL"), isCallEnabled);
130 if (__showDeleteOption == true)
132 pItemContext->AddElement(IDA_LIST_ELEMENT_DELETE, ResourceManager::GetString(L"IDS_COM_SK_DELETE"));
134 pItemContext->SetElementBackgroundColor(IDA_LIST_ELEMENT_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, COLOR_DELETE_ELEMENT_NORMAL);
135 pItemContext->SetElementBackgroundColor(IDA_LIST_ELEMENT_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_PRESSED, COLOR_DELETE_ELEMENT_PRESSED);
136 pItemContext->SetElementTextColor(IDA_LIST_ELEMENT_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, COLOR_DELETE_ELEMENT_TEXT);
138 pItem->SetContextItem(pItemContext);
143 Tizen::Ui::Controls::GroupItem*
144 SearchListEventListener::CreateGroupItem(int groupIndex, int itemWidth)
146 GroupItem* pItem = new (std::nothrow) GroupItem();
147 pItem->Construct(Dimension(itemWidth, H_GROUP_ITEM));
148 pItem->SetElement(ResourceManager::GetString("IDS_COM_BODY_CONTACTS") + L" (" + Integer::ToString(__pContactListPresentationModel->GetSearchedContactCount()) + L")");
154 SearchListEventListener::DeleteItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
156 CustomItem* pCustomItem = static_cast<CustomItem *>(pItem);
157 pCustomItem->RemoveAllElements();
166 SearchListEventListener::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::GroupItem* pItem, int itemWidth)
175 SearchListEventListener::SetShowDeleteOption(bool showDeleteOption)
177 __showDeleteOption = showDeleteOption;