Fix for N_SE-44385
[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                         // Regular expression to check the beginning is with Pause/Wait
949                         String phoneNumberPattern(L"^(,|;)");
950                         RegularExpression checkPhoneNumber;
951                         checkPhoneNumber.Construct(phoneNumberPattern);
952                         //If phone number starts with , or ; then show an error popup
953                         bool resultMatch = checkPhoneNumber.Match(contactNo,false);
954                         if(resultMatch == true)
955                         {
956                                 MessageBox numberStartsWithPW;
957                                 String msg(L"Phone number ");
958                                 msg.Append(contactNo);
959                                 msg.Append(L" is Invalid");
960                                 numberStartsWithPW.Construct(L"Invalid Number", msg, MSGBOX_STYLE_NONE,3000);
961                                 int modalResult = 0;
962                                 numberStartsWithPW.ShowAndWait(modalResult);
963                                 return;
964                         }
965                         if (DialOutgoingCall(contactNo) == true)
966                         {
967                                 __pDialPresentationModel->ClearSearchResults();
968                                 pEditField->Clear();
969                                 ShowSearchGadget();
970                                 HideSearchBox();
971                         }
972                         return;
973                 }
974                 else
975                 {
976                         //show latest dialed or incoming number from Logs
977                         String* number = __pDialPresentationModel->FetchLatestNumberFromLogsN();
978                         if(number != null)
979                         {
980                                 ShowFormattedText(pEditField,*number);
981                                 UpdateSearchResults();
982                                 HideSearchGadget();
983                                 delete number;
984                         }
985                 }
986         }
987         break;
988
989         case PAUSE_KEY:
990         {
991                 ShowFormattedText(pEditField,STAR_KEY);
992                 if (pEditField->GetTextLength() == 0)
993                 {
994                         ShowSearchGadget();
995                         HideSearchBox();
996                 }
997                 else
998                 {
999                         HideSearchGadget();
1000                         UpdateSearchResults();
1001                 }
1002         }
1003         break;
1004
1005         /*case HASH_KEY:
1006         {
1007                 pEditField->AppendText(L"#");
1008                 if (pEditField->GetTextLength() == 0)
1009                 {
1010                         ShowSearchGadget();
1011                         HideSearchBox();
1012                 }
1013                 else
1014                 {
1015                         HideSearchGadget();
1016                         UpdateSearchResults();
1017                 }
1018         }
1019         break;*/
1020
1021 /*      case VIDEOCALL_KEY:
1022         {
1023                 //Not yet Supported
1024         }
1025         break;*/
1026
1027         case CANCEL_KEY:
1028         {
1029                 if(pApp->IsOpenAsAppControl() == true)
1030                 {
1031                         pApp->Terminate();
1032                         return;
1033                 }
1034         }
1035         break;
1036
1037         case IDA_BTN_ADD_TO_CONTACTS:
1038         {
1039                 if(pEditField->GetTextLength() > 0)
1040                 {
1041                         String contactNo = pEditField->GetText();
1042                         contactNo.Replace(L"-",L"");
1043                         result r = __pDialPresentationModel->LaunchAddContactsAppControl(contactNo);
1044                         if (r == E_SUCCESS)
1045                         {
1046                                 SetAppControlLaunched(true);
1047                         }
1048                         return;
1049                 }
1050         }
1051         break;
1052
1053         case IDA_SPEEDDIAL_POPUP_YES:
1054         {
1055                 if(__pConfirmationPopup != null)
1056                 {
1057                         __pConfirmationPopup->SetShowState(false);
1058                 }
1059                 SwitchToSpeedDialForm();
1060         }
1061         break;
1062
1063         case IDA_SPEEDDIAL_POPUP_NO:
1064         {
1065                 if(__pConfirmationPopup != null)
1066                 {
1067                         __pConfirmationPopup->SetShowState(false);
1068                 }
1069         }
1070         break;
1071
1072         case IDA_MENU_ADD_PAUSE:
1073         {
1074                 AddPause();
1075         }
1076         break;
1077
1078         case IDA_MENU_ADD_WAIT:
1079         {
1080                 AddWait();
1081         }
1082         break;
1083
1084         case IDA_MENU_EXIT:
1085         {
1086                 //Close Phone App
1087                 pApp->Terminate();
1088                 return;
1089         }
1090         break;
1091
1092         case IDA_MENU_SEND_MESSAGE:
1093         {
1094                 String contactNo = pEditField->GetText();
1095                 contactNo.Replace(L"-",L"");
1096                 result r = __pDialPresentationModel->OpenMessagingAppControl(contactNo);
1097                 if(r == E_SUCCESS)
1098                 {
1099                         SetAppControlLaunched(true);
1100                 }
1101                 return;
1102         }
1103         break;
1104
1105         case IDA_MENU_SPEED_DIAL:
1106         {
1107                 SwitchToSpeedDialForm();
1108                 return;
1109         }
1110         break;
1111
1112         case IDA_BTN_USE_CONTACT_DATA:
1113         {
1114                 DialContactInfo* pDialInfo = __pDialPresentationModel->GetSuggestionAtIndex(0);
1115                 if(pDialInfo != null)
1116                 {
1117                         //fetch contact number
1118                         String phNumber = pDialInfo->GetPhoneNumber();
1119                         if(phNumber.Equals(pEditField->GetText()) == false)
1120                         {
1121                                 pEditField->Clear();
1122                                 ShowFormattedText(pEditField,phNumber);
1123                                 pEditField->Invalidate(true);
1124                                 if (__isSearchListOpened == true)
1125                                 {
1126                                         HideSearchListView();
1127                                 }
1128                                 UpdateSearchResults();
1129                         }
1130                 }
1131         }
1132         break;
1133
1134         case IDA_BTN_DISPLAY_CONTACTS:
1135         {
1136                 if (__isSearchListOpened == true)
1137                 {
1138                         Form* pForm = dynamic_cast<Form *>(GetParent());
1139                         int noOfItems = MAX_SEARCH_LIST_ITEMS;
1140                         if(__pDialPresentationModel->GetNumberOfSuggestions() < (noOfItems+1))
1141                         {
1142                                 noOfItems = __pDialPresentationModel->GetNumberOfSuggestions() - 1;
1143                         }
1144                         if(pForm != null && (pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
1145                         {
1146                                 if(noOfItems > 1)
1147                                 {
1148                                         SetOrigPosUseContact();
1149                                 }
1150                         }
1151                         HideSearchListView();
1152                 }
1153                 else
1154                 {
1155                         ShowSearchListView();
1156                 }
1157         }
1158         break;
1159
1160         default:
1161                 break;
1162         }
1163         pEditField->Invalidate(true);
1164
1165         AppLogDebug("EXIT");
1166         return;
1167 }
1168
1169 void
1170 DialTabDialer::OnLongPressGestureDetected(TouchLongPressGestureDetector& gestureDetector)
1171 {
1172         AppLogDebug("ENTER");
1173         if (GetAppControlLaunched() == true)
1174         {
1175                 //If call AppControl is already launched, ignore any further requests.
1176                 return ;
1177         }
1178
1179         if (gestureDetector.GetControl() != null)
1180         {
1181                 Button* pButton = static_cast<Button*>(gestureDetector.GetControl());
1182                 int actionId = pButton->GetActionId();
1183                 switch(actionId)
1184                 {
1185                 case NUM_KEY1:
1186                 case NUM_KEY2:
1187                 case NUM_KEY3:
1188                 case NUM_KEY4:
1189                 case NUM_KEY5:
1190                 case NUM_KEY6:
1191                 case NUM_KEY7:
1192                 case NUM_KEY8:
1193                 case NUM_KEY9:
1194                 {
1195                         //first check if there is any number present in the edit fiels
1196                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1197                         if(pEditField->GetTextLength() != 0)
1198                         {
1199                                 //append / clear last character to contact
1200                                 int oldtextlen = pEditField->GetTextLength();
1201                                 ShowFormattedText(pEditField, actionId);
1202                                 if (pEditField->GetTextLength() == 0)
1203                                 {
1204                                         __pDialPresentationModel->ClearSearchResults();
1205                                         ShowSearchGadget();
1206                                         HideSearchBox();
1207                                 }
1208                                 else
1209                                 {
1210                                         if(oldtextlen != pEditField->GetTextLength())
1211                                         {
1212                                                 HideSearchGadget();
1213                                                 UpdateSearchResults();
1214                                         }
1215                                 }
1216                                 pEditField->Invalidate(true);
1217                                 break;
1218                         }
1219                         //Check if Speed Dial setting exist for pressed key
1220                         String* contactNumber = __pDialPresentationModel->FetchSpeedDialNumberN(actionId);
1221                         if(contactNumber != null)
1222                         {
1223                                 ArrayList* pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1224                                 pArgs->Construct();
1225                                 //pass ownership to arraylist
1226                                 pArgs->Add(contactNumber);
1227                                 SendUserEvent(REQUEST_CALL_SPEED_DIAL_NUM,pArgs);
1228                         }
1229                         else
1230                         {
1231                                 //show speed Dial Confirmation Popup msg
1232                                 if(actionId == NUM_KEY1)
1233                                 {
1234                                         SendUserEvent(REQUEST_SHOW_VOICE_MAIL_POPUP,null);
1235                                 }
1236                                 else
1237                                 {
1238                                         SendUserEvent(REQUEST_SHOW_SPEED_DIAL_POPUP,null);
1239                                 }
1240                         }
1241
1242                 }
1243                 break;
1244
1245                 case PAUSE_KEY:
1246                 {
1247                         AddPause();
1248                 }
1249                 break;
1250
1251                 case HASH_KEY:
1252                 {
1253                         //Handle Mute / UnMute
1254                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1255                         if(pEditField->GetTextLength() == 0)
1256                         {
1257                                 bool enabled = false;
1258                                 String title = L"http://tizen.org/setting/sound.silent_mode";
1259                                 SettingInfo::GetValue(title, enabled);
1260                                 //enable or disable the phone silent mode.
1261                                 result r = E_FAILURE;
1262                                 r = SettingInfo::SetValue(title, !enabled);
1263                                 if(r == E_SUCCESS)
1264                                 {
1265                                         ShowSilentModeToggle(!enabled);
1266                                 }
1267                         }
1268                 }
1269                 break;
1270
1271                 case CLEAR_KEY:
1272                 {
1273                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1274                         if (pEditField != null && pEditField->GetTextLength() > 0)
1275                         {
1276                                 pEditField->Clear();
1277                                 pEditField->SetTextSize(IDI_MAX_TXT_FONT);
1278                                 //pEditField->SetCursorPosition(0);
1279                                 pEditField->SetFocus();
1280                                 pEditField->Invalidate(true);
1281                                 HideSearchBox();
1282                                 ShowSearchGadget();
1283                         }
1284                 }
1285                 break;
1286                 case CALL_KEY:
1287                 {
1288
1289                         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1290                         if(pEditField != null && pEditField->GetTextLength() > 0)
1291                         {
1292                                 String contactNo = pEditField->GetText();
1293                                 contactNo.Replace(L"-",L"");
1294                                 ShowCallContextMenu(contactNo);
1295                         }
1296
1297                 }
1298                 break;
1299                 case NUM_KEY0:
1300                 {
1301                         AddPlus();
1302                 }
1303                 break;
1304
1305                 default:
1306                         break;
1307                 }
1308         }
1309
1310         AppLogDebug("EXIT");
1311         return;
1312 }
1313
1314 void
1315 DialTabDialer::ShowCallContextMenu(Tizen::Base::String& contactNumber)
1316 {
1317
1318         AppLogDebug("ENTER");
1319
1320         Form *pForm = dynamic_cast<Form*>(GetParent());
1321         Button* pCallButton = static_cast<Button*>(pForm->GetControl(IDC_BUTTON_CALL,true));
1322         Panel* pLastRowPanel = static_cast<Panel*>(pForm->GetControl(IDC_PANEL_LASTROW,true));
1323         int portraitAnchorPositionY = pForm->GetHeight() - pLastRowPanel->GetHeight() +
1324                         ((pLastRowPanel->GetHeight()- pCallButton->GetHeight())/2);
1325         int portraitAnchorPositionX = pLastRowPanel->GetWidth()/2;
1326         int landscapeAnchorPositionX =  pForm->GetWidth()/2 + pLastRowPanel->GetWidth()/2 - pCallButton->GetWidth()/2;
1327         if(__pCallContextMenu != null)
1328         {
1329                 delete __pCallContextMenu;
1330                 __pCallContextMenu = null;
1331         }
1332         __pCallContextMenu = new (std::nothrow) ContextMenu();
1333         __pCallContextMenu->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
1334         //minimum available option count
1335         int visibleItems = MIN_CONTEXT_MENU_ITEMS + 1;
1336         __pCallContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_ADD_PAUSE), IDA_MENU_ADD_PAUSE);
1337         __pCallContextMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_ADD_WAIT), IDA_MENU_ADD_WAIT);
1338         __pCallContextMenu->AddActionEventListener(*this);
1339         __pCallContextMenu->SetFocusable(true);
1340         __pCallContextMenu->SetMaxVisibleItemsCount(visibleItems);
1341         // Set the anchor position of the ContextMenu
1342         if(pForm != null && (pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
1343         {
1344                 __pCallContextMenu->SetAnchorPosition(Point(landscapeAnchorPositionX, portraitAnchorPositionY));
1345         }
1346         else
1347         {
1348         __pCallContextMenu->SetAnchorPosition(Point(portraitAnchorPositionX, portraitAnchorPositionY));
1349         }
1350         // Show the ContextMenu
1351         __pCallContextMenu->Show();
1352
1353         AppLogDebug("EXIT");
1354         return;
1355
1356 }
1357
1358
1359 void
1360 DialTabDialer::AddPause(void)
1361 {
1362         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1363         if (pEditField != null && pEditField->GetTextLength() > 0)
1364         {
1365                 ShowFormattedText(pEditField,PAUSE_KEY);
1366                 HideSearchGadget();
1367                 UpdateSearchResults();
1368                 pEditField->Invalidate(true);
1369         }
1370
1371         return;
1372 }
1373
1374 void
1375 DialTabDialer::AddWait(void)
1376 {
1377         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1378         if (pEditField != null)
1379         {
1380                 ShowFormattedText(pEditField,WAIT_KEY);
1381                 if (pEditField->GetTextLength() == 0)
1382                 {
1383                         ShowSearchGadget();
1384                         HideSearchBox();
1385                 }
1386                 else
1387                 {
1388                         HideSearchGadget();
1389                         UpdateSearchResults();
1390                 }
1391                 pEditField->Invalidate(true);
1392         }
1393
1394         return;
1395 }
1396
1397 void
1398 DialTabDialer::AddPlus(void)
1399 {
1400         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1401         if (pEditField != null)
1402         {
1403                 ShowFormattedText(pEditField,PLUS_KEY);
1404                 if (pEditField->GetTextLength() == 0)
1405                 {
1406                         ShowSearchGadget();
1407                         HideSearchBox();
1408                 }
1409                 else
1410                 {
1411                         HideSearchGadget();
1412                         UpdateSearchResults();
1413                 }
1414                 pEditField->Invalidate(true);
1415         }
1416         return;
1417 }
1418
1419 bool
1420 DialTabDialer::DialOutgoingCall(const String& contactNumber)
1421 {
1422         AppLogDebug("Enter");
1423         bool isSuccess = false;
1424         if (__isAppControlLaunched == true)
1425         {
1426                 //If call AppControl is already launched, ignore any further requests.
1427                 return isSuccess;
1428         }
1429
1430         if(__dialerState == DIALER_STATE_FIRST_SCENE || __dialerState == DIALER_STATE_NORMAL_APPCONTROL)
1431         {
1432                 ErrorCodes error = __pDialPresentationModel->DialCall(contactNumber);
1433                 if (error == ERROR_NONE)
1434                 {
1435                         __isAppControlLaunched = true;
1436                         isSuccess = true;
1437                 }
1438                 else
1439                 {
1440                         __isAppControlLaunched = false;
1441                         isSuccess = false;
1442                         //Show error message Popup
1443                         if (__pErrorMsgPopup == null)
1444                         {
1445                                 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
1446                                 __pErrorMsgPopup->ShowErrorMsgPopupN(error);
1447                         }
1448                 }
1449         }
1450         else
1451         {
1452                 //Dialer was launched as AppControl in "AddCall" Scenario.
1453                 if (__dialerState == DIALER_STATE_ADD_CALL_APPCONTROL)
1454                 {
1455                         isSuccess = true;
1456                         HashMap resultData;
1457                         resultData.Construct();
1458                         resultData.Add(new (std::nothrow) String(PARAM_PHONE_NUMBER), new (std::nothrow) String(contactNumber));
1459                         //send "APP_CTRL_RESULT_SUCCEEDED" and 'contactNumber' as result.
1460                         PhoneApp* pApp = static_cast<PhoneApp*>(UiApp::GetInstance());
1461                         pApp->SendAppControlResponseMessage(APP_CTRL_RESULT_SUCCEEDED, &resultData);
1462                         resultData.RemoveAll(true);
1463                         pApp->Terminate();
1464                 }
1465         }
1466         return isSuccess;
1467 }
1468
1469 void
1470 DialTabDialer::SwitchToSpeedDialForm(void)
1471 {
1472         SceneManager* pSceneManager = SceneManager::GetInstance();
1473         AppAssert(pSceneManager);
1474         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_SPEED_DIAL), null);
1475         return;
1476 }
1477
1478 void
1479 DialTabDialer::ShowSpeedDialConfirmationPopup(bool isVoiceMail)
1480 {
1481         String popupTitleMsg;
1482         String popupMsg;
1483         Label* pMsgLabel;
1484         if(__pConfirmationPopup == null)
1485         {
1486                 FloatRectangle rect = GetBoundsF();
1487                 __pConfirmationPopup = new (std::nothrow) Popup();
1488                 __pConfirmationPopup->Construct(true, FloatDimension(W_SPEEDDIAL_POPUP, H_SPEEDDIAL_POPUP));
1489
1490                 rect = __pConfirmationPopup->GetBoundsF();
1491                 pMsgLabel = new (std::nothrow) Label();
1492                 if(isVoiceMail == true)
1493                 {
1494                         popupTitleMsg = AppUtility::GetResourceString(IDS_DIALER_VOICE_POPUP_TITLE_MSG);
1495                         popupMsg = AppUtility::GetResourceString(IDS_DIALER_VOICE_POPUP_MSG);
1496                 }
1497                 else
1498                 {
1499                         popupTitleMsg = AppUtility::GetResourceString(IDS_DIALER_SPEEDDIAL_POPUP_TITLE_MSG);
1500                         popupMsg = AppUtility::GetResourceString(IDS_DIALER_SPEEDDIAL_POPUP_MSG);
1501                 }
1502                 __pConfirmationPopup->SetTitleText(popupTitleMsg);
1503                 __pConfirmationPopup->SetPropagatedKeyEventListener(this);
1504                 __pConfirmationPopup->Invalidate(true);
1505                 pMsgLabel->Construct(Rectangle(0, IDI_PADDING, rect.width, H_POPUP_MSG_LABEL), popupMsg);
1506                 pMsgLabel->SetName(IDC_SPEED_DIAL_TXT_LABEL);
1507                 pMsgLabel->SetTextConfig(44,LABEL_TEXT_STYLE_NORMAL);
1508                 pMsgLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1509                 pMsgLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1510                 __pConfirmationPopup->AddControl(*pMsgLabel);
1511
1512                 rect = pMsgLabel->GetBoundsF();
1513                 Button *pButtonYes = new (std::nothrow) Button();
1514                 String btnName = AppUtility::GetResourceString(IDS_SPEEDDIAL_POP_YES_BTN_STRING);
1515                 pButtonYes->Construct(Rectangle(rect.x+ IDI_PADDING, (rect.y + rect.height + IDI_PADDING), ((rect.width - (3 * IDI_PADDING)) / 2), H_POPUP_BTN), btnName);
1516                 pButtonYes->SetActionId(IDA_SPEEDDIAL_POPUP_YES);
1517                 pButtonYes->AddActionEventListener(*this);
1518                 __pConfirmationPopup->AddControl(*pButtonYes);
1519
1520                 rect = pButtonYes->GetBoundsF();
1521                 Button *pButtonNo = new (std::nothrow) Button();
1522                 btnName = AppUtility::GetResourceString(IDS_SPEEDDIAL_POP_NO_BTN_STRING);
1523                 pButtonNo->Construct(Rectangle((rect.x + rect.width + IDI_PADDING), rect.y, rect.width, rect.height), btnName);
1524                 pButtonNo->SetActionId(IDA_SPEEDDIAL_POPUP_NO);
1525                 pButtonNo->AddActionEventListener(*this);
1526                 __pConfirmationPopup->AddControl(pButtonNo);
1527         }
1528         else
1529         {
1530                 if(isVoiceMail == true)
1531                 {
1532                         popupTitleMsg = AppUtility::GetResourceString(IDS_DIALER_VOICE_POPUP_TITLE_MSG);
1533                         popupMsg = AppUtility::GetResourceString(IDS_DIALER_VOICE_POPUP_MSG);
1534                 }
1535                 else
1536                 {
1537                         popupTitleMsg = AppUtility::GetResourceString(IDS_DIALER_SPEEDDIAL_POPUP_TITLE_MSG);
1538                         popupMsg = AppUtility::GetResourceString(IDS_DIALER_SPEEDDIAL_POPUP_MSG);
1539                 }
1540                 __pConfirmationPopup->SetTitleText(popupTitleMsg);
1541                 pMsgLabel = static_cast<Label*>(__pConfirmationPopup->GetControl(IDC_SPEED_DIAL_TXT_LABEL, true));
1542                 pMsgLabel->SetText(popupMsg);
1543
1544         }
1545         //Show Popup message
1546         __pConfirmationPopup->SetShowState(true);
1547         __pConfirmationPopup->Show();
1548 }
1549
1550 void
1551 DialTabDialer::ShowAddToContactsButton(void)
1552 {
1553         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1554         Button* pButtonContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
1555         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
1556         Button* pButtonPullUp = static_cast<Button*>(GetControl(IDC_BUTTON_PULL_UP, true));
1557         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
1558         pButtonContacts->SetShowState(false);
1559         pButtonDropDown->SetShowState(false);
1560         pButtonPullUp->SetShowState(false);
1561         pButtonAddContacts->SetShowState(true);
1562         pSearchPanel->SetShowState(true);
1563         pSearchPanel->Invalidate(true);
1564         return;
1565 }
1566
1567 void
1568 DialTabDialer::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
1569 {
1570         switch(requestId)
1571         {
1572                 case REQUEST_SHOW_SUGGESTION:
1573                 {
1574                         String* pDisplayname = static_cast<String*> (pArgs->GetAt(0));
1575                         String* pMobileNo = static_cast<String*> (pArgs->GetAt(1));
1576                         String* pMatchedSearchStr = static_cast<String*> (pArgs->GetAt(2));
1577                         String* pResultCount = static_cast<String*> (pArgs->GetAt(3));
1578                         if(pDisplayname != null && pMobileNo != null && pMatchedSearchStr != null && pResultCount != null)
1579                         {
1580                                 if (__isSearchListOpened == true)
1581                                 {
1582                                         HideSearchListView();
1583                                 }
1584                                 ShowSuggestionBox(*pDisplayname, *pMobileNo, *pMatchedSearchStr, *pResultCount);
1585                         }
1586                         delete pArgs;
1587                 }
1588                 break;
1589
1590                 case REQUEST_SHOW_ADD_TO_CONTACTS:
1591                 {
1592                         if (__isSearchListOpened == true)
1593                         {
1594                                 HideSearchListView();
1595                         }
1596                         ShowAddToContactsButton();
1597                 }
1598                 break;
1599
1600                 case REQUEST_CALL_SPEED_DIAL_NUM:
1601                 {
1602                         if(pArgs != null)
1603                         {
1604                                 String *number = static_cast<String*> (pArgs->GetAt(0));
1605                                 //dial a call.
1606                                 if(number != null)
1607                                 {
1608                                         DialOutgoingCall(*number);
1609                                 }
1610                                 delete pArgs;
1611                         }
1612                 }
1613                 break;
1614
1615                 case REQUEST_SHOW_VOICE_MAIL_POPUP:
1616                 {
1617                         ShowSpeedDialConfirmationPopup(true);
1618                 }
1619                 break;
1620                 case REQUEST_SHOW_SPEED_DIAL_POPUP:
1621                 {
1622                         //show speed Dial Confirmation Popup msg
1623                         ShowSpeedDialConfirmationPopup();
1624                 }
1625                 break;
1626         }
1627
1628 }
1629 void
1630 DialTabDialer::SetShiftedPosUseContact(void)
1631 {
1632         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1633         Panel* pPanelUseContact = static_cast<Panel*>(pSearchPanel->GetControl(IDC_PANEL_USE_CONTACT, true));
1634         Panel* pPanelDropDown = static_cast<Panel*>(pSearchPanel->GetControl(IDC_PANEL_DROPDOWN, true));
1635
1636         Point pointUseContact = pPanelUseContact->GetPosition();
1637         pointUseContact.y = 0;
1638         Point pointDropDown = pPanelDropDown->GetPosition();
1639         pointDropDown.y = 10;
1640
1641         pPanelUseContact->SetPosition(pointUseContact.x,pointUseContact.y);
1642         pPanelDropDown->SetPosition(pointDropDown.x,pointDropDown.y);
1643
1644         pPanelUseContact->SetShowState(true);
1645         pPanelDropDown->SetShowState(true);
1646
1647         SetControlAlwaysOnTop(*pPanelUseContact,true);
1648         SetControlAlwaysOnTop(*pPanelDropDown,true);
1649         pSearchPanel->Invalidate(true);
1650 }
1651 void
1652 DialTabDialer::SetOrigPosUseContact(void)
1653 {
1654         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1655         Panel* pPanelUseContact = static_cast<Panel*>(pSearchPanel->GetControl(IDC_PANEL_USE_CONTACT, true));
1656         Panel* pPanelDropDown = static_cast<Panel*>(pSearchPanel->GetControl(IDC_PANEL_DROPDOWN, true));
1657
1658         Point pointUseContact = pPanelUseContact->GetPosition();
1659         pointUseContact.y = 119;
1660         Point pointDropDown = pPanelDropDown->GetPosition();
1661         pointDropDown.y = 147;
1662
1663         pPanelUseContact->SetPosition(pointUseContact.x,pointUseContact.y);
1664         pPanelDropDown->SetPosition(pointDropDown.x,pointDropDown.y);
1665
1666         SetControlAlwaysOnTop(*pPanelUseContact,true);
1667         SetControlAlwaysOnTop(*pPanelDropDown,true);
1668         pSearchPanel->Invalidate(true);
1669 }
1670
1671 void
1672 DialTabDialer::ShowSuggestionBox(String& name, String& mobileNo, String& matchedKey, String& resultCount)
1673 {
1674         AppLogDebug("ENTER");
1675
1676         //"UseContact" Button
1677         Button* pButtonUseContacts = static_cast<Button*>(GetControl(IDC_BUTTON_USE_CONTACT, true));
1678         Canvas pCanvasNormalContacts;
1679         pCanvasNormalContacts.Construct(pButtonUseContacts->GetBounds());
1680         Canvas pCanvasPressedContacts;
1681         pCanvasPressedContacts.Construct(pButtonUseContacts->GetBounds());
1682         String mobileStr = AppUtility::GetResourceString(IDS_DIALER_MOBILE_STR);
1683         pCanvasNormalContacts.SetBackgroundColor(COLOR_SEARCHLIST_BG);
1684         pCanvasNormalContacts.Clear();
1685         //Add text, Bg to normal state
1686         DialUtil::DrawTextAndHighlightedKeywordToCanvas(name, matchedKey, FONT_SUGGESTION_NAME, pCanvasNormalContacts, POSITION_SUGGESTION_NAME);
1687         DialUtil::DrawTextAndHighlightedKeywordToCanvas(mobileNo, matchedKey, FONT_SUGGESTION_MOBILE, pCanvasNormalContacts, POSITION_SUGGESTION_NUMBER);
1688         //Add text, Bg to pressed state
1689         pCanvasPressedContacts.SetBackgroundColor(COLOR_SEARCHLIST_PRESS_BG);
1690         pCanvasPressedContacts.Clear();
1691         DialUtil::DrawTextAndHighlightedKeywordToCanvas(name, matchedKey, FONT_SUGGESTION_NAME, pCanvasPressedContacts, POSITION_SUGGESTION_NAME);
1692         DialUtil::DrawTextAndHighlightedKeywordToCanvas(mobileNo, matchedKey, FONT_SUGGESTION_MOBILE, pCanvasPressedContacts, POSITION_SUGGESTION_NUMBER);
1693         //add normal, pressed bg bitmap to button
1694         DialUtil::DrawCanvasToButton(&pCanvasNormalContacts, &pCanvasPressedContacts, pButtonUseContacts);
1695
1696         //"DropDown" Button
1697         Button* pButtonDropDown = static_cast<Button*>(GetControl(IDC_BUTTON_DROP_DOWN, true));
1698         Canvas pCanvasNormalDropDown;
1699         pCanvasNormalDropDown.Construct(pButtonDropDown->GetBounds());
1700         Canvas pCanvasPressedDropDown;
1701         pCanvasPressedDropDown.Construct(pButtonDropDown->GetBounds());
1702         //Add text, Bg to normal state
1703         DialUtil::Draw9PatchToCanvas(pCanvasNormalDropDown, IDB_BTN_OPTION_BG_ICON);
1704         DialUtil::DrawTextToCanvas(resultCount, FONT_EXPAND_BUTTON_TEXT, pCanvasNormalDropDown, POSITION_CENTER, BUTTON_STATUS_NORMAL);
1705         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasNormalDropDown, POSITION_BOTTOM_CENTER);
1706         //Add text, Bg to pressed state
1707         DialUtil::Draw9PatchToCanvas(pCanvasPressedDropDown, IDB_BTN_OPTION_PRESS_BG_ICON);
1708         DialUtil::DrawTextToCanvas(resultCount, FONT_EXPAND_BUTTON_TEXT, pCanvasPressedDropDown, POSITION_CENTER, BUTTON_STATUS_NORMAL);
1709         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_PRESS_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasPressedDropDown, POSITION_BOTTOM_CENTER);
1710         //add background to button
1711         DialUtil::DrawCanvasToButton(&pCanvasNormalDropDown, &pCanvasPressedDropDown, pButtonDropDown);
1712
1713         //"Pull UP" Button
1714         Button* pButtonPullUp = static_cast<Button*>(GetControl(IDC_BUTTON_PULL_UP, true));
1715         Canvas pCanvasNormalPullUp;
1716         pCanvasNormalPullUp.Construct(pButtonPullUp->GetBounds());
1717         Canvas pCanvasPressedPullUp;
1718         pCanvasPressedPullUp.Construct(pButtonPullUp->GetBounds());
1719         //Add text, Bg to normal state
1720         DialUtil::Draw9PatchToCanvas(pCanvasNormalPullUp, IDB_BTN_OPTION_BG_ICON);
1721         DialUtil::DrawTextToCanvas(resultCount, FONT_EXPAND_BUTTON_TEXT, pCanvasNormalPullUp, POSITION_CENTER, BUTTON_STATUS_NORMAL);
1722         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_UP_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasNormalPullUp, POSITION_BOTTOM_CENTER);
1723         //Add text, Bg to pressed state
1724         DialUtil::Draw9PatchToCanvas(pCanvasPressedPullUp, IDB_BTN_OPTION_PRESS_BG_ICON);
1725         DialUtil::DrawTextToCanvas(resultCount, FONT_EXPAND_BUTTON_TEXT, pCanvasPressedPullUp, POSITION_CENTER, BUTTON_STATUS_NORMAL);
1726         DialUtil::DrawImageToCanvas(IDB_POPUP_BUBBLE_UP_PRESS_ICON, Dimension(W_SUGGESTION_POPUP_BUBBLE_ICON, H_SUGGESTION_POPUP_BUBBLE_ICON), pCanvasPressedPullUp, POSITION_BOTTOM_CENTER);
1727         //add background to button
1728         DialUtil::DrawCanvasToButton(&pCanvasNormalPullUp, &pCanvasPressedPullUp, pButtonPullUp);
1729
1730         Button* pButtonAddContacts = static_cast<Button*>(GetControl(IDC_BUTTON_ADD_CONTACTS, true));
1731         pButtonAddContacts->SetShowState(false);
1732
1733         Form* pForm = dynamic_cast<Form *>(GetParent());
1734         int noOfItems = MAX_SEARCH_LIST_ITEMS;
1735         if(__pDialPresentationModel->GetNumberOfSuggestions() < (noOfItems+1))
1736         {
1737                 noOfItems = __pDialPresentationModel->GetNumberOfSuggestions() - 1;
1738         }
1739         if(pForm != null && (pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || pForm->GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
1740         {
1741                 SetOrigPosUseContact();
1742         }
1743         pButtonUseContacts->SetShowState(true);
1744
1745         Panel* pSearchListPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_LIST, true));
1746         //Show pull up or drop down based on list view state
1747         if(pSearchListPanel->GetShowState() == false)
1748         {
1749                 pButtonPullUp->SetShowState(false);
1750                 pButtonPullUp->Invalidate(false);
1751
1752                 pButtonDropDown->SetShowState(true);
1753                 pButtonDropDown->Invalidate(true);
1754         }
1755         else
1756         {
1757                 pButtonDropDown->SetShowState(false);
1758                 pButtonDropDown->Invalidate(false);
1759
1760                 pButtonPullUp->SetShowState(true);
1761                 pButtonPullUp->Invalidate(true);
1762         }
1763
1764         Panel* pSearchPanel = static_cast<Panel*>(GetControl(IDC_PANEL_SEARCH_BOX, true));
1765         pSearchPanel->SetShowState(true);
1766         pSearchPanel->Invalidate(true);
1767
1768         AppLogDebug("EXIT");
1769         return;
1770 }
1771
1772 void
1773 DialTabDialer::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
1774 {
1775         DialContactInfo* pDialInfo = __pDialPresentationModel->GetSuggestionAtIndex(index+1);
1776         if(pDialInfo != null)
1777         {
1778                 String phNumber = pDialInfo->GetPhoneNumber();
1779                 EditField* pTextBox = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1780                 if(pTextBox != null)
1781                 {
1782                         pTextBox->Clear();
1783                         ShowFormattedText(pTextBox,phNumber);
1784                         pTextBox->Invalidate(true);
1785                 }
1786                 HideSearchListView();
1787                 UpdateSearchResults();
1788         }
1789         return;
1790 }
1791
1792 void
1793 DialTabDialer::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1794 {
1795         AppLogDebug("Enter");
1796         Form* pForm = static_cast<Form*>(GetParent());
1797
1798         Label* pEditFieldBgLbl = static_cast<Label*>(GetControl(L"IDC_LABEL_BACKGROUND", true));
1799         Dimension editFieldBgLblDimen = pEditFieldBgLbl->GetSize();
1800         if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
1801         {
1802                 editFieldBgLblDimen.height = 461;
1803         }
1804         else if(orientationStatus == ORIENTATION_STATUS_PORTRAIT || orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
1805         {
1806                 editFieldBgLblDimen.height = 315;
1807         }
1808         pEditFieldBgLbl->SetSize(editFieldBgLblDimen);
1809
1810         //Show last row label bg in landscape only.
1811         Panel* pLastRowPanel = static_cast<Panel*>(GetControl(IDC_PANEL_LASTROW, true));
1812         Rectangle lastRowRect = pLastRowPanel->GetBounds();
1813         lastRowRect.y = pForm->GetClientAreaBounds().height - lastRowRect.height;
1814         pLastRowPanel->SetBounds(lastRowRect);
1815         Label* pLastRowLabel = static_cast<Label*>(pLastRowPanel->GetControl(IDC_LABEL_LASTROW_BG, true));
1816         if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
1817         {
1818                 pLastRowLabel->SetShowState(true);
1819         }
1820         else if(orientationStatus == ORIENTATION_STATUS_PORTRAIT || orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
1821         {
1822                 pLastRowLabel->SetShowState(false);
1823         }
1824
1825         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1826         if (pEditField->GetTextLength() > 0)
1827         {
1828                 if (__pDialPresentationModel->GetNumberOfSuggestions() == 0)
1829                 {
1830                         ShowAddToContactsButton();
1831                 }
1832                 else
1833                 {
1834                         //contact suggestion is present, change it bitmap based on new orientation
1835                         DialContactInfo* pDialInfo = __pDialPresentationModel->GetSuggestionAtIndex(0);
1836                         if (pDialInfo != null)
1837                         {
1838                                 String name = pDialInfo->GetDisplayName();
1839                                 String mobileNo = pDialInfo->GetPhoneNumber();
1840                                 String* pMatchedSearchStr = pDialInfo->GetSearchKey();
1841                                 String resultCount;
1842                                 resultCount.Append(__pDialPresentationModel->GetNumberOfSuggestions());
1843                                 ShowSuggestionBox(name, mobileNo, *pMatchedSearchStr, resultCount);
1844                         }
1845                         //Check if search list view is open
1846                         if(__isSearchListOpened == true)
1847                         {
1848                                 HideSearchListView();
1849                                 ShowSearchListView();
1850                         }
1851                 }
1852         }
1853
1854         //reset the bitmaps to button based on new orientation.
1855         if (__pDialKeypad != null)
1856         {
1857                 __pDialKeypad->SetBitmapToKeypadButtons();
1858                 __pDialKeypad->Invalidate(true);
1859         }
1860
1861         Invalidate(true);
1862         return;
1863 }
1864
1865 void
1866 DialTabDialer::HandlePopupClosed(void)
1867 {
1868         Draw();
1869         if(__pErrorMsgPopup != null)
1870         {
1871                 __pErrorMsgPopup->SetShowState(false);
1872         }
1873         return;
1874 }
1875
1876 void
1877 DialTabDialer::OnForeground(void)
1878 {
1879         AppLogDebug("Enter");
1880         __isAppForeground = true;
1881         //If app control was launched
1882         //as we do not know if it success or failed
1883         // we need to UpdateSearchResults
1884         //Returned from app control if app control does not
1885         //send any response we need to do this
1886         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1887         String editText(L"");
1888         if(pEditField != null)
1889         {
1890                 editText = pEditField->GetText();
1891         }
1892
1893         if(editText.IsEmpty() == true)
1894         {
1895                 //Fetch auto area code setting, if present
1896                 SettingsPresentationModel::GetInstance()->GetActivePrefixDialNumber(editText);
1897                 if(editText.IsEmpty() == false)
1898                 {
1899                         editText.Replace(L"P",L";");
1900                         editText.Replace(L"p",L";");
1901                 }
1902         }
1903
1904         if(pEditField != null)
1905         {
1906                 ShowFormattedText(pEditField,editText);
1907                 //pEditField->SetCursorPosition(editText.GetLength());
1908                 pEditField->Invalidate(true);
1909                 //show search results
1910                 if (pEditField->GetTextLength() == 0)
1911                 {
1912                         ShowSearchGadget();
1913                         HideSearchBox();
1914                 }
1915                 else
1916                 {
1917                         HideSearchGadget();
1918                         UpdateSearchResults();
1919                 }
1920         }
1921         SetAppControlLaunched(false);
1922 }
1923
1924 void
1925 DialTabDialer::OnBackground(void)
1926 {
1927         AppLogDebug("Enter");
1928         __isAppForeground = false;
1929 }
1930
1931 bool
1932 DialTabDialer::IsForeground()
1933 {
1934         AppLogDebug("Enter %d",__isAppForeground);
1935         return __isAppForeground;
1936 }
1937
1938 void
1939 DialTabDialer::OnContactsChanged(const IList& contactChangeInfoList)
1940 {
1941         if(contactChangeInfoList.GetCount() > 0)
1942         {
1943                 //clear old search results
1944                 __pDialPresentationModel->ClearSearchResults();
1945                 UpdateSearchResults();
1946         }
1947 }
1948
1949 void
1950 DialTabDialer::SetAppControlLaunched(bool launched)
1951 {
1952         AppLogDebug("%d",__isAppControlLaunched);
1953         __isAppControlLaunched = launched;
1954 }
1955
1956 bool
1957 DialTabDialer::GetAppControlLaunched(void)
1958 {
1959         AppLogDebug("%d",__isAppControlLaunched);
1960         return __isAppControlLaunched;
1961 }
1962
1963 void
1964 DialTabDialer::OnTextValueChanged(const Tizen::Ui::Control& source)
1965 {
1966         AppLogDebug("OnTextValueChanged");
1967         EditField* pEditField = static_cast<EditField*>(GetControl(IDC_NUMERIC_EDITFIELD, true));
1968         if (pEditField->GetTextLength() == 0)
1969         {
1970                 ShowSearchGadget();
1971                 HideSearchBox();
1972         }
1973         else
1974         {
1975                 String number = pEditField->GetText();
1976                 pEditField->Clear();
1977                 ShowFormattedText(pEditField,number);
1978                 HideSearchGadget();
1979                 UpdateSearchResults();
1980         }
1981 }
1982
1983 void
1984 DialTabDialer::ShowOptionsMenu()
1985 {
1986         if(__pOptionMenu != null)
1987         {
1988                 delete __pOptionMenu;
1989                 __pOptionMenu = null;
1990         }
1991         __pOptionMenu = new (std::nothrow) OptionMenu();
1992         __pOptionMenu->Construct();
1993         __pOptionMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_SEND_MSG), IDA_MENU_SEND_MESSAGE);
1994         __pOptionMenu->AddItem(AppUtility::GetResourceString(IDS_DIALER_MENU_ITEM_SPEED_DIAL), IDA_MENU_SPEED_DIAL);
1995         __pOptionMenu->AddActionEventListener(*this);
1996         __pOptionMenu->SetShowState(true);
1997         __pOptionMenu->Show();
1998 }
1999
2000 bool
2001 DialTabDialer::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
2002 {
2003         AppLogDebug("Enter");
2004         if(keyEventInfo.GetKeyCode() == KEY_BACK)
2005         {
2006                 if(__pConfirmationPopup != null && __pConfirmationPopup->GetShowState() == true)
2007                 {
2008                         __pConfirmationPopup->SetShowState(false);
2009                 }
2010         }
2011         return false;
2012 }
2013
2014 void
2015 DialTabDialer::ShowSilentModeToggle(bool bEnabled)
2016 {
2017         // Creates an instance of MessageBox
2018         String message = (bEnabled ? AppUtility::GetResourceString(IDS_SILENT_MODE_ENABLED):AppUtility::GetResourceString(IDS_SILENT_MODE_DISABLED));
2019         MessageBox silentMsgBox;
2020
2021         silentMsgBox.Construct(L"", message, MSGBOX_STYLE_NONE, 2000);
2022         // Calls ShowAndWait() : Draws and Shows itself and processes events
2023         SetFocus();
2024         int modalResult;
2025         silentMsgBox.ShowAndWait(modalResult);
2026 }