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                         __pDialPresentationModel->ClearSearchResults();
648                         HideSearchBox();
649                 }
650                 else
651                 {
652                         UpdateSearchResults();
653                 }
654         }
655         break;
656
657         case CALL_KEY:
658         {
659                 if (pEditField->GetTextLength() > 0)
660                 {
661                         String contactNo = pEditField->GetText();
662                         contactNo.Replace(L"-",L"");
663                         SwitchToOutgoingCallScreen(contactNo);
664                         return;
665                 }
666                 else
667                 {
668                         //show latest dialed or incoming number from Logs
669                         String* number = __pDialPresentationModel->FetchLatestNumberFromLogsN();
670                         if(number != null)
671                         {
672                                 pEditField->SetText(*number);
673                                 UpdateSearchResults();
674                                 delete number;
675                         }
676                 }
677         }
678         break;
679
680         case PAUSE_KEY:
681         {
682                 pEditField->AppendText(L"*");
683                 if (pEditField->GetTextLength() == 0)
684                 {
685                         HideSearchBox();
686                 }
687                 else
688                 {
689                         UpdateSearchResults();
690                 }
691         }
692         break;
693
694         case HASH_KEY:
695         {
696                 pEditField->AppendText(L"#");
697                 if (pEditField->GetTextLength() == 0)
698                 {
699                         HideSearchBox();
700                 }
701                 else
702                 {
703                         UpdateSearchResults();
704                 }
705         }
706         break;
707
708         case VIDEOCALL_KEY:
709         {
710                 //Not yet Supported
711         }
712         break;
713
714         case CANCEL_KEY:
715         {
716                 PhoneApp* pApp = static_cast<PhoneApp*>(UiApp::GetInstance());
717                 bool isAppControl = pApp->IsOpenAsAppControl();
718                 if(isAppControl == true && __pPreviousSceneId == null)
719                 {
720                         pApp->Terminate();
721                 }
722                 else if(__pCallPresentor->GetCurrentCallCount() > 0)
723                 {
724                         //Switch back to previous screen
725                         SwitchToPreviousActiveCallScreen();
726                         return;
727                 }
728         }
729         break;
730
731         case IDA_BTN_SHOW_CONTEXTMENU:
732         {
733                 // Show the ContextMenu
734                 String contactNo = pEditField->GetText();
735                 contactNo.Replace(L"-",L"");
736                 ShowContextMenu(contactNo);
737                 if (__isSearchListOpened == true)
738                 {
739                         HideSearchListView();
740                 }
741         }
742         break;
743
744         case IDA_MENU_SEND_MESSAGE:
745         {
746                 String contactNo = pEditField->GetText();
747                 contactNo.Replace(L"-",L"");
748                 __pDialPresentationModel->OpenMessagingAppControl(contactNo);
749                 return;
750         }
751         break;
752
753         case IDA_BTN_ADD_TO_CONTACTS:
754         case IDA_MENU_ADD_CONTACT:
755         {
756                 if(pEditField->GetTextLength() > 0)
757                 {
758                         String contactNo = pEditField->GetText();
759                         contactNo.Replace(L"-",L"");
760                         __pDialPresentationModel->AddContactsToAddressBook(contactNo);
761                         SetAppControlLaunched(true);
762                         return;
763                 }
764         }
765         break;
766
767         case IDA_SPEEDDIAL_POPUP_YES:
768         {
769                 __pConfirmationPopup->SetShowState(false);
770                 SwitchToSpeedDialForm();
771         }
772         break;
773
774         case IDA_SPEEDDIAL_POPUP_NO:
775         {
776                 __pConfirmationPopup->SetShowState(false);
777                 Invalidate(true);
778         }
779         break;
780
781         case IDA_MENU_SPEED_DIAL:
782         {
783                 SwitchToSpeedDialForm();
784                 return;
785         }
786         break;
787
788         case IDA_MENU_ADD_PAUSE:
789         {
790                 AddPause();
791         }
792         break;
793
794         case IDA_MENU_ADD_WAIT:
795         {
796                 AddWait();
797         }
798         break;
799
800         case IDA_MENU_EXIT:
801         {
802                 if(__pCallPresentor->GetCurrentCallCount() > 0)
803                 {
804                         //Switch back to previous screen
805                         SwitchToPreviousActiveCallScreen();
806                         return;
807                 }
808                 else
809                 {
810                         //Close Phone App
811                         UiApp::GetInstance()->Terminate();
812                 }
813         }
814         break;
815
816         case IDA_BTN_USE_CONTACT_DATA:
817         {
818                 DialContactInfo* pDialInfo = __pDialPresentationModel->GetSuggestionAtIndex(0);
819                 if(pDialInfo != null)
820                 {
821                         //fetch contact number
822                         String phNumber = pDialInfo->GetPhoneNumber();
823                         if(phNumber.Equals(pEditField->GetText()) == false)
824                         {
825                                 pEditField->Clear();
826                                 pEditField->SetText(phNumber);
827                                 pEditField->Invalidate(true);
828                                 if (__isSearchListOpened == true)
829                                 {
830                                         HideSearchListView();
831                                 }
832                                 __pDialPresentationModel->ClearSearchResults();
833                                 UpdateSearchResults();
834                         }
835                 }
836         }
837         break;
838
839         case IDA_BTN_DISPLAY_CONTACTS:
840         {
841                 if (__isSearchListOpened == true)
842                 {
843                         HideSearchListView();
844                 }
845                 else
846                 {
847                         ShowSearchListView();
848                 }
849         }
850         break;
851
852         default:
853                 break;
854         }
855         pEditField->Invalidate(true);
856
857         AppLogDebug("EXIT");
858         return;
859 }
860
861 void
862 DialTabDialer::OnLongPressGestureDetected(TouchLongPressGestureDetector& gestureDetector)
863 {
864         AppLogDebug("ENTER");
865
866         if (gestureDetector.GetControl() != null)
867         {
868                 Button* pButton = static_cast<Button*>(gestureDetector.GetControl());
869                 int actionId = pButton->GetActionId();
870                 switch(actionId)
871                 {
872                 case NUM_KEY2:
873                 case NUM_KEY3:
874                 case NUM_KEY4:
875                 case NUM_KEY5:
876                 case NUM_KEY6:
877                 case NUM_KEY7:
878                 case NUM_KEY8:
879                 case NUM_KEY9:
880                 {
881                         //Check if Speed Dial setting exist for pressed key
882                         String* contactNumber = __pDialPresentationModel->FetchSpeedDialNumberN(actionId);
883                         if(contactNumber != null)
884                         {
885                                 ArrayList* pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
886                                 pArgs->Construct();
887                                 //pass ownership to arraylist
888                                 pArgs->Add(contactNumber);
889                                 SendUserEvent(REQUEST_CALL_SPEED_DIAL_NUM,pArgs);
890                         }
891                         else
892                         {
893                                 //show speed Dial Confirmation Popup msg
894                                 SendUserEvent(REQUEST_SHOW_SPEED_DIAL_POPUP,null);
895                         }
896
897                 }
898                 break;
899
900                 case PAUSE_KEY:
901                 {
902                         AddPause();
903                 }
904                 break;
905
906                 case HASH_KEY:
907                 {
908                         //Handle Mute / UnMute
909                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
910                         if(pEditField->GetTextLength() == 0)
911                         {
912                                 bool enabled = false;
913                                 String title = L"http://tizen.org/setting/sound.silent_mode";
914                                 SettingInfo::GetValue(title, enabled);
915                                 //enable or disable the phone silent mode.
916                                 result r = E_FAILURE;
917                                 r = SettingInfo::SetValue(title, !enabled);
918                                 if(r == E_OBJ_NOT_FOUND)
919                                 {
920                                         AppLog("Object not found");
921                                 }
922                         }
923                 }
924                 break;
925
926                 case CLEAR_KEY:
927                 {
928                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
929                         if (pEditField != null && pEditField->GetTextLength() > 0)
930                         {
931                                 pEditField->Clear();
932                                 pEditField->SetTextSize(IDI_MAX_TXT_FONT);
933                                 pEditField->SetCursorPosition(0);
934                                 pEditField->SetFocus();
935                                 pEditField->Invalidate(true);
936                                 HideSearchBox();
937                         }
938                 }
939                 break;
940                 case NUM_KEY0:
941                 {
942                         AddPlus();
943                 }
944                 break;
945
946                 default:
947                         break;
948                 }
949         }
950
951         AppLogDebug("EXIT");
952         return;
953 }
954
955 void
956 DialTabDialer::ShowContextMenu(String& contactNumber)
957 {
958         AppLogDebug("ENTER");
959
960         if(__pContextMenu != null)
961         {
962                 delete __pContextMenu;
963                 __pContextMenu = null;
964         }
965         __pContextMenu = new (std::nothrow) ContextMenu();
966         __pContextMenu->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
967
968         //minimum available option count
969         int visibleItems = MIN_CONTEXT_MENU_ITEMS;
970
971         //Show SendMsg Option only if NOT opened from Outgoing Call
972         if(__pPreviousSceneId == null)
973         {
974                 __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_SEND_MSG), IDA_MENU_SEND_MESSAGE);
975                 visibleItems++;
976         }
977         //Don't show 'AddContact' if empty text field
978         //or contact number is already saved.
979         if(contactNumber.IsEmpty() != true)
980         {
981                 Contact* pContact = __pCallPresentor->GetContactN(contactNumber);
982                 if(pContact == null)
983                 {
984                         __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_ADD_CONTACT), IDA_MENU_ADD_CONTACT);
985                         visibleItems++;
986                 }
987                 else
988                 {
989                         delete pContact;
990                 }
991         }
992         __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_SPEED_DIAL), IDA_MENU_SPEED_DIAL);
993         __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_ADD_PAUSE), IDA_MENU_ADD_PAUSE);
994         __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_ADD_WAIT), IDA_MENU_ADD_WAIT);
995         __pContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_EXIT), IDA_MENU_EXIT);
996         __pContextMenu->AddActionEventListener(*this);
997
998         __pContextMenu->SetMaxVisibleItemsCount(visibleItems);
999         // Set the anchor position of the ContextMenu
1000         __pContextMenu->SetAnchorPosition(Point(X_CONTEXT_MENU_ANCHOR, Y_CONTEXT_MENU_ANCHOR));
1001         // Show the ContextMenu
1002         __pContextMenu->Show();
1003
1004         AppLogDebug("EXIT");
1005         return;
1006 }
1007
1008 void
1009 DialTabDialer::AddPause(void)
1010 {
1011         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1012         if (pEditField != null)
1013         {
1014                 pEditField->AppendText(L";");
1015                 if (pEditField->GetTextLength() == 0)
1016                 {
1017                         HideSearchBox();
1018                 }
1019                 else
1020                 {
1021                 __pDialPresentationModel->ClearSearchResults();
1022                         UpdateSearchResults();
1023                 }
1024                 pEditField->Invalidate(true);
1025         }
1026         return;
1027 }
1028
1029 void
1030 DialTabDialer::AddWait(void)
1031 {
1032         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1033         if (pEditField != null)
1034         {
1035                 pEditField->AppendText(L",");
1036                 if (pEditField->GetTextLength() == 0)
1037                 {
1038                         HideSearchBox();
1039                 }
1040                 else
1041                 {
1042                         __pDialPresentationModel->ClearSearchResults();
1043                         UpdateSearchResults();
1044                 }
1045                 pEditField->Invalidate(true);
1046         }
1047         return;
1048 }
1049
1050 void
1051 DialTabDialer::AddPlus(void)
1052 {
1053         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1054         if (pEditField != null)
1055         {
1056                 pEditField->AppendText(L"+");
1057                 if (pEditField->GetTextLength() == 0)
1058                 {
1059                         HideSearchBox();
1060                 }
1061                 else
1062                 {
1063                 __pDialPresentationModel->ClearSearchResults();
1064                         UpdateSearchResults();
1065                 }
1066                 pEditField->Invalidate(true);
1067         }
1068         return;
1069 }
1070
1071 void
1072 DialTabDialer::SwitchToPreviousActiveCallScreen(void)
1073 {
1074         AppLogDebug("ENTER");
1075
1076         SceneManager* pSceneManager = SceneManager::GetInstance();
1077         AppAssert(pSceneManager);
1078         if(__pCallPresentor == null)
1079         {
1080                 __pCallPresentor = CallPresentationModel::GetInstance();
1081         }
1082         //Fetch call info list
1083         IListT<CallInfo>* pCallList = __pCallPresentor->GetCallListN();
1084         IEnumeratorT<CallInfo>* pCallEnum = pCallList->GetEnumeratorN();
1085         if(pCallEnum != null)
1086         {
1087                 ArrayList* pCallArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1088                 pCallArgs->Construct();
1089                 while(pCallEnum->MoveNext() == E_SUCCESS)
1090                 {
1091                         CallInfo callInfo;
1092                         if(pCallEnum->GetCurrent(callInfo) == E_SUCCESS)
1093                         {
1094                                 CallInfo* pActiveCall = new (std::nothrow) CallInfo();
1095                                 *pActiveCall = callInfo;
1096                                 pCallArgs->Add(pActiveCall);
1097                         }
1098                 }
1099
1100                 if(pCallArgs->GetCount() == 1 && (static_cast<CallInfo*>(pCallArgs->GetAt(0)))->IsConferenceCall() == true)
1101                 {
1102                         //move back to previous conf. call screen - ownership of 'pCallArgs' transferred
1103                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CONFCALL), pCallArgs);
1104                 }
1105                 else
1106                 {
1107                         //move back to previous screen - ownership of 'pCallArgs' transferred
1108                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ACTIVECALL), pCallArgs);
1109                 }
1110
1111                 delete pCallEnum;
1112                 pCallEnum = null;
1113         }
1114         delete pCallList;
1115         pCallList = null;
1116         AppLogDebug("EXIT");
1117 }
1118
1119 void
1120 DialTabDialer::SwitchToOutgoingCallScreen(const String& contactNumber)
1121 {
1122         AppLogDebug("ENTER");
1123
1124         SceneManager* pSceneManager = SceneManager::GetInstance();
1125         AppAssert(pSceneManager);
1126
1127         //Check if dialing a call is possible
1128         if(__pCallPresentor == null)
1129         {
1130                 __pCallPresentor = CallPresentationModel::GetInstance();
1131         }
1132         bool isSimInitialized = __pCallPresentor->CheckSimInitializationIsCompleted();
1133         if (isSimInitialized == true)
1134         {
1135                 //make an outgoing call with given number
1136                 String* contactTxt = new (std::nothrow) String(contactNumber);
1137                 //switch to dialing outgoing call form
1138                 ArrayList* pContact = new (std::nothrow) ArrayList(SingleObjectDeleter);
1139                 pContact->Construct(1);
1140                 pContact->Add(contactTxt);
1141                 //Check if dialing an emergency call
1142                 bool isEmergencyCall = __pCallPresentor->IsEmergencyNumber(*contactTxt, true);
1143                 if (isEmergencyCall)
1144                 {
1145                         pSceneManager->GoForward( ForwardSceneTransition( IDSCN_SCENE_OUT_EMERGENCYCALL), pContact);
1146                 }
1147                 else
1148                 {
1149                         pSceneManager->GoForward( ForwardSceneTransition(IDSCN_SCENE_OUTCALL), pContact);
1150                 }
1151         }
1152         else
1153         {
1154                 //TODO: check what to do for SOS calls
1155                 //Show error message Popup
1156                 if (__pErrorMsgPopup == null)
1157                 {
1158                         __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
1159                 }
1160                 __pErrorMsgPopup->ShowErrorMsgPopupN(ERROR_CODE_SIM_INITIALIZATION_FAILED);
1161         }
1162         AppLogDebug("EXIT");
1163         return;
1164 }
1165
1166 void
1167 DialTabDialer::SwitchToSpeedDialForm(void)
1168 {
1169         SceneManager* pSceneManager = SceneManager::GetInstance();
1170         AppAssert(pSceneManager);
1171         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_SPEED_DIAL), null);
1172         return;
1173 }
1174
1175 void
1176 DialTabDialer::ShowSpeedDialConfirmationPopup(void)
1177 {
1178         if(__pConfirmationPopup == null)
1179         {
1180                 Rectangle rect = GetBounds();
1181                 __pConfirmationPopup = new (std::nothrow) Popup();
1182                 __pConfirmationPopup->Construct(false, Dimension(rect.width, H_SPEEDDIAL_POPUP));
1183
1184                 rect = __pConfirmationPopup->GetBounds();
1185                 Label* pMsgLabel = new (std::nothrow) Label();
1186                 String popupMsg = AppUtility::GetResourceString(IDS_DIALER_SPEEDDIAL_POPUP_MSG);
1187                 pMsgLabel->Construct(Rectangle(0, IDI_PADDING, rect.width, H_POPUP_MSG_LABEL), popupMsg);
1188                 pMsgLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1189                 pMsgLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1190                 __pConfirmationPopup->AddControl(*pMsgLabel);
1191
1192                 rect = pMsgLabel->GetBounds();
1193                 Button *pButtonYes = new (std::nothrow) Button();
1194                 String btnName = AppUtility::GetResourceString(IDS_SPEEDDIAL_POP_YES_BTN_STRING);
1195                 pButtonYes->Construct(Rectangle(rect.x, (rect.y + rect.height + IDI_PADDING), ((rect.width - (6 * IDI_PADDING)) / 2), H_POPUP_BTN), btnName);
1196                 pButtonYes->SetActionId(IDA_SPEEDDIAL_POPUP_YES);
1197                 pButtonYes->AddActionEventListener(*this);
1198                 __pConfirmationPopup->AddControl(*pButtonYes);
1199
1200                 rect = pButtonYes->GetBounds();
1201                 Button *pButtonNo = new (std::nothrow) Button();
1202                 btnName = AppUtility::GetResourceString(IDS_SPEEDDIAL_POP_NO_BTN_STRING);
1203                 pButtonNo->Construct(Rectangle((rect.x + rect.width + IDI_PADDING), rect.y, rect.width, rect.height), btnName);
1204                 pButtonNo->SetActionId(IDA_SPEEDDIAL_POPUP_NO);
1205                 pButtonNo->AddActionEventListener(*this);
1206                 __pConfirmationPopup->AddControl(*pButtonNo);
1207         }
1208         //Show Popup message
1209         __pConfirmationPopup->SetShowState(true);
1210         __pConfirmationPopup->Show();
1211 }
1212
1213 void
1214 DialTabDialer::ShowAddToContactsButton(void)
1215 {
1216         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1217         Button* pButtonContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
1218         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
1219         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
1220         pButtonContacts->SetShowState(false);
1221         pButtonDropDown->SetShowState(false);
1222         pButtonAddContacts->SetShowState(true);
1223         pSearchPanel->SetShowState(true);
1224         pSearchPanel->Invalidate(true);
1225         return;
1226 }
1227
1228 void
1229 DialTabDialer::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
1230 {
1231         switch(requestId)
1232         {
1233                 case REQUEST_SHOW_SUGGESTION:
1234                 {
1235                         String *displayname = static_cast<String*> (pArgs->GetAt(0));
1236                         String *mobileNo = static_cast<String*> (pArgs->GetAt(1));
1237                         String *resultCount = static_cast<String*> (pArgs->GetAt(2));
1238                         if(displayname != null && mobileNo != null && resultCount != null)
1239                         {
1240                                 ShowSuggestionBox(*displayname, *mobileNo, *resultCount);
1241                         }
1242                         delete pArgs;
1243                 }
1244                 break;
1245
1246                 case REQUEST_SHOW_ADD_TO_CONTACTS:
1247                 {
1248                         ShowAddToContactsButton();
1249                 }
1250                 break;
1251
1252                 case REQUEST_CALL_SPEED_DIAL_NUM:
1253                 {
1254                         if(pArgs != null)
1255                         {
1256                                 String *number = static_cast<String*> (pArgs->GetAt(0));
1257                                 //dial a call.
1258                                 if(number != null)
1259                                 {
1260                                         SwitchToOutgoingCallScreen(*number);
1261                                 }
1262                                 delete pArgs;
1263                         }
1264                 }
1265                 break;
1266
1267                 case REQUEST_SHOW_SPEED_DIAL_POPUP:
1268                 {
1269                         //show speed Dial Confirmation Popup msg
1270                         ShowSpeedDialConfirmationPopup();
1271                 }
1272                 break;
1273         }
1274
1275 }
1276 void
1277 DialTabDialer::ShowSuggestionBox(String& name, String& mobileNo, String& resultCount)
1278 {
1279         AppLogDebug("ENTER");
1280
1281         //"UseContact" Button
1282         Button* pButtonContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
1283         Canvas pCanvasNormalContacts;
1284         pCanvasNormalContacts.Construct(pButtonContacts->GetBounds());
1285         Canvas pCanvasPressedContacts;
1286         pCanvasPressedContacts.Construct(pButtonContacts->GetBounds());
1287         String mobileStr = AppUtility::GetResourceString(IDS_DIALER_MOBILE_STR);
1288         //Add text, Bg to normal state
1289         DialUtil::Draw9PatchToCanvas(pCanvasNormalContacts, IDB_BTN_OPTION_BG_ICON);
1290         DialUtil::DrawTextToCanvas(name, FONT_SUGGESTION_NAME, pCanvasNormalContacts, POSITION_TOP_LEFT, BUTTON_STATUS_NORMAL);
1291         DialUtil::DrawTextToCanvas(mobileStr, FONT_SUGGESTION_MOBILE, pCanvasNormalContacts, POSITION_BOTTOM_LEFT, BUTTON_STATUS_NORMAL);
1292         DialUtil::DrawTextToCanvas(mobileNo, FONT_SUGGESTION_NUMBER, pCanvasNormalContacts, POSITION_BOTTOM_CENTER, BUTTON_STATUS_NORMAL);
1293         //Add text, Bg to pressed state
1294         DialUtil::Draw9PatchToCanvas(pCanvasPressedContacts, IDB_BTN_OPTION_PRESS_BG_ICON);
1295         DialUtil::DrawTextToCanvas(name, FONT_SUGGESTION_NAME, pCanvasPressedContacts, POSITION_TOP_LEFT, BUTTON_STATUS_NORMAL);
1296         DialUtil::DrawTextToCanvas(mobileStr, FONT_SUGGESTION_MOBILE, pCanvasPressedContacts, POSITION_BOTTOM_LEFT, BUTTON_STATUS_NORMAL);
1297         DialUtil::DrawTextToCanvas(mobileNo, FONT_SUGGESTION_NUMBER, pCanvasPressedContacts, POSITION_BOTTOM_CENTER, BUTTON_STATUS_NORMAL);
1298         //add normal, pressed bg bitmap to button
1299         DialUtil::DrawCanvasToButton(&pCanvasNormalContacts, &pCanvasPressedContacts, pButtonContacts);
1300
1301         //"DropDown" Button
1302         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
1303         Canvas pCanvasNormalDropDown;
1304         pCanvasNormalDropDown.Construct(pButtonDropDown->GetBounds());
1305         Canvas pCanvasPressedDropDown;
1306         pCanvasPressedDropDown.Construct(pButtonDropDown->GetBounds());
1307         //Add text, Bg to normal state
1308         DialUtil::Draw9PatchToCanvas(pCanvasNormalDropDown, IDB_BTN_OPTION_BG_ICON);
1309         DialUtil::DrawTextToCanvas(resultCount, FONT_SUGGESTION_LIST_NUMBER, pCanvasNormalDropDown, POSITION_TOP_CENTER, BUTTON_STATUS_NORMAL);
1310         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasNormalDropDown, POSITION_BOTTOM_CENTER);
1311         //Add text, Bg to pressed state
1312         DialUtil::Draw9PatchToCanvas(pCanvasPressedDropDown, IDB_BTN_OPTION_PRESS_BG_ICON);
1313         DialUtil::DrawTextToCanvas(resultCount, FONT_SUGGESTION_LIST_NUMBER, pCanvasPressedDropDown, POSITION_TOP_CENTER, BUTTON_STATUS_NORMAL);
1314         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasPressedDropDown, POSITION_BOTTOM_CENTER);
1315         //add background to button
1316         DialUtil::DrawCanvasToButton(&pCanvasNormalDropDown, &pCanvasPressedDropDown, pButtonDropDown);
1317
1318         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
1319         pButtonContacts->SetShowState(true);
1320         pButtonDropDown->SetShowState(true);
1321         pButtonDropDown->Invalidate(true);
1322         pButtonAddContacts->SetShowState(false);
1323
1324         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1325         pSearchPanel->SetShowState(true);
1326         pSearchPanel->Invalidate(true);
1327
1328         AppLogDebug("EXIT");
1329         return;
1330 }
1331
1332 void
1333 DialTabDialer::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
1334 {
1335         DialContactInfo* pDialInfo = __pDialPresentationModel->GetSuggestionAtIndex(index+1);
1336         if(pDialInfo != null)
1337         {
1338                 String phNumber = pDialInfo->GetPhoneNumber();
1339                 EditField* pTextBox = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1340                 if(pTextBox != null)
1341                 {
1342                         pTextBox->Clear();
1343                         pTextBox->SetText(phNumber);
1344                         pTextBox->Invalidate(true);
1345                 }
1346                 HideSearchListView();
1347                 __pDialPresentationModel->ClearSearchResults();
1348                 UpdateSearchResults();
1349         }
1350         return;
1351 }
1352
1353 void
1354 DialTabDialer::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1355 {
1356         Form* pForm = static_cast<Form*>(GetParent());
1357         pForm->SetOrientation(ORIENTATION_PORTRAIT);
1358         pForm->Invalidate(true);
1359         return;
1360 }
1361
1362 void
1363 DialTabDialer::HandlePopupClosed(void)
1364 {
1365         Draw();
1366         delete __pErrorMsgPopup;
1367         __pErrorMsgPopup = null;
1368         return;
1369 }
1370
1371 bool
1372 DialTabDialer::IsOpenedFromOtherView(void)
1373 {
1374         if(__pPreviousSceneId != null)
1375         {
1376                 return true;
1377         }
1378         return false;
1379 }
1380
1381 void
1382 DialTabDialer::OnForeground(void)
1383 {
1384         AppLogDebug("Enter");
1385         __isAppForeground = true;
1386         //If app control was launched
1387         //as we do not know if it success or failed
1388         // we need to UpdateSearchResults
1389         //Returned from app control if app control does not
1390         //send any response we need to do this
1391         SetAppControlLaunched(false);
1392 }
1393
1394 void
1395 DialTabDialer::OnBackground(void)
1396 {
1397         AppLogDebug("Enter");
1398         __isAppForeground = false;
1399 }
1400
1401 bool
1402 DialTabDialer::IsForeground()
1403 {
1404         AppLogDebug("Enter %d",__isAppForeground);
1405         return __isAppForeground;
1406 }
1407
1408 void
1409 DialTabDialer::OnContactsChanged(const IList& contactChangeInfoList)
1410 {
1411         if(contactChangeInfoList.GetCount() > 0)
1412         {
1413                 //clear old search results
1414                 __pDialPresentationModel->ClearSearchResults();
1415                 UpdateSearchResults();
1416         }
1417 }
1418
1419 void
1420 DialTabDialer::SetAppControlLaunched(bool launched)
1421 {
1422         AppLogDebug("%d",__isAppControlLaunched);
1423         __isAppControlLaunched = launched;
1424 }
1425
1426 bool
1427 DialTabDialer::GetAppControlLaunched(void)
1428 {
1429         AppLogDebug("%d",__isAppControlLaunched);
1430         return __isAppControlLaunched;
1431 }
1432
1433