aa1007115eec25346bd7592f2c61daa8733e0794
[apps/osp/Call.git] / src / CallEndCallForm.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    CallEndCallForm.cpp
19  * @brief       End Call form implementation
20  */
21 #include <FApp.h>
22 #include <FUi.h>
23 #include <FMedia.h>
24 #include "CallApp.h"
25 #include "CallAppUtility.h"
26 #include "CallEndCallForm.h"
27 #include "CallButtonsPanel.h"
28 #include "CallPresentationModel.h"
29 #include "CallSceneRegister.h"
30 #include "CallTypes.h"
31 #include "CallAppControlRequestMgr.h"
32
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Media;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
41 using namespace Tizen::Social;
42
43 //constants
44 const int IDI_APP_END_TIMER = 3000;
45 const int W_PHOTO_LABEL = 720;
46 const int H_PHOTO_LABEL = 720;
47 const int X_PHOTO_LBL = 166;
48 const int Y_PHOTO_LBL = 232;
49 const int W_PHOTO_LBL = 388;
50 const int H_PHOTO_LBL = 388;
51 const int END_CALL_TIMER_VAL = 2000;
52 const int END_CALL_WAIT_TIMER_VAL = 500;
53 static const wchar_t* IDL_END_CALL_FORM = L"IDL_END_CALL_FORM";
54 static const wchar_t* IDC_NUMBER1_LABEL = L"IDC_NUMBER1_LABEL";
55 static const wchar_t* IDC_CALLER1_LABEL = L"IDC_CALLER1_LABEL";
56 static const wchar_t* IDC_KEY_BG_LABEL = L"IDC_KEY_BG_LABEL";
57 static const wchar_t* IDC_CALLER1_BIGPHOTO_LABEL = L"IDC_CALLER1_BIGPHOTO_LABEL";
58 static const wchar_t* IDB_END_CALL_DEFAULT_ICON = L"C01-1_call_default_caller ID_720x720.png";
59 static const wchar_t* IDC_VOICECALL_BUTTON = L"IDC_VOICECALL_BUTTON";
60 static const wchar_t* IDC_VIDEOCALL_BUTTON = L"IDC_VIDEOCALL_BUTTON";
61 static const wchar_t* IDC_ADD_TO_CONTACT_BUTTON = L"IDC_ADD_TO_CONTACT_BUTTON";
62 static const wchar_t* IDC_MSG_BUTTON = L"IDC_MSG_BUTTON";
63
64
65
66 EndCallForm::EndCallForm(void)
67 : BaseForm(FORMTYPE_ENDCALL)
68 {
69         __pCallButtonsPanel = null;
70         __pContactNumber = null;
71         __pEndCallEventTimer = null;
72         __pSmallPhotoLabel = null;
73         __isMsgAppControlLaunched = false;
74         __isContactAppControlLaunched = false;
75         __pAddressBook = null;
76 }
77
78 EndCallForm::~EndCallForm(void)
79 {
80         if (__pEndCallEventTimer != null)
81         {
82                 __pEndCallEventTimer->Cancel();
83                 delete __pEndCallEventTimer;
84                 __pEndCallEventTimer = null;
85         }
86         if (__pSmallPhotoLabel != null)
87         {
88                 __pSmallPhotoLabel = null;
89         }
90         if (__pAddressBook != null)
91         {
92                 delete __pAddressBook;
93                 __pAddressBook = null;
94         }
95 }
96
97 void
98 EndCallForm::Initialize(void)
99 {
100         Construct(IDL_END_CALL_FORM);
101 }
102
103 result
104 EndCallForm::OnInitializing(void)
105 {
106         result r = E_SUCCESS;
107
108         //initialize keypad and buttons
109         InitializeCallButtonsPanel();
110
111         __pEndCallEventTimer = new (std::nothrow) Tizen::Base::Runtime::Timer();
112         r = __pEndCallEventTimer->Construct(*this);
113
114         __pCallPresentor = CallPresentationModel::GetInstance();
115         return r;
116 }
117
118 void
119 EndCallForm::InitializeCallButtonsPanel(void)
120 {
121         Label* pKeysBgLbl = static_cast<Label*>(GetControl(IDC_KEY_BG_LABEL, true));
122         Bitmap* pBgBitmap = AppUtility::GetBitmapFromResourcesN(IDB_BACKGROUND_BITMAP, pKeysBgLbl->GetWidth(), pKeysBgLbl->GetHeight());
123         if (pBgBitmap != null)
124         {
125                 pKeysBgLbl->SetBackgroundBitmap(*pBgBitmap);
126         }
127         if (__pCallButtonsPanel == null)
128         {
129                 __pCallButtonsPanel = new (std::nothrow) CallButtonsPanel();
130                 __pCallButtonsPanel->ConstructPanel(this, FORMTYPE_ENDCALL);
131                 __pCallButtonsPanel->SetBounds(pKeysBgLbl->GetBounds());
132                 AddControl(__pCallButtonsPanel);
133         }
134
135         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetPortraitLayoutN());
136         if (pRelativeLayout != null)
137         {
138                 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
139         }
140         pRelativeLayout = dynamic_cast<RelativeLayout*>(GetLandscapeLayoutN());
141         if (pRelativeLayout != null)
142         {
143                 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_LEFT_TO_LEFT);
144                 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
145         }
146 }
147
148 void
149 EndCallForm::AddKeyPadActionListener(const String& keyName, CommandIds cmdId)
150 {
151         Button* pButton = static_cast<Button*>(GetControl(keyName));
152         if (pButton != null)
153         {
154                 pButton->SetActionId(cmdId);
155                 pButton->AddActionEventListener(*this);
156         }
157 }
158
159 result
160 EndCallForm::OnTerminating(void)
161 {
162         result r = E_SUCCESS;
163
164         if (__pCallPresentor)
165         {
166                 //Abort any AppControl Request running already to show incoming call screen
167                 if (__pCallPresentor->IsAppControlRunning() == true)
168                 {
169                         __pCallPresentor->AbortAppControlRequest();
170                 }
171                 __pCallPresentor = null;
172         }
173         return r;
174 }
175
176 void
177 EndCallForm::OnActionPerformed(const Control& source, int actionId)
178 {
179         SceneManager* pSceneManager = SceneManager::GetInstance();
180         AppAssert(pSceneManager);
181
182         switch (actionId)
183         {
184         case IDA_VOICE_CALL:
185         {
186                 if(CallAppControlRequestMgr::GetInstance()->IsAppControlRunning() == true)
187                 {
188                         return;
189                 }
190                 if (__isMsgAppControlLaunched == true)
191                 {
192                         //AppControl already launched.
193                         return;
194                 }
195                 //check if EndCallTimer is running, then cancel it
196                 if(__pEndCallEventTimer != null)
197                 {
198                         __pEndCallEventTimer->Cancel();
199                 }
200                 //make an outgoing call with given number
201                 String* contactTxt = new (std::nothrow) String(*__pContactNumber);
202                 //switch to dialing outgoing call form
203                 ArrayList* pContact = new (std::nothrow) ArrayList(SingleObjectDeleter);
204                 pContact->Construct();
205                 pContact->Add(contactTxt);
206
207                 //Check if dialing a call is possible
208                 bool isSimInitialized = __pCallPresentor->CheckSimInitializationIsCompleted();
209                 if (isSimInitialized)
210                 {
211                         //Disable all buttons
212                         Button* pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON,true));
213                         pButton->SetEnabled(false);
214                         pButton->Invalidate(true);
215                         pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON,true));
216                         pButton->SetEnabled(false);
217                         pButton->Invalidate(true);
218                         pButton = static_cast<Button*>(GetControl(IDC_ADD_TO_CONTACT_BUTTON,true));
219                         if(pButton->GetShowState() == true)
220                         {
221                                 pButton->SetEnabled(false);
222                                 pButton->Invalidate(true);
223                         }
224                         pButton = static_cast<Button*>(GetControl(IDC_MSG_BUTTON,true));
225                         pButton->SetEnabled(false);
226                         pButton->Invalidate(true);
227                         //Check if dialing an emergency call
228                         bool isEmergencyCall = __pCallPresentor->IsEmergencyNumber(*contactTxt, true);
229                         if (isEmergencyCall)
230                         {
231                                 pSceneManager->GoForward( ForwardSceneTransition( IDSCN_SCENE_OUT_EMERGENCYCALL,
232                                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pContact);
233                         }
234                         else
235                         {
236                                 pSceneManager->GoForward( ForwardSceneTransition(IDSCN_SCENE_OUTCALL,
237                                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pContact);
238                         }
239                 }
240                 else
241                 {
242                         //Show error message Popup
243                         HandleTelephonyError(ERROR_CODE_SIM_INITIALIZATION_FAILED);
244                 }
245         }
246         break;
247
248         case IDA_VIDEO_CALL:
249                 //Make Video Call
250                 break;
251
252         case IDA_MESSAGE:
253         {
254                 if (__isMsgAppControlLaunched == true)
255                 {
256                         //AppControl already launched.
257                         return;
258                 }
259                 //launch message AppControl
260                 __isMsgAppControlLaunched = __pCallPresentor->LaunchComposeMessageAppControl(*__pContactNumber, this);
261                 if (__isMsgAppControlLaunched == true && __pEndCallEventTimer != null)
262                 {
263                         //cancel EndCallTimer, if AppControl request was successful.
264                         __pEndCallEventTimer->Cancel();
265                         //Disable the call buttons
266                         Button* pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON,true));
267                         pButton->SetEnabled(false);
268                         pButton->Invalidate(true);
269                         pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON,true));
270                         pButton->SetEnabled(false);
271                         pButton->Invalidate(true);
272                         pButton = static_cast<Button*>(GetControl(IDC_ADD_TO_CONTACT_BUTTON,true));
273                         if(pButton->GetShowState() == true)
274                         {
275                                 pButton->SetEnabled(false);
276                                 pButton->Invalidate(true);
277                         }
278                 }
279         }
280         break;
281
282         case IDA_ADD_TO_CONTACTS:
283         {
284                 if(__isContactAppControlLaunched == true)
285                 {
286                         //AppControl already launched.
287                         AppLogDebug("__isContactAppControlLaunched == true");
288                         return;
289                 }
290                 HandleAddToContacts();
291                 Button* pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON,true));
292                 pButton->SetEnabled(false);
293                 pButton->Invalidate(true);
294                 pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON,true));
295                 pButton->SetEnabled(false);
296                 pButton->Invalidate(true);
297                 pButton = static_cast<Button*>(GetControl(IDC_ADD_TO_CONTACT_BUTTON,true));
298                 if(pButton->GetShowState() == true)
299                 {
300                         pButton->SetEnabled(false);
301                         pButton->Invalidate(true);
302                 }
303                 pButton = static_cast<Button*>(GetControl(IDC_MSG_BUTTON,true));
304                 pButton->SetEnabled(false);
305                 pButton->Invalidate(true);
306         }
307         break;
308
309         default:
310                 break;
311         }
312 }
313
314 void
315 EndCallForm::HandleAddToContacts(void)
316 {
317         AppLogDebug("Enter");
318
319         Contact* pContact = __pCallPresentor->GetContactN(*__pContactNumber);
320         //Launch Contact AppControl
321         String requestParameter;
322         if (pContact != null)
323         {
324                 //View Contact
325                 requestParameter.Append(pContact->GetRecordId());
326                 __isContactAppControlLaunched = __pCallPresentor->LaunchViewContactAppControl(requestParameter, this);
327                 delete pContact;
328                 pContact = null;
329         }
330         else
331         {
332                 //Add To Contact
333                 requestParameter.Append(*__pContactNumber);
334                 __isContactAppControlLaunched = __pCallPresentor->LaunchAddContactAppControl(requestParameter, this);
335         }
336
337         if (__isContactAppControlLaunched == true && __pEndCallEventTimer != null)
338         {
339                 //cancel EndCallTimer, if AppControl request was success.
340                 __pEndCallEventTimer->Cancel();
341         }
342 }
343
344 void
345 EndCallForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
346 {
347         //set itself as listener
348         __pCallPresentor->SetTelEventListener(this);
349         //listen to Foreground events
350         CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
351         pPhoneApp->AddAppStateChangeListener(*this);
352         __isMsgAppControlLaunched = false;
353         __isContactAppControlLaunched = false;
354
355         switch (__formType)
356         {
357         case FORMTYPE_ENDCALL:
358         {
359                 //fetch ended call details
360                 AppCallInfo* pEndCall = static_cast<AppCallInfo*>(pArgs->GetAt(0));
361
362                 //contact number
363                 __pContactNumber = new (std::nothrow) String();
364                 if(pEndCall->IsConferenceCall() == false)
365                 {
366                         if(pEndCall->GetContactNumber().IsEmpty() == false)
367                         {
368                                 __pContactNumber->Append(pEndCall->GetContactNumber());
369                         }
370                         else
371                         {
372                                 __pContactNumber->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
373                         }
374                 }
375                 else
376                 {
377                         String count;
378                         count.Append(pEndCall->GetCallerListCount());
379                         count.Append(" ");
380                         count.Append(AppUtility::GetResourceString(IDS_PEOPLE_STR));
381                         __pContactNumber->Append(count);
382                 }
383
384                 //Fetch & show contact person details
385                 ShowPersonDetails(*__pContactNumber, IDC_CALLER1_LABEL, IDC_CALLER1_BIGPHOTO_LABEL,pEndCall);
386                 //If call is hidden means contact number is empty,
387                 //or if call is from known number(i.e present in contacts db), Then do NOT show "Add to Contact" button.
388                 if (pEndCall->GetContactInfo() != null)
389                 {
390                         //Check if contact is deleted in mean time.
391                         Contact* pContact = __pCallPresentor->GetContactN(pEndCall->GetContactNumber());
392                         //before setting check if the contact is deleted
393                         if(pContact != null)
394                         {
395                                 ShowViewContactButton();
396                                 delete pContact;
397                                 pContact = null;
398                         }
399                         else
400                         {
401                                 ShowAddContactButton();
402                         }
403                 }
404                 else
405                 {
406                         //Show AddToContact
407                         ShowAddContactButton();
408                 }
409
410                 //Check if call is Emergency call or Hidden call,
411                 //then disable all button in Call button panel.
412                 if(pEndCall->IsConferenceCall() == false)
413                 {
414                         if (pEndCall->IsEmergency() == true || pEndCall->GetContactNumber().IsEmpty() == true)
415                         {
416                                 __pCallButtonsPanel->SetEndCallPanelState(false);
417                         }
418                         else
419                         {
420                                 __pCallButtonsPanel->SetEndCallPanelState(true);
421                         }
422                 }
423                 else
424                 {
425                         __pCallButtonsPanel->SetEndCallPanelState(false);
426                 }
427
428                 //check if we reached the end call form of an outgoing call then don't show add to contacts
429                 if(pEndCall->GetCalllogType() == CALL_LOG_TYPE_VOICE_OUTGOING)
430                 {
431                         __pCallButtonsPanel->ShowOrHideAddtoContactsButton(false);
432                 }
433                 else if(pEndCall->GetCalllogType() == CALL_LOG_TYPE_VOICE_INCOMING)
434                 {
435                         if(pEndCall->GetContactNumber().IsEmpty() == false)
436                         {
437                                 __pCallButtonsPanel->ShowOrHideAddtoContactsButton(true);
438                         }
439                 }
440
441         }
442         break;
443
444         default:
445                 break;
446         }
447
448         //Before starting end call timer check if messaging appcontrol was launched during incoming call
449         if (__pEndCallEventTimer && __pCallPresentor->IsAppControlRunning() == false)
450         {
451                 __pEndCallEventTimer->Start(IDI_APP_END_TIMER);
452         }
453
454         if (pArgs)
455         {
456                 pArgs->RemoveAll();
457                 delete pArgs;
458                 pArgs = null;
459         }
460         CallApp* pCallApp = static_cast<CallApp*>(CallApp::GetInstance());
461         pCallApp->SetTopMostWindow(false);
462         AddOrientationEventListener(*this);
463         __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
464         //Add address book listener to listen to contacts changed events
465         if(__pAddressBook != null)
466         {
467                 __pAddressBook->SetAddressbookChangeEventListener(this);
468         }
469 }
470
471 void
472 EndCallForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
473 {
474         if (__pEndCallEventTimer != null)
475         {
476                 __pEndCallEventTimer->Cancel();
477         }
478         if (__pContactNumber)
479         {
480                 delete __pContactNumber;
481                 __pContactNumber = null;
482         }
483         if (__pSmallPhotoLabel != null)
484         {
485                 __pSmallPhotoLabel->SetShowState(false);
486         }
487         //remove contact change event listener
488         if(__pAddressBook != null)
489         {
490                 __pAddressBook->SetAddressbookChangeEventListener(null);
491         }
492         //remove itself as listener
493         CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
494         pPhoneApp->RemoveAppStateChangeListener(*this);
495         RemoveOrientationEventListener(*this);
496 }
497
498 result
499 EndCallForm::OnDraw(void)
500 {
501         return E_SUCCESS;
502 }
503
504 void
505 EndCallForm::ShowViewContactButton(void)
506 {
507         __pCallButtonsPanel->ShowViewContactButton();
508 }
509
510 void
511 EndCallForm::ShowAddContactButton(void)
512 {
513         __pCallButtonsPanel->ShowAddContactButton();
514 }
515
516 void
517 EndCallForm::ShowPhoneNumber(const String& phoneNumber, const String& lblName)
518 {
519         String formattedNumber = phoneNumber;
520         Label* pContactLbl = static_cast<Label*>(GetControl(lblName));
521         pContactLbl->SetText(formattedNumber);
522 }
523
524 void
525 EndCallForm::ShowPersonDetails(const String& phoneNumber, const String& nameLblName, const String& photoLblName, AppCallInfo* pCallInfo)
526 {
527         //show phone number
528         ShowPhoneNumber(phoneNumber, IDC_NUMBER1_LABEL);
529
530         Label* pNameLbl = static_cast<Label*>(GetControl(nameLblName));
531         Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLblName));
532
533         String* pDisplayName;
534         if(pCallInfo->IsConferenceCall() == false)
535         {
536                 //fetch contact details based on phone number
537                 pDisplayName = pCallInfo->FetchLatestCallerNameN(phoneNumber);
538         }
539         else
540         {
541                 pDisplayName = new (std::nothrow) String(AppUtility::GetResourceString(IDS_CONFERENCE_CALL_STRING));
542         }
543         Bitmap* pPhotoBitmap = null;
544         if(pCallInfo->IsConferenceCall() == false)
545         {
546                 pPhotoBitmap = pCallInfo->FetchLatestCallerPhotoN(phoneNumber);
547         }
548
549         //passing an empty string to SetText fails in label,
550         //if previously valid text has been set
551         if (pDisplayName != null && pDisplayName->IsEmpty() == true && pNameLbl->GetText().IsEmpty() == false)
552         {
553                 pDisplayName->Append(L" ");
554         }
555
556         // show display name on name Label
557         if (pDisplayName != null)
558         {
559                 pNameLbl->SetText(*pDisplayName);
560         }
561
562         // If record not found or no photo id present for user,
563         //fetch default bitmap.
564         if (pPhotoBitmap != null)
565         {
566                 if(pPhotoBitmap->GetHeight() <= H_SMALL_PHOTO
567                                 && pPhotoBitmap->GetWidth() <= W_SMALL_PHOTO)
568                 {
569                         ShowThumbnailImage(pPhotoBitmap,photoLblName);
570                 }
571                 else
572                 {
573                         Canvas* pCanvas = new (std::nothrow) Canvas;
574                         Rectangle canvasRect(Rectangle(0, 0, pPhotoLbl->GetBounds().width, pPhotoLbl->GetBounds().height));
575                         pCanvas->Construct(canvasRect);
576                         //draw the contact bitmap
577                         pCanvas->DrawBitmap(canvasRect,*pPhotoBitmap);
578                         Bitmap* pNewPhotoId = new Bitmap();
579                         pNewPhotoId->Construct(*pCanvas, pCanvas->GetBounds());
580                         delete pCanvas;
581
582                         pPhotoLbl->SetBackgroundBitmap(*pNewPhotoId);
583                         pPhotoLbl->Invalidate(true);
584                         delete pNewPhotoId;
585                 }
586         }
587         else
588         {
589                 //Set Default Photo
590                 Bitmap* pDefaultPhoto = null;
591                 if(pCallInfo->IsConferenceCall() == false)
592                 {
593                         pDefaultPhoto = AppUtility::GetBitmapFromResourcesN(IDB_END_CALL_DEFAULT_ICON,W_PHOTO_LABEL,H_PHOTO_LABEL);
594                 }
595                 else
596                 {
597                         pDefaultPhoto = AppUtility::GetBitmapFromResourcesN(IDB_CONFERENCE_BG_ICON,W_CONFERENCE_PHOTO,H_CONFERENCE_PHOTO);
598                 }
599                 if (pDefaultPhoto != null)
600                 {
601                         pPhotoLbl->SetBackgroundBitmap(*pDefaultPhoto);
602                         pPhotoLbl->Invalidate(true);
603                         delete pDefaultPhoto;
604                 }
605         }
606         RequestRedraw(true);
607         //free resources
608         if (pDisplayName)
609         {
610                 delete pDisplayName;
611                 pDisplayName = null;
612         }
613         if (pPhotoBitmap)
614         {
615                 delete pPhotoBitmap;
616                 pPhotoBitmap = null;
617         }
618 }
619
620 void
621 EndCallForm::ShowThumbnailImage(const Bitmap* pPhotoId,const String& photoLabel)
622 {
623         Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLabel));
624
625         if (pPhotoLbl != null && pPhotoId != null)
626         {
627                 Canvas* pCanvas = new (std::nothrow) Canvas;
628                 Bitmap* pBackground = AppUtility::GetBitmapFromResourcesN(IDB_CALL_THUMBNAIL_BACKGROUND,W_CALL_THUMBNAIL,H_CALL_THUMBNAIL);
629                 Bitmap* pShadow = AppUtility::GetBitmapFromResourcesN(IDB_CALL_THUMBNAIL_SHADOW,W_CALL_THUMBNAIL_SHADOW,H_CALL_THUMBNAIL_SHADOW);
630                 Rectangle canvasRect(Rectangle(0, 0, pPhotoLbl->GetBounds().width, pPhotoLbl->GetBounds().height));
631                 pCanvas->Construct(canvasRect);
632                 //draw the back ground
633                 pCanvas->DrawBitmap(canvasRect,*pBackground);
634                 //draw shadow (to be enabled after correct shadow image is provided )
635                 //pCanvas->DrawBitmap(Rectangle((pPhotoLbl->GetBounds().width/2)-(W_CALL_THUMBNAIL_SHADOW/2),
636                         //      (pPhotoLbl->GetBounds().height/2)-(H_CALL_THUMBNAIL_SHADOW/2),W_CALL_THUMBNAIL_SHADOW,H_CALL_THUMBNAIL_SHADOW),*pShadow);
637                 //draw the contact bitmap
638                 pCanvas->DrawBitmap(Rectangle((pPhotoLbl->GetBounds().width/2)-(W_SMALL_PHOTO/2),
639                                 (pPhotoLbl->GetBounds().height/2)-(H_SMALL_PHOTO/2),W_SMALL_PHOTO,H_SMALL_PHOTO),*pPhotoId);
640                 Bitmap* pNewPhotoId = new Bitmap();
641                 pNewPhotoId->Construct(*pCanvas, pCanvas->GetBounds());
642                 delete pCanvas;
643
644                 pPhotoLbl->SetBackgroundBitmap(*pNewPhotoId);
645                 pPhotoLbl->Invalidate(true);
646                 delete pNewPhotoId;
647                 delete pBackground;
648                 delete pShadow;
649         }
650 }
651
652 void
653 EndCallForm::ShowCallersPhotoThumbnail(const Bitmap& pPhotoId)
654 {
655         if (__pSmallPhotoLabel != null)
656         {
657                 RemoveControl(__pSmallPhotoLabel);
658                 __pSmallPhotoLabel = null;
659         }
660         //Draw Small Photo and show on small photo label
661         __pSmallPhotoLabel  = new (std::nothrow) Label();//static_cast<Label*>(GetControl(IDC_SMALL_PHOTO_LABEL));
662         __pSmallPhotoLabel->Construct(Rectangle(X_PHOTO_LBL, Y_PHOTO_LBL, W_PHOTO_LBL, H_PHOTO_LBL), L"");
663         __pSmallPhotoLabel->SetBackgroundColor(Color(0,0,0));
664         __pSmallPhotoLabel->SetBackgroundBitmap(pPhotoId);
665         // Add a Label to the Form
666         AddControl(__pSmallPhotoLabel);
667         __pSmallPhotoLabel->Invalidate(true);
668 }
669
670 void
671 EndCallForm::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
672 {
673         //goto initial scene or close application, since this was last active call.
674         HandleLastCallCompletion();
675 }
676
677 void
678 EndCallForm::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
679 {
680         AppLogDebug("Enter");
681         if (__isMsgAppControlLaunched == true)
682         {
683                 //Message AppControl request completed.
684                 __isMsgAppControlLaunched = false;
685                 __pCallPresentor->AppControlRequestCompleted();
686         }
687         if(__isContactAppControlLaunched == true)
688         {
689                 //notify app control completed
690                 __isContactAppControlLaunched = false;
691                 __pCallPresentor->AppControlRequestCompleted();
692         }
693         //AppControl completed, goto initial scene if present
694         //else exit.
695         HandleLastCallCompletion();
696 }
697
698 void
699 EndCallForm::HandleLastCallCompletion(void)
700 {
701         //Check if message sending is in progress if yes
702         //wait for it to complete by restarting the timer
703         AppLogDebug("Enter");
704         if(__pCallPresentor->IsMessageSendingInProgress() == true)
705         {
706                 __pEndCallEventTimer->Start(END_CALL_WAIT_TIMER_VAL);
707         }
708         else
709         {
710                 CallApp* pPhoneApp = (static_cast<CallApp*>(UiApp::GetInstance()));
711                 pPhoneApp->Terminate();
712         }
713 }
714
715 void
716 EndCallForm::OnForeground(void)
717 {
718         AppLogDebug("Enter");
719         //If Contact app control was launched
720         //as we do not know if it success or failed.
721         if(__isContactAppControlLaunched == true)
722         {
723                 if(__pEndCallEventTimer != null)
724                 {
725                         __pEndCallEventTimer->Start(END_CALL_TIMER_VAL);
726                 }
727                 UpdatePersonDetail();
728                 //notify app control completed
729                 __isContactAppControlLaunched = false;
730                 __pCallPresentor->AppControlRequestCompleted();
731         }
732         else if (__isMsgAppControlLaunched == true)
733         {
734                 //Message AppControl request completed.
735                 if(__pEndCallEventTimer != null)
736                 {
737                         __pEndCallEventTimer->Start(2000);
738                 }
739                 __isMsgAppControlLaunched = false;
740                 __pCallPresentor->AppControlRequestCompleted();
741         }
742         else if(__pCallPresentor->IsAppControlRunning() == true)
743         {
744                 if(__pEndCallEventTimer != null)
745                 {
746                         __pEndCallEventTimer->Start(2000);
747                 }
748                 __pCallPresentor->AppControlRequestCompleted();
749         }
750         //Enable all buttons
751         Button* pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON,true));
752         pButton->SetEnabled(false);
753         pButton->Invalidate(true);
754         pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON,true));
755         pButton->SetEnabled(true);
756         pButton->Invalidate(true);
757         pButton = static_cast<Button*>(GetControl(IDC_ADD_TO_CONTACT_BUTTON,true));
758         if(pButton->GetShowState() == true)
759         {
760                 pButton->SetEnabled(true);
761                 pButton->Invalidate(true);
762         }
763         pButton = static_cast<Button*>(GetControl(IDC_MSG_BUTTON,true));
764         pButton->SetEnabled(true);
765         pButton->Invalidate(true);
766         AppLogDebug("Exit");
767 }
768
769 void
770 EndCallForm::OnBackground(void)
771 {
772         AppLogDebug("Enter");
773 }
774
775 void
776 EndCallForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
777 {
778         AppLogDebug("Enter");
779         if (__pCallButtonsPanel != null)
780         {
781                 //update position of call buttons panel
782                 Label* pKeysBgLbl = static_cast<Label*>(GetControl(IDC_KEY_BG_LABEL, true));
783                 __pCallButtonsPanel->SetBounds(pKeysBgLbl->GetBounds());
784                 //bring button on top
785                 __pCallButtonsPanel->SetButtonPosition();
786                 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetPortraitLayoutN());
787                 if (pRelativeLayout != null)
788                 {
789                         //pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_TOP_TO_TOP);
790                 }
791                 pRelativeLayout = dynamic_cast<RelativeLayout*>(GetLandscapeLayoutN());
792                 if (pRelativeLayout != null)
793                 {
794                         pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_LEFT_TO_LEFT);
795                         pRelativeLayout->SetRelation(*__pCallButtonsPanel, *this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
796                 }
797         }
798 }
799
800 void
801 EndCallForm::OnContactsChanged(const IList& contactChangeInfoList)
802 {
803         UpdatePersonDetail();
804 }
805
806 void
807 EndCallForm::UpdatePersonDetail()
808 {
809         AppLog("Enter");
810         if (__pContactNumber != null && __pContactNumber->IsEmpty() == false)
811         {
812                 AppCallInfo* ActiveCallInfo = new (std::nothrow) AppCallInfo();
813                 ActiveCallInfo->SetContactNumber(*__pContactNumber);
814                 Contact* pContact = __pCallPresentor->GetContactN(*__pContactNumber);
815                 if (pContact != null)
816                 {
817                         ActiveCallInfo->SetContactInfo(*pContact);
818                 }
819                 //before setting check if the contact is deleted
820                 if(pContact != null)
821                 {
822                         ShowViewContactButton();
823                         delete pContact;
824                         pContact = null;
825                 }
826                 else
827                 {
828                         ShowAddContactButton();
829                 }
830                 ShowPersonDetails(*__pContactNumber, IDC_CALLER1_LABEL, IDC_CALLER1_BIGPHOTO_LABEL,ActiveCallInfo);
831                 delete ActiveCallInfo;
832         }
833         AppLog("Exit");
834 }