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 CommonUtils.cpp
19 * @brief commonly used functions
24 #include <FGraphics.h>
25 #include "PhnAppUtility.h"
26 #include "PhnCommonUtils.h"
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Base::Collection;
34 const int ID_NAME_STRING = 100;
35 const int ID_NUMBER_STRING = 101;
36 const int ID_TIME_STRING = 102;
37 const int ID_CONTACT_BITMAP = 103;
38 const int ID_CALLTYPE_BITMAP = 104;
41 const int X_TEXT_LINE1_ITEM = 16;
42 const int Y_TEXT_LINE1_ITEM = 10;
43 const int H_TEXT_LINE1_ITEM = 60;
44 const int W_TEXT_LINE1_ITEM = 560;
46 const int X_TEXT_LINE2_ITEM = 64;
47 const int Y_TEXT_LINE2_ITEM = 70;
48 const int H_TEXT_LINE2_ITEM = 48;
49 const int W_TEXT_LINE2_ITEM = 256;
51 const int X_TEXT_TIME_ITEM = 320;
52 const int Y_TEXT_TIME_ITEM = 70;
53 const int H_TEXT_TIME_ITEM = 48;
54 const int W_TEXT_TIME_ITEM = 256;
56 const int X_CONTACT_BITMAP_ITEM = 592;
57 const int Y_CONTACT_BITMAP_ITEM = 0;
58 const int H_CONTACT_BITMAP_ITEM = 128;
59 const int W_CONTACT_BITMAP_ITEM = 128;
61 const int X_CALLTYPE_BITMAP_ITEM = 16;
62 const int Y_CALLTYPE_BITMAP_ITEM = 70 + 8;
63 const int H_CALLTYPE_BITMAP_ITEM = 32;
64 const int W_CALLTYPE_BITMAP_ITEM = 32;
66 const int X_DIALER_BTN_TXT = 13;
67 const int W_DIALER_BTN_NUM_TXT = 77;
68 const int W_DIALER_BTN_ALPHA_TXT = 121;
70 const int W_ENRICHED_TEXT = 190;
71 const int X_ENRICHED_TEXT = 143;
74 DialUtil::GetTextFontN(int textFontStyle)
76 Font* font = new (std::nothrow) Font();
78 switch (textFontStyle)
80 case FONT_CALLING_TEXT:
82 font->Construct(FONT_STYLE_PLAIN, 94);
86 case FONT_KEYPAD_NUMBER:
88 font->Construct(FONT_STYLE_PLAIN, 116);
92 case FONT_KEYPAD_TEXT:
94 font->Construct(FONT_STYLE_BOLD, 40);
100 font->Construct(FONT_STYLE_BOLD, 56);
104 case FONT_KEYPAD_PLUS:
106 font->Construct(FONT_STYLE_BOLD, 64);
110 case FONT_KEYPAD_CANCEL:
112 font->Construct(FONT_STYLE_PLAIN, 34);
116 case FONT_SUGGESTION_NAME:
118 font->Construct(FONT_STYLE_PLAIN, 40);
122 case FONT_SUGGESTION_MOBILE:
124 font->Construct(FONT_STYLE_PLAIN, 35);
128 case FONT_SUGGESTION_NUMBER:
130 font->Construct(FONT_STYLE_PLAIN, 35);
134 case FONT_SUGGESTION_LIST_NUMBER:
136 font->Construct(FONT_STYLE_PLAIN, 40);
144 DialUtil::GetTextColorN(int textColor, int buttonStatus)
146 Color* color = new (std::nothrow) Color();
148 if (buttonStatus == BUTTON_STATUS_PRESSED)
150 color->SetColorComponents(249, 249, 249);
156 case FONT_CALLING_TEXT:
158 color->SetColorComponents(0, 0, 0);
162 case FONT_KEYPAD_NUMBER:
164 color->SetColorComponents(255, 255, 255);
168 case FONT_KEYPAD_TEXT:
170 case FONT_KEYPAD_PLUS:
172 color->SetColorComponents(148, 177, 200);
176 case FONT_KEYPAD_CANCEL:
178 color->SetColorComponents(255, 255, 255);
182 case FONT_SUGGESTION_NAME:
184 color->SetColorComponents(255, 255, 255);
188 case FONT_SUGGESTION_MOBILE:
190 color->SetColorComponents(148, 177, 200);
194 case FONT_HIGHLIGHT_SEARCH_KEYWORD:
195 case FONT_SUGGESTION_NUMBER:
197 color->SetColorComponents(26, 214, 227);
201 case FONT_SUGGESTION_LIST_NUMBER:
203 color->SetColorComponents(124, 189, 224);
211 DialUtil::IsNumericString(Tizen::Base::String& keyWord)
213 bool isDigit = false;
214 String digitStr(L"");
215 if(keyWord.SubString(0,1,digitStr) == E_SUCCESS)
218 if(Integer::Parse(digitStr,digit) == E_SUCCESS)
227 DialUtil::Draw9PatchToCanvas(Canvas& pCanvas, const String& bgImg)
229 AppResource* pAppResource = AppResource::GetInstance();
230 Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
232 if (pBitmap->IsNinePatchedBitmap())
234 pCanvas.DrawNinePatchedBitmap(pCanvas.GetBounds(), *pBitmap);
242 DialUtil::DrawImageToCanvas(const String& image, Dimension imageDimention, Canvas& pCanvas, int pos)
244 //create and scale bitmap
245 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(image, imageDimention.width, imageDimention.height);
247 //Find position to draw bitmap
248 Point bitmapPos(0, 0);
253 bitmapPos.SetPosition(X_DIALER_BTN_TXT + (W_DIALER_BTN_NUM_TXT - pBitmap->GetWidth()) / 2, (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
259 bitmapPos.SetPosition(X_DIALER_BTN_TXT + W_DIALER_BTN_NUM_TXT + ((W_DIALER_BTN_ALPHA_TXT - pBitmap->GetWidth()) / 2), (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
263 case POSITION_CENTER:
265 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
269 case POSITION_BOTTOM_CENTER:
271 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, pCanvas.GetBounds().height / 2 + (pCanvas.GetBounds().height / 2 - pBitmap->GetHeight()) / 2);
277 pCanvas.DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
285 DialUtil::DrawTextToCanvas(const String& buttonText, int textFontStyle, Canvas& pCanvas, int pos, int buttonStatus)
287 AppLogDebug("ENTER");
288 if (buttonText == null)
294 Font* font = GetTextFontN(textFontStyle);
297 Color* textColor = GetTextColorN(textFontStyle, buttonStatus);
299 //create text element
300 TextElement* pTextElement = new (std::nothrow) TextElement();
301 pTextElement->Construct(buttonText);
302 pTextElement->SetTextColor(*textColor);
303 pTextElement->SetFont(*font);
306 //get dimensions of the text
307 Dimension textDimension;
308 font->GetTextExtent(buttonText, buttonText.GetLength(), textDimension);
309 if(textFontStyle != FONT_KEYPAD_NUMBER)
311 textDimension.height += font->GetDescender();
314 //create enriched text
315 EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
316 pEnrichedText->Construct(textDimension);
317 pEnrichedText->Add(*pTextElement);
319 //set the position of the text in canvas
325 //Margin 13, rectangle for left text (13,0,77, height of canvas), center aligned
326 textPos.SetPosition(X_DIALER_BTN_TXT + ((W_DIALER_BTN_NUM_TXT - pEnrichedText->GetWidth()) / 2), (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
332 //rectangle for right text (13+77,0, 121, height of canvas), center aligned
333 textPos.SetPosition(X_DIALER_BTN_TXT + W_DIALER_BTN_NUM_TXT + ((121 - pEnrichedText->GetWidth()) / 2), (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
337 case POSITION_CENTER:
339 //rectangle for image : entire canvas, center aligned
340 textPos.SetPosition((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2, (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
344 case POSITION_TOP_LEFT:
346 textPos.SetPosition(10, (pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2);
350 case POSITION_TOP_CENTER:
352 textPos.SetPosition((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2, (pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2);
356 case POSITION_BOTTOM_LEFT:
358 textPos.SetPosition(10, pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
362 case POSITION_BOTTOM_CENTER:
364 int width = pEnrichedText->GetWidth();
365 if(width > W_ENRICHED_TEXT)
367 textPos.SetPosition(X_ENRICHED_TEXT, pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
371 textPos.SetPosition(10 + ((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2), pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
378 //Draw EnrichedText to canvas
379 pCanvas.DrawText(textPos, *pEnrichedText);
382 pEnrichedText->RemoveAll(true);
383 delete pEnrichedText;
391 DialUtil::DrawCanvasToButton(Canvas* pCanvasNormal, Canvas* pCanvasPressed, Button* pButton)
393 Bitmap* pNormalBgBmp = new (std::nothrow) Bitmap();
394 pNormalBgBmp->Construct(*pCanvasNormal, pCanvasNormal->GetBounds());
396 pButton->SetNormalBackgroundBitmap(*pNormalBgBmp);
398 if (pCanvasPressed != null)
400 Bitmap* pPressedBgBmp = new (std::nothrow) Bitmap();
401 pPressedBgBmp->Construct(*pCanvasPressed, pCanvasPressed->GetBounds());
402 pButton->SetPressedBackgroundBitmap(*pPressedBgBmp);
403 delete pPressedBgBmp;
404 pPressedBgBmp = null;
408 pButton->SetPressedBackgroundBitmap(*pNormalBgBmp);
411 pButton->SetDisabledBitmap(Point(0, 0), *pNormalBgBmp);
412 pButton->Invalidate(true);
420 DialUtil::ConvertDialedNumberToString(int dialNumber)
471 DialUtil::FetchPossibleNamesListN(const String& prevSearchStr, int nextDigit)
473 //Fetch matching names for mapping char for digit, e.g. 2->ABC, 3->DEF.
474 ArrayList* pNamesList = new (std::nothrow) ArrayList(SingleObjectDeleter);
475 pNamesList->Construct(8);
477 if(nextDigit >=2 && nextDigit <= 9)
483 pNamesList->Add((new String(prevSearchStr+L"a")));
484 pNamesList->Add((new String(prevSearchStr+L"b")));
485 pNamesList->Add((new String(prevSearchStr+L"c")));
486 pNamesList->Add((new String(prevSearchStr+L"A")));
487 pNamesList->Add((new String(prevSearchStr+L"B")));
488 pNamesList->Add((new String(prevSearchStr+L"C")));
494 pNamesList->Add((new String(prevSearchStr+L"d")));
495 pNamesList->Add((new String(prevSearchStr+L"e")));
496 pNamesList->Add((new String(prevSearchStr+L"f")));
497 pNamesList->Add((new String(prevSearchStr+L"D")));
498 pNamesList->Add((new String(prevSearchStr+L"E")));
499 pNamesList->Add((new String(prevSearchStr+L"F")));
505 pNamesList->Add((new String(prevSearchStr+L"g")));
506 pNamesList->Add((new String(prevSearchStr+L"h")));
507 pNamesList->Add((new String(prevSearchStr+L"i")));
508 pNamesList->Add((new String(prevSearchStr+L"G")));
509 pNamesList->Add((new String(prevSearchStr+L"H")));
510 pNamesList->Add((new String(prevSearchStr+L"I")));
516 pNamesList->Add((new String(prevSearchStr+L"j")));
517 pNamesList->Add((new String(prevSearchStr+L"k")));
518 pNamesList->Add((new String(prevSearchStr+L"l")));
519 pNamesList->Add((new String(prevSearchStr+L"J")));
520 pNamesList->Add((new String(prevSearchStr+L"K")));
521 pNamesList->Add((new String(prevSearchStr+L"L")));
527 pNamesList->Add((new String(prevSearchStr+L"m")));
528 pNamesList->Add((new String(prevSearchStr+L"n")));
529 pNamesList->Add((new String(prevSearchStr+L"o")));
530 pNamesList->Add((new String(prevSearchStr+L"M")));
531 pNamesList->Add((new String(prevSearchStr+L"N")));
532 pNamesList->Add((new String(prevSearchStr+L"O")));
538 pNamesList->Add((new String(prevSearchStr+L"p")));
539 pNamesList->Add((new String(prevSearchStr+L"q")));
540 pNamesList->Add((new String(prevSearchStr+L"r")));
541 pNamesList->Add((new String(prevSearchStr+L"s")));
542 pNamesList->Add((new String(prevSearchStr+L"P")));
543 pNamesList->Add((new String(prevSearchStr+L"Q")));
544 pNamesList->Add((new String(prevSearchStr+L"R")));
545 pNamesList->Add((new String(prevSearchStr+L"S")));
551 pNamesList->Add((new String(prevSearchStr+L"t")));
552 pNamesList->Add((new String(prevSearchStr+L"u")));
553 pNamesList->Add((new String(prevSearchStr+L"v")));
554 pNamesList->Add((new String(prevSearchStr+L"T")));
555 pNamesList->Add((new String(prevSearchStr+L"U")));
556 pNamesList->Add((new String(prevSearchStr+L"V")));
562 pNamesList->Add((new String(prevSearchStr+L"w")));
563 pNamesList->Add((new String(prevSearchStr+L"x")));
564 pNamesList->Add((new String(prevSearchStr+L"y")));
565 pNamesList->Add((new String(prevSearchStr+L"z")));
566 pNamesList->Add((new String(prevSearchStr+L"W")));
567 pNamesList->Add((new String(prevSearchStr+L"X")));
568 pNamesList->Add((new String(prevSearchStr+L"Y")));
569 pNamesList->Add((new String(prevSearchStr+L"Z")));
579 DialUtil::ConvertNameToNumericKeys(String& subContactName, String& possibleKeysTyped)
581 for(int charPos=0;charPos < subContactName.GetLength();charPos++)
584 subContactName.GetCharAt(charPos,nextChar);
590 possibleKeysTyped.Append(2);
596 possibleKeysTyped.Append(3);
602 possibleKeysTyped.Append(4);
608 possibleKeysTyped.Append(5);
614 possibleKeysTyped.Append(6);
621 possibleKeysTyped.Append(7);
627 possibleKeysTyped.Append(8);
634 possibleKeysTyped.Append(9);