aad8adad37985d1abe1156631b26b4ea985c038b
[apps/osp/Dial.git] / src / PhnCommonUtils.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  *  @file   CommonUtils.cpp
19  *  @brief  commonly used functions
20  */
21
22 #include <FApp.h>
23 #include <FMedia.h>
24 #include <FGraphics.h>
25 #include "PhnAppUtility.h"
26 #include "PhnCommonUtils.h"
27
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;
33
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;
39 const int ID_NAME_STRING_COUNTER = 105;
40 const int ID_LOGCALL_BITMAP = 50;
41 const int ID_NAME_STRING_FONT_SIZE = 44;
42 static const int X_LIST_DISPNAME = 26;
43 static const int Y_LIST_DISPNAME = 22;
44 static const int X_LIST_NUMBER = 26;
45 static const int Y_LIST_NUMBER = 76;//22+54;
46
47 const int X_TEXT_LINE1_ITEM = 16;
48 const int Y_TEXT_LINE1_ITEM = 10;
49 const int H_TEXT_LINE1_ITEM = 60;
50 const int W_TEXT_LINE1_ITEM = 560;
51 const int W_TEXT_LINE1_ITEM_RIGHT_MARGIN = 170;
52 const int W_TEXT_LINE1_ITEM_COUNTER = 80;
53
54 const int X_TEXT_LINE2_ITEM = 64;
55 const int Y_TEXT_LINE2_ITEM = 70;
56 const int H_TEXT_LINE2_ITEM = 48;
57 const int W_TEXT_LINE2_ITEM = 256;
58 const int W_TEXT_LINE2_ITEM_RIGHT_MARGIN = 230;
59 const int W_TEXT_LINE2_ITEM_RIGHT_MARGIN_DELETE = 96;
60
61 const int X_TEXT_TIME_ITEM = 440;
62 const int Y_TEXT_TIME_ITEM = 70;
63 const int H_TEXT_TIME_ITEM = 48;
64 const int W_TEXT_TIME_ITEM = 256;
65 const int X_TEXT_TIME_ITEM_RIGHT_MARGIN = 280;
66
67 const int X_CONTACT_BITMAP_ITEM = 592;
68 const int Y_CONTACT_BITMAP_ITEM = 0;
69 const int H_CONTACT_BITMAP_ITEM = 177;
70 const int W_CONTACT_BITMAP_ITEM = 177;
71
72 const int X_CALLTYPE_BITMAP_ITEM = 16;
73 const int Y_CALLTYPE_BITMAP_ITEM = 70 + 8;
74 const int H_CALLTYPE_BITMAP_ITEM = 32;
75 const int W_CALLTYPE_BITMAP_ITEM = 32;
76
77 //New Keypad Button Images for numbers
78 const int X_DIALER_BTN_IMG = 0;
79 const int Y_DIALER_BTN_IMG = 10;
80
81 //Call Patch Coordinates
82 const int X_CALL_PATCH = 36;
83 const int Y_CALL_PATCH = 18;
84 const int W_CALL_PATCH = 444;
85 const int H_CALL_PATCH = 104;
86
87 //Clear Button Patch Coordinates
88 const int X_CLEAR_PATCH = 0;
89 const int Y_CLEAR_PATCH = 18;
90 const int W_CLEAR_PATCH = 180;
91 const int H_CLEAR_PATCH = 104;
92
93 const int X_LOGCALL_BITMAP_ITEM = 660;
94 const int Y_LOGCALL_BITMAP_ITEM = 10;
95 const int W_LOGCALL_BITMAP_ITEM = 38;
96 const int H_LOGCALL_BITMAP_ITEM = 38;
97 const int X_LOGCALL_BITMAP_RIGHT_MARGIN = 60;
98
99 const int X_DIALER_BTN_TXT = 13;
100 const int W_DIALER_BTN_NUM_TXT = 77;
101 const int W_DIALER_BTN_ALPHA_TXT = 121;
102
103 const int W_ENRICHED_TEXT = 190;
104 const int X_ENRICHED_TEXT = 143;
105 const int IDI_RIGHT_MARGIN_USE_CONTACT_BTN = 220;
106 const int H_USE_CONTACT_BTN = 60;
107
108 Font*
109 DialUtil::GetTextFontN(int textFontStyle)
110 {
111         Font* font = new (std::nothrow) Font();
112
113         switch (textFontStyle)
114         {
115         case FONT_CALLING_TEXT:
116         {
117                 font->Construct(FONT_STYLE_PLAIN, 94);
118         }
119         break;
120
121         case FONT_SEARCH_TEXT:
122         {
123                 font->Construct(FONT_STYLE_PLAIN, 36);
124         }
125         break;
126
127         case FONT_KEYPAD_NUMBER:
128         {
129                 font->Construct(FONT_STYLE_PLAIN, 116);
130         }
131         break;
132
133         case FONT_KEYPAD_TEXT:
134         {
135                 font->Construct(FONT_STYLE_PLAIN, 28);
136         }
137         break;
138
139         case FONT_KEYPAD_P:
140         {
141                 font->Construct(FONT_STYLE_PLAIN, 28);
142         }
143         break;
144
145         case FONT_KEYPAD_PLUS:
146         {
147                 font->Construct(FONT_STYLE_PLAIN, 40);
148         }
149         break;
150
151         case FONT_KEYPAD_CANCEL:
152         {
153                 font->Construct(FONT_STYLE_PLAIN, 34);
154         }
155         break;
156
157         case FONT_SUGGESTION_NAME:
158         {
159                 font->Construct(FONT_STYLE_PLAIN, 44);
160         }
161         break;
162
163         case FONT_SUGGESTION_MOBILE:
164         {
165                 font->Construct(FONT_STYLE_PLAIN, 35);
166         }
167         break;
168
169         case FONT_SUGGESTION_NUMBER:
170         {
171                 font->Construct(FONT_STYLE_PLAIN, 32);
172         }
173         break;
174
175         case FONT_SUGGESTION_LIST_NUMBER:
176         {
177                 font->Construct(FONT_STYLE_PLAIN, 40);
178         }
179         break;
180         case FONT_EXPAND_BUTTON_TEXT:
181         {
182                 font->Construct(FONT_STYLE_PLAIN, 30);
183         }
184         break;
185         case FONT_SPEEDDIAL_BTN_NUMBER:
186         {
187                 font->Construct(FONT_STYLE_BOLD, 86);
188         }
189         break;
190         }
191         return font;
192 }
193
194 Color*
195 DialUtil::GetTextColorN(int textColor, int buttonStatus)
196 {
197         Color* color = new (std::nothrow) Color();
198
199         if (buttonStatus == BUTTON_STATUS_PRESSED)
200         {
201                 //color->SetColorComponents(249, 249, 249);
202                 color->SetColorComponents(145, 135, 114);
203                 return color;
204         }
205
206         switch (textColor)
207         {
208         case FONT_CALLING_TEXT:
209         {
210                 color->SetColorComponents(0, 0, 0);
211         }
212         break;
213
214         case FONT_SEARCH_TEXT:
215         {
216                 color->SetColorComponents(156, 159, 162);
217         }
218         break;
219
220         case FONT_SPEEDDIAL_BTN_NUMBER:
221         case FONT_KEYPAD_NUMBER:
222         {
223                 color->SetColorComponents(255, 255, 255);
224         }
225         break;
226
227         case FONT_KEYPAD_TEXT:
228         case FONT_KEYPAD_P:
229         case FONT_KEYPAD_PLUS:
230         {
231                 color->SetColorComponents(145, 135, 114);
232         }
233         break;
234
235         case FONT_KEYPAD_CANCEL:
236         {
237                 color->SetColorComponents(255, 255, 255);
238         }
239         break;
240
241         case FONT_SUGGESTION_NAME:
242         {
243                 color->SetColorComponents(0, 0, 0);
244         }
245         break;
246
247         case FONT_SUGGESTION_MOBILE:
248         {
249                 color->SetColorComponents(153, 153, 153);
250         }
251         break;
252
253         case FONT_HIGHLIGHT_SEARCH_KEYWORD:
254         {
255                 color->SetColorComponents(59, 115, 182);
256         }
257         break;
258         case FONT_SUGGESTION_NUMBER:
259         {
260                 color->SetColorComponents(153, 153, 153);
261         }
262         break;
263
264         case FONT_SUGGESTION_LIST_NUMBER:
265         {
266                 color->SetColorComponents(50, 50, 50);
267         }
268         break;
269         case FONT_EXPAND_BUTTON_TEXT:
270         {
271                 color->SetColorComponents(50, 50, 50);
272         }
273         break;
274         }
275         return color;
276 }
277
278 bool
279 DialUtil::IsNumericString(Tizen::Base::String& keyWord)
280 {
281         bool isDigit = false;
282         String digitStr(L"");
283         if(keyWord.SubString(0,1,digitStr) == E_SUCCESS)
284         {
285                 int digit;
286                 if(Integer::Parse(digitStr,digit) == E_SUCCESS)
287                 {
288                         isDigit = true;
289                 }
290         }
291         return isDigit;
292 }
293 void
294 DialUtil::DrawBitmapToCanvas(Tizen::Graphics::Canvas& pCanvas, const Tizen::Base::String& bgImg)
295 {
296         AppResource* pAppResource = AppResource::GetInstance();
297         Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
298         pCanvas.DrawBitmap(pCanvas.GetBounds(),*pBitmap);
299 }
300
301 void
302 DialUtil::DrawClear9PatchToCanvas(Tizen::Graphics::Canvas& pCanvas, const Tizen::Base::String& bgImg)
303 {
304         AppResource* pAppResource = AppResource::GetInstance();
305         Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
306         if (pBitmap->IsNinePatchedBitmap())
307         {
308                 pCanvas.DrawNinePatchedBitmap(Rectangle(X_CLEAR_PATCH,Y_CLEAR_PATCH,W_CLEAR_PATCH,H_CLEAR_PATCH), *pBitmap);
309         }
310         pCanvas.DrawBitmap(Rectangle(X_CLEAR_PATCH,Y_CLEAR_PATCH, W_CLEAR_PATCH, H_CLEAR_PATCH), *pBitmap);
311         delete pBitmap;
312
313 }
314
315 void
316 DialUtil::DrawCall9PatchToCanvas(Tizen::Graphics::Canvas& pCanvas, const Tizen::Base::String& bgImg)
317 {
318         AppResource* pAppResource = AppResource::GetInstance();
319         Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
320         if (pBitmap->IsNinePatchedBitmap())
321         {
322                 pCanvas.DrawNinePatchedBitmap(Rectangle(X_CALL_PATCH,Y_CALL_PATCH,W_CALL_PATCH,H_CALL_PATCH), *pBitmap);
323         }
324         pCanvas.DrawBitmap(Rectangle(X_CALL_PATCH,Y_CALL_PATCH, W_CALL_PATCH, H_CALL_PATCH), *pBitmap);
325         delete pBitmap;
326
327 }
328
329 void
330 DialUtil::Draw9PatchToCanvas(Canvas& pCanvas, const String& bgImg)
331 {
332         AppResource* pAppResource = AppResource::GetInstance();
333         Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
334
335         pBitmap->GetWidth();
336         if (pBitmap->IsNinePatchedBitmap())
337         {
338                 pCanvas.DrawNinePatchedBitmap(pCanvas.GetBounds(), *pBitmap);
339         }
340         else
341         {
342                 pCanvas.DrawBitmap(pCanvas.GetBounds(),*pBitmap);
343         }
344         delete pBitmap;
345
346         return;
347 }
348
349
350 void
351 DialUtil::DrawKeypadImageToCanvas(const Tizen::Base::String& image, Tizen::Graphics::Dimension imageDimention, Tizen::Graphics::Canvas& pCanvas, int pos)
352 {
353         //create and scale bitmap
354         Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(image, imageDimention.width, imageDimention.height);
355         //Find position to draw bitmap
356         Point bitmapPos(0, 0);
357
358         switch(pos)
359         {
360         case POSITION_TOP_CENTER:
361         {
362                 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2,Y_DIALER_BTN_IMG);
363         }
364         break;
365         case POSITION_BOTTOM_CENTER:
366         {
367                 //bitmapPos.SetPosition(X_DIALER_BTN_IMG,Y_DIALER_BTN_IMG);
368                 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, 20 + pCanvas.GetBounds().height / 2 + (pCanvas.GetBounds().height / 2 - pBitmap->GetHeight()) / 2);
369         }
370         break;
371         }
372
373         pCanvas.DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
374         delete pBitmap;
375         pBitmap = null;
376
377         return;
378
379 }
380
381
382
383
384 void
385 DialUtil::DrawImageToCanvas(const String& image, Dimension imageDimention, Canvas& pCanvas, int pos)
386 {
387         //create and scale bitmap
388         Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(image, imageDimention.width, imageDimention.height);
389
390         //Find position to draw bitmap
391         Point bitmapPos(0, 0);
392         switch (pos)
393         {
394         case POSITION_LEFT:
395         {
396                 bitmapPos.SetPosition(X_DIALER_BTN_TXT + (W_DIALER_BTN_NUM_TXT - pBitmap->GetWidth()) / 2, (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
397         }
398         break;
399
400         case POSITION_RIGHT:
401         {
402                 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);
403         }
404         break;
405
406         case POSITION_CENTER:
407         {
408                 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
409         }
410         break;
411
412         case POSITION_BOTTOM_CENTER:
413         {
414                 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, pCanvas.GetBounds().height / 2 + (pCanvas.GetBounds().height / 2 - pBitmap->GetHeight()) / 2);
415         }
416         break;
417         }
418
419         //draw bitmap
420         pCanvas.DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
421         delete pBitmap;
422         pBitmap = null;
423
424         return;
425 }
426
427 void
428 DialUtil::DrawKeypadTextToCanvas(const String& buttonText, int textFontStyle, Canvas& pCanvas, int pos, int buttonStatus)
429 {
430         AppLogDebug("ENTER");
431         if (buttonText == null)
432         {
433                 return;
434         }
435
436         //get text font
437         Font* font = GetTextFontN(textFontStyle);
438
439         //get text color
440         Color* textColor = GetTextColorN(textFontStyle, buttonStatus);
441
442         //create text element
443         TextElement* pTextElement = new (std::nothrow) TextElement();
444         pTextElement->Construct(buttonText);
445         pTextElement->SetTextColor(*textColor);
446         pTextElement->SetFont(*font);
447         delete textColor;
448
449         //get dimensions of the text
450         FloatDimension textDimension;
451         font->GetTextExtent(buttonText, buttonText.GetLength(), textDimension);
452         if(textFontStyle != FONT_KEYPAD_NUMBER)
453         {
454                 textDimension.height += font->GetDescender();
455         }
456
457         //create enriched text
458         EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
459         pEnrichedText->Construct(textDimension);
460         pEnrichedText->Add(*pTextElement);
461
462         //set the position of the text in canvas
463         Point textPos(0, 0);
464         switch (pos)
465         {
466         case POSITION_BOTTOM_CENTER:
467         {
468                 int width = pEnrichedText->GetWidth();
469                 textPos.SetPosition(((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2),
470                                                                                                                     20 + pCanvas.GetBounds().height / 2
471                                                                                                                         + ((pCanvas.GetBounds().height / 2
472                                                                                                                         - pEnrichedText->GetHeight()) / 2));
473         }
474         break;
475         }
476
477         //Draw EnrichedText to canvas
478         pCanvas.DrawText(textPos, *pEnrichedText);
479
480         // Cleans up
481         pEnrichedText->RemoveAll(true);
482         delete pEnrichedText;
483         delete font;
484
485         AppLogDebug("EXIT");
486         return;
487 }
488
489 void
490 DialUtil::DrawTextToCanvas(const String& buttonText, int textFontStyle, Canvas& pCanvas, int pos, int buttonStatus)
491 {
492         if (buttonText == null)
493         {
494                 return;
495         }
496
497         //get text font
498         Font* font = GetTextFontN(textFontStyle);
499
500         //get text color
501         Color* textColor = GetTextColorN(textFontStyle, buttonStatus);
502
503         //create text element
504         TextElement* pTextElement = new (std::nothrow) TextElement();
505         pTextElement->Construct(buttonText);
506         pTextElement->SetTextColor(*textColor);
507         pTextElement->SetFont(*font);
508         delete textColor;
509
510         //get dimensions of the text
511         FloatDimension textDimension;
512         font->GetTextExtent(buttonText, buttonText.GetLength(), textDimension);
513         if(textFontStyle != FONT_KEYPAD_NUMBER)
514         {
515                 textDimension.height += font->GetDescender();
516         }
517
518         //create enriched text
519         EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
520         pEnrichedText->Construct(textDimension);
521         pEnrichedText->Add(*pTextElement);
522
523         //set the position of the text in canvas
524         Point textPos(0, 0);
525         switch (pos)
526         {
527         case POSITION_LEFT:
528         {
529                 //Margin 13, rectangle for left text (13,0,77, height of canvas), center aligned
530                 textPos.SetPosition(X_DIALER_BTN_TXT + ((W_DIALER_BTN_NUM_TXT - pEnrichedText->GetWidth()) / 2), (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
531         }
532         break;
533
534         case POSITION_RIGHT:
535         {
536                 //rectangle for right text (13+77,0, 121, height of canvas), center aligned
537                 textPos.SetPosition(X_DIALER_BTN_TXT + W_DIALER_BTN_NUM_TXT + ((121 - pEnrichedText->GetWidth()) / 2), (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
538         }
539         break;
540
541         case POSITION_CENTER:
542         {
543                 //rectangle for image : entire canvas, center aligned
544                 textPos.SetPosition((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2, (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
545         }
546         break;
547
548         case POSITION_TOP_LEFT:
549         {
550                 textPos.SetPosition(10, (pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2);
551         }
552         break;
553
554         case POSITION_TOP_CENTER:
555         {
556                 textPos.SetPosition((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2, (pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2);
557         }
558         break;
559
560         case POSITION_BOTTOM_LEFT:
561         {
562                 textPos.SetPosition(10, pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
563         }
564         break;
565
566         case POSITION_BOTTOM_CENTER:
567         {
568                 int width = pEnrichedText->GetWidth();
569                 if(width > W_ENRICHED_TEXT)
570                 {
571                         textPos.SetPosition(X_ENRICHED_TEXT, pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
572                 }
573                 else
574                 {
575                         textPos.SetPosition(10 + ((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2), pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
576                 }
577
578         }
579         break;
580         case POSITION_SUGGESTION_NAME:
581         {
582                 textPos.SetPosition(X_LIST_DISPNAME,Y_LIST_DISPNAME);
583         }
584         break;
585         case POSITION_SUGGESTION_NUMBER:
586         {
587                 textPos.SetPosition(X_LIST_NUMBER,Y_LIST_NUMBER);
588         }
589         break;
590         }
591
592
593         //Draw EnrichedText to canvas
594         pCanvas.DrawText(textPos, *pEnrichedText);
595
596         // Cleans up
597         pEnrichedText->RemoveAll(true);
598         delete pEnrichedText;
599         delete font;
600
601         AppLogDebug("EXIT");
602         return;
603 }
604
605 void
606 DialUtil::DrawCanvasToButton(Canvas* pCanvasNormal, Canvas* pCanvasPressed, Button* pButton)
607 {
608         Bitmap* pNormalBgBmp = new (std::nothrow) Bitmap();
609         pNormalBgBmp->Construct(*pCanvasNormal, pCanvasNormal->GetBounds());
610
611         pButton->SetNormalBackgroundBitmap(*pNormalBgBmp);
612
613         if (pCanvasPressed != null)
614         {
615                 Bitmap* pPressedBgBmp = new (std::nothrow) Bitmap();
616                 pPressedBgBmp->Construct(*pCanvasPressed, pCanvasPressed->GetBounds());
617                 pButton->SetPressedBackgroundBitmap(*pPressedBgBmp);
618                 delete pPressedBgBmp;
619                 pPressedBgBmp = null;
620         }
621         else
622         {
623                 pButton->SetPressedBackgroundBitmap(*pNormalBgBmp);
624         }
625
626         pButton->SetDisabledBitmap(Point(0, 0), *pNormalBgBmp);
627         pButton->Invalidate(true);
628         delete pNormalBgBmp;
629         pNormalBgBmp = null;
630
631         return;
632 }
633
634 String
635 DialUtil::ConvertDialedNumberToString(int dialNumber)
636 {
637         switch (dialNumber)
638         {
639         case NUM_KEY1:
640         {
641                 return L"1";
642         }
643         case NUM_KEY2:
644         {
645                 return L"2";
646         }
647         case NUM_KEY3:
648         {
649                 return L"3";
650         }
651         case NUM_KEY4:
652         {
653                 return L"4";
654         }
655         case NUM_KEY5:
656         {
657                 return L"5";
658         }
659         case NUM_KEY6:
660         {
661                 return L"6";
662         }
663         case NUM_KEY7:
664         {
665                 return L"7";
666         }
667         case NUM_KEY8:
668         {
669                 return L"8";
670         }
671         case NUM_KEY9:
672         {
673                 return L"9";
674         }
675         break;
676         case NUM_KEY0:
677         {
678                 return L"0";
679         }
680         break;
681         case HASH_KEY:
682         {
683                 return L"#";
684         }
685         break;
686         case PAUSE_KEY:
687         {
688                 return L";";
689         }
690         break;
691         case WAIT_KEY:
692         {
693                 return L",";
694         }
695         break;
696         case STAR_KEY:
697         {
698                 return L"*";
699         }
700         break;
701         case PLUS_KEY:
702         {
703                 return L"+";
704         }
705         break;
706         }
707         return null;
708 }
709
710 IList*
711 DialUtil::FetchPossibleNamesListN(const String& prevSearchStr, int nextDigit)
712 {
713         //Fetch matching names for mapping char for digit, e.g. 2->ABC, 3->DEF.
714         ArrayList* pNamesList = new (std::nothrow) ArrayList(SingleObjectDeleter);
715         pNamesList->Construct(8);
716
717         if(nextDigit >=2 && nextDigit <= 9)
718         {
719                 switch(nextDigit)
720                 {
721                 case 2:
722                 {
723                         pNamesList->Add((new String(prevSearchStr+L"a")));
724                         pNamesList->Add((new String(prevSearchStr+L"b")));
725                         pNamesList->Add((new String(prevSearchStr+L"c")));
726                         pNamesList->Add((new String(prevSearchStr+L"A")));
727                         pNamesList->Add((new String(prevSearchStr+L"B")));
728                         pNamesList->Add((new String(prevSearchStr+L"C")));
729                 }
730                 break;
731
732                 case 3:
733                 {
734                         pNamesList->Add((new String(prevSearchStr+L"d")));
735                         pNamesList->Add((new String(prevSearchStr+L"e")));
736                         pNamesList->Add((new String(prevSearchStr+L"f")));
737                         pNamesList->Add((new String(prevSearchStr+L"D")));
738                         pNamesList->Add((new String(prevSearchStr+L"E")));
739                         pNamesList->Add((new String(prevSearchStr+L"F")));
740                 }
741                 break;
742
743                 case 4:
744                 {
745                         pNamesList->Add((new String(prevSearchStr+L"g")));
746                         pNamesList->Add((new String(prevSearchStr+L"h")));
747                         pNamesList->Add((new String(prevSearchStr+L"i")));
748                         pNamesList->Add((new String(prevSearchStr+L"G")));
749                         pNamesList->Add((new String(prevSearchStr+L"H")));
750                         pNamesList->Add((new String(prevSearchStr+L"I")));
751                 }
752                 break;
753
754                 case 5:
755                 {
756                         pNamesList->Add((new String(prevSearchStr+L"j")));
757                         pNamesList->Add((new String(prevSearchStr+L"k")));
758                         pNamesList->Add((new String(prevSearchStr+L"l")));
759                         pNamesList->Add((new String(prevSearchStr+L"J")));
760                         pNamesList->Add((new String(prevSearchStr+L"K")));
761                         pNamesList->Add((new String(prevSearchStr+L"L")));
762                 }
763                 break;
764
765                 case 6:
766                 {
767                         pNamesList->Add((new String(prevSearchStr+L"m")));
768                         pNamesList->Add((new String(prevSearchStr+L"n")));
769                         pNamesList->Add((new String(prevSearchStr+L"o")));
770                         pNamesList->Add((new String(prevSearchStr+L"M")));
771                         pNamesList->Add((new String(prevSearchStr+L"N")));
772                         pNamesList->Add((new String(prevSearchStr+L"O")));
773                 }
774                 break;
775
776                 case 7:
777                 {
778                         pNamesList->Add((new String(prevSearchStr+L"p")));
779                         pNamesList->Add((new String(prevSearchStr+L"q")));
780                         pNamesList->Add((new String(prevSearchStr+L"r")));
781                         pNamesList->Add((new String(prevSearchStr+L"s")));
782                         pNamesList->Add((new String(prevSearchStr+L"P")));
783                         pNamesList->Add((new String(prevSearchStr+L"Q")));
784                         pNamesList->Add((new String(prevSearchStr+L"R")));
785                         pNamesList->Add((new String(prevSearchStr+L"S")));
786                 }
787                 break;
788
789                 case 8:
790                 {
791                         pNamesList->Add((new String(prevSearchStr+L"t")));
792                         pNamesList->Add((new String(prevSearchStr+L"u")));
793                         pNamesList->Add((new String(prevSearchStr+L"v")));
794                         pNamesList->Add((new String(prevSearchStr+L"T")));
795                         pNamesList->Add((new String(prevSearchStr+L"U")));
796                         pNamesList->Add((new String(prevSearchStr+L"V")));
797                 }
798                 break;
799
800                 case 9:
801                 {
802                         pNamesList->Add((new String(prevSearchStr+L"w")));
803                         pNamesList->Add((new String(prevSearchStr+L"x")));
804                         pNamesList->Add((new String(prevSearchStr+L"y")));
805                         pNamesList->Add((new String(prevSearchStr+L"z")));
806                         pNamesList->Add((new String(prevSearchStr+L"W")));
807                         pNamesList->Add((new String(prevSearchStr+L"X")));
808                         pNamesList->Add((new String(prevSearchStr+L"Y")));
809                         pNamesList->Add((new String(prevSearchStr+L"Z")));
810                 }
811                 break;
812
813                 }
814         }
815         return pNamesList;
816 }
817
818 void
819 DialUtil::ConvertNameToNumericKeys(String& subContactName, String& possibleKeysTyped)
820 {
821         for(int charPos=0;charPos < subContactName.GetLength();charPos++)
822         {
823                 wchar_t nextChar;
824                 subContactName.GetCharAt(charPos,nextChar);
825                 switch(nextChar)
826                 {
827                 case 'a':case 'A':
828                 case 'b':case 'B':
829                 case 'c':case 'C':
830                         possibleKeysTyped.Append(2);
831                         break;
832
833                 case 'd':case 'D':
834                 case 'e':case 'E':
835                 case 'f':case 'F':
836                         possibleKeysTyped.Append(3);
837                         break;
838
839                 case 'g':case 'G':
840                 case 'h':case 'H':
841                 case 'i':case 'I':
842                         possibleKeysTyped.Append(4);
843                         break;
844
845                 case 'j':case 'J':
846                 case 'k':case 'K':
847                 case 'l':case 'L':
848                         possibleKeysTyped.Append(5);
849                         break;
850
851                 case 'm':case 'M':
852                 case 'n':case 'N':
853                 case 'o':case 'O':
854                         possibleKeysTyped.Append(6);
855                         break;
856
857                 case 'p':case 'P':
858                 case 'q':case 'Q':
859                 case 'r':case 'R':
860                 case 's':case 'S':
861                         possibleKeysTyped.Append(7);
862                         break;
863
864                 case 't':case 'T':
865                 case 'u':case 'U':
866                 case 'v':case 'V':
867                         possibleKeysTyped.Append(8);
868                         break;
869
870                 case 'w':case 'W':
871                 case 'x':case 'X':
872                 case 'y':case 'Y':
873                 case 'z':case 'Z':
874                         possibleKeysTyped.Append(9);
875                         break;
876
877                 default:
878                         break;
879                 }
880         }
881 }
882
883 EnrichedText*
884 DialUtil::ConstructEnrichedTextN(String& text, String& matchedKeyword, int textFontStyle, Dimension txtDimension)
885 {
886         //get text font
887         Font* fontName = DialUtil::GetTextFontN(textFontStyle);
888         //get text color
889         Color* textColor = DialUtil::GetTextColorN(textFontStyle, BUTTON_STATUS_NORMAL);
890         //highlighted text Color
891         Color* highlightedTxtColor = DialUtil::GetTextColorN(FONT_HIGHLIGHT_SEARCH_KEYWORD, BUTTON_STATUS_NORMAL);
892
893         EnrichedText* pEnrichedName = new (std::nothrow) EnrichedText();
894         pEnrichedName->Construct(txtDimension);
895         pEnrichedName->SetTextWrapStyle(TEXT_WRAP_NONE);
896         //Text is divided in 3 parts - pre-text, highlighted matchedKeyword, post-text.
897         String preTxt(L"");
898         String highlightTxt(L"");
899         String postTxt(L"");
900         if(matchedKeyword.IsEmpty() == false)
901         {
902                 int searchIndex;
903                 result r = text.IndexOf(matchedKeyword,0,searchIndex);
904                 if(r == E_SUCCESS)
905                 {
906                         if(searchIndex > 0)
907                         {
908                                 text.SubString(0,searchIndex,preTxt);
909                         }
910                         text.SubString(searchIndex, matchedKeyword.GetLength(),highlightTxt);
911                         text.SubString((searchIndex + matchedKeyword.GetLength()),postTxt);
912                 }
913                 else
914                 {
915                         preTxt = text;
916                 }
917         }
918
919         TextElement* pTextName = null;
920         if(preTxt.IsEmpty() == false)
921         {
922                 //create text element
923                 pTextName = new (std::nothrow) TextElement();
924                 pTextName->Construct(preTxt);
925                 pTextName->SetFont(*fontName);
926                 pTextName->SetTextColor(*textColor);
927                 //ownership of 'pTextName' transferred to 'pEnrichedName'
928                 pEnrichedName->Add(*pTextName);
929         }
930
931         if(highlightTxt.IsEmpty() == false)
932         {
933                 //create text element
934                 pTextName = new (std::nothrow) TextElement();
935                 pTextName->Construct(highlightTxt);
936                 pTextName->SetFont(*fontName);
937                 // Highlighted search text
938                 pTextName->SetTextColor(*highlightedTxtColor);
939                 pEnrichedName->Add(*pTextName);
940         }
941
942         if(postTxt.IsEmpty() == false)
943         {
944                 //create text element
945                 pTextName = new (std::nothrow) TextElement();
946                 pTextName->Construct(postTxt);
947                 pTextName->SetFont(*fontName);
948                 pTextName->SetTextColor(*textColor);
949                 pEnrichedName->Add(*pTextName);
950         }
951
952         delete fontName;
953         delete textColor;
954         delete highlightedTxtColor;
955
956         return pEnrichedName;
957 }
958
959 void
960 DialUtil::DrawTextAndHighlightedKeywordToCanvas(String& buttonText, String& matchedKeyword, int textFontStyle, Canvas& pCanvas, int pos)
961 {
962         if (buttonText == null)
963         {
964                 return;
965         }
966
967         //Convert to enriched text with highlighted keyword
968         Dimension txtDimension (pCanvas.GetBounds().width - IDI_RIGHT_MARGIN_USE_CONTACT_BTN, H_USE_CONTACT_BTN);
969         EnrichedText* pEnrichedText = ConstructEnrichedTextN(buttonText, matchedKeyword, textFontStyle, txtDimension);
970
971         //set the position of the text in canvas
972         Point textPos(0, 0);
973         switch (pos)
974         {
975         case POSITION_SUGGESTION_NAME:
976         {
977                 textPos.SetPosition(X_LIST_DISPNAME,Y_LIST_DISPNAME);
978         }
979         break;
980
981         case POSITION_SUGGESTION_NUMBER:
982         {
983                 textPos.SetPosition(X_LIST_NUMBER,Y_LIST_NUMBER);
984         }
985         break;
986         }
987
988         //Draw EnrichedText to canvas
989         pCanvas.DrawText(textPos, *pEnrichedText);
990         // Cleans up
991         pEnrichedText->RemoveAll(true);
992         delete pEnrichedText;
993
994         AppLogDebug("EXIT");
995         return;
996 }