7bd1c6f092e0dc840a3ca541a404d6163bebd9a1
[apps/osp/Dial.git] / src / PhnTabDialer.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        PhnTabDialer.cpp
19  * @brief       The dialer Tab
20  */
21 #include <FApp.h>
22 #include <FMedia.h>
23 #include <FSystem.h>
24 #include <FTelephony.h>
25 #include "PhnAppUtility.h"
26 #include "PhnPhoneApp.h"
27 #include "PhnCalllogManager.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 using namespace Tizen::Telephony;
48 using namespace Tizen::Base::Utility;
49
50 //Constants
51 const int H_SPEEDDIAL_POPUP = 350;
52 const int W_SPEEDDIAL_POPUP = 720;
53 const int H_POPUP_MSG_LABEL = 100;
54 const int H_POPUP_BTN = 90;
55 const int H_SEARCHLIST_ITEM = 140;
56 const int IDI_PADDING = 15;
57 const int IDI_MAX_LIMIT_LENGTH = 18;
58 const int IDI_MAX_TXT_FONT = 94;
59 const int IDI_MIN_TXT_FONT = 67;
60 const int IDI_DELTA_FONT_SIZE = 5;
61 const int MAX_SEARCH_LIST_ITEMS = 6;
62 const int MAX_SEARCH_LIST_ITEMS_LANDSCAPE = 2;
63 const int MIN_CONTEXT_MENU_ITEMS = 1;
64 const int X_CONTEXT_MENU_ANCHOR = 57;
65 const int Y_CONTEXT_MENU_ANCHOR = 1218;
66 const int X_CONTEXT_MENU_LANDSCAPE_ANCHOR = 666;
67 const int Y_CONTEXT_MENU_LANDSCAPE_ANCHOR = 545;
68 const int X_CALL_CONTEXT_MENU_ANCHOR = 360;
69 const int Y_CALL_CONTEXT_MENU_ANCHOR = 1168;
70 const int X_CALL_CONTEXT_MENU_LANDSCAPE_ANCHOR = 815;
71 const int Y_CALL_CONTEXT_MENU_LANDSCAPE_ANCHOR = 650;
72 const int MAX_NUMBER_WITH_SEPERATOR = 12;
73 const int MIN_NUMBER_WITH_ONE_SEPERATOR = 3;
74 const int MIN_NUMBER_WITH_TWO_SEPERATOR = 7;
75 const int MAX_TXT_LENGTH_WITH_SEPERATOR = 11;
76 const int MAX_VISIBLE_TXT_WITH_MIN_FONT = 15;
77 const int W_MORE_BUTTON = 74;
78 const int H_MORE_BUTTON = 74;
79 const int W_SUGGESTION_POPUP_BUBBLE_ICON = 40;
80 const int H_SUGGESTION_POPUP_BUBBLE_ICON = 20;
81
82 //resources
83 static const wchar_t* IDL_PANEL_DIALER = L"IDL_PANEL_DIALER";
84 const wchar_t* IDC_NUMERIC_EDITFIELD = L"IDC_EDITFIELD";
85 const wchar_t* IDC_PANEL_SEARCH_BOX = L"IDC_PANEL_SEARCH_BOX";
86 const wchar_t* IDC_BUTTON_ADD_CONTACTS = L"IDC_BUTTON_ADD_CONTACTS";
87 const wchar_t* IDC_BUTTON_USE_CONTACT = L"IDC_BUTTON_USE_CONTACT";
88 const wchar_t* IDC_BUTTON_DROP_DOWN = L"IDC_BUTTON_DROP_DOWN";
89 const wchar_t* IDC_BUTTON_PULL_UP = L"IDC_BUTTON_PULL_UP";
90 const wchar_t* IDC_PANEL_SEARCH_LIST = L"IDC_PANEL_SEARCH_LIST";
91 const wchar_t* IDC_PANEL_MENU = L"IDC_PANEL_MENU";
92 const wchar_t* IDC_BUTTON_MENU = L"IDC_BUTTON_MENU";
93 const wchar_t* IDC_LISTVIEW_SEARCH = L"IDC_LISTVIEW_SEARCH";
94 const wchar_t* IDC_BUTTON_SEARCHFIELD = L"IDC_BUTTON_SEARCHFIELD";
95 const wchar_t* IDC_BUTTON_SEARCHICON = L"IDC_BUTTON_SEARCHICON";
96 const wchar_t* IDC_LABEL_LASTROW_BG = L"IDC_LABEL_LASTROW_BG";
97 const wchar_t* IDC_PANEL_DROPDOWN = L"IDC_PANEL_DROPDOWN";
98 const wchar_t* IDC_PANEL_USE_CONTACT = L"IDC_PANEL_USE_CONTACT";
99 const wchar_t* IDC_SPEED_DIAL_TXT_LABEL = L"IDC_SPEED_DIAL_TXT_LABEL";
100
101
102 //Button Dimensions
103 const int DialTabDialer::IDI_BGBITMAP_WIDTH = 75;
104 const int DialTabDialer::IDI_BGBITMAP_HEIGHT = 75;
105 const int DialTabDialer::IDI_BGBITMAP_POS_X = 56;
106 const int DialTabDialer::IDI_BGBITMAP_POS_Y = 56;
107 const int DialTabDialer::IDI_TEXT1_SIZE = 116;
108 const int DialTabDialer::IDI_TEXT2_SIZE = 40;
109 const int MAXUSECONTACTNAMELENGTH = 20;
110 const int MAXUSECONTACTNUMBERLENGTH = 27;
111
112 //color
113 const unsigned int COLOR_SEARCHLIST_BG = Color32<248, 246, 239>::Value;
114 const unsigned int COLOR_SEARCHLIST_PRESS_BG = Color32<87, 135, 194>::Value;
115
116 DialTabDialer::DialTabDialer(void)
117 {
118         AppLogDebug("ENTER");
119         __pDialPresentationModel = null;
120         __pSuggestionListProvider = null;
121         __pSearchListView = null;
122         __isSearchListOpened = false;
123         __pErrorMsgPopup = null;
124         __pCallContextMenu = null;
125         __pDialKeypad = null;
126         __pConfirmationPopup = null;
127         __isAppForeground = true;
128         __pAddressBook = null;
129         __isAppControlLaunched = false;
130         __dialerState = DIALER_STATE_FIRST_SCENE;
131         __pOptionMenu = null;
132         AppLogDebug("EXIT");
133 }
134
135 DialTabDialer::~DialTabDialer(void)
136 {
137         AppLogDebug("ENTER");
138
139         if(__pDialKeypad != null)
140         {
141                 __pDialKeypad = null;
142         }
143         if(__pConfirmationPopup != null)
144         {
145                 delete __pConfirmationPopup;
146                 __pConfirmationPopup = null;
147         }
148         if (__pAddressBook != null)
149         {
150                 delete __pAddressBook;
151                 __pAddressBook = null;
152         }
153         if(__pErrorMsgPopup != null)
154         {
155                 delete __pErrorMsgPopup;
156                 __pErrorMsgPopup = null;
157         }
158         delete __pOptionMenu;
159         delete __pCallContextMenu;
160         AppLogDebug("EXIT");
161 }
162
163 bool
164 DialTabDialer::Initialize(void)
165 {
166         AppLogDebug("ENTER");
167         Construct(IDL_PANEL_DIALER);
168         AppLogDebug("EXIT");
169         return true;
170 }
171
172 result
173 DialTabDialer::OnInitializing(void)
174 {
175         AppLogDebug("ENTER");
176         result r = E_SUCCESS;
177         // Layout setting
178         Form* pForm = dynamic_cast<Form*>(GetParent());
179         if(pForm == null)
180         {
181                 return E_FAILURE;
182         }
183
184         __pDialPresentationModel = new DialPresentationModel(*this);
185         __pSuggestionListProvider = new SuggestionItemProvider(*__pDialPresentationModel);
186         __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
187
188         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(pForm->GetLandscapeLayoutN());
189         if (pRelativeLayout != null)
190         {
191                 pRelativeLayout->SetHorizontalFitPolicy(*this, FIT_POLICY_PARENT);
192                 pRelativeLayout->SetVerticalFitPolicy(*this, FIT_POLICY_PARENT);
193                 delete pRelativeLayout;
194         }
195         pRelativeLayout = dynamic_cast<RelativeLayout*>(pForm->GetPortraitLayoutN());
196         if (pRelativeLayout != null)
197         {
198                 pRelativeLayout->SetHorizontalFitPolicy(*this, FIT_POLICY_PARENT);
199                 pRelativeLayout->SetVerticalFitPolicy(*this, FIT_POLICY_PARENT);
200                 delete pRelativeLayout;
201         }
202
203         //hide footer
204         pForm->GetFooter()->SetShowState(false);
205
206         //Construct menu
207         ConstructSearchMenu();
208         //Initialize text box
209         InitializeContactsTextBox();
210         //Create and hide Search data display panel
211         InitializeSearchBox();
212         //initialize search list view and hide it.
213         InitializeSearchListView();
214         HideSearchListView();
215         //Construct keypad
216         ConstructKeypad();
217
218         AppLogDebug("EXIT");
219         return r;
220 }
221
222 result
223 DialTabDialer::OnTerminating(void)
224 {
225         result r = E_SUCCESS;
226         if (__pDialPresentationModel != null)
227         {
228                 delete __pDialPresentationModel;
229                 __pDialPresentationModel = null;
230         }
231         if (__pSuggestionListProvider != null)
232         {
233                 delete __pSuggestionListProvider;
234                 __pSuggestionListProvider = null;
235         }
236         // Add your termination code here
237         return r;
238 }
239
240 void
241 DialTabDialer::InitializeContactsTextBox(void)
242 {
243         AppLogDebug("ENTER");
244
245         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
246         if (pEditField != null)
247         {
248
249                 //clear text
250                 pEditField->SetOverlayKeypadCommandButtonVisible(false);
251                 pEditField->Clear();
252         }
253
254         AppLogDebug("EXIT");
255         return;
256 }
257
258 void
259 DialTabDialer::ShowFormattedText(EditField* pEditField, String contactNumber)
260 {
261         contactNumber.Replace(L"-",L"");
262         int textLength = contactNumber.GetLength();
263         if(textLength == 0)
264         {
265                 pEditField->Clear();
266                 pEditField->Invalidate(true);
267                 AppLogDebug("EXIT");
268                 return;
269         }
270         //Insert separator if required
271         if(textLength < MAX_NUMBER_WITH_SEPERATOR)
272         {
273                 if(textLength > MIN_NUMBER_WITH_TWO_SEPERATOR)
274                 {
275                         contactNumber.Insert(L"-",MIN_NUMBER_WITH_TWO_SEPERATOR);
276                 }
277                 if(textLength > MIN_NUMBER_WITH_ONE_SEPERATOR)
278                 {
279                         contactNumber.Insert(L"-",MIN_NUMBER_WITH_ONE_SEPERATOR);
280                 }
281         }
282         //update text length
283         textLength = contactNumber.GetLength();
284
285         //need to change font to fit inside text box
286         //With size 94 -> 12 chars, 67 -> 18 chars
287         int fontSize = pEditField->GetTextSize();
288
289         if(textLength < MAX_VISIBLE_TXT_WITH_MIN_FONT)
290         {
291                 //clearing
292                 fontSize += IDI_DELTA_FONT_SIZE;
293         }
294         else if(textLength > MAX_TXT_LENGTH_WITH_SEPERATOR)
295         {
296                 //appending
297                 fontSize -= IDI_DELTA_FONT_SIZE;
298         }
299
300         if(fontSize > IDI_MAX_TXT_FONT )
301         {
302                 fontSize = IDI_MAX_TXT_FONT;
303         }
304         if(fontSize < IDI_MIN_TXT_FONT)
305         {
306                 fontSize = IDI_MIN_TXT_FONT;
307         }
308         pEditField->SetTextSize(fontSize);
309         //set text to edit field
310         pEditField->SetText(contactNumber);
311         //pEditField->SetFocus();
312         pEditField->SetCursorPosition(contactNumber.GetLength()+1);
313         AppLogDebug("EXIT");
314         return;
315 }
316
317 void
318 DialTabDialer::ShowFormattedText(EditField* pEditField, int actionId)
319 {
320         AppLogDebug("ENTER");
321         bool clearflag = false;
322         int startpos=-1,endpos=-1;
323         pEditField->GetBlockRange(startpos,endpos);
324         AppLogDebug("GetBlockRange %d %d",startpos,endpos);
325
326         if((actionId != CLEAR_KEY) && (pEditField->GetRemainingLength()==0))
327         {
328                 return;
329         }
330         if(startpos != -1)
331         {
332                 if(actionId == CLEAR_KEY)
333                 {
334                         clearflag = true;
335                 }
336                 pEditField->Remove();
337                 pEditField->ReleaseBlock();
338
339         }
340
341         String contactNumber = pEditField->GetText();
342         int intialCursorPos = pEditField->GetCursorPosition();
343         if(actionId == CLEAR_KEY && intialCursorPos == 0)
344         {
345                 return;
346         }
347
348         if(pEditField->GetText().Contains(L"-"))
349         {
350                 if( intialCursorPos > MIN_NUMBER_WITH_ONE_SEPERATOR)
351                 {
352                         intialCursorPos--;
353                 }
354                 if(intialCursorPos > MIN_NUMBER_WITH_TWO_SEPERATOR)
355                 {
356                         intialCursorPos--;
357                 }
358         }
359
360         contactNumber.Replace(L"-",L"");
361
362         if(actionId == CLEAR_KEY)
363         {
364                 if(clearflag == false)
365                 {
366                         contactNumber.Remove(intialCursorPos-1,1);
367                         intialCursorPos--;
368                 }
369         }
370         else
371         {
372                 contactNumber.Insert(DialUtil::ConvertDialedNumberToString(actionId),intialCursorPos);
373                 intialCursorPos++;
374         }
375
376
377         int textLength = contactNumber.GetLength();
378         if(textLength == 0)
379         {
380                 pEditField->Clear();
381                 pEditField->Invalidate(true);
382                 AppLogDebug("EXIT");
383                 return;
384         }
385
386         //Insert separator if required
387         if(textLength < MAX_NUMBER_WITH_SEPERATOR)
388         {
389                 if(textLength > MIN_NUMBER_WITH_TWO_SEPERATOR)
390                 {
391                         contactNumber.Insert(L"-",MIN_NUMBER_WITH_TWO_SEPERATOR);
392                         if(intialCursorPos > MIN_NUMBER_WITH_TWO_SEPERATOR)
393                         {
394                                 intialCursorPos++;
395                         }
396                 }
397                 if(textLength > MIN_NUMBER_WITH_ONE_SEPERATOR)
398                 {
399                         contactNumber.Insert(L"-",MIN_NUMBER_WITH_ONE_SEPERATOR);
400                         if(intialCursorPos > MIN_NUMBER_WITH_ONE_SEPERATOR)
401                         {
402                                 intialCursorPos++;
403                         }
404
405                 }
406         }
407         //update text length
408         textLength = contactNumber.GetLength();
409
410         //need to change font to fit inside text box
411         //With size 94 -> 12 chars, 67 -> 18 chars
412         int fontSize = pEditField->GetTextSize();
413         if((actionId == CLEAR_KEY) && (textLength < MAX_VISIBLE_TXT_WITH_MIN_FONT))
414         {
415                 //clearing
416                 fontSize += IDI_DELTA_FONT_SIZE;
417         }
418         else if(textLength > MAX_TXT_LENGTH_WITH_SEPERATOR)
419         {
420                 //appending
421                 fontSize -= IDI_DELTA_FONT_SIZE;
422         }
423
424         if(fontSize > IDI_MAX_TXT_FONT)
425         {
426                 fontSize = IDI_MAX_TXT_FONT;
427         }
428         if(fontSize < IDI_MIN_TXT_FONT)
429         {
430                 fontSize = IDI_MIN_TXT_FONT;
431         }
432         pEditField->SetTextSize(fontSize);
433         //set text to edit field
434         pEditField->SetText(contactNumber);
435         //pEditField->SetFocus();
436         pEditField->SetCursorPosition(intialCursorPos);
437         AppLogDebug("EXIT");
438         return;
439 }
440
441 //search box
442 void
443 DialTabDialer::InitializeSearchBox(void)
444 {
445         AppLogDebug("ENTER");
446
447         //search panel
448         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
449         pSearchPanel->SetShowState(false);
450
451         //"Add to contacts" button
452         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
453         pButtonAddContacts->SetActionId(IDA_BTN_ADD_TO_CONTACTS);
454         pButtonAddContacts->AddActionEventListener(*this);
455         pButtonAddContacts->SetShowState(false);
456
457         //"Use Contacts" button
458         Button* pButtonContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
459         pButtonContacts->SetActionId(IDA_BTN_USE_CONTACT_DATA);
460         pButtonContacts->AddActionEventListener(*this);
461         //"Drop-Down" Button
462         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
463         pButtonDropDown->SetActionId(IDA_BTN_DISPLAY_CONTACTS);
464         pButtonDropDown->AddActionEventListener(*this);
465         Button* pButtonPullUp = static_cast<Button*>(GetControl(IDC_BUTTON_PULL_UP, true));
466         pButtonPullUp->SetActionId(IDA_BTN_DISPLAY_CONTACTS);
467         pButtonPullUp->AddActionEventListener(*this);
468
469         pSearchPanel->Invalidate(true);
470         AppLogDebug("EXIT");
471         return;
472 }
473
474 void
475 DialTabDialer::UpdateSearchResults(void)
476 {
477         AppLogDebug("ENTER");
478
479         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
480         //send request to search for suggestion list
481         String searchStr = pEditField->GetText();
482         searchStr.Replace(L"-",L"");
483         if(searchStr.IsEmpty() == false)
484         {
485                 __pDialPresentationModel->FetchSuggestionList(searchStr);
486         }
487
488         AppLogDebug("EXIT");
489         return;
490 }
491
492 void
493 DialTabDialer::HideSearchBox(void)
494 {
495         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
496         pButtonAddContacts->SetShowState(false);
497         Button* pButtonContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
498         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
499         pButtonContacts->SetShowState(true);
500         pButtonDropDown->SetShowState(true);
501
502         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
503         pSearchPanel->SetShowState(false);
504         pSearchPanel->Invalidate(true);
505
506         HideSearchListView();
507         return;
508 }
509
510 void
511 DialTabDialer::InitializeSearchListView(void)
512 {
513         //update new bounds
514         __pSearchListView = static_cast<ListView*>(GetControl(IDC_LISTVIEW_SEARCH,true));
515         if(__pSearchListView != null)
516         {
517                 __pSearchListView->SetSweepEnabled(true);
518                 __pSearchListView->SetItemProvider(*__pSuggestionListProvider);
519                 __pSearchListView->AddListViewItemEventListener(*this);
520                 __pSearchListView->SetBackgroundColor(Color(COLOR_SEARCHLIST_BG));
521                 Panel* pSearchListPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_LIST, true));
522                 if(pSearchListPanel != null)
523                 {
524                         SetControlAlwaysOnTop(*pSearchListPanel, true);
525                 }
526         }
527 }
528
529 void
530 DialTabDialer::ShowSearchListView(void)
531 {
532         AppLogDebug("ENTER");
533
534         Form* pForm = dynamic_cast<Form *>(GetParent());
535         if(pForm == null)
536         {
537                 AppLog("pForm == null");
538                 return;
539         }
540         //find the no. of search rows to be shown - Maximum 5 can be shown.
541         int noOfItems = MAX_SEARCH_LIST_ITEMS;
542         if(pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
543         {
544                 noOfItems = MAX_SEARCH_LIST_ITEMS_LANDSCAPE;
545         }
546         if(__pDialPresentationModel->GetNumberOfSuggestions() < (noOfItems+1))
547         {
548                 noOfItems = __pDialPresentationModel->GetNumberOfSuggestions() - 1;
549         }
550         if(noOfItems <= 0)
551         {
552                 return;
553         }
554
555         if(pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
556         {
557                 if(noOfItems > 1)
558                 {
559                         SetShiftedPosUseContact();
560                 }
561                 else if(noOfItems <= 1)
562                 {
563                         SetOrigPosUseContact();
564                 }
565         }
566
567         Panel* pSearchListPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_LIST, true));
568         if(pSearchListPanel != null)
569         {
570                 Rectangle searchPanelbounds = pSearchListPanel->GetBounds();
571                 if(pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
572                 {
573                         if(noOfItems > 1)
574                         {
575                                 searchPanelbounds.y = 350;
576                                 searchPanelbounds.height = 500;
577                         }
578                         if(noOfItems <= 1)
579                         {
580                                 searchPanelbounds.y = 470;
581
582                         }
583                 }
584                 pSearchListPanel->SetBounds(searchPanelbounds);
585                 pSearchListPanel->SetShowState(true);
586                 pSearchListPanel->InvalidateBounds(searchPanelbounds);
587         }
588
589         if (__pSearchListView != null)
590         {
591                 //update new bounds
592                 Rectangle searchListbounds = __pSearchListView->GetBounds();
593                 if(pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
594                 {
595                         searchListbounds.height = H_SEARCHLIST_ITEM * noOfItems;
596                 }
597                 else
598                 {
599                         searchListbounds.height = H_SEARCHLIST_ITEM * noOfItems;
600                 }
601                 __pSearchListView->SetMinimumSize(Dimension(searchListbounds.width - 100,searchListbounds.height));
602                 __pSearchListView->SetBounds(searchListbounds);
603                 Form* pForm = dynamic_cast<Form *>(GetParent());
604                 if(pSearchListPanel->GetBounds().y + __pSearchListView->GetBounds().height > pForm->GetClientAreaBounds().height)
605                 {
606                         searchListbounds.height -= (pSearchListPanel->GetBounds().y + __pSearchListView->GetBounds().height) - pForm->GetClientAreaBounds().height;
607                         __pSearchListView->SetMinimumSize(Dimension(searchListbounds.width - 100,searchListbounds.height));
608                         __pSearchListView->SetBounds(searchListbounds);
609                 }
610                 __pSearchListView->InvalidateBounds(searchListbounds);
611                 __pSearchListView->SetItemProvider(*__pSuggestionListProvider);
612                 __pSearchListView->UpdateList();
613                 __pSearchListView->ScrollToItem(0);
614
615         }
616
617         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
618         Button* pButtonPullUp = static_cast<Button*>(GetControl(IDC_BUTTON_PULL_UP, true));
619         //Show dropdown button
620         pButtonDropDown->SetShowState(false);
621         pButtonDropDown->Invalidate(false);
622         pButtonPullUp->SetShowState(true);
623         pButtonPullUp->Invalidate(true);
624         __isSearchListOpened = true;
625         AppLogDebug("EXIT");
626         return;
627 }
628
629 void
630 DialTabDialer::HideSearchListView(void)
631 {
632         Panel* pSearchListPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_LIST, true));
633         pSearchListPanel->SetShowState(false);
634         pSearchListPanel->Invalidate(true);
635
636         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
637         Button* pButtonPullUp = static_cast<Button*>(GetControl(IDC_BUTTON_PULL_UP, true));
638         //Show dropdown button
639         pButtonPullUp->SetShowState(false);
640         pButtonPullUp->Invalidate(true);
641         pButtonDropDown->SetShowState(true);
642         pButtonDropDown->Invalidate(true);
643         __isSearchListOpened = false;
644         return;
645 }
646
647 void
648 DialTabDialer::ShowSearchGadget(void)
649 {
650         //Commenting as search is not supported for 2.1
651         /*Button* pButtonSearchIcon = static_cast<Button*>(GetControl(IDC_BUTTON_SEARCHICON, true));
652         pButtonSearchIcon->SetShowState(true);
653         Button* pButtonSearchField = static_cast<Button*>(GetControl(IDC_BUTTON_SEARCHFIELD, true));
654         pButtonSearchField->SetShowState(true);
655         Button* pButtonClear = static_cast<Button*>(GetControl(IDC_BUTTON_KEYPADCLEAR, true));
656         pButtonClear->SetShowState(false);
657         Invalidate(true);*/
658         return;
659 }
660
661
662 void
663 DialTabDialer::HideSearchGadget(void)
664 {
665         //Commenting as search is not supported for 2.1
666         /*Button* pButtonSearchIcon = static_cast<Button*>(GetControl(IDC_BUTTON_SEARCHICON, true));
667         pButtonSearchIcon->SetShowState(false);
668         Button* pButtonSearchField = static_cast<Button*>(GetControl(IDC_BUTTON_SEARCHFIELD, true));
669         pButtonSearchField->SetShowState(false);
670         Button* pButtonClear = static_cast<Button*>(GetControl(IDC_BUTTON_KEYPADCLEAR, true));
671         pButtonClear->SetShowState(true);*/
672         return;
673 }
674
675
676 void
677 DialTabDialer::ConstructSearchMenu(void)
678 {
679         AppLogDebug("ENTER");
680
681         //Construct button for menu open and close
682         Button* pButtonSearchField = static_cast<Button*>(GetControl(IDC_BUTTON_SEARCHFIELD, true));
683         pButtonSearchField->SetActionId(IDA_SEARCH_FIELD);
684         pButtonSearchField->AddActionEventListener(*this);
685         Button* pButtonSearchIcon = static_cast<Button*>(GetControl(IDC_BUTTON_SEARCHICON, true));
686         pButtonSearchIcon->SetActionId(IDA_SEARCH_ICON);
687         pButtonSearchIcon->AddActionEventListener(*this);
688         //Hiding as search is not supported for 2.1
689         pButtonSearchIcon->SetShowState(false);
690         pButtonSearchField->SetShowState(false);
691
692         AppLogDebug("EXIT");
693         return;
694 }
695
696 void
697 DialTabDialer::ConstructKeypad(void)
698 {
699         AppLogDebug("ENTER");
700         //Construct Alpha numeric Keypad
701         if(__pDialKeypad == null)
702         {
703                 __pDialKeypad = new (std::nothrow) DialerKeypad(__dialerState);
704                 __pDialKeypad->ConstructPanel(this, this);
705                 //add keypad to dial panel
706                 AddControl(__pDialKeypad);
707                 __pDialKeypad->AddListenersToLastRowButtons();
708         }
709         AppLogDebug("EXIT");
710         return;
711 }
712
713 void
714 DialTabDialer::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
715 {
716         AppLogDebug("ENTER");
717         //When outgoing call is made and immediately before a call is made if
718         // we switch to logs then __isAppControlLaunched wont be set to false anywhere else
719         //as OnforeGround of logs will get called instead . Hence Keypad wont work.
720         SetAppControlLaunched(false);
721         PhoneApp* pPhoneApp = static_cast<PhoneApp*>(PhoneApp::GetInstance());
722         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
723         pEditField->SetFocus();
724         String editText(L"");
725
726         //While coming from Logs scene, disable footer
727         Form* pForm = dynamic_cast<Form*>(GetParent());
728         if(pForm == null)
729         {
730                 AppLog("pForm == null");
731                 return;
732         }
733         pForm->GetFooter()->SetShowState(false);
734         pForm->AddOrientationEventListener(*this);
735         Label* pLastRowLabel = static_cast<Label*>(GetControl(IDC_LABEL_LASTROW_BG, true));
736         OrientationStatus orientationStatus = pForm->GetOrientationStatus();
737         if (orientationStatus == ORIENTATION_STATUS_PORTRAIT || orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
738         {
739                 pLastRowLabel->SetShowState(false);
740         }
741         else if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
742         {
743                 pLastRowLabel->SetShowState(true);
744         }
745
746         //If opened as AppControl then it is either from Single Active Call
747         //or Conf. Call screen with 'Add Call' scenario.
748         __dialerState = DIALER_STATE_FIRST_SCENE;
749         if (pPhoneApp->IsOpenAsAppControl() == true)
750         {
751                 __dialerState = DIALER_STATE_ADD_CALL_APPCONTROL;
752                 if(pArgs != null)
753                 {
754                         String* pPhoneNumber = static_cast<String*>(pArgs->GetAt(0));
755                         if(pPhoneNumber != null && pPhoneNumber->IsEmpty() == false)
756                         {
757                                 //From AppControl request for normal call
758                                 editText.Append(*pPhoneNumber);
759                                 __dialerState = DIALER_STATE_NORMAL_APPCONTROL;
760                         }
761                         delete pArgs;
762                         pArgs = null;
763                 }
764         }
765         else
766         {
767                 if(pEditField != null)
768                 {
769                         editText = pEditField->GetText();
770                 }
771         }
772         //If this is not an AppControlRequest and editText is empty, then fetch auto area code.
773         if(editText.IsEmpty() == true)
774         {
775                 //Fetch auto area code setting, if present
776                 SettingsPresentationModel::GetInstance()->GetActivePrefixDialNumber(editText);
777                 if(editText.IsEmpty() == false)
778                 {
779                         editText.Replace(L"P",L";");
780                         editText.Replace(L"p",L";");
781                 }
782         }
783
784         if(pEditField != null)
785         {
786                 ShowFormattedText(pEditField,editText);
787                 pEditField->SetFocus();
788                 pEditField->Invalidate(true);
789                 __pDialPresentationModel->ClearSearchResults();
790                 //show search results
791                 if (pEditField->GetTextLength() == 0)
792                 {
793                         ShowSearchGadget();
794                         HideSearchBox();
795                 }
796                 else
797                 {
798                         HideSearchGadget();
799                         UpdateSearchResults();
800                 }
801         }
802
803         if (__pDialKeypad != null)
804         {
805                 __pDialKeypad->SetBitmapToKeypadButtons();
806                 __pDialKeypad->Invalidate(true);
807         }
808         pPhoneApp->AddAppStateChangeListener(*this);
809         //Add address book listener to listen to contacts changed events
810         if(__pAddressBook != null)
811         {
812                 __pAddressBook->SetAddressbookChangeEventListener(this);
813         }
814         //Set the last row position and height programatically
815         Panel*  plastRowPanel = static_cast<Panel*>(GetParent()->GetControl(IDC_PANEL_LASTROW,true));
816         int yPos =  pForm->GetClientAreaBounds().height - plastRowPanel->GetBounds().height;
817         plastRowPanel->SetPosition(0,yPos);
818         Invalidate(true);
819         if(pEditField != null)
820         {
821                 pEditField->AddTextEventListener(*this);
822         }
823         AppLogDebug("EXIT");
824         return;
825 }
826
827 void
828 DialTabDialer::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
829 {
830         AppLogDebug("ENTER");
831         //While coming from Logs scene, disable footer
832         Form* pForm = static_cast<Form*>(GetParent());
833         pForm->RemoveOrientationEventListener(*this);
834         PhoneApp* pPhoneApp = static_cast<PhoneApp*>(PhoneApp::GetInstance());
835         //hide search result list, if shown.
836         if (__isSearchListOpened == true)
837         {
838                 HideSearchListView();
839         }
840
841         if(__pConfirmationPopup != null)
842         {
843                 __pConfirmationPopup->SetShowState(false);
844         }
845         pPhoneApp->RemoveAppStateChangeListener(*this);
846         //remove contact change event listener
847         if(__pAddressBook != null)
848         {
849                 __pAddressBook->SetAddressbookChangeEventListener(null);
850         }
851         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
852         int startpos=-1,endpos=-1;
853         pEditField->GetBlockRange(startpos,endpos);
854         AppLogDebug("GetBlockRange %d %d",startpos,endpos);
855         if(startpos != -1)
856         {
857                 pEditField->Remove();
858                 pEditField->ReleaseBlock();
859         }
860         pEditField->RemoveTextEventListener(*this);
861         AppLogDebug("EXIT");
862         return;
863 }
864
865 void
866 DialTabDialer::OnActionPerformed(const Control& source, int actionId)
867 {
868         AppLogDebug("ENTER");
869
870         PhoneApp* pApp = static_cast<PhoneApp*>(UiApp::GetInstance());
871         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
872         if (pEditField == null || GetAppControlLaunched() == true)
873         {
874                 AppLogDebug("GetAppControlLaunched() == true");
875                 return;
876         }
877
878         switch (actionId)
879         {
880         case IDA_SEARCH_FIELD:
881         case IDA_SEARCH_ICON:
882         {
883                 //Put Search click launch code here
884                 AppLog("Search ICON/Field Clicked");
885                 AppManager* pAppManager = AppManager::GetInstance();
886                 pAppManager->LaunchApplication(PROVIDER_ID_CONTACTS);
887         }
888         break;
889
890         case IDA_BTN_SHOW_CONTEXTMENU:
891         {
892                 // Show the ContextMenu
893                 String contactNo = pEditField->GetText();
894                 contactNo.Replace(L"-",L"");
895                 ShowOptionsMenu();
896                 if (__isSearchListOpened == true)
897                 {
898                         HideSearchListView();
899                 }
900         }
901         break;
902
903         case NUM_KEY1:
904         case NUM_KEY2:
905         case NUM_KEY3:
906         case NUM_KEY4:
907         case NUM_KEY5:
908         case NUM_KEY6:
909         case NUM_KEY7:
910         case NUM_KEY8:
911         case NUM_KEY9:
912         case NUM_KEY0:
913         case CLEAR_KEY:
914         case HASH_KEY:
915         {
916                 //append / clear last character to contact
917                 int oldtextlen = pEditField->GetTextLength();
918                 ShowFormattedText(pEditField, actionId);
919                 if (pEditField->GetTextLength() == 0)
920                 {
921                         __pDialPresentationModel->ClearSearchResults();
922                         ShowSearchGadget();
923                         HideSearchBox();
924                 }
925                 else
926                 {
927                         if(oldtextlen != pEditField->GetTextLength())
928                         {
929                                 HideSearchGadget();
930                                 UpdateSearchResults();
931                         }
932                 }
933         }
934         break;
935
936         case CALL_KEY:
937         {
938                 //If context menu is shown do not trigger call
939                 //As platform sends release event when context menu is shown
940                 if(__pCallContextMenu != null && __pCallContextMenu->GetShowState() == true)
941                 {
942                         return;
943                 }
944                 if (pEditField->GetTextLength() > 0)
945                 {
946                         String contactNo = pEditField->GetText();
947                         contactNo.Replace(L"-",L"");
948                         String phoneNumberPattern(L"#$");
949                         RegularExpression checkPhoneNumber;
950                         checkPhoneNumber.Construct(phoneNumberPattern);
951                         //If phone number ends with # then show an error popup
952                 /*      bool resultMatch = checkPhoneNumber.Match(contactNo,false);
953                         if(resultMatch == true)
954                         {
955                                 MessageBox numberEndsWithHash;
956                                 String msg(L"Phone number ");
957                                 msg.Append(contactNo);
958                                 msg.Append(L" ends with # ");
959                                 numberEndsWithHash.Construct(L"GPRS is not supported", msg, MSGBOX_STYLE_NONE,3000);
960                                 int modalResult = 0;
961                                 numberEndsWithHash.ShowAndWait(modalResult);
962                                 return;
963                         }*/
964                         if (DialOutgoingCall(contactNo) == true)
965                         {
966                                 __pDialPresentationModel->ClearSearchResults();
967                                 pEditField->Clear();
968                                 ShowSearchGadget();
969                                 HideSearchBox();
970                         }
971                         return;
972                 }
973                 else
974                 {
975                         //show latest dialed or incoming number from Logs
976                         String* number = __pDialPresentationModel->FetchLatestNumberFromLogsN();
977                         if(number != null)
978                         {
979                                 ShowFormattedText(pEditField,*number);
980                                 UpdateSearchResults();
981                                 HideSearchGadget();
982                                 delete number;
983                         }
984                 }
985         }
986         break;
987
988         case PAUSE_KEY:
989         {
990                 ShowFormattedText(pEditField,STAR_KEY);
991                 if (pEditField->GetTextLength() == 0)
992                 {
993                         ShowSearchGadget();
994                         HideSearchBox();
995                 }
996                 else
997                 {
998                         HideSearchGadget();
999                         UpdateSearchResults();
1000                 }
1001         }
1002         break;
1003
1004         /*case HASH_KEY:
1005         {
1006                 pEditField->AppendText(L"#");
1007                 if (pEditField->GetTextLength() == 0)
1008                 {
1009                         ShowSearchGadget();
1010                         HideSearchBox();
1011                 }
1012                 else
1013                 {
1014                         HideSearchGadget();
1015                         UpdateSearchResults();
1016                 }
1017         }
1018         break;*/
1019
1020 /*      case VIDEOCALL_KEY:
1021         {
1022                 //Not yet Supported
1023         }
1024         break;*/
1025
1026         case CANCEL_KEY:
1027         {
1028                 if(pApp->IsOpenAsAppControl() == true)
1029                 {
1030                         pApp->Terminate();
1031                         return;
1032                 }
1033         }
1034         break;
1035
1036         case IDA_BTN_ADD_TO_CONTACTS:
1037         {
1038                 if(pEditField->GetTextLength() > 0)
1039                 {
1040                         String contactNo = pEditField->GetText();
1041                         contactNo.Replace(L"-",L"");
1042                         result r = __pDialPresentationModel->LaunchAddContactsAppControl(contactNo);
1043                         if (r == E_SUCCESS)
1044                         {
1045                                 SetAppControlLaunched(true);
1046                         }
1047                         return;
1048                 }
1049         }
1050         break;
1051
1052         case IDA_SPEEDDIAL_POPUP_YES:
1053         {
1054                 if(__pConfirmationPopup != null)
1055                 {
1056                         __pConfirmationPopup->SetShowState(false);
1057                 }
1058                 SwitchToSpeedDialForm();
1059         }
1060         break;
1061
1062         case IDA_SPEEDDIAL_POPUP_NO:
1063         {
1064                 if(__pConfirmationPopup != null)
1065                 {
1066                         __pConfirmationPopup->SetShowState(false);
1067                 }
1068         }
1069         break;
1070
1071         case IDA_MENU_ADD_PAUSE:
1072         {
1073                 AddPause();
1074         }
1075         break;
1076
1077         case IDA_MENU_ADD_WAIT:
1078         {
1079                 AddWait();
1080         }
1081         break;
1082
1083         case IDA_MENU_EXIT:
1084         {
1085                 //Close Phone App
1086                 pApp->Terminate();
1087                 return;
1088         }
1089         break;
1090
1091         case IDA_MENU_SEND_MESSAGE:
1092         {
1093                 String contactNo = pEditField->GetText();
1094                 contactNo.Replace(L"-",L"");
1095                 result r = __pDialPresentationModel->OpenMessagingAppControl(contactNo);
1096                 if(r == E_SUCCESS)
1097                 {
1098                         SetAppControlLaunched(true);
1099                 }
1100                 return;
1101         }
1102         break;
1103
1104         case IDA_MENU_SPEED_DIAL:
1105         {
1106                 SwitchToSpeedDialForm();
1107                 return;
1108         }
1109         break;
1110
1111         case IDA_BTN_USE_CONTACT_DATA:
1112         {
1113                 DialContactInfo* pDialInfo = __pDialPresentationModel->GetSuggestionAtIndex(0);
1114                 if(pDialInfo != null)
1115                 {
1116                         //fetch contact number
1117                         String phNumber = pDialInfo->GetPhoneNumber();
1118                         if(phNumber.Equals(pEditField->GetText()) == false)
1119                         {
1120                                 pEditField->Clear();
1121                                 ShowFormattedText(pEditField,phNumber);
1122                                 pEditField->Invalidate(true);
1123                                 if (__isSearchListOpened == true)
1124                                 {
1125                                         HideSearchListView();
1126                                 }
1127                                 UpdateSearchResults();
1128                         }
1129                 }
1130         }
1131         break;
1132
1133         case IDA_BTN_DISPLAY_CONTACTS:
1134         {
1135                 if (__isSearchListOpened == true)
1136                 {
1137                         Form* pForm = dynamic_cast<Form *>(GetParent());
1138                         int noOfItems = MAX_SEARCH_LIST_ITEMS;
1139                         if(__pDialPresentationModel->GetNumberOfSuggestions() < (noOfItems+1))
1140                         {
1141                                 noOfItems = __pDialPresentationModel->GetNumberOfSuggestions() - 1;
1142                         }
1143                         if(pForm != null && (pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
1144                         {
1145                                 if(noOfItems > 1)
1146                                 {
1147                                         SetOrigPosUseContact();
1148                                 }
1149                         }
1150                         HideSearchListView();
1151                 }
1152                 else
1153                 {
1154                         ShowSearchListView();
1155                 }
1156         }
1157         break;
1158
1159         default:
1160                 break;
1161         }
1162         pEditField->Invalidate(true);
1163
1164         AppLogDebug("EXIT");
1165         return;
1166 }
1167
1168 void
1169 DialTabDialer::OnLongPressGestureDetected(TouchLongPressGestureDetector& gestureDetector)
1170 {
1171         AppLogDebug("ENTER");
1172         if (GetAppControlLaunched() == true)
1173         {
1174                 //If call AppControl is already launched, ignore any further requests.
1175                 return ;
1176         }
1177
1178         if (gestureDetector.GetControl() != null)
1179         {
1180                 Button* pButton = static_cast<Button*>(gestureDetector.GetControl());
1181                 int actionId = pButton->GetActionId();
1182                 switch(actionId)
1183                 {
1184                 case NUM_KEY1:
1185                 case NUM_KEY2:
1186                 case NUM_KEY3:
1187                 case NUM_KEY4:
1188                 case NUM_KEY5:
1189                 case NUM_KEY6:
1190                 case NUM_KEY7:
1191                 case NUM_KEY8:
1192                 case NUM_KEY9:
1193                 {
1194                         //first check if there is any number present in the edit fiels
1195                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1196                         if(pEditField->GetTextLength() != 0)
1197                         {
1198                                 //append / clear last character to contact
1199                                 int oldtextlen = pEditField->GetTextLength();
1200                                 ShowFormattedText(pEditField, actionId);
1201                                 if (pEditField->GetTextLength() == 0)
1202                                 {
1203                                         __pDialPresentationModel->ClearSearchResults();
1204                                         ShowSearchGadget();
1205                                         HideSearchBox();
1206                                 }
1207                                 else
1208                                 {
1209                                         if(oldtextlen != pEditField->GetTextLength())
1210                                         {
1211                                                 HideSearchGadget();
1212                                                 UpdateSearchResults();
1213                                         }
1214                                 }
1215                                 pEditField->Invalidate(true);
1216                                 break;
1217                         }
1218                         //Check if Speed Dial setting exist for pressed key
1219                         String* contactNumber = __pDialPresentationModel->FetchSpeedDialNumberN(actionId);
1220                         if(contactNumber != null)
1221                         {
1222                                 ArrayList* pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1223                                 pArgs->Construct();
1224                                 //pass ownership to arraylist
1225                                 pArgs->Add(contactNumber);
1226                                 SendUserEvent(REQUEST_CALL_SPEED_DIAL_NUM,pArgs);
1227                         }
1228                         else
1229                         {
1230                                 //show speed Dial Confirmation Popup msg
1231                                 if(actionId == NUM_KEY1)
1232                                 {
1233                                         SendUserEvent(REQUEST_SHOW_VOICE_MAIL_POPUP,null);
1234                                 }
1235                                 else
1236                                 {
1237                                         SendUserEvent(REQUEST_SHOW_SPEED_DIAL_POPUP,null);
1238                                 }
1239                         }
1240
1241                 }
1242                 break;
1243
1244                 case PAUSE_KEY:
1245                 {
1246                         AddPause();
1247                 }
1248                 break;
1249
1250                 case HASH_KEY:
1251                 {
1252                         //Handle Mute / UnMute
1253                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1254                         if(pEditField->GetTextLength() == 0)
1255                         {
1256                                 bool enabled = false;
1257                                 String title = L"http://tizen.org/setting/sound.silent_mode";
1258                                 SettingInfo::GetValue(title, enabled);
1259                                 //enable or disable the phone silent mode.
1260                                 result r = E_FAILURE;
1261                                 r = SettingInfo::SetValue(title, !enabled);
1262                                 if(r == E_SUCCESS)
1263                                 {
1264                                         ShowSilentModeToggle(!enabled);
1265                                 }
1266                         }
1267                 }
1268                 break;
1269
1270                 case CLEAR_KEY:
1271                 {
1272                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1273                         if (pEditField != null && pEditField->GetTextLength() > 0)
1274                         {
1275                                 pEditField->Clear();
1276                                 pEditField->SetTextSize(IDI_MAX_TXT_FONT);
1277                                 //pEditField->SetCursorPosition(0);
1278                                 pEditField->SetFocus();
1279                                 pEditField->Invalidate(true);
1280                                 HideSearchBox();
1281                                 ShowSearchGadget();
1282                         }
1283                 }
1284                 break;
1285                 case CALL_KEY:
1286                 {
1287
1288                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1289                         if(pEditField != null && pEditField->GetTextLength() > 0)
1290                         {
1291                                 String contactNo = pEditField->GetText();
1292                                 contactNo.Replace(L"-",L"");
1293                                 ShowCallContextMenu(contactNo);
1294                         }
1295
1296                 }
1297                 break;
1298                 case NUM_KEY0:
1299                 {
1300                         AddPlus();
1301                 }
1302                 break;
1303
1304                 default:
1305                         break;
1306                 }
1307         }
1308
1309         AppLogDebug("EXIT");
1310         return;
1311 }
1312
1313 void
1314 DialTabDialer::ShowCallContextMenu(Tizen::Base::String& contactNumber)
1315 {
1316
1317         AppLogDebug("ENTER");
1318
1319         Form *pForm = dynamic_cast<Form*>(GetParent());
1320         Button* pCallButton = static_cast<Button*>(pForm->GetControl(IDC_BUTTON_CALL,true));
1321         Panel* pLastRowPanel = static_cast<Panel*>(pForm->GetControl(IDC_PANEL_LASTROW,true));
1322         int portraitAnchorPositionY = pForm->GetHeight() - pLastRowPanel->GetHeight() +
1323                         ((pLastRowPanel->GetHeight()- pCallButton->GetHeight())/2);
1324         int portraitAnchorPositionX = pLastRowPanel->GetWidth()/2;
1325         int landscapeAnchorPositionX =  pForm->GetWidth()/2 + pLastRowPanel->GetWidth()/2 - pCallButton->GetWidth()/2;
1326         if(__pCallContextMenu != null)
1327         {
1328                 delete __pCallContextMenu;
1329                 __pCallContextMenu = null;
1330         }
1331         __pCallContextMenu = new (std::nothrow) ContextMenu();
1332         __pCallContextMenu->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
1333         //minimum available option count
1334         int visibleItems = MIN_CONTEXT_MENU_ITEMS + 1;
1335         __pCallContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_ADD_PAUSE), IDA_MENU_ADD_PAUSE);
1336         __pCallContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_ADD_WAIT), IDA_MENU_ADD_WAIT);
1337         __pCallContextMenu->AddActionEventListener(*this);
1338         __pCallContextMenu->SetFocusable(true);
1339         __pCallContextMenu->SetMaxVisibleItemsCount(visibleItems);
1340         // Set the anchor position of the ContextMenu
1341         if(pForm != null && (pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
1342         {
1343                 __pCallContextMenu->SetAnchorPosition(Point(landscapeAnchorPositionX, portraitAnchorPositionY));
1344         }
1345         else
1346         {
1347         __pCallContextMenu->SetAnchorPosition(Point(portraitAnchorPositionX, portraitAnchorPositionY));
1348         }
1349         // Show the ContextMenu
1350         __pCallContextMenu->Show();
1351
1352         AppLogDebug("EXIT");
1353         return;
1354
1355 }
1356
1357
1358 void
1359 DialTabDialer::AddPause(void)
1360 {
1361         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1362         if (pEditField != null && pEditField->GetTextLength() > 0)
1363         {
1364                 ShowFormattedText(pEditField,PAUSE_KEY);
1365                 HideSearchGadget();
1366                 UpdateSearchResults();
1367                 pEditField->Invalidate(true);
1368         }
1369
1370         return;
1371 }
1372
1373 void
1374 DialTabDialer::AddWait(void)
1375 {
1376         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1377         if (pEditField != null)
1378         {
1379                 ShowFormattedText(pEditField,WAIT_KEY);
1380                 if (pEditField->GetTextLength() == 0)
1381                 {
1382                         ShowSearchGadget();
1383                         HideSearchBox();
1384                 }
1385                 else
1386                 {
1387                         HideSearchGadget();
1388                         UpdateSearchResults();
1389                 }
1390                 pEditField->Invalidate(true);
1391         }
1392
1393         return;
1394 }
1395
1396 void
1397 DialTabDialer::AddPlus(void)
1398 {
1399         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1400         if (pEditField != null)
1401         {
1402                 ShowFormattedText(pEditField,PLUS_KEY);
1403                 if (pEditField->GetTextLength() == 0)
1404                 {
1405                         ShowSearchGadget();
1406                         HideSearchBox();
1407                 }
1408                 else
1409                 {
1410                         HideSearchGadget();
1411                         UpdateSearchResults();
1412                 }
1413                 pEditField->Invalidate(true);
1414         }
1415         return;
1416 }
1417
1418 bool
1419 DialTabDialer::DialOutgoingCall(const String& contactNumber)
1420 {
1421         AppLogDebug("Enter");
1422         bool isSuccess = false;
1423         if (__isAppControlLaunched == true)
1424         {
1425                 //If call AppControl is already launched, ignore any further requests.
1426                 return isSuccess;
1427         }
1428
1429         if(__dialerState == DIALER_STATE_FIRST_SCENE || __dialerState == DIALER_STATE_NORMAL_APPCONTROL)
1430         {
1431                 ErrorCodes error = __pDialPresentationModel->DialCall(contactNumber);
1432                 if (error == ERROR_NONE)
1433                 {
1434                         __isAppControlLaunched = true;
1435                         isSuccess = true;
1436                 }
1437                 else
1438                 {
1439                         __isAppControlLaunched = false;
1440                         isSuccess = false;
1441                         //Show error message Popup
1442                         if (__pErrorMsgPopup == null)
1443                         {
1444                                 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
1445                                 __pErrorMsgPopup->ShowErrorMsgPopupN(error);
1446                         }
1447                 }
1448         }
1449         else
1450         {
1451                 //Dialer was launched as AppControl in "AddCall" Scenario.
1452                 if (__dialerState == DIALER_STATE_ADD_CALL_APPCONTROL)
1453                 {
1454                         isSuccess = true;
1455                         HashMap resultData;
1456                         resultData.Construct();
1457                         resultData.Add(new (std::nothrow) String(PARAM_PHONE_NUMBER), new (std::nothrow) String(contactNumber));
1458                         //send "APP_CTRL_RESULT_SUCCEEDED" and 'contactNumber' as result.
1459                         PhoneApp* pApp = static_cast<PhoneApp*>(UiApp::GetInstance());
1460                         pApp->SendAppControlResponseMessage(APP_CTRL_RESULT_SUCCEEDED, &resultData);
1461                         resultData.RemoveAll(true);
1462                         pApp->Terminate();
1463                 }
1464         }
1465         return isSuccess;
1466 }
1467
1468 void
1469 DialTabDialer::SwitchToSpeedDialForm(void)
1470 {
1471         SceneManager* pSceneManager = SceneManager::GetInstance();
1472         AppAssert(pSceneManager);
1473         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_SPEED_DIAL), null);
1474         return;
1475 }
1476
1477 void
1478 DialTabDialer::ShowSpeedDialConfirmationPopup(bool isVoiceMail)
1479 {
1480         String popupTitleMsg;
1481         String popupMsg;
1482         Label* pMsgLabel;
1483         if(__pConfirmationPopup == null)
1484         {
1485                 FloatRectangle rect = GetBoundsF();
1486                 __pConfirmationPopup = new (std::nothrow) Popup();
1487                 __pConfirmationPopup->Construct(true, FloatDimension(W_SPEEDDIAL_POPUP, H_SPEEDDIAL_POPUP));
1488
1489                 rect = __pConfirmationPopup->GetBoundsF();
1490                 pMsgLabel = new (std::nothrow) Label();
1491                 if(isVoiceMail == true)
1492                 {
1493                         popupTitleMsg = AppUtility::GetResourceString(IDS_DIALER_VOICE_POPUP_TITLE_MSG);
1494                         popupMsg = AppUtility::GetResourceString(IDS_DIALER_VOICE_POPUP_MSG);
1495                 }
1496                 else
1497                 {
1498                         popupTitleMsg = AppUtility::GetResourceString(IDS_DIALER_SPEEDDIAL_POPUP_TITLE_MSG);
1499                         popupMsg = AppUtility::GetResourceString(IDS_DIALER_SPEEDDIAL_POPUP_MSG);
1500                 }
1501                 __pConfirmationPopup->SetTitleText(popupTitleMsg);
1502                 __pConfirmationPopup->SetPropagatedKeyEventListener(this);
1503                 __pConfirmationPopup->Invalidate(true);
1504                 pMsgLabel->Construct(Rectangle(0, IDI_PADDING, rect.width, H_POPUP_MSG_LABEL), popupMsg);
1505                 pMsgLabel->SetName(IDC_SPEED_DIAL_TXT_LABEL);
1506                 pMsgLabel->SetTextConfig(44,LABEL_TEXT_STYLE_NORMAL);
1507                 pMsgLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1508                 pMsgLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1509                 __pConfirmationPopup->AddControl(*pMsgLabel);
1510
1511                 rect = pMsgLabel->GetBoundsF();
1512                 Button *pButtonYes = new (std::nothrow) Button();
1513                 String btnName = AppUtility::GetResourceString(IDS_SPEEDDIAL_POP_YES_BTN_STRING);
1514                 pButtonYes->Construct(Rectangle(rect.x+ IDI_PADDING, (rect.y + rect.height + IDI_PADDING), ((rect.width - (3 * IDI_PADDING)) / 2), H_POPUP_BTN), btnName);
1515                 pButtonYes->SetActionId(IDA_SPEEDDIAL_POPUP_YES);
1516                 pButtonYes->AddActionEventListener(*this);
1517                 __pConfirmationPopup->AddControl(*pButtonYes);
1518
1519                 rect = pButtonYes->GetBoundsF();
1520                 Button *pButtonNo = new (std::nothrow) Button();
1521                 btnName = AppUtility::GetResourceString(IDS_SPEEDDIAL_POP_NO_BTN_STRING);
1522                 pButtonNo->Construct(Rectangle((rect.x + rect.width + IDI_PADDING), rect.y, rect.width, rect.height), btnName);
1523                 pButtonNo->SetActionId(IDA_SPEEDDIAL_POPUP_NO);
1524                 pButtonNo->AddActionEventListener(*this);
1525                 __pConfirmationPopup->AddControl(pButtonNo);
1526         }
1527         else
1528         {
1529                 if(isVoiceMail == true)
1530                 {
1531                         popupTitleMsg = AppUtility::GetResourceString(IDS_DIALER_VOICE_POPUP_TITLE_MSG);
1532                         popupMsg = AppUtility::GetResourceString(IDS_DIALER_VOICE_POPUP_MSG);
1533                 }
1534                 else
1535                 {
1536                         popupTitleMsg = AppUtility::GetResourceString(IDS_DIALER_SPEEDDIAL_POPUP_TITLE_MSG);
1537                         popupMsg = AppUtility::GetResourceString(IDS_DIALER_SPEEDDIAL_POPUP_MSG);
1538                 }
1539                 __pConfirmationPopup->SetTitleText(popupTitleMsg);
1540                 pMsgLabel = static_cast<Label*>(__pConfirmationPopup->GetControl(IDC_SPEED_DIAL_TXT_LABEL, true));
1541                 pMsgLabel->SetText(popupMsg);
1542
1543         }
1544         //Show Popup message
1545         __pConfirmationPopup->SetShowState(true);
1546         __pConfirmationPopup->Show();
1547 }
1548
1549 void
1550 DialTabDialer::ShowAddToContactsButton(void)
1551 {
1552         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1553         Button* pButtonContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
1554         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
1555         Button* pButtonPullUp = static_cast<Button*>(GetControl(IDC_BUTTON_PULL_UP, true));
1556         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
1557         pButtonContacts->SetShowState(false);
1558         pButtonDropDown->SetShowState(false);
1559         pButtonPullUp->SetShowState(false);
1560         pButtonAddContacts->SetShowState(true);
1561         pSearchPanel->SetShowState(true);
1562         pSearchPanel->Invalidate(true);
1563         return;
1564 }
1565
1566 void
1567 DialTabDialer::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
1568 {
1569         switch(requestId)
1570         {
1571                 case REQUEST_SHOW_SUGGESTION:
1572                 {
1573                         String* pDisplayname = static_cast<String*> (pArgs->GetAt(0));
1574                         String* pMobileNo = static_cast<String*> (pArgs->GetAt(1));
1575                         String* pMatchedSearchStr = static_cast<String*> (pArgs->GetAt(2));
1576                         String* pResultCount = static_cast<String*> (pArgs->GetAt(3));
1577                         if(pDisplayname != null && pMobileNo != null && pMatchedSearchStr != null && pResultCount != null)
1578                         {
1579                                 if (__isSearchListOpened == true)
1580                                 {
1581                                         HideSearchListView();
1582                                 }
1583                                 ShowSuggestionBox(*pDisplayname, *pMobileNo, *pMatchedSearchStr, *pResultCount);
1584                         }
1585                         delete pArgs;
1586                 }
1587                 break;
1588
1589                 case REQUEST_SHOW_ADD_TO_CONTACTS:
1590                 {
1591                         if (__isSearchListOpened == true)
1592                         {
1593                                 HideSearchListView();
1594                         }
1595                         ShowAddToContactsButton();
1596                 }
1597                 break;
1598
1599                 case REQUEST_CALL_SPEED_DIAL_NUM:
1600                 {
1601                         if(pArgs != null)
1602                         {
1603                                 String *number = static_cast<String*> (pArgs->GetAt(0));
1604                                 //dial a call.
1605                                 if(number != null)
1606                                 {
1607                                         DialOutgoingCall(*number);
1608                                 }
1609                                 delete pArgs;
1610                         }
1611                 }
1612                 break;
1613
1614                 case REQUEST_SHOW_VOICE_MAIL_POPUP:
1615                 {
1616                         ShowSpeedDialConfirmationPopup(true);
1617                 }
1618                 break;
1619                 case REQUEST_SHOW_SPEED_DIAL_POPUP:
1620                 {
1621                         //show speed Dial Confirmation Popup msg
1622                         ShowSpeedDialConfirmationPopup();
1623                 }
1624                 break;
1625         }
1626
1627 }
1628 void
1629 DialTabDialer::SetShiftedPosUseContact(void)
1630 {
1631         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1632         Panel* pPanelUseContact = static_cast<Panel*>(pSearchPanel->GetControl(IDC_PANEL_USE_CONTACT, true));
1633         Panel* pPanelDropDown = static_cast<Panel*>(pSearchPanel->GetControl(IDC_PANEL_DROPDOWN, true));
1634
1635         Point pointUseContact = pPanelUseContact->GetPosition();
1636         pointUseContact.y = 0;
1637         Point pointDropDown = pPanelDropDown->GetPosition();
1638         pointDropDown.y = 10;
1639
1640         pPanelUseContact->SetPosition(pointUseContact.x,pointUseContact.y);
1641         pPanelDropDown->SetPosition(pointDropDown.x,pointDropDown.y);
1642
1643         pPanelUseContact->SetShowState(true);
1644         pPanelDropDown->SetShowState(true);
1645
1646         SetControlAlwaysOnTop(*pPanelUseContact,true);
1647         SetControlAlwaysOnTop(*pPanelDropDown,true);
1648         pSearchPanel->Invalidate(true);
1649 }
1650 void
1651 DialTabDialer::SetOrigPosUseContact(void)
1652 {
1653         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1654         Panel* pPanelUseContact = static_cast<Panel*>(pSearchPanel->GetControl(IDC_PANEL_USE_CONTACT, true));
1655         Panel* pPanelDropDown = static_cast<Panel*>(pSearchPanel->GetControl(IDC_PANEL_DROPDOWN, true));
1656
1657         Point pointUseContact = pPanelUseContact->GetPosition();
1658         pointUseContact.y = 119;
1659         Point pointDropDown = pPanelDropDown->GetPosition();
1660         pointDropDown.y = 147;
1661
1662         pPanelUseContact->SetPosition(pointUseContact.x,pointUseContact.y);
1663         pPanelDropDown->SetPosition(pointDropDown.x,pointDropDown.y);
1664
1665         SetControlAlwaysOnTop(*pPanelUseContact,true);
1666         SetControlAlwaysOnTop(*pPanelDropDown,true);
1667         pSearchPanel->Invalidate(true);
1668 }
1669
1670 void
1671 DialTabDialer::ShowSuggestionBox(String& name, String& mobileNo, String& matchedKey, String& resultCount)
1672 {
1673         AppLogDebug("ENTER");
1674
1675         //"UseContact" Button
1676         Button* pButtonUseContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
1677         Canvas pCanvasNormalContacts;
1678         pCanvasNormalContacts.Construct(pButtonUseContacts->GetBounds());
1679         Canvas pCanvasPressedContacts;
1680         pCanvasPressedContacts.Construct(pButtonUseContacts->GetBounds());
1681         String mobileStr = AppUtility::GetResourceString(IDS_DIALER_MOBILE_STR);
1682         pCanvasNormalContacts.SetBackgroundColor(COLOR_SEARCHLIST_BG);
1683         pCanvasNormalContacts.Clear();
1684         //Add text, Bg to normal state
1685         DialUtil::DrawTextAndHighlightedKeywordToCanvas(name, matchedKey, FONT_SUGGESTION_NAME, pCanvasNormalContacts, POSITION_SUGGESTION_NAME);
1686         DialUtil::DrawTextAndHighlightedKeywordToCanvas(mobileNo, matchedKey, FONT_SUGGESTION_MOBILE, pCanvasNormalContacts, POSITION_SUGGESTION_NUMBER);
1687         //Add text, Bg to pressed state
1688         pCanvasPressedContacts.SetBackgroundColor(COLOR_SEARCHLIST_PRESS_BG);
1689         pCanvasPressedContacts.Clear();
1690         DialUtil::DrawTextAndHighlightedKeywordToCanvas(name, matchedKey, FONT_SUGGESTION_NAME, pCanvasPressedContacts, POSITION_SUGGESTION_NAME);
1691         DialUtil::DrawTextAndHighlightedKeywordToCanvas(mobileNo, matchedKey, FONT_SUGGESTION_MOBILE, pCanvasPressedContacts, POSITION_SUGGESTION_NUMBER);
1692         //add normal, pressed bg bitmap to button
1693         DialUtil::DrawCanvasToButton(&pCanvasNormalContacts, &pCanvasPressedContacts, pButtonUseContacts);
1694
1695         //"DropDown" Button
1696         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
1697         Canvas pCanvasNormalDropDown;
1698         pCanvasNormalDropDown.Construct(pButtonDropDown->GetBounds());
1699         Canvas pCanvasPressedDropDown;
1700         pCanvasPressedDropDown.Construct(pButtonDropDown->GetBounds());
1701         //Add text, Bg to normal state
1702         DialUtil::Draw9PatchToCanvas(pCanvasNormalDropDown, IDB_BTN_OPTION_BG_ICON);
1703         DialUtil::DrawTextToCanvas(resultCount, FONT_EXPAND_BUTTON_TEXT, pCanvasNormalDropDown, POSITION_CENTER, BUTTON_STATUS_NORMAL);
1704         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasNormalDropDown, POSITION_BOTTOM_CENTER);
1705         //Add text, Bg to pressed state
1706         DialUtil::Draw9PatchToCanvas(pCanvasPressedDropDown, IDB_BTN_OPTION_PRESS_BG_ICON);
1707         DialUtil::DrawTextToCanvas(resultCount, FONT_EXPAND_BUTTON_TEXT, pCanvasPressedDropDown, POSITION_CENTER, BUTTON_STATUS_NORMAL);
1708         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_PRESS_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasPressedDropDown, POSITION_BOTTOM_CENTER);
1709         //add background to button
1710         DialUtil::DrawCanvasToButton(&pCanvasNormalDropDown, &pCanvasPressedDropDown, pButtonDropDown);
1711
1712         //"Pull UP" Button
1713         Button* pButtonPullUp = static_cast<Button*>(GetControl(IDC_BUTTON_PULL_UP, true));
1714         Canvas pCanvasNormalPullUp;
1715         pCanvasNormalPullUp.Construct(pButtonPullUp->GetBounds());
1716         Canvas pCanvasPressedPullUp;
1717         pCanvasPressedPullUp.Construct(pButtonPullUp->GetBounds());
1718         //Add text, Bg to normal state
1719         DialUtil::Draw9PatchToCanvas(pCanvasNormalPullUp, IDB_BTN_OPTION_BG_ICON);
1720         DialUtil::DrawTextToCanvas(resultCount, FONT_EXPAND_BUTTON_TEXT, pCanvasNormalPullUp, POSITION_CENTER, BUTTON_STATUS_NORMAL);
1721         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_UP_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasNormalPullUp, POSITION_BOTTOM_CENTER);
1722         //Add text, Bg to pressed state
1723         DialUtil::Draw9PatchToCanvas(pCanvasPressedPullUp, IDB_BTN_OPTION_PRESS_BG_ICON);
1724         DialUtil::DrawTextToCanvas(resultCount, FONT_EXPAND_BUTTON_TEXT, pCanvasPressedPullUp, POSITION_CENTER, BUTTON_STATUS_NORMAL);
1725         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_UP_PRESS_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasPressedPullUp, POSITION_BOTTOM_CENTER);
1726         //add background to button
1727         DialUtil::DrawCanvasToButton(&pCanvasNormalPullUp, &pCanvasPressedPullUp, pButtonPullUp);
1728
1729         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
1730         pButtonAddContacts->SetShowState(false);
1731
1732         Form* pForm = dynamic_cast<Form *>(GetParent());
1733         int noOfItems = MAX_SEARCH_LIST_ITEMS;
1734         if(__pDialPresentationModel->GetNumberOfSuggestions() < (noOfItems+1))
1735         {
1736                 noOfItems = __pDialPresentationModel->GetNumberOfSuggestions() - 1;
1737         }
1738         if(pForm != null && (pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
1739         {
1740                 SetOrigPosUseContact();
1741         }
1742         pButtonUseContacts->SetShowState(true);
1743
1744         Panel* pSearchListPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_LIST, true));
1745         //Show pull up or drop down based on list view state
1746         if(pSearchListPanel->GetShowState() == false)
1747         {
1748                 pButtonPullUp->SetShowState(false);
1749                 pButtonPullUp->Invalidate(false);
1750
1751                 pButtonDropDown->SetShowState(true);
1752                 pButtonDropDown->Invalidate(true);
1753         }
1754         else
1755         {
1756                 pButtonDropDown->SetShowState(false);
1757                 pButtonDropDown->Invalidate(false);
1758
1759                 pButtonPullUp->SetShowState(true);
1760                 pButtonPullUp->Invalidate(true);
1761         }
1762
1763         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1764         pSearchPanel->SetShowState(true);
1765         pSearchPanel->Invalidate(true);
1766
1767         AppLogDebug("EXIT");
1768         return;
1769 }
1770
1771 void
1772 DialTabDialer::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
1773 {
1774         DialContactInfo* pDialInfo = __pDialPresentationModel->GetSuggestionAtIndex(index+1);
1775         if(pDialInfo != null)
1776         {
1777                 String phNumber = pDialInfo->GetPhoneNumber();
1778                 EditField* pTextBox = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1779                 if(pTextBox != null)
1780                 {
1781                         pTextBox->Clear();
1782                         ShowFormattedText(pTextBox,phNumber);
1783                         pTextBox->Invalidate(true);
1784                 }
1785                 HideSearchListView();
1786                 UpdateSearchResults();
1787         }
1788         return;
1789 }
1790
1791 void
1792 DialTabDialer::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1793 {
1794         AppLogDebug("Enter");
1795         Form* pForm = static_cast<Form*>(GetParent());
1796
1797         Label* pEditFieldBgLbl = static_cast<Label*>(GetControl(L"IDC_LABEL_BACKGROUND", true));
1798         Dimension editFieldBgLblDimen = pEditFieldBgLbl->GetSize();
1799         if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
1800         {
1801                 editFieldBgLblDimen.height = 461;
1802         }
1803         else if(orientationStatus == ORIENTATION_STATUS_PORTRAIT || orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
1804         {
1805                 editFieldBgLblDimen.height = 315;
1806         }
1807         pEditFieldBgLbl->SetSize(editFieldBgLblDimen);
1808
1809         //Show last row label bg in landscape only.
1810         Panel* pLastRowPanel = static_cast<Panel*>(GetControl(IDC_PANEL_LASTROW, true));
1811         Rectangle lastRowRect = pLastRowPanel->GetBounds();
1812         lastRowRect.y = pForm->GetClientAreaBounds().height - lastRowRect.height;
1813         pLastRowPanel->SetBounds(lastRowRect);
1814         Label* pLastRowLabel = static_cast<Label*>(pLastRowPanel->GetControl(IDC_LABEL_LASTROW_BG, true));
1815         if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
1816         {
1817                 pLastRowLabel->SetShowState(true);
1818         }
1819         else if(orientationStatus == ORIENTATION_STATUS_PORTRAIT || orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
1820         {
1821                 pLastRowLabel->SetShowState(false);
1822         }
1823
1824         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1825         if (pEditField->GetTextLength() > 0)
1826         {
1827                 if (__pDialPresentationModel->GetNumberOfSuggestions() == 0)
1828                 {
1829                         ShowAddToContactsButton();
1830                 }
1831                 else
1832                 {
1833                         //contact suggestion is present, change it bitmap based on new orientation
1834                         DialContactInfo* pDialInfo = __pDialPresentationModel->GetSuggestionAtIndex(0);
1835                         if (pDialInfo != null)
1836                         {
1837                                 String name = pDialInfo->GetDisplayName();
1838                                 String mobileNo = pDialInfo->GetPhoneNumber();
1839                                 String* pMatchedSearchStr = pDialInfo->GetSearchKey();
1840                                 String resultCount;
1841                                 resultCount.Append(__pDialPresentationModel->GetNumberOfSuggestions());
1842                                 ShowSuggestionBox(name, mobileNo, *pMatchedSearchStr, resultCount);
1843                         }
1844                         //Check if search list view is open
1845                         if(__isSearchListOpened == true)
1846                         {
1847                                 HideSearchListView();
1848                                 ShowSearchListView();
1849                         }
1850                 }
1851         }
1852
1853         //reset the bitmaps to button based on new orientation.
1854         if (__pDialKeypad != null)
1855         {
1856                 __pDialKeypad->SetBitmapToKeypadButtons();
1857                 __pDialKeypad->Invalidate(true);
1858         }
1859
1860         Invalidate(true);
1861         return;
1862 }
1863
1864 void
1865 DialTabDialer::HandlePopupClosed(void)
1866 {
1867         Draw();
1868         if(__pErrorMsgPopup != null)
1869         {
1870                 __pErrorMsgPopup->SetShowState(false);
1871         }
1872         return;
1873 }
1874
1875 void
1876 DialTabDialer::OnForeground(void)
1877 {
1878         AppLogDebug("Enter");
1879         __isAppForeground = true;
1880         //If app control was launched
1881         //as we do not know if it success or failed
1882         // we need to UpdateSearchResults
1883         //Returned from app control if app control does not
1884         //send any response we need to do this
1885         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1886         String editText(L"");
1887         if(pEditField != null)
1888         {
1889                 editText = pEditField->GetText();
1890         }
1891
1892         if(editText.IsEmpty() == true)
1893         {
1894                 //Fetch auto area code setting, if present
1895                 SettingsPresentationModel::GetInstance()->GetActivePrefixDialNumber(editText);
1896                 if(editText.IsEmpty() == false)
1897                 {
1898                         editText.Replace(L"P",L";");
1899                         editText.Replace(L"p",L";");
1900                 }
1901         }
1902
1903         if(pEditField != null)
1904         {
1905                 ShowFormattedText(pEditField,editText);
1906                 //pEditField->SetCursorPosition(editText.GetLength());
1907                 pEditField->Invalidate(true);
1908                 //show search results
1909                 if (pEditField->GetTextLength() == 0)
1910                 {
1911                         ShowSearchGadget();
1912                         HideSearchBox();
1913                 }
1914                 else
1915                 {
1916                         HideSearchGadget();
1917                         UpdateSearchResults();
1918                 }
1919         }
1920         SetAppControlLaunched(false);
1921 }
1922
1923 void
1924 DialTabDialer::OnBackground(void)
1925 {
1926         AppLogDebug("Enter");
1927         __isAppForeground = false;
1928 }
1929
1930 bool
1931 DialTabDialer::IsForeground()
1932 {
1933         AppLogDebug("Enter %d",__isAppForeground);
1934         return __isAppForeground;
1935 }
1936
1937 void
1938 DialTabDialer::OnContactsChanged(const IList& contactChangeInfoList)
1939 {
1940         if(contactChangeInfoList.GetCount() > 0)
1941         {
1942                 //clear old search results
1943                 __pDialPresentationModel->ClearSearchResults();
1944                 UpdateSearchResults();
1945         }
1946 }
1947
1948 void
1949 DialTabDialer::SetAppControlLaunched(bool launched)
1950 {
1951         AppLogDebug("%d",__isAppControlLaunched);
1952         __isAppControlLaunched = launched;
1953 }
1954
1955 bool
1956 DialTabDialer::GetAppControlLaunched(void)
1957 {
1958         AppLogDebug("%d",__isAppControlLaunched);
1959         return __isAppControlLaunched;
1960 }
1961
1962 void
1963 DialTabDialer::OnTextValueChanged(const Tizen::Ui::Control& source)
1964 {
1965         AppLogDebug("OnTextValueChanged");
1966         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1967         if (pEditField->GetTextLength() == 0)
1968         {
1969                 ShowSearchGadget();
1970                 HideSearchBox();
1971         }
1972         else
1973         {
1974                 String number = pEditField->GetText();
1975                 pEditField->Clear();
1976                 ShowFormattedText(pEditField,number);
1977                 HideSearchGadget();
1978                 UpdateSearchResults();
1979         }
1980 }
1981
1982 void
1983 DialTabDialer::ShowOptionsMenu()
1984 {
1985         if(__pOptionMenu != null)
1986         {
1987                 delete __pOptionMenu;
1988                 __pOptionMenu = null;
1989         }
1990         __pOptionMenu = new (std::nothrow) OptionMenu();
1991         __pOptionMenu->Construct();
1992         __pOptionMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_SEND_MSG), IDA_MENU_SEND_MESSAGE);
1993         __pOptionMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_SPEED_DIAL), IDA_MENU_SPEED_DIAL);
1994         __pOptionMenu->AddActionEventListener(*this);
1995         __pOptionMenu->SetShowState(true);
1996         __pOptionMenu->Show();
1997 }
1998
1999 bool
2000 DialTabDialer::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
2001 {
2002         AppLogDebug("Enter");
2003         if(keyEventInfo.GetKeyCode() == KEY_BACK)
2004         {
2005                 if(__pConfirmationPopup != null && __pConfirmationPopup->GetShowState() == true)
2006                 {
2007                         __pConfirmationPopup->SetShowState(false);
2008                 }
2009         }
2010         return false;
2011 }
2012
2013 void
2014 DialTabDialer::ShowSilentModeToggle(bool bEnabled)
2015 {
2016         // Creates an instance of MessageBox
2017         String message = (bEnabled ? AppUtility::GetResourceString(IDS_SILENT_MODE_ENABLED):AppUtility::GetResourceString(IDS_SILENT_MODE_DISABLED));
2018         MessageBox silentMsgBox;
2019
2020         silentMsgBox.Construct(L"", message, MSGBOX_STYLE_NONE, 2000);
2021         // Calls ShowAndWait() : Draws and Shows itself and processes events
2022         SetFocus();
2023         int modalResult;
2024         silentMsgBox.ShowAndWait(modalResult);
2025 }