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