Applied latest source code
[apps/native/preloaded/Phone.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 = 160;
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         if(pBitmap != null)
299         {
300                 pCanvas.DrawBitmap(pCanvas.GetBounds(),*pBitmap);
301                 delete pBitmap;
302         }
303 }
304
305 void
306 DialUtil::DrawClear9PatchToCanvas(Tizen::Graphics::Canvas& pCanvas, const Tizen::Base::String& bgImg)
307 {
308         AppResource* pAppResource = AppResource::GetInstance();
309         Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
310         if (pBitmap->IsNinePatchedBitmap())
311         {
312                 pCanvas.DrawNinePatchedBitmap(Rectangle(X_CLEAR_PATCH,Y_CLEAR_PATCH,W_CLEAR_PATCH,H_CLEAR_PATCH), *pBitmap);
313         }
314         pCanvas.DrawBitmap(Rectangle(X_CLEAR_PATCH,Y_CLEAR_PATCH, W_CLEAR_PATCH, H_CLEAR_PATCH), *pBitmap);
315         delete pBitmap;
316
317 }
318
319 void
320 DialUtil::DrawCall9PatchToCanvas(Tizen::Graphics::Canvas& pCanvas, const Tizen::Base::String& bgImg)
321 {
322         AppResource* pAppResource = AppResource::GetInstance();
323         Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
324         if (pBitmap->IsNinePatchedBitmap())
325         {
326                 pCanvas.DrawNinePatchedBitmap(Rectangle(X_CALL_PATCH,Y_CALL_PATCH,W_CALL_PATCH,H_CALL_PATCH), *pBitmap);
327         }
328         pCanvas.DrawBitmap(Rectangle(X_CALL_PATCH,Y_CALL_PATCH, W_CALL_PATCH, H_CALL_PATCH), *pBitmap);
329         delete pBitmap;
330
331 }
332
333 void
334 DialUtil::Draw9PatchToCanvas(Canvas& pCanvas, const String& bgImg)
335 {
336         AppResource* pAppResource = AppResource::GetInstance();
337         Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
338
339         pBitmap->GetWidth();
340         if (pBitmap->IsNinePatchedBitmap())
341         {
342                 pCanvas.DrawNinePatchedBitmap(pCanvas.GetBounds(), *pBitmap);
343         }
344         else
345         {
346                 pCanvas.DrawBitmap(pCanvas.GetBounds(),*pBitmap);
347         }
348         delete pBitmap;
349
350         return;
351 }
352
353
354 void
355 DialUtil::DrawKeypadImageToCanvas(const Tizen::Base::String& image, Tizen::Graphics::Dimension imageDimention, Tizen::Graphics::Canvas& pCanvas, int pos)
356 {
357         //create and scale bitmap
358         Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(image, imageDimention.width, imageDimention.height);
359         //Find position to draw bitmap
360         Point bitmapPos(0, 0);
361
362         switch(pos)
363         {
364         case POSITION_TOP_CENTER:
365         {
366                 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2,Y_DIALER_BTN_IMG);
367         }
368         break;
369         case POSITION_BOTTOM_CENTER:
370         {
371                 //bitmapPos.SetPosition(X_DIALER_BTN_IMG,Y_DIALER_BTN_IMG);
372                 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, 20 + pCanvas.GetBounds().height / 2 + (pCanvas.GetBounds().height / 2 - pBitmap->GetHeight()) / 2);
373         }
374         break;
375         }
376
377         pCanvas.DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
378         delete pBitmap;
379         pBitmap = null;
380
381         return;
382
383 }
384
385
386
387
388 void
389 DialUtil::DrawImageToCanvas(const String& image, Dimension imageDimention, Canvas& pCanvas, int pos)
390 {
391         //create and scale bitmap
392         Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(image, imageDimention.width, imageDimention.height);
393
394         //Find position to draw bitmap
395         Point bitmapPos(0, 0);
396         switch (pos)
397         {
398         case POSITION_LEFT:
399         {
400                 bitmapPos.SetPosition(X_DIALER_BTN_TXT + (W_DIALER_BTN_NUM_TXT - pBitmap->GetWidth()) / 2, (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
401         }
402         break;
403
404         case POSITION_RIGHT:
405         {
406                 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);
407         }
408         break;
409
410         case POSITION_CENTER:
411         {
412                 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
413         }
414         break;
415
416         case POSITION_BOTTOM_CENTER:
417         {
418                 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, pCanvas.GetBounds().height / 2 + (pCanvas.GetBounds().height / 2 - pBitmap->GetHeight()) / 2);
419         }
420         break;
421         }
422
423         //draw bitmap
424         pCanvas.DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
425         delete pBitmap;
426         pBitmap = null;
427
428         return;
429 }
430
431 void
432 DialUtil::DrawKeypadTextToCanvas(const String& buttonText, int textFontStyle, Canvas& pCanvas, int pos, int buttonStatus)
433 {
434         AppLogDebug("ENTER");
435         if (buttonText == null)
436         {
437                 return;
438         }
439
440         //get text font
441         Font* font = GetTextFontN(textFontStyle);
442
443         //get text color
444         Color* textColor = GetTextColorN(textFontStyle, buttonStatus);
445
446         //create text element
447         TextElement* pTextElement = new (std::nothrow) TextElement();
448         pTextElement->Construct(buttonText);
449         pTextElement->SetTextColor(*textColor);
450         pTextElement->SetFont(*font);
451         delete textColor;
452
453         //get dimensions of the text
454         FloatDimension textDimension;
455         font->GetTextExtent(buttonText, buttonText.GetLength(), textDimension);
456         if(textFontStyle != FONT_KEYPAD_NUMBER)
457         {
458                 textDimension.height += font->GetDescender();
459         }
460
461         //create enriched text
462         EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
463         pEnrichedText->Construct(textDimension);
464         pEnrichedText->Add(*pTextElement);
465
466         //set the position of the text in canvas
467         Point textPos(0, 0);
468         switch (pos)
469         {
470         case POSITION_BOTTOM_CENTER:
471         {
472                 textPos.SetPosition(((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2),
473                                                                                                                     20 + pCanvas.GetBounds().height / 2
474                                                                                                                         + ((pCanvas.GetBounds().height / 2
475                                                                                                                         - pEnrichedText->GetHeight()) / 2));
476         }
477         break;
478         }
479
480         //Draw EnrichedText to canvas
481         pCanvas.DrawText(textPos, *pEnrichedText);
482
483         // Cleans up
484         pEnrichedText->RemoveAll(true);
485         delete pEnrichedText;
486         delete font;
487
488         AppLogDebug("EXIT");
489         return;
490 }
491
492 void
493 DialUtil::DrawTextToCanvas(const String& buttonText, int textFontStyle, Canvas& pCanvas, int pos, int buttonStatus)
494 {
495         if (buttonText == null)
496         {
497                 return;
498         }
499
500         //get text font
501         Font* font = GetTextFontN(textFontStyle);
502
503         //get text color
504         Color* textColor = GetTextColorN(textFontStyle, buttonStatus);
505
506         //create text element
507         TextElement* pTextElement = new (std::nothrow) TextElement();
508         pTextElement->Construct(buttonText);
509         pTextElement->SetTextColor(*textColor);
510         pTextElement->SetFont(*font);
511         delete textColor;
512
513         //get dimensions of the text
514         FloatDimension textDimension;
515         font->GetTextExtent(buttonText, buttonText.GetLength(), textDimension);
516         if(textFontStyle != FONT_KEYPAD_NUMBER)
517         {
518                 textDimension.height += font->GetDescender();
519         }
520
521         //create enriched text
522         EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
523         pEnrichedText->Construct(textDimension);
524         pEnrichedText->Add(*pTextElement);
525
526         //set the position of the text in canvas
527         Point textPos(0, 0);
528         switch (pos)
529         {
530         case POSITION_LEFT:
531         {
532                 //Margin 13, rectangle for left text (13,0,77, height of canvas), center aligned
533                 textPos.SetPosition(X_DIALER_BTN_TXT + ((W_DIALER_BTN_NUM_TXT - pEnrichedText->GetWidth()) / 2), (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
534         }
535         break;
536
537         case POSITION_RIGHT:
538         {
539                 //rectangle for right text (13+77,0, 121, height of canvas), center aligned
540                 textPos.SetPosition(X_DIALER_BTN_TXT + W_DIALER_BTN_NUM_TXT + ((121 - pEnrichedText->GetWidth()) / 2), (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
541         }
542         break;
543
544         case POSITION_CENTER:
545         {
546                 //rectangle for image : entire canvas, center aligned
547                 textPos.SetPosition((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2, (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
548         }
549         break;
550
551         case POSITION_TOP_LEFT:
552         {
553                 textPos.SetPosition(10, (pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2);
554         }
555         break;
556
557         case POSITION_TOP_CENTER:
558         {
559                 textPos.SetPosition((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2, (pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2);
560         }
561         break;
562
563         case POSITION_BOTTOM_LEFT:
564         {
565                 textPos.SetPosition(10, pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
566         }
567         break;
568
569         case POSITION_BOTTOM_CENTER:
570         {
571                 int width = pEnrichedText->GetWidth();
572                 if(width > W_ENRICHED_TEXT)
573                 {
574                         textPos.SetPosition(X_ENRICHED_TEXT, pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
575                 }
576                 else
577                 {
578                         textPos.SetPosition(10 + ((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2), pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
579                 }
580
581         }
582         break;
583         case POSITION_SUGGESTION_NAME:
584         {
585                 textPos.SetPosition(X_LIST_DISPNAME,Y_LIST_DISPNAME);
586         }
587         break;
588         case POSITION_SUGGESTION_NUMBER:
589         {
590                 textPos.SetPosition(X_LIST_NUMBER,Y_LIST_NUMBER);
591         }
592         break;
593         }
594
595
596         //Draw EnrichedText to canvas
597         pCanvas.DrawText(textPos, *pEnrichedText);
598
599         // Cleans up
600         pEnrichedText->RemoveAll(true);
601         delete pEnrichedText;
602         delete font;
603
604         AppLogDebug("EXIT");
605         return;
606 }
607
608 void
609 DialUtil::DrawCanvasToButton(Canvas* pCanvasNormal, Canvas* pCanvasPressed, Button* pButton)
610 {
611         Bitmap* pNormalBgBmp = new (std::nothrow) Bitmap();
612         pNormalBgBmp->Construct(*pCanvasNormal, pCanvasNormal->GetBounds());
613
614         pButton->SetNormalBackgroundBitmap(*pNormalBgBmp);
615
616         if (pCanvasPressed != null)
617         {
618                 Bitmap* pPressedBgBmp = new (std::nothrow) Bitmap();
619                 pPressedBgBmp->Construct(*pCanvasPressed, pCanvasPressed->GetBounds());
620                 pButton->SetPressedBackgroundBitmap(*pPressedBgBmp);
621                 delete pPressedBgBmp;
622                 pPressedBgBmp = null;
623         }
624         else
625         {
626                 pButton->SetPressedBackgroundBitmap(*pNormalBgBmp);
627         }
628
629         pButton->SetDisabledBitmap(Point(0, 0), *pNormalBgBmp);
630         pButton->Invalidate(true);
631         delete pNormalBgBmp;
632         pNormalBgBmp = null;
633
634         return;
635 }
636
637 String
638 DialUtil::ConvertDialedNumberToString(int dialNumber)
639 {
640         switch (dialNumber)
641         {
642         case NUM_KEY1:
643         {
644                 return L"1";
645         }
646         case NUM_KEY2:
647         {
648                 return L"2";
649         }
650         case NUM_KEY3:
651         {
652                 return L"3";
653         }
654         case NUM_KEY4:
655         {
656                 return L"4";
657         }
658         case NUM_KEY5:
659         {
660                 return L"5";
661         }
662         case NUM_KEY6:
663         {
664                 return L"6";
665         }
666         case NUM_KEY7:
667         {
668                 return L"7";
669         }
670         case NUM_KEY8:
671         {
672                 return L"8";
673         }
674         case NUM_KEY9:
675         {
676                 return L"9";
677         }
678         break;
679         case NUM_KEY0:
680         {
681                 return L"0";
682         }
683         break;
684         case HASH_KEY:
685         {
686                 return L"#";
687         }
688         break;
689         case PAUSE_KEY:
690         {
691                 return L";";
692         }
693         break;
694         case WAIT_KEY:
695         {
696                 return L",";
697         }
698         break;
699         case STAR_KEY:
700         {
701                 return L"*";
702         }
703         break;
704         case PLUS_KEY:
705         {
706                 return L"+";
707         }
708         break;
709         }
710         return null;
711 }
712
713 IList*
714 DialUtil::FetchPossibleNamesListN(const String& prevSearchStr, int nextDigit)
715 {
716         //Fetch matching names for mapping char for digit, e.g. 2->ABC, 3->DEF.
717         ArrayList* pNamesList = new (std::nothrow) ArrayList(SingleObjectDeleter);
718         pNamesList->Construct(8);
719
720         if(nextDigit >=2 && nextDigit <= 9)
721         {
722                 switch(nextDigit)
723                 {
724                 case 2:
725                 {
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                         pNamesList->Add((new String(prevSearchStr+L"A")));
730                         pNamesList->Add((new String(prevSearchStr+L"B")));
731                         pNamesList->Add((new String(prevSearchStr+L"C")));
732                 }
733                 break;
734
735                 case 3:
736                 {
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                         pNamesList->Add((new String(prevSearchStr+L"D")));
741                         pNamesList->Add((new String(prevSearchStr+L"E")));
742                         pNamesList->Add((new String(prevSearchStr+L"F")));
743                 }
744                 break;
745
746                 case 4:
747                 {
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                         pNamesList->Add((new String(prevSearchStr+L"G")));
752                         pNamesList->Add((new String(prevSearchStr+L"H")));
753                         pNamesList->Add((new String(prevSearchStr+L"I")));
754                 }
755                 break;
756
757                 case 5:
758                 {
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                         pNamesList->Add((new String(prevSearchStr+L"J")));
763                         pNamesList->Add((new String(prevSearchStr+L"K")));
764                         pNamesList->Add((new String(prevSearchStr+L"L")));
765                 }
766                 break;
767
768                 case 6:
769                 {
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                         pNamesList->Add((new String(prevSearchStr+L"M")));
774                         pNamesList->Add((new String(prevSearchStr+L"N")));
775                         pNamesList->Add((new String(prevSearchStr+L"O")));
776                 }
777                 break;
778
779                 case 7:
780                 {
781                         pNamesList->Add((new String(prevSearchStr+L"p")));
782                         pNamesList->Add((new String(prevSearchStr+L"q")));
783                         pNamesList->Add((new String(prevSearchStr+L"r")));
784                         pNamesList->Add((new String(prevSearchStr+L"s")));
785                         pNamesList->Add((new String(prevSearchStr+L"P")));
786                         pNamesList->Add((new String(prevSearchStr+L"Q")));
787                         pNamesList->Add((new String(prevSearchStr+L"R")));
788                         pNamesList->Add((new String(prevSearchStr+L"S")));
789                 }
790                 break;
791
792                 case 8:
793                 {
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                         pNamesList->Add((new String(prevSearchStr+L"T")));
798                         pNamesList->Add((new String(prevSearchStr+L"U")));
799                         pNamesList->Add((new String(prevSearchStr+L"V")));
800                 }
801                 break;
802
803                 case 9:
804                 {
805                         pNamesList->Add((new String(prevSearchStr+L"w")));
806                         pNamesList->Add((new String(prevSearchStr+L"x")));
807                         pNamesList->Add((new String(prevSearchStr+L"y")));
808                         pNamesList->Add((new String(prevSearchStr+L"z")));
809                         pNamesList->Add((new String(prevSearchStr+L"W")));
810                         pNamesList->Add((new String(prevSearchStr+L"X")));
811                         pNamesList->Add((new String(prevSearchStr+L"Y")));
812                         pNamesList->Add((new String(prevSearchStr+L"Z")));
813                 }
814                 break;
815
816                 }
817         }
818         return pNamesList;
819 }
820
821 void
822 DialUtil::ConvertNameToNumericKeys(String& subContactName, String& possibleKeysTyped)
823 {
824         for(int charPos=0;charPos < subContactName.GetLength();charPos++)
825         {
826                 wchar_t nextChar;
827                 subContactName.GetCharAt(charPos,nextChar);
828                 switch(nextChar)
829                 {
830                 case 'a':case 'A':
831                 case 'b':case 'B':
832                 case 'c':case 'C':
833                         possibleKeysTyped.Append(2);
834                         break;
835
836                 case 'd':case 'D':
837                 case 'e':case 'E':
838                 case 'f':case 'F':
839                         possibleKeysTyped.Append(3);
840                         break;
841
842                 case 'g':case 'G':
843                 case 'h':case 'H':
844                 case 'i':case 'I':
845                         possibleKeysTyped.Append(4);
846                         break;
847
848                 case 'j':case 'J':
849                 case 'k':case 'K':
850                 case 'l':case 'L':
851                         possibleKeysTyped.Append(5);
852                         break;
853
854                 case 'm':case 'M':
855                 case 'n':case 'N':
856                 case 'o':case 'O':
857                         possibleKeysTyped.Append(6);
858                         break;
859
860                 case 'p':case 'P':
861                 case 'q':case 'Q':
862                 case 'r':case 'R':
863                 case 's':case 'S':
864                         possibleKeysTyped.Append(7);
865                         break;
866
867                 case 't':case 'T':
868                 case 'u':case 'U':
869                 case 'v':case 'V':
870                         possibleKeysTyped.Append(8);
871                         break;
872
873                 case 'w':case 'W':
874                 case 'x':case 'X':
875                 case 'y':case 'Y':
876                 case 'z':case 'Z':
877                         possibleKeysTyped.Append(9);
878                         break;
879
880                 default:
881                         break;
882                 }
883         }
884 }
885
886 EnrichedText*
887 DialUtil::ConstructEnrichedTextN(String& text, String& matchedKeyword, int textFontStyle, Dimension txtDimension)
888 {
889         //get text font
890         Font* fontName = DialUtil::GetTextFontN(textFontStyle);
891         //get text color
892         Color* textColor = DialUtil::GetTextColorN(textFontStyle, BUTTON_STATUS_NORMAL);
893         //highlighted text Color
894         Color* highlightedTxtColor = DialUtil::GetTextColorN(FONT_HIGHLIGHT_SEARCH_KEYWORD, BUTTON_STATUS_NORMAL);
895
896         EnrichedText* pEnrichedName = new (std::nothrow) EnrichedText();
897         pEnrichedName->Construct(txtDimension);
898         pEnrichedName->SetTextWrapStyle(TEXT_WRAP_NONE);
899         //Text is divided in 3 parts - pre-text, highlighted matchedKeyword, post-text.
900         String preTxt(L"");
901         String highlightTxt(L"");
902         String postTxt(L"");
903         if(matchedKeyword.IsEmpty() == false)
904         {
905                 int searchIndex;
906                 result r = text.IndexOf(matchedKeyword,0,searchIndex);
907                 if(r == E_SUCCESS)
908                 {
909                         if(searchIndex > 0)
910                         {
911                                 text.SubString(0,searchIndex,preTxt);
912                         }
913                         text.SubString(searchIndex, matchedKeyword.GetLength(),highlightTxt);
914                         text.SubString((searchIndex + matchedKeyword.GetLength()),postTxt);
915                 }
916                 else
917                 {
918                         preTxt = text;
919                 }
920         }
921
922         TextElement* pTextName = null;
923         if(preTxt.IsEmpty() == false)
924         {
925                 //create text element
926                 pTextName = new (std::nothrow) TextElement();
927                 pTextName->Construct(preTxt);
928                 pTextName->SetFont(*fontName);
929                 pTextName->SetTextColor(*textColor);
930                 //ownership of 'pTextName' transferred to 'pEnrichedName'
931                 pEnrichedName->Add(*pTextName);
932         }
933
934         if(highlightTxt.IsEmpty() == false)
935         {
936                 //create text element
937                 pTextName = new (std::nothrow) TextElement();
938                 pTextName->Construct(highlightTxt);
939                 pTextName->SetFont(*fontName);
940                 // Highlighted search text
941                 pTextName->SetTextColor(*highlightedTxtColor);
942                 pEnrichedName->Add(*pTextName);
943         }
944
945         if(postTxt.IsEmpty() == false)
946         {
947                 //create text element
948                 pTextName = new (std::nothrow) TextElement();
949                 pTextName->Construct(postTxt);
950                 pTextName->SetFont(*fontName);
951                 pTextName->SetTextColor(*textColor);
952                 pEnrichedName->Add(*pTextName);
953         }
954
955         delete fontName;
956         delete textColor;
957         delete highlightedTxtColor;
958
959         return pEnrichedName;
960 }
961
962 void
963 DialUtil::DrawTextAndHighlightedKeywordToCanvas(String& buttonText, String& matchedKeyword, int textFontStyle, Canvas& pCanvas, int pos)
964 {
965         if (buttonText == null)
966         {
967                 return;
968         }
969
970         //Convert to enriched text with highlighted keyword
971         Dimension txtDimension (pCanvas.GetBounds().width - IDI_RIGHT_MARGIN_USE_CONTACT_BTN, H_USE_CONTACT_BTN);
972         EnrichedText* pEnrichedText = ConstructEnrichedTextN(buttonText, matchedKeyword, textFontStyle, txtDimension);
973
974         //set the position of the text in canvas
975         Point textPos(0, 0);
976         switch (pos)
977         {
978         case POSITION_SUGGESTION_NAME:
979         {
980                 textPos.SetPosition(X_LIST_DISPNAME,Y_LIST_DISPNAME);
981         }
982         break;
983
984         case POSITION_SUGGESTION_NUMBER:
985         {
986                 textPos.SetPosition(X_LIST_NUMBER,Y_LIST_NUMBER);
987         }
988         break;
989         }
990
991         //Draw EnrichedText to canvas
992         pCanvas.DrawText(textPos, *pEnrichedText);
993         // Cleans up
994         pEnrichedText->RemoveAll(true);
995         delete pEnrichedText;
996
997         AppLogDebug("EXIT");
998         return;
999 }