3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file ClkCityListCustomItem
20 * @brief This header file contains the declarations of the CityListCustomItem
24 #include <FUiControls.h>
25 #include "ClkCityListCustomItem.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Utility;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Ui::Controls;
33 static const int IDA_FORMAT_STRING = 101;
34 static const int IDA_FORMAT_SUB_STRING = 102;
35 static const int IDA_FORMAT_RIGHT_SUB_STRING = 103;
37 CityListCustomItem::CityListCustomItem(void)
46 CityListCustomItem::~CityListCustomItem(void)
52 CityListCustomItem::Construct(int width, int height, bool searchBarModeOn)
57 searchBarModeInput = searchBarModeOn;
58 const Dimension dim(width, height);
59 r = CustomItem::Construct(dim, LIST_ANNEX_STYLE_NORMAL);
65 CityListCustomItem::SetText(String& text)
71 CityListCustomItem::GetText(void)
77 CityListCustomItem::SetSubText(String& text)
80 __subText.Append(text);
84 CityListCustomItem::GetSubText(void)
90 CityListCustomItem::SetRightSubText(String& text)
92 __rightSubText.Clear();
93 __rightSubText.Append(text);
97 CityListCustomItem::GetRightSubText(void)
99 return __rightSubText;
103 CityListCustomItem::Make(String& searchText, int mainTextFont)
105 result r = E_SUCCESS;
106 Color pressedTextColor = Color(255, 255, 255);
107 int textSize = mainTextFont;
110 int width_Element = __width - 60;
111 int width_text = width_Element - 200;
112 int width_rightSubText = 200;
113 int stringHeight = mainTextFont + 18;
114 int subStringHeight = 42;
115 int subStringFont = 32;
117 EnrichedText subText;
118 EnrichedText rightSubText;
119 TextElement* textElement = null;
120 TextElement* subTextElement = null;
121 TextElement* rightSubTextElement = null;
122 int compareValue = -1;
125 String* token = NULL;
131 Color textColor = Color(0, 0, 0);
132 Color redColor = Color(59, 115, 182);
133 String strSearchText = L"";
136 text.Construct(Dimension(width_text, stringHeight));
137 subText.Construct(Dimension(width_Element, subStringHeight));
138 rightSubText.Construct(Dimension(width_Element,subStringHeight));
142 if (searchText == L"")
144 token = new String();
156 length = __text.GetLength();
158 strSearchText = searchText;
159 strSearchText.ToLowerCase();
163 token = new String();
173 r = str.IndexOf(strSearchText, 0, index);
175 if(r == E_OBJ_NOT_FOUND)
179 __text.Remove(0, __text.GetLength());
186 __text.SubString(0, searchText.GetLength(), *token);
187 __text.Remove(0,searchText.GetLength());
193 __text.SubString(0, index, *token);
195 __text.Remove(0, index);
199 length = __text.GetLength();
203 textFont.Construct(FONT_STYLE_BOLD, textSize);
205 length = tokens.GetCount();
206 while (count < length)
208 pStr = static_cast< String* > (tokens.GetAt(count));
210 textElement = new (std::nothrow) TextElement();
211 textElement->Construct();
213 textElement->SetFont(textFont);
214 textElement->SetText(*pStr);
217 //compareValue = String::Compare(searchText, *pStr);
218 compareValue = pStr->Equals(searchText, false);
220 if (compareValue == 1)
222 textElement->SetTextColor(redColor);
226 textElement->SetTextColor(textColor);
229 text.Add(*textElement);
233 AddElement(Rectangle(xMargin, yMargin, width_text, stringHeight), IDA_FORMAT_STRING, text);
235 text.RemoveAll(true);
236 tokens.RemoveAll(true);
238 if (searchText == L"")
240 token = new String();
252 length = __subText.GetLength();
254 strSearchText = searchText;
255 strSearchText.ToLowerCase();
259 token = new String();
269 r = str.IndexOf(strSearchText, 0, index);
271 if(r == E_OBJ_NOT_FOUND)
275 __subText.Remove(0, __subText.GetLength());
282 __subText.SubString(0, searchText.GetLength(), *token);
283 __subText.Remove(0,searchText.GetLength());
289 __subText.SubString(0, index, *token);
291 __subText.Remove(0, index);
295 length = __subText.GetLength();
299 subTextFont.Construct(FONT_STYLE_BOLD, subStringFont);
302 if (searchBarModeInput == true)
303 textColor = Color(0,0,0);
305 textColor = Color(128,128,128);
307 length = tokens.GetCount();
309 rightSubText.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
311 while (count < length)
313 pStr = static_cast< String* > (tokens.GetAt(count));
315 subTextElement = new (std::nothrow) TextElement();
316 subTextElement->Construct();
318 subTextElement->SetFont(subTextFont);
319 subTextElement->SetText(*pStr);
321 //compareValue = String::Compare(searchText, *pStr);
323 compareValue = pStr->Equals(searchText, false);
325 if (compareValue == 1)
327 subTextElement->SetTextColor(redColor);
331 subTextElement->SetTextColor(textColor);
334 subText.Add(*subTextElement);
339 AddElement(Rectangle(xMargin, yMargin + stringHeight, width_Element, subStringHeight), IDA_FORMAT_SUB_STRING, subText);
341 subText.RemoveAll(true);
342 tokens.RemoveAll(true);
344 if(searchText == L"")
346 token = new String();
353 *token = __rightSubText;
358 tokens.Add(new String("GMT"));
359 __rightSubText.Remove(0, 3);
360 length = __rightSubText.GetLength();
364 token = new String();
371 r = __rightSubText.IndexOf(searchText, 0, index);
373 if (r == E_OBJ_NOT_FOUND)
375 *token = __rightSubText;
377 __rightSubText.Remove(0, __rightSubText.GetLength());
389 __rightSubText.SubString(0, index, *token);
391 __rightSubText.Remove(0, index);
394 __rightSubText.Remove(0,searchText.GetLength());
395 token = new String();
405 length = __rightSubText.GetLength();
412 if (searchBarModeInput == true)
413 textColor = Color(0,0,0);
415 textColor = Color(128,128,128);
417 length = tokens.GetCount();
419 rightSubText.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
421 while (count < length)
423 pStr = static_cast< String* > (tokens.GetAt(count));
425 rightSubTextElement = new (std::nothrow) TextElement();
426 rightSubTextElement->Construct();
428 rightSubTextElement->SetFont(subTextFont);
429 rightSubTextElement->SetText(*pStr);
431 compareValue = String::Compare(searchText, *pStr);
433 if (compareValue == 0 && count > 0)
435 rightSubTextElement->SetTextColor(redColor);
439 rightSubTextElement->SetTextColor(textColor);
442 rightSubText.Add(*rightSubTextElement);
447 AddElement(Rectangle(xMargin + width_text - 18 /*+ 16*/, yMargin, width_rightSubText, subStringHeight), IDA_FORMAT_RIGHT_SUB_STRING, rightSubText);
449 rightSubText.RemoveAll(true);
450 tokens.RemoveAll(true);