2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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 PhnSuggestionItemProvider.cpp
19 * @brief Suggestion list item provider class
25 #include "PhnAppUtility.h"
26 #include "PhnCommonUtils.h"
27 #include "PhnDialContactInfo.h"
28 #include "PhnDialPresentationModel.h"
29 #include "PhnSuggestionItemProvider.h"
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Media;
35 using namespace Tizen::System;
36 using namespace Tizen::Social;
37 using namespace Tizen::Base::Collection;
39 SuggestionItemProvider::SuggestionItemProvider(
40 DialPresentationModel& pDialPresentationModel) :
41 __dialPresentationModel(pDialPresentationModel)
45 SuggestionItemProvider::~SuggestionItemProvider(void)
50 SuggestionItemProvider::CreateItem(int index, int itemWidth)
52 CustomItem* pItem = null;
53 //Check if any suggestion exist at 'index+1'.
54 DialContactInfo* pDialInfo = __dialPresentationModel.GetSuggestionAtIndex(index+1);
59 //Construct List view item
60 pItem = new (std::nothrow) CustomItem();
61 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
62 pItem->Construct(Dimension(itemWidth, 128), style);
64 //create enriched text - Display name with Keyword
65 String* keyWord = pDialInfo->GetSearchKey();
66 EnrichedText* pEnrichedName = ConstructEnrichedTextN(pDialInfo->GetDisplayName(), *keyWord , FONT_SUGGESTION_NAME, BUTTON_STATUS_NORMAL);
67 pItem->AddElement(Rectangle(16, 10, 445, 60), 202, *pEnrichedName);
71 //create text element - Phone number with Keyword
72 String phoneNumber(L"Mobile ");
73 phoneNumber.Append(pDialInfo->GetPhoneNumber());
74 EnrichedText* pEnrichedMobile = ConstructEnrichedTextN(phoneNumber, *keyWord, FONT_SUGGESTION_MOBILE, BUTTON_STATUS_NORMAL);
75 pItem->AddElement(Rectangle(16, 70, 445, 48), 204, *pEnrichedMobile);
76 delete pEnrichedMobile;
77 pEnrichedMobile =null;
79 //Fetch contact's thumbnail
80 Bitmap* pContactBitmap = pDialInfo->GetThumbnailN();
82 if(pContactBitmap == null)
84 pContactBitmap = AppUtility::GetBitmapFromResourcesN(L"C01-1_icon_contacts.png");
86 pItem->AddElement(Rectangle(445, 16, 96, 96), 206, *pContactBitmap);
87 delete pContactBitmap;
93 SuggestionItemProvider::ConstructEnrichedTextN(String& text, String& keyword, int textFontStyle, int buttonStatus)
96 Font* fontName = DialUtil::GetTextFontN(textFontStyle);
98 Color* textColor = DialUtil::GetTextColorN(textFontStyle, buttonStatus);
99 //highlighted text Color
100 Color* highlightedTxtColor = DialUtil::GetTextColorN(FONT_HIGHLIGHT_SEARCH_KEYWORD,buttonStatus);
102 EnrichedText* pEnrichedName = new (std::nothrow) EnrichedText();
103 pEnrichedName->Construct(Dimension(400, 60));
105 //Text is divided in 3 parts - pre-text, highlighted keyword, post-text.
107 String highlightTxt(L"");
109 if(keyword.IsEmpty() == false)
112 result r = text.IndexOf(keyword,0,searchIndex);
117 text.SubString(0,searchIndex,preTxt);
119 text.SubString(searchIndex,keyword.GetLength(),highlightTxt);
120 text.SubString((searchIndex+keyword.GetLength()),postTxt);
128 TextElement* pTextName = null;
129 if(preTxt.IsEmpty() == false)
131 //create text element
132 pTextName = new (std::nothrow) TextElement();
133 pTextName->Construct(preTxt);
134 pTextName->SetFont(*fontName);
135 pTextName->SetTextColor(*textColor);
136 //ownership of 'pTextName' transferred to 'pEnrichedName'
137 pEnrichedName->Add(*pTextName);
140 if(highlightTxt.IsEmpty() == false)
142 //create text element
143 pTextName = new (std::nothrow) TextElement();
144 pTextName->Construct(highlightTxt);
145 pTextName->SetFont(*fontName);
146 // Highlighted search text
147 pTextName->SetTextColor(*highlightedTxtColor);
148 pEnrichedName->Add(*pTextName);
151 if(postTxt.IsEmpty() == false)
153 //create text element
154 pTextName = new (std::nothrow) TextElement();
155 pTextName->Construct(postTxt);
156 pTextName->SetFont(*fontName);
157 pTextName->SetTextColor(*textColor);
158 pEnrichedName->Add(*pTextName);
163 delete highlightedTxtColor;
165 return pEnrichedName;
169 SuggestionItemProvider::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
180 SuggestionItemProvider::GetItemCount(void)
182 return __dialPresentationModel.GetNumberOfSuggestions() - 1;