Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnTabDialer.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
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        PhnTabDialer.cpp
19  * @brief       The dialer Tab
20  */
21 #include <FApp.h>
22 #include <FMedia.h>
23 #include <FSystem.h>
24 #include "PhnAppUtility.h"
25 #include "PhnPhoneApp.h"
26 #include "PhnCalllogManager.h"
27 #include "PhnCallPresentationModel.h"
28 #include "PhnCommonUtils.h"
29 #include "PhnDialAppForm.h"
30 #include "PhnDialContactInfo.h"
31 #include "PhnDialerKeypad.h"
32 #include "PhnTabDialer.h"
33 #include "PhnSceneRegister.h"
34 #include "PhnSettingsPresentationModel.h"
35 #include "PhnTypes.h"
36
37 using namespace Tizen::App;
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Media;
42 using namespace Tizen::Ui;
43 using namespace Tizen::Ui::Controls;
44 using namespace Tizen::Ui::Scenes;
45 using namespace Tizen::Social;
46 using namespace Tizen::System;
47
48 //Constants
49 const int H_SPEEDDIAL_POPUP = 300;
50 const int H_POPUP_MSG_LABEL = 100;
51 const int H_POPUP_BTN = 90;
52 const int H_SEARCHLIST_ITEM = 129;
53 const int IDI_PADDING = 15;
54 const int IDI_MAX_LIMIT_LENGTH = 18;
55 const int IDI_MAX_TXT_FONT = 94;
56 const int IDI_MIN_TXT_FONT = 67;
57 const int IDI_DELTA_FONT_SIZE = 5;
58 const wchar_t* IDI_ADD_TO_CONTACTS_STR = L"Add To Contacts";
59 const int MAX_SEARCH_LIST_ITEMS = 5;
60 const int MIN_CONTEXT_MENU_ITEMS = 4;
61 const int X_CONTEXT_MENU_ANCHOR = 614;
62 const int Y_CONTEXT_MENU_ANCHOR = 504;
63 const int MAX_NUMBER_WITH_SEPERATOR = 11;
64 const int MIN_NUMBER_WITH_ONE_SEPERATOR = 3;
65 const int MIN_NUMBER_WITH_TWO_SEPERATOR = 7;
66 const int MAX_TXT_LENGTH_WITH_SEPERATOR = 12;
67 const int MAX_VISIBLE_TXT_WITH_MIN_FONT = 18;
68 const int W_MORE_BUTTON = 65;
69 const int H_MORE_BUTTON = 65;
70 const int W_SUGGESTION_POPUP_BUBBLE_ICON = 45;
71 const int H_SUGGESTION_POPUP_BUBBLE_ICON = 30;
72
73 //resources
74 const wchar_t* IDL_PANEL_DIALER = L"IDL_PANEL_DIALER";
75 const wchar_t* IDC_NUMERIC_EDITFIELD = L"IDC_EDITFIELD";
76 const wchar_t* IDC_PANEL_SEARCH_BOX = L"IDC_PANEL_SEARCH_BOX";
77 const wchar_t* IDC_BUTTON_ADD_CONTACTS = L"IDC_BUTTON_ADD_CONTACTS";
78 const wchar_t* IDC_BUTTON_USE_CONTACT = L"IDC_BUTTON_USE_CONTACT";
79 const wchar_t* IDC_BUTTON_DROP_DOWN = L"IDC_BUTTON_DROP_DOWN";
80 const wchar_t* IDC_PANEL_SEARCH_LIST = L"IDC_PANEL_SEARCH_LIST";
81 static const wchar_t* IDC_PANEL_DISPLAY_DATA = L"IDC_PANEL_DISPLAY_DATA";
82 const wchar_t* IDC_PANEL_MENU = L"IDC_PANEL_MENU";
83 const wchar_t* IDC_BUTTON_MENU = L"IDC_BUTTON_MENU";
84 const wchar_t* IDC_LISTVIEW_SEARCH = L"IDC_LISTVIEW_SEARCH";
85
86 //Button Dimensions
87 const int DialTabDialer::IDI_BGBITMAP_WIDTH = 75;
88 const int DialTabDialer::IDI_BGBITMAP_HEIGHT = 75;
89 const int DialTabDialer::IDI_BGBITMAP_POS_X = 56;
90 const int DialTabDialer::IDI_BGBITMAP_POS_Y = 56;
91 const int DialTabDialer::IDI_TEXT1_SIZE = 116;
92 const int DialTabDialer::IDI_TEXT2_SIZE = 40;
93
94 //color
95 const unsigned int COLOR_SEARCHLIST_BG = Color32<43, 107, 144>::Value;
96
97 DialTabDialer::DialTabDialer(void)
98 {
99         AppLogDebug("ENTER");
100         __pDialPresentationModel = null;
101         __pSuggestionListProvider = null;
102         __pSearchListView = null;
103         __isSearchListOpened = false;
104         __pErrorMsgPopup = null;
105         __pCallPresentor = null;
106         __pContextMenu = null;
107         __pPreviousSceneId = null;
108         __pDialKeypad = null;
109         __pConfirmationPopup = null;
110         __isAppForeground = true;
111         __pAddressBook = null;
112         __isAppControlLaunched = false;
113         AppLogDebug("EXIT");
114 }
115
116 DialTabDialer::~DialTabDialer(void)
117 {
118         AppLogDebug("ENTER");
119
120         if(__pDialKeypad != null)
121         {
122                 //RemoveControl() also deletes the child control.
123                 RemoveControl(*__pDialKeypad);
124                 __pDialKeypad = null;
125         }
126         if(__pConfirmationPopup != null)
127         {
128                 delete __pConfirmationPopup;
129                 __pConfirmationPopup = null;
130         }
131         if (__pAddressBook != null)
132         {
133                 delete __pAddressBook;
134                 __pAddressBook = null;
135         }
136         delete __pContextMenu;
137         AppLogDebug("EXIT");
138 }
139
140 bool
141 DialTabDialer::Initialize(void)
142 {
143         AppLogDebug("ENTER");
144         Construct(IDL_PANEL_DIALER);
145         AppLogDebug("EXIT");
146         return true;
147 }
148
149 result
150 DialTabDialer::OnInitializing(void)
151 {
152         AppLogDebug("ENTER");
153         result r = E_SUCCESS;
154
155         // Layout setting
156         Form* pForm = dynamic_cast<Form*>(GetParent());
157         if(pForm == null)
158         {
159                 return E_FAILURE;
160         }
161
162         __pDialPresentationModel = new DialPresentationModel(*this);
163         __pSuggestionListProvider = new SuggestionItemProvider(*__pDialPresentationModel);
164         __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
165
166         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(pForm->GetLandscapeLayoutN());
167         if (pRelativeLayout != null)
168         {
169                 pRelativeLayout->SetHorizontalFitPolicy(*this, FIT_POLICY_PARENT);
170                 pRelativeLayout->SetVerticalFitPolicy(*this, FIT_POLICY_PARENT);
171                 delete pRelativeLayout;
172         }
173         pRelativeLayout = dynamic_cast<RelativeLayout*>(pForm->GetPortraitLayoutN());
174         if (pRelativeLayout != null)
175         {
176                 pRelativeLayout->SetHorizontalFitPolicy(*this, FIT_POLICY_PARENT);
177                 pRelativeLayout->SetVerticalFitPolicy(*this, FIT_POLICY_PARENT);
178                 delete pRelativeLayout;
179         }
180
181         //hide footer
182         pForm->GetFooter()->SetShowState(false);
183         pForm->AddOrientationEventListener(*this);
184
185         //Construct menu
186         ConstructMenu();
187         //Initialize text box
188         InitializeContactsTextBox();
189         //Create and hide Search data display panel
190         InitializeSearchBox();
191         //initialize search list view and hide it.
192         InitializeSearchListView();
193         HideSearchListView();
194         AppLogDebug("EXIT");
195         return r;
196 }
197
198 result
199 DialTabDialer::OnTerminating(void)
200 {
201         result r = E_SUCCESS;
202         if (__pDialPresentationModel != null)
203         {
204                 delete __pDialPresentationModel;
205                 __pDialPresentationModel = null;
206         }
207         if (__pSuggestionListProvider != null)
208         {
209                 delete __pSuggestionListProvider;
210                 __pSuggestionListProvider = null;
211         }
212         // Add your termination code here
213         return r;
214 }
215
216 void
217 DialTabDialer::InitializeContactsTextBox(void)
218 {
219         AppLogDebug("ENTER");
220         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
221         if (pEditField != null)
222         {
223                 //clear text
224                 pEditField->Clear();
225         }
226
227         AppLogDebug("EXIT");
228         return;
229 }
230
231 void
232 DialTabDialer::ShowFormattedText(EditField* pEditField, int actionId)
233 {
234         AppLogDebug("ENTER");
235         String contactNumber = pEditField->GetText();
236         contactNumber.Replace(L"-",L"");
237         if(actionId == CLEAR_KEY)
238         {
239                 contactNumber.Remove(contactNumber.GetLength() - 1, 1);
240         }
241         else
242         {
243                 contactNumber.Append(DialUtil::ConvertDialedNumberToString(actionId));
244         }
245
246         int textLength = contactNumber.GetLength();
247         if(textLength == 0)
248         {
249                 pEditField->Clear();
250                 pEditField->SetCursorPosition(0);
251                 pEditField->SetFocus();
252                 pEditField->Invalidate(true);
253                 AppLogDebug("EXIT");
254                 return;
255         }
256
257         //Insert separator if required
258         if(textLength < MAX_NUMBER_WITH_SEPERATOR)
259         {
260                 if(textLength > MIN_NUMBER_WITH_TWO_SEPERATOR)
261                 {
262                         contactNumber.Insert(L"-",MIN_NUMBER_WITH_TWO_SEPERATOR);
263                 }
264                 if(textLength > MIN_NUMBER_WITH_ONE_SEPERATOR)
265                 {
266                         contactNumber.Insert(L"-",MIN_NUMBER_WITH_ONE_SEPERATOR);
267                 }
268         }
269         //update text length
270         textLength = contactNumber.GetLength();
271
272         //need to change font to fit inside text box
273         //With size 94 -> 12 chars, 67 -> 18 chars
274         int fontSize = pEditField->GetTextSize();
275         if((actionId == CLEAR_KEY) && (textLength < MAX_VISIBLE_TXT_WITH_MIN_FONT))
276         {
277                 //clearing
278                 fontSize += IDI_DELTA_FONT_SIZE;
279         }
280         else if(textLength > MAX_TXT_LENGTH_WITH_SEPERATOR)
281         {
282                 //appending
283                 fontSize -= IDI_DELTA_FONT_SIZE;
284         }
285
286         if(fontSize > IDI_MAX_TXT_FONT)
287         {
288                 fontSize = IDI_MAX_TXT_FONT;
289         }
290         if(fontSize < IDI_MIN_TXT_FONT)
291         {
292                 fontSize = IDI_MIN_TXT_FONT;
293         }
294         pEditField->SetTextSize(fontSize);
295         //set text to edit field
296         pEditField->SetText(contactNumber);
297         pEditField->SetCursorPosition(contactNumber.GetLength());
298         pEditField->SetFocus();
299         AppLogDebug("EXIT");
300         return;
301 }
302
303 //search box
304 void
305 DialTabDialer::InitializeSearchBox(void)
306 {
307         AppLogDebug("ENTER");
308
309         //search panel
310         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
311         pSearchPanel->SetShowState(false);
312         pSearchPanel->Invalidate(true);
313
314         //"Add to contacts" button
315         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
316         pButtonAddContacts->SetActionId(IDA_BTN_ADD_TO_CONTACTS);
317         pButtonAddContacts->AddActionEventListener(*this);
318         Canvas pCanvasNormalAdd;
319         pCanvasNormalAdd.Construct(pButtonAddContacts->GetBounds());
320         Canvas pCanvasPressedAdd;
321         pCanvasPressedAdd.Construct(pButtonAddContacts->GetBounds());
322         DialUtil::Draw9PatchToCanvas(pCanvasNormalAdd, IDB_BTN_OPTION_BG_ICON);
323         DialUtil::Draw9PatchToCanvas(pCanvasPressedAdd, IDB_BTN_OPTION_PRESS_BG_ICON);
324         DialUtil::DrawTextToCanvas(IDI_ADD_TO_CONTACTS_STR, FONT_SUGGESTION_NAME, pCanvasNormalAdd, POSITION_CENTER, BUTTON_STATUS_NORMAL);
325         DialUtil::DrawTextToCanvas(IDI_ADD_TO_CONTACTS_STR, FONT_SUGGESTION_NAME, pCanvasPressedAdd, POSITION_CENTER, BUTTON_STATUS_NORMAL);
326         DialUtil::DrawCanvasToButton(&pCanvasNormalAdd, &pCanvasPressedAdd, pButtonAddContacts);
327         pButtonAddContacts->SetShowState(false);
328
329         //"Use Contacts" button
330         Button* pButtonContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
331         pButtonContacts->SetActionId(IDA_BTN_USE_CONTACT_DATA);
332         pButtonContacts->AddActionEventListener(*this);
333         //"Drop-Down" Button
334         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
335         pButtonDropDown->SetActionId(IDA_BTN_DISPLAY_CONTACTS);
336         pButtonDropDown->AddActionEventListener(*this);
337
338         AppLogDebug("EXIT");
339         return;
340 }
341
342 void
343 DialTabDialer::UpdateSearchResults(void)
344 {
345         AppLogDebug("ENTER");
346
347         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
348         //send request to search for suggestion list
349         String searchStr = pEditField->GetText();
350         searchStr.Replace(L"-",L"");
351         if(searchStr.IsEmpty() == false)
352         {
353                 __pDialPresentationModel->FetchSuggestionList(searchStr);
354         }
355
356         AppLogDebug("EXIT");
357         return;
358 }
359
360 void
361 DialTabDialer::HideSearchBox(void)
362 {
363         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
364         pButtonAddContacts->SetShowState(false);
365         Button* pButtonContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
366         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
367         pButtonContacts->SetShowState(true);
368         pButtonDropDown->SetShowState(true);
369
370         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
371         pSearchPanel->SetShowState(false);
372         pSearchPanel->Invalidate(true);
373         return;
374 }
375
376 void
377 DialTabDialer::InitializeSearchListView(void)
378 {
379         //update new bounds
380         __pSearchListView = static_cast<ListView*>(GetControl(IDC_LISTVIEW_SEARCH,true));
381         if(__pSearchListView != null)
382         {
383                 __pSearchListView->SetSweepEnabled(true);
384                 __pSearchListView->SetItemProvider(*__pSuggestionListProvider);
385                 __pSearchListView->AddListViewItemEventListener(*this);
386                 __pSearchListView->SetBackgroundColor(Color(COLOR_SEARCHLIST_BG));
387                 Panel* pSearchListPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_LIST, true));
388                 if(pSearchListPanel != null)
389                 {
390                         SetControlAlwaysOnTop(*pSearchListPanel, true);
391                 }
392         }
393 }
394
395 void
396 DialTabDialer::ShowSearchListView(void)
397 {
398         AppLogDebug("ENTER");
399
400         //find the no. of search rows to be shown - Maximum 5 can be shown.
401         int noOfItems = MAX_SEARCH_LIST_ITEMS;
402         if(__pDialPresentationModel->GetNumberOfSuggestions() < (noOfItems+1))
403         {
404                 noOfItems = __pDialPresentationModel->GetNumberOfSuggestions() - 1;
405         }
406         if(noOfItems <= 0)
407         {
408                 return;
409         }
410
411
412         if (__pSearchListView != null)
413         {
414                 //update new bounds
415                 Rectangle searchListbounds = __pSearchListView->GetBounds();
416                 searchListbounds.height = H_SEARCHLIST_ITEM * noOfItems;
417                 __pSearchListView->SetBounds(searchListbounds);
418                 __pSearchListView->SetItemProvider(*__pSuggestionListProvider);
419         }
420
421         Panel* pSearchListPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_LIST, true));
422         if(pSearchListPanel != null)
423         {
424                 pSearchListPanel->SetShowState(true);
425                 pSearchListPanel->Invalidate(true);
426         }
427
428         __isSearchListOpened = true;
429         AppLogDebug("EXIT");
430         return;
431 }
432
433 void
434 DialTabDialer::HideSearchListView(void)
435 {
436         Panel* pSearchListPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_LIST, true));
437         pSearchListPanel->SetShowState(false);
438         pSearchListPanel->Invalidate(true);
439         __isSearchListOpened = false;
440         return;
441 }
442
443 void
444 DialTabDialer::ConstructMenu(void)
445 {
446         AppLogDebug("ENTER");
447
448         //Construct button for menu open and close
449         Panel* pDisplayPanel = static_cast<Panel*>(GetControl(IDC_PANEL_DISPLAY_DATA, true));
450         Button* pButton = static_cast<Button*>(GetControl(IDC_BUTTON_MENU, true));
451         pButton->SetActionId(IDA_BTN_SHOW_CONTEXTMENU);
452         pButton->AddActionEventListener(*this);
453
454         Canvas pCanvasNormal;
455         pCanvasNormal.Construct(pButton->GetBounds());
456         Canvas pCanvasPressed;
457         pCanvasPressed.Construct(pButton->GetBounds());
458
459         DialUtil::Draw9PatchToCanvas(pCanvasNormal, IDB_BTN_OPTION_BG_ICON);
460         DialUtil::DrawImageToCanvas(IDB_BTN_MORE_ICON, Dimension(W_MORE_BUTTON, H_MORE_BUTTON), pCanvasNormal, POSITION_CENTER);
461         DialUtil::Draw9PatchToCanvas(pCanvasPressed, IDB_BTN_OPTION_PRESS_BG_ICON);
462         DialUtil::DrawImageToCanvas(IDB_BTN_MORE_PRESS_ICON, Dimension(W_MORE_BUTTON, H_MORE_BUTTON), pCanvasPressed, POSITION_CENTER);
463         DialUtil::DrawCanvasToButton(&pCanvasNormal, &pCanvasPressed, pButton);
464         pDisplayPanel->Invalidate(true);
465
466         AppLogDebug("EXIT");
467         return;
468 }
469
470 void
471 DialTabDialer::ConstructKeypad(int dialerState)
472 {
473         AppLogDebug("ENTER");
474         if(__pDialKeypad != null)
475         {
476                 //RemoveControl() also deletes the child control.
477                 RemoveControl(*__pDialKeypad);
478                 __pDialKeypad = null;
479         }
480         //Construct Alpha numeric Keypad
481         if(__pDialKeypad == null)
482         {
483                 __pDialKeypad = new (std::nothrow) DialerKeypad(DialerKeypad::DialerState(dialerState));
484                 __pDialKeypad->ConstructPanel(this, this);
485                 //add keypad to dial panel
486                 AddControl(*__pDialKeypad);
487         }
488         AppLogDebug("EXIT");
489         return;
490 }
491
492 void
493 DialTabDialer::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
494 {
495         AppLogDebug("ENTER");
496         PhoneApp* pPhoneApp = static_cast<PhoneApp*>(PhoneApp::GetInstance());
497         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
498         String editText(L"");
499
500         if(__pCallPresentor == null)
501         {
502                 __pCallPresentor = CallPresentationModel::GetInstance();
503         }
504         //While coming from Logs scene, disable footer
505         const Form* pForm = dynamic_cast<Form*>(GetParent());
506         if(pForm != null)
507         {
508                 pForm->GetFooter()->SetShowState(false);
509         }
510         //If previous scene is present & it is either Single Active Call
511         //or Conf. Call with 'Add Call' scenario.
512         DialerKeypad::DialerState dialerState = DialerKeypad::DIALER_STATE_FIRST_SCENE;
513         if (__pCallPresentor->GetCurrentCallCount() > 0)
514         {
515                 __pPreviousSceneId = new (std::nothrow) SceneId(previousSceneId);
516                 dialerState = DialerKeypad::DIALER_STATE_ADD_CALL;
517                 if(pArgs != null)
518                 {
519                         pArgs->RemoveAll();
520                         delete pArgs;
521                 }
522                 pArgs = null;
523         }
524         else
525         {
526                 if (pArgs != null)
527                 {
528                         //From AppControl request for normal call
529                         dialerState = DialerKeypad::DIALER_STATE_NORMAL_APPCONTROL;
530                         String* tmpStr = static_cast<String*>(pArgs->GetAt(0));
531                         if(tmpStr != null)
532                         {
533                                 editText.Append(*tmpStr);
534                         }
535                         delete pArgs;
536                         pArgs = null;
537                 }
538         }
539
540         if(editText.IsEmpty() == true)
541         {
542                 //Fetch auto area code setting, if present
543                 int retvalue = 0;
544                 result res;
545                 SettingsPresentationModel::GetInstance()->GetActivePrefixDialNumber(editText);
546                 res = Integer::Parse(editText,retvalue);
547                 if(res != E_SUCCESS)
548                 {
549                         editText.Clear();
550         }
551         }
552
553         if(pEditField != null)
554         {
555                 pEditField->SetText(editText);
556                 pEditField->SetCursorPosition(editText.GetLength());
557                 pEditField->SetFocus();
558                 pEditField->Invalidate(true);
559                 //show search results
560                 if (editText.GetLength() == 0)
561                 {
562                         HideSearchBox();
563                 }
564                 else
565                 {
566                         UpdateSearchResults();
567                 }
568         }
569
570         //Construct keypad
571         ConstructKeypad(dialerState);
572
573         //hide footer
574         Form* form = static_cast<Form*>(GetParent());
575         form->GetFooter()->SetShowState(false);
576         pPhoneApp->AddAppStateChangeListener(*this);
577         //Add addressbook listener to listen to contacts changed events
578         if(__pAddressBook != null)
579         {
580                 __pAddressBook->SetEventListener(this);
581         }
582
583         AppLogDebug("EXIT");
584         return;
585 }
586
587 void
588 DialTabDialer::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
589 {
590         AppLogDebug("ENTER");
591         PhoneApp* pPhoneApp = static_cast<PhoneApp*>(PhoneApp::GetInstance());
592         //hide search result list, if shown.
593         if (__isSearchListOpened == true)
594         {
595                 HideSearchListView();
596         }
597         if(__pPreviousSceneId != null)
598         {
599                 delete __pPreviousSceneId;
600                 __pPreviousSceneId = null;
601         }
602         if(__pConfirmationPopup != null)
603         {
604                 delete __pConfirmationPopup;
605                 __pConfirmationPopup = null;
606         }
607         pPhoneApp->RemoveAppStateChangeListener(*this);
608         //remove contact change event listener
609         if(__pAddressBook != null)
610         {
611                 __pAddressBook->SetEventListener(null);
612         }
613         AppLogDebug("EXIT");
614         return;
615 }
616
617 void
618 DialTabDialer::OnActionPerformed(const Control& source, int actionId)
619 {
620         AppLogDebug("ENTER");
621
622         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
623         if (pEditField == null || GetAppControlLaunched() == true)
624         {
625                 AppLogDebug("GetAppControlLaunched() == true");
626                 return;
627         }
628
629         switch (actionId)
630         {
631         case NUM_KEY1:
632         case NUM_KEY2:
633         case NUM_KEY3:
634         case NUM_KEY4:
635         case NUM_KEY5:
636         case NUM_KEY6:
637         case NUM_KEY7:
638         case NUM_KEY8:
639         case NUM_KEY9:
640         case NUM_KEY0:
641         case CLEAR_KEY:
642         {
643                 //append / clear last character to contact
644                 ShowFormattedText(pEditField, actionId);
645                 if (pEditField->GetTextLength() == 0)
646                 {
647                         HideSearchBox();
648                 }
649                 else
650                 {
651                         UpdateSearchResults();
652                 }
653         }
654         break;
655
656         case CALL_KEY:
657         {
658                 if (pEditField->GetTextLength() > 0)
659                 {
660                         String contactNo = pEditField->GetText();
661                         contactNo.Replace(L"-",L"");
662                         SwitchToOutgoingCallScreen(contactNo);
663                         return;
664                 }
665                 else
666                 {
667                         //show latest dialed or incoming number from Logs
668                         String* number = __pDialPresentationModel->FetchLatestNumberFromLogsN();
669                         if(number != null)
670                         {
671                                 pEditField->SetText(*number);
672                                 UpdateSearchResults();
673                                 delete number;
674                         }
675                 }
676         }
677         break;
678
679         case PAUSE_KEY:
680         {
681                 pEditField->AppendText(L"*");
682                 if (pEditField->GetTextLength() == 0)
683                 {
684                         HideSearchBox();
685                 }
686                 else
687                 {
688                         UpdateSearchResults();
689                 }
690         }
691         break;
692
693         case HASH_KEY:
694         {
695                 pEditField->AppendText(L"#");
696                 if (pEditField->GetTextLength() == 0)
697                 {
698                         HideSearchBox();
699                 }
700                 else
701                 {
702                         UpdateSearchResults();
703                 }
704         }
705         break;
706
707         case VIDEOCALL_KEY:
708         {
709                 //Not yet Supported
710         }
711         break;
712
713         case CANCEL_KEY:
714         {
715                 PhoneApp* pApp = static_cast<PhoneApp*>(UiApp::GetInstance());
716                 bool isAppControl = pApp->IsOpenAsAppControl();
717                 if(isAppControl == true && __pPreviousSceneId == null)
718                 {
719                         pApp->Terminate();
720                 }
721                 else if(__pCallPresentor->GetCurrentCallCount() > 0)
722                 {
723                         //Switch back to previous screen
724                         SwitchToPreviousActiveCallScreen();
725                         return;
726                 }
727         }
728         break;
729
730         case IDA_BTN_SHOW_CONTEXTMENU:
731         {
732                 // Show the ContextMenu
733                 String contactNo = pEditField->GetText();
734                 contactNo.Replace(L"-",L"");
735                 ShowContextMenu(contactNo);
736                 if (__isSearchListOpened == true)
737                 {
738                         HideSearchListView();
739                 }
740         }
741         break;
742
743         case IDA_MENU_SEND_MESSAGE:
744         {
745                 String contactNo = pEditField->GetText();
746                 contactNo.Replace(L"-",L"");
747                 __pDialPresentationModel->OpenMessagingAppControl(contactNo);
748                 return;
749         }
750         break;
751
752         case IDA_BTN_ADD_TO_CONTACTS:
753         case IDA_MENU_ADD_CONTACT:
754         {
755                 if(pEditField->GetTextLength() > 0)
756                 {
757                         String contactNo = pEditField->GetText();
758                         contactNo.Replace(L"-",L"");
759                         __pDialPresentationModel->AddContactsToAddressBook(contactNo);
760                         SetAppControlLaunched(true);
761                         return;
762                 }
763         }
764         break;
765
766         case IDA_SPEEDDIAL_POPUP_YES:
767         {
768                 __pConfirmationPopup->SetShowState(false);
769                 SwitchToSpeedDialForm();
770         }
771         break;
772
773         case IDA_SPEEDDIAL_POPUP_NO:
774         {
775                 __pConfirmationPopup->SetShowState(false);
776                 Invalidate(true);
777         }
778         break;
779
780         case IDA_MENU_SPEED_DIAL:
781         {
782                 SwitchToSpeedDialForm();
783                 return;
784         }
785         break;
786
787         case IDA_MENU_ADD_PAUSE:
788         {
789                 AddPause();
790         }
791         break;
792
793         case IDA_MENU_ADD_WAIT:
794         {
795                 AddWait();
796         }
797         break;
798
799         case IDA_MENU_EXIT:
800         {
801                 if(__pCallPresentor->GetCurrentCallCount() > 0)
802                 {
803                         //Switch back to previous screen
804                         SwitchToPreviousActiveCallScreen();
805                         return;
806                 }
807                 else
808                 {
809                         //Close Phone App
810                         UiApp::GetInstance()->Terminate();
811                 }
812         }
813         break;
814
815         case IDA_BTN_USE_CONTACT_DATA:
816         {
817                 DialContactInfo* pDialInfo = __pDialPresentationModel->GetSuggestionAtIndex(0);
818                 if(pDialInfo != null)
819                 {
820                         //fetch contact number
821                         String phNumber = pDialInfo->GetPhoneNumber();
822                         if(phNumber.Equals(pEditField->GetText()) == false)
823                         {
824                                 pEditField->Clear();
825                                 pEditField->SetText(phNumber);
826                                 pEditField->Invalidate(true);
827                                 if (__isSearchListOpened == true)
828                                 {
829                                         HideSearchListView();
830                                 }
831                                 UpdateSearchResults();
832                         }
833                 }
834         }
835         break;
836
837         case IDA_BTN_DISPLAY_CONTACTS:
838         {
839                 if (__isSearchListOpened == true)
840                 {
841                         HideSearchListView();
842                 }
843                 else
844                 {
845                         ShowSearchListView();
846                 }
847         }
848         break;
849
850         default:
851                 break;
852         }
853         pEditField->Invalidate(true);
854
855         AppLogDebug("EXIT");
856         return;
857 }
858
859 void
860 DialTabDialer::OnLongPressGestureDetected(TouchLongPressGestureDetector& gestureDetector)
861 {
862         AppLogDebug("ENTER");
863
864         if (gestureDetector.GetControl() != null)
865         {
866                 Button* pButton = static_cast<Button*>(gestureDetector.GetControl());
867                 int actionId = pButton->GetActionId();
868                 switch(actionId)
869                 {
870                 case NUM_KEY2:
871                 case NUM_KEY3:
872                 case NUM_KEY4:
873                 case NUM_KEY5:
874                 case NUM_KEY6:
875                 case NUM_KEY7:
876                 case NUM_KEY8:
877                 case NUM_KEY9:
878                 {
879                         //Check if Speed Dial setting exist for pressed key
880                         String* contactNumber = __pDialPresentationModel->FetchSpeedDialNumberN(actionId);
881                         if(contactNumber != null)
882                         {
883                                 ArrayList* pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
884                                 pArgs->Construct();
885                                 //pass ownership to arraylist
886                                 pArgs->Add(contactNumber);
887                                 SendUserEvent(REQUEST_CALL_SPEED_DIAL_NUM,pArgs);
888                         }
889                         else
890                         {
891                                 //show speed Dial Confirmation Popup msg
892                                 SendUserEvent(REQUEST_SHOW_SPEED_DIAL_POPUP,null);
893                         }
894
895                 }
896                 break;
897
898                 case PAUSE_KEY:
899                 {
900                         AddPause();
901                 }
902                 break;
903
904                 case HASH_KEY:
905                 {
906                         //Handle Mute / UnMute
907                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
908                         if(pEditField->GetTextLength() == 0)
909                         {
910                                 bool enabled = false;
911                                 String title = L"http://tizen.org/setting/sound.silent_mode";
912                                 SettingInfo::GetValue(title, enabled);
913                                 //enable or disable the phone silent mode.
914                                 result r = E_FAILURE;
915                                 r = SettingInfo::SetValue(title, !enabled);
916                                 if(r == E_OBJ_NOT_FOUND)
917                                 {
918                                         AppLog("Object not found");
919                                 }
920                         }
921                 }
922                 break;
923
924                 case CLEAR_KEY:
925                 {
926                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
927                         if (pEditField != null && pEditField->GetTextLength() > 0)
928                         {
929                                 pEditField->Clear();
930                                 pEditField->SetTextSize(IDI_MAX_TXT_FONT);
931                                 pEditField->SetCursorPosition(0);
932                                 pEditField->SetFocus();
933                                 pEditField->Invalidate(true);
934                                 HideSearchBox();
935                         }
936                 }
937                 break;
938                 case NUM_KEY0:
939                 {
940                         AddPlus();
941                 }
942                 break;
943
944                 default:
945                         break;
946                 }
947         }
948
949         AppLogDebug("EXIT");
950         return;
951 }
952
953 void
954 DialTabDialer::ShowContextMenu(String& contactNumber)
955 {
956         AppLogDebug("ENTER");
957
958         if(__pContextMenu != null)
959         {
960                 delete __pContextMenu;
961                 __pContextMenu = null;
962         }
963         __pContextMenu = new (std::nothrow) ContextMenu();
964         __pContextMenu->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
965
966         //minimum available option count
967         int visibleItems = MIN_CONTEXT_MENU_ITEMS;
968
969         //Show SendMsg Option only if NOT opened from Outgoing Call
970         if(__pPreviousSceneId == null)
971         {
972                 __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_SEND_MSG), IDA_MENU_SEND_MESSAGE);
973                 visibleItems++;
974         }
975         //Don't show 'AddContact' if empty text field
976         //or contact number is already saved.
977         if(contactNumber.IsEmpty() != true)
978         {
979                 Contact* pContact = __pCallPresentor->GetContactN(contactNumber);
980                 if(pContact == null)
981                 {
982                         __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_ADD_CONTACT), IDA_MENU_ADD_CONTACT);
983                         visibleItems++;
984                 }
985                 else
986                 {
987                         delete pContact;
988                 }
989         }
990         __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_SPEED_DIAL), IDA_MENU_SPEED_DIAL);
991         __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_ADD_PAUSE), IDA_MENU_ADD_PAUSE);
992         __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_ADD_WAIT), IDA_MENU_ADD_WAIT);
993         __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_EXIT), IDA_MENU_EXIT);
994         __pContextMenu->AddActionEventListener(*this);
995
996         __pContextMenu->SetMaxVisibleItemsCount(visibleItems);
997         // Set the anchor position of the ContextMenu
998         __pContextMenu->SetAnchorPosition(Point(X_CONTEXT_MENU_ANCHOR, Y_CONTEXT_MENU_ANCHOR));
999         // Show the ContextMenu
1000         __pContextMenu->Show();
1001
1002         AppLogDebug("EXIT");
1003         return;
1004 }
1005
1006 void
1007 DialTabDialer::AddPause(void)
1008 {
1009         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1010         if (pEditField != null)
1011         {
1012                 pEditField->AppendText(L";");
1013                 if (pEditField->GetTextLength() == 0)
1014                 {
1015                         HideSearchBox();
1016                 }
1017                 else
1018                 {
1019                         UpdateSearchResults();
1020                 }
1021                 pEditField->Invalidate(true);
1022         }
1023         return;
1024 }
1025
1026 void
1027 DialTabDialer::AddWait(void)
1028 {
1029         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1030         if (pEditField != null)
1031         {
1032                 pEditField->AppendText(L",");
1033                 if (pEditField->GetTextLength() == 0)
1034                 {
1035                         HideSearchBox();
1036                 }
1037                 else
1038                 {
1039                         UpdateSearchResults();
1040                 }
1041                 pEditField->Invalidate(true);
1042         }
1043         return;
1044 }
1045
1046 void
1047 DialTabDialer::AddPlus(void)
1048 {
1049         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1050         if (pEditField != null)
1051         {
1052                 pEditField->AppendText(L"+");
1053                 if (pEditField->GetTextLength() == 0)
1054                 {
1055                         HideSearchBox();
1056                 }
1057                 else
1058                 {
1059                         UpdateSearchResults();
1060                 }
1061                 pEditField->Invalidate(true);
1062         }
1063         return;
1064 }
1065
1066 void
1067 DialTabDialer::SwitchToPreviousActiveCallScreen(void)
1068 {
1069         AppLogDebug("ENTER");
1070
1071         SceneManager* pSceneManager = SceneManager::GetInstance();
1072         AppAssert(pSceneManager);
1073         if(__pCallPresentor == null)
1074         {
1075                 __pCallPresentor = CallPresentationModel::GetInstance();
1076         }
1077         //Fetch call info list
1078         IListT<CallInfo>* pCallList = __pCallPresentor->GetCallListN();
1079         IEnumeratorT<CallInfo>* pCallEnum = pCallList->GetEnumeratorN();
1080         if(pCallEnum != null)
1081         {
1082                 ArrayList* pCallArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1083                 pCallArgs->Construct();
1084                 while(pCallEnum->MoveNext() == E_SUCCESS)
1085                 {
1086                         CallInfo callInfo;
1087                         if(pCallEnum->GetCurrent(callInfo) == E_SUCCESS)
1088                         {
1089                                 CallInfo* pActiveCall = new (std::nothrow) CallInfo();
1090                                 *pActiveCall = callInfo;
1091                                 pCallArgs->Add(pActiveCall);
1092                         }
1093                 }
1094
1095                 if(pCallArgs->GetCount() == 1 && (static_cast<CallInfo*>(pCallArgs->GetAt(0)))->IsConferenceCall() == true)
1096                 {
1097                         //move back to previous conf. call screen - ownership of 'pCallArgs' transferred
1098                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL), pCallArgs);
1099                 }
1100                 else
1101                 {
1102                         //move back to previous screen - ownership of 'pCallArgs' transferred
1103                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL), pCallArgs);
1104                 }
1105
1106                 delete pCallEnum;
1107                 pCallEnum = null;
1108         }
1109         delete pCallList;
1110         pCallList = null;
1111         AppLogDebug("EXIT");
1112 }
1113
1114 void
1115 DialTabDialer::SwitchToOutgoingCallScreen(const String& contactNumber)
1116 {
1117         AppLogDebug("ENTER");
1118
1119         SceneManager* pSceneManager = SceneManager::GetInstance();
1120         AppAssert(pSceneManager);
1121
1122         //Check if dialing a call is possible
1123         if(__pCallPresentor == null)
1124         {
1125                 __pCallPresentor = CallPresentationModel::GetInstance();
1126         }
1127         bool isSimInitialized = __pCallPresentor->CheckSimInitializationIsCompleted();
1128         if (isSimInitialized == true)
1129         {
1130                 //make an outgoing call with given number
1131                 String* contactTxt = new (std::nothrow) String(contactNumber);
1132                 //switch to dialing outgoing call form
1133                 ArrayList* pContact = new (std::nothrow) ArrayList(SingleObjectDeleter);
1134                 pContact->Construct(1);
1135                 pContact->Add(contactTxt);
1136                 //Check if dialing an emergency call
1137                 bool isEmergencyCall = __pCallPresentor->IsEmergencyNumber(*contactTxt, true);
1138                 if (isEmergencyCall)
1139                 {
1140                         pSceneManager->GoForward( ForwardSceneTransition( IDSCN_SCENE_OUT_EMERGENCYCALL), pContact);
1141                 }
1142                 else
1143                 {
1144                         pSceneManager->GoForward( ForwardSceneTransition(IDSCN_SCENE_OUTCALL), pContact);
1145                 }
1146         }
1147         else
1148         {
1149                 //TODO: check what to do for SOS calls
1150                 //Show error message Popup
1151                 if (__pErrorMsgPopup == null)
1152                 {
1153                         __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
1154                 }
1155                 __pErrorMsgPopup->ShowErrorMsgPopupN(ERROR_CODE_SIM_INITIALIZATION_FAILED);
1156         }
1157         AppLogDebug("EXIT");
1158         return;
1159 }
1160
1161 void
1162 DialTabDialer::SwitchToSpeedDialForm(void)
1163 {
1164         SceneManager* pSceneManager = SceneManager::GetInstance();
1165         AppAssert(pSceneManager);
1166         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_SPEED_DIAL), null);
1167         return;
1168 }
1169
1170 void
1171 DialTabDialer::ShowSpeedDialConfirmationPopup(void)
1172 {
1173         if(__pConfirmationPopup == null)
1174         {
1175                 Rectangle rect = GetBounds();
1176                 __pConfirmationPopup = new (std::nothrow) Popup();
1177                 __pConfirmationPopup->Construct(false, Dimension(rect.width, H_SPEEDDIAL_POPUP));
1178
1179                 rect = __pConfirmationPopup->GetBounds();
1180                 Label* pMsgLabel = new (std::nothrow) Label();
1181                 String popupMsg = AppUtility::GetResourceString(IDS_DIALER_SPEEDDIAL_POPUP_MSG);
1182                 pMsgLabel->Construct(Rectangle(0, IDI_PADDING, rect.width, H_POPUP_MSG_LABEL), popupMsg);
1183                 pMsgLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1184                 pMsgLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1185                 __pConfirmationPopup->AddControl(*pMsgLabel);
1186
1187                 rect = pMsgLabel->GetBounds();
1188                 Button *pButtonYes = new (std::nothrow) Button();
1189                 String btnName = AppUtility::GetResourceString(IDS_SPEEDDIAL_POP_YES_BTN_STRING);
1190                 pButtonYes->Construct(Rectangle(rect.x, (rect.y + rect.height + IDI_PADDING), ((rect.width - (6 * IDI_PADDING)) / 2), H_POPUP_BTN), btnName);
1191                 pButtonYes->SetActionId(IDA_SPEEDDIAL_POPUP_YES);
1192                 pButtonYes->AddActionEventListener(*this);
1193                 __pConfirmationPopup->AddControl(*pButtonYes);
1194
1195                 rect = pButtonYes->GetBounds();
1196                 Button *pButtonNo = new (std::nothrow) Button();
1197                 btnName = AppUtility::GetResourceString(IDS_SPEEDDIAL_POP_NO_BTN_STRING);
1198                 pButtonNo->Construct(Rectangle((rect.x + rect.width + IDI_PADDING), rect.y, rect.width, rect.height), btnName);
1199                 pButtonNo->SetActionId(IDA_SPEEDDIAL_POPUP_NO);
1200                 pButtonNo->AddActionEventListener(*this);
1201                 __pConfirmationPopup->AddControl(*pButtonNo);
1202         }
1203         //Show Popup message
1204         __pConfirmationPopup->SetShowState(true);
1205         __pConfirmationPopup->Show();
1206 }
1207
1208 void
1209 DialTabDialer::ShowAddToContactsButton(void)
1210 {
1211         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1212         Button* pButtonContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
1213         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
1214         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
1215         pButtonContacts->SetShowState(false);
1216         pButtonDropDown->SetShowState(false);
1217         pButtonAddContacts->SetShowState(true);
1218         pSearchPanel->SetShowState(true);
1219         pSearchPanel->Invalidate(true);
1220         return;
1221 }
1222
1223 void
1224 DialTabDialer::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
1225 {
1226         switch(requestId)
1227         {
1228                 case REQUEST_SHOW_SUGGESTION:
1229                 {
1230                         String *displayname = static_cast<String*> (pArgs->GetAt(0));
1231                         String *mobileNo = static_cast<String*> (pArgs->GetAt(1));
1232                         String *resultCount = static_cast<String*> (pArgs->GetAt(2));
1233                         if(displayname != null && mobileNo != null && resultCount != null)
1234                         {
1235                                 ShowSuggestionBox(*displayname, *mobileNo, *resultCount);
1236                         }
1237                         delete pArgs;
1238                 }
1239                 break;
1240
1241                 case REQUEST_SHOW_ADD_TO_CONTACTS:
1242                 {
1243                         ShowAddToContactsButton();
1244                 }
1245                 break;
1246
1247                 case REQUEST_CALL_SPEED_DIAL_NUM:
1248                 {
1249                         if(pArgs != null)
1250                         {
1251                                 String *number = static_cast<String*> (pArgs->GetAt(0));
1252                                 //dial a call.
1253                                 if(number != null)
1254                                 {
1255                                         SwitchToOutgoingCallScreen(*number);
1256                                 }
1257                                 delete pArgs;
1258                         }
1259                 }
1260                 break;
1261
1262                 case REQUEST_SHOW_SPEED_DIAL_POPUP:
1263                 {
1264                         //show speed Dial Confirmation Popup msg
1265                         ShowSpeedDialConfirmationPopup();
1266                 }
1267                 break;
1268         }
1269
1270 }
1271 void
1272 DialTabDialer::ShowSuggestionBox(String& name, String& mobileNo, String& resultCount)
1273 {
1274         AppLogDebug("ENTER");
1275
1276         //"UseContact" Button
1277         Button* pButtonContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
1278         Canvas pCanvasNormalContacts;
1279         pCanvasNormalContacts.Construct(pButtonContacts->GetBounds());
1280         Canvas pCanvasPressedContacts;
1281         pCanvasPressedContacts.Construct(pButtonContacts->GetBounds());
1282         String mobileStr = AppUtility::GetResourceString(IDS_DIALER_MOBILE_STR);
1283         //Add text, Bg to normal state
1284         DialUtil::Draw9PatchToCanvas(pCanvasNormalContacts, IDB_BTN_OPTION_BG_ICON);
1285         DialUtil::DrawTextToCanvas(name, FONT_SUGGESTION_NAME, pCanvasNormalContacts, POSITION_TOP_LEFT, BUTTON_STATUS_NORMAL);
1286         DialUtil::DrawTextToCanvas(mobileStr, FONT_SUGGESTION_MOBILE, pCanvasNormalContacts, POSITION_BOTTOM_LEFT, BUTTON_STATUS_NORMAL);
1287         DialUtil::DrawTextToCanvas(mobileNo, FONT_SUGGESTION_NUMBER, pCanvasNormalContacts, POSITION_BOTTOM_CENTER, BUTTON_STATUS_NORMAL);
1288         //Add text, Bg to pressed state
1289         DialUtil::Draw9PatchToCanvas(pCanvasPressedContacts, IDB_BTN_OPTION_PRESS_BG_ICON);
1290         DialUtil::DrawTextToCanvas(name, FONT_SUGGESTION_NAME, pCanvasPressedContacts, POSITION_TOP_LEFT, BUTTON_STATUS_NORMAL);
1291         DialUtil::DrawTextToCanvas(mobileStr, FONT_SUGGESTION_MOBILE, pCanvasPressedContacts, POSITION_BOTTOM_LEFT, BUTTON_STATUS_NORMAL);
1292         DialUtil::DrawTextToCanvas(mobileNo, FONT_SUGGESTION_NUMBER, pCanvasPressedContacts, POSITION_BOTTOM_CENTER, BUTTON_STATUS_NORMAL);
1293         //add normal, pressed bg bitmap to button
1294         DialUtil::DrawCanvasToButton(&pCanvasNormalContacts, &pCanvasPressedContacts, pButtonContacts);
1295
1296         //"DropDown" Button
1297         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
1298         Canvas pCanvasNormalDropDown;
1299         pCanvasNormalDropDown.Construct(pButtonDropDown->GetBounds());
1300         Canvas pCanvasPressedDropDown;
1301         pCanvasPressedDropDown.Construct(pButtonDropDown->GetBounds());
1302         //Add text, Bg to normal state
1303         DialUtil::Draw9PatchToCanvas(pCanvasNormalDropDown, IDB_BTN_OPTION_BG_ICON);
1304         DialUtil::DrawTextToCanvas(resultCount, FONT_SUGGESTION_LIST_NUMBER, pCanvasNormalDropDown, POSITION_TOP_CENTER, BUTTON_STATUS_NORMAL);
1305         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasNormalDropDown, POSITION_BOTTOM_CENTER);
1306         //Add text, Bg to pressed state
1307         DialUtil::Draw9PatchToCanvas(pCanvasPressedDropDown, IDB_BTN_OPTION_PRESS_BG_ICON);
1308         DialUtil::DrawTextToCanvas(resultCount, FONT_SUGGESTION_LIST_NUMBER, pCanvasPressedDropDown, POSITION_TOP_CENTER, BUTTON_STATUS_NORMAL);
1309         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasPressedDropDown, POSITION_BOTTOM_CENTER);
1310         //add background to button
1311         DialUtil::DrawCanvasToButton(&pCanvasNormalDropDown, &pCanvasPressedDropDown, pButtonDropDown);
1312
1313         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
1314         pButtonContacts->SetShowState(true);
1315         pButtonDropDown->SetShowState(true);
1316         pButtonDropDown->Invalidate(true);
1317         pButtonAddContacts->SetShowState(false);
1318
1319         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1320         pSearchPanel->SetShowState(true);
1321         pSearchPanel->Invalidate(true);
1322
1323         AppLogDebug("EXIT");
1324         return;
1325 }
1326
1327 void
1328 DialTabDialer::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
1329 {
1330         DialContactInfo* pDialInfo = __pDialPresentationModel->GetSuggestionAtIndex(index+1);
1331         if(pDialInfo != null)
1332         {
1333                 String phNumber = pDialInfo->GetPhoneNumber();
1334                 EditField* pTextBox = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1335                 if(pTextBox != null)
1336                 {
1337                         pTextBox->Clear();
1338                         pTextBox->SetText(phNumber);
1339                         pTextBox->Invalidate(true);
1340                 }
1341                 HideSearchListView();
1342                 UpdateSearchResults();
1343         }
1344         return;
1345 }
1346
1347 void
1348 DialTabDialer::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1349 {
1350         Form* pForm = static_cast<Form*>(GetParent());
1351         pForm->SetOrientation(ORIENTATION_PORTRAIT);
1352         pForm->Invalidate(true);
1353         return;
1354 }
1355
1356 void
1357 DialTabDialer::HandlePopupClosed(void)
1358 {
1359         Draw();
1360         delete __pErrorMsgPopup;
1361         __pErrorMsgPopup = null;
1362         return;
1363 }
1364
1365 bool
1366 DialTabDialer::IsOpenedFromOtherView(void)
1367 {
1368         if(__pPreviousSceneId != null)
1369         {
1370                 return true;
1371         }
1372         return false;
1373 }
1374
1375 void
1376 DialTabDialer::OnForeground(void)
1377 {
1378         AppLogDebug("Enter");
1379         __isAppForeground = true;
1380         //If app control was launched
1381         //as we do not know if it success or failed
1382         // we need to UpdateSearchResults
1383         //Returned from app control if app control does not
1384         //send any response we need to do this
1385         SetAppControlLaunched(false);
1386 }
1387
1388 void
1389 DialTabDialer::OnBackground(void)
1390 {
1391         AppLogDebug("Enter");
1392         __isAppForeground = false;
1393 }
1394
1395 bool
1396 DialTabDialer::IsForeground()
1397 {
1398         AppLogDebug("Enter %d",__isAppForeground);
1399         return __isAppForeground;
1400 }
1401
1402 void
1403 DialTabDialer::OnContactsChanged(const IList& contactChangeInfoList)
1404 {
1405         if(contactChangeInfoList.GetCount() > 0)
1406         {
1407                 //clear old search results
1408                 __pDialPresentationModel->ClearSearchResults();
1409                 UpdateSearchResults();
1410         }
1411 }
1412
1413 void
1414 DialTabDialer::SetAppControlLaunched(bool launched)
1415 {
1416         AppLogDebug("%d",__isAppControlLaunched);
1417         __isAppControlLaunched = launched;
1418 }
1419
1420 bool
1421 DialTabDialer::GetAppControlLaunched(void)
1422 {
1423         AppLogDebug("%d",__isAppControlLaunched);
1424         return __isAppControlLaunched;
1425 }
1426
1427