8917b4aefb31e434b94f5abdd5997e67ea70b33e
[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                         __pCallButtonsPanel->ShowOrHideAddtoContactsButton(true);
397                 }
398
399         }
400         break;
401
402         default:
403                 break;
404         }
405
406         //Before starting end call timer check if messaging appcontrol was launched during incoming call
407         if (__pEndCallEventTimer && __pCallPresentor->IsAppControlRunning() == false)
408         {
409                 __pEndCallEventTimer->Start(IDI_APP_END_TIMER);
410         }
411
412         if (pArgs)
413         {
414                 pArgs->RemoveAll();
415                 delete pArgs;
416                 pArgs = null;
417         }
418         CallApp* pCallApp = static_cast<CallApp*>(CallApp::GetInstance());
419         pCallApp->SetTopMostWindow(false);
420         AddOrientationEventListener(*this);
421 }
422
423 void
424 EndCallForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
425 {
426         if (__pEndCallEventTimer != null)
427         {
428                 __pEndCallEventTimer->Cancel();
429         }
430         if (__pContactNumber)
431         {
432                 delete __pContactNumber;
433                 __pContactNumber = null;
434         }
435         if (__pSmallPhotoLabel != null)
436         {
437                 __pSmallPhotoLabel->SetShowState(false);
438         }
439         //remove itself as listener
440         CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
441         pPhoneApp->RemoveAppStateChangeListener(*this);
442         RemoveOrientationEventListener(*this);
443 }
444
445 result
446 EndCallForm::OnDraw(void)
447 {
448         return E_SUCCESS;
449 }
450
451 void
452 EndCallForm::ShowViewContactButton(void)
453 {
454         __pCallButtonsPanel->ShowViewContactButton();
455 }
456
457 void
458 EndCallForm::ShowAddContactButton(void)
459 {
460         __pCallButtonsPanel->ShowAddContactButton();
461 }
462
463 void
464 EndCallForm::ShowPhoneNumber(const String& phoneNumber, const String& lblName)
465 {
466         String formattedNumber = phoneNumber;
467         Label* pContactLbl = static_cast<Label*>(GetControl(lblName));
468         pContactLbl->SetText(formattedNumber);
469 }
470
471 void
472 EndCallForm::ShowPersonDetails(const String& phoneNumber, const String& nameLblName, const String& photoLblName, AppCallInfo* pCallInfo)
473 {
474         //show phone number
475         ShowPhoneNumber(phoneNumber, IDC_NUMBER1_LABEL);
476
477         Label* pNameLbl = static_cast<Label*>(GetControl(nameLblName));
478         Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLblName));
479
480         //fetch contact details based on phone number
481         String* pDisplayName = pCallInfo->FetchCallerNameN();
482         Bitmap* pPhotoBitmap = pCallInfo->FetchCallerPhotoN();
483
484         //passing an empty string to SetText fails in label,
485         //if previously valid text has been set
486         if (pDisplayName != null && pDisplayName->IsEmpty() == true && pNameLbl->GetText().IsEmpty() == false)
487         {
488                 pDisplayName->Append(L" ");
489         }
490
491         // show display name on name Label
492         if (pDisplayName != null)
493         {
494                 pNameLbl->SetText(*pDisplayName);
495         }
496
497         // If record not found or no photo id present for user,
498         //fetch default bitmap.
499         if (pPhotoBitmap != null)
500         {
501                 if(pPhotoBitmap->GetHeight() <= H_SMALL_PHOTO
502                                 && pPhotoBitmap->GetWidth() <= W_SMALL_PHOTO)
503                 {
504                         ShowThumbnailImage(pPhotoBitmap,photoLblName);
505                 }
506                 else
507                 {
508                         Canvas* pCanvas = new (std::nothrow) Canvas;
509                         Rectangle canvasRect(Rectangle(0, 0, pPhotoLbl->GetBounds().width, pPhotoLbl->GetBounds().height));
510                         pCanvas->Construct(canvasRect);
511                         //draw the contact bitmap
512                         pCanvas->DrawBitmap(canvasRect,*pPhotoBitmap);
513                         Bitmap* pNewPhotoId = new Bitmap();
514                         pNewPhotoId->Construct(*pCanvas, pCanvas->GetBounds());
515                         delete pCanvas;
516
517                         pPhotoLbl->SetBackgroundBitmap(*pNewPhotoId);
518                         pPhotoLbl->Invalidate(true);
519                         delete pNewPhotoId;
520                 }
521         }
522         else
523         {
524                 //Set Default Photo
525                 Bitmap* pDefaultPhoto = AppUtility::GetBitmapFromResourcesN(IDB_END_CALL_DEFAULT_ICON,W_PHOTO_LABEL,H_PHOTO_LABEL);
526                 if (pDefaultPhoto != null)
527                 {
528                         pPhotoLbl->SetBackgroundBitmap(*pDefaultPhoto);
529                         pPhotoLbl->Invalidate(true);
530                         delete pDefaultPhoto;
531                 }
532         }
533         RequestRedraw(true);
534         //free resources
535         if (pDisplayName)
536         {
537                 delete pDisplayName;
538                 pDisplayName = null;
539         }
540         if (pPhotoBitmap)
541         {
542                 delete pPhotoBitmap;
543                 pPhotoBitmap = null;
544         }
545 }
546
547 void
548 EndCallForm::ShowThumbnailImage(const Bitmap* pPhotoId,const String& photoLabel)
549 {
550         Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLabel));
551
552         if (pPhotoLbl != null && pPhotoId != null)
553         {
554                 Canvas* pCanvas = new (std::nothrow) Canvas;
555                 Bitmap* pBackground = AppUtility::GetBitmapFromResourcesN(IDB_CALL_THUMBNAIL_BACKGROUND,W_CALL_THUMBNAIL,H_CALL_THUMBNAIL);
556                 Bitmap* pShadow = AppUtility::GetBitmapFromResourcesN(IDB_CALL_THUMBNAIL_SHADOW,W_CALL_THUMBNAIL_SHADOW,H_CALL_THUMBNAIL_SHADOW);
557                 Rectangle canvasRect(Rectangle(0, 0, pPhotoLbl->GetBounds().width, pPhotoLbl->GetBounds().height));
558                 pCanvas->Construct(canvasRect);
559                 //draw the back ground
560                 pCanvas->DrawBitmap(canvasRect,*pBackground);
561                 //draw shadow (to be enabled after correct shadow image is provided )
562                 //pCanvas->DrawBitmap(Rectangle((pPhotoLbl->GetBounds().width/2)-(W_CALL_THUMBNAIL_SHADOW/2),
563                         //      (pPhotoLbl->GetBounds().height/2)-(H_CALL_THUMBNAIL_SHADOW/2),W_CALL_THUMBNAIL_SHADOW,H_CALL_THUMBNAIL_SHADOW),*pShadow);
564                 //draw the contact bitmap
565                 pCanvas->DrawBitmap(Rectangle((pPhotoLbl->GetBounds().width/2)-(W_SMALL_PHOTO/2),
566                                 (pPhotoLbl->GetBounds().height/2)-(H_SMALL_PHOTO/2),W_SMALL_PHOTO,H_SMALL_PHOTO),*pPhotoId);
567                 Bitmap* pNewPhotoId = new Bitmap();
568                 pNewPhotoId->Construct(*pCanvas, pCanvas->GetBounds());
569                 delete pCanvas;
570
571                 pPhotoLbl->SetBackgroundBitmap(*pNewPhotoId);
572                 pPhotoLbl->Invalidate(true);
573                 delete pNewPhotoId;
574                 delete pBackground;
575                 delete pShadow;
576         }
577 }
578
579 void
580 EndCallForm::ShowCallersPhotoThumbnail(const Bitmap& pPhotoId)
581 {
582         if (__pSmallPhotoLabel != null)
583         {
584                 RemoveControl(*__pSmallPhotoLabel);
585                 __pSmallPhotoLabel = null;
586         }
587         //Draw Small Photo and show on small photo label
588         __pSmallPhotoLabel  = new (std::nothrow) Label();//static_cast<Label*>(GetControl(IDC_SMALL_PHOTO_LABEL));
589         __pSmallPhotoLabel->Construct(Rectangle(X_PHOTO_LBL, Y_PHOTO_LBL, W_PHOTO_LBL, H_PHOTO_LBL), L"");
590         __pSmallPhotoLabel->SetBackgroundColor(Color(0,0,0));
591         __pSmallPhotoLabel->SetBackgroundBitmap(pPhotoId);
592         // Add a Label to the Form
593         AddControl(*__pSmallPhotoLabel);
594         __pSmallPhotoLabel->Invalidate(true);
595 }
596
597 void
598 EndCallForm::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
599 {
600         //goto initial scene or close application, since this was last active call.
601         HandleLastCallCompletion();
602 }
603
604 void
605 EndCallForm::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
606 {
607         AppLogDebug("Enter");
608         if (__isMsgAppControlLaunched == true)
609         {
610                 //Message AppControl request completed.
611                 __isMsgAppControlLaunched = false;
612                 __pCallPresentor->AppControlRequestCompleted();
613         }
614         if(__isContactAppControlLaunched == true)
615         {
616                 //notify app control completed
617                 __isContactAppControlLaunched = false;
618                 __pCallPresentor->AppControlRequestCompleted();
619         }
620         //AppControl completed, goto initial scene if present
621         //else exit.
622         HandleLastCallCompletion();
623 }
624
625 void
626 EndCallForm::HandleLastCallCompletion(void)
627 {
628         CallApp* pPhoneApp = (static_cast<CallApp*>(UiApp::GetInstance()));
629         pPhoneApp->Terminate();
630 }
631
632 void
633 EndCallForm::OnForeground(void)
634 {
635         AppLogDebug("Enter");
636         //If Contact app control was launched
637         //as we do not know if it success or failed.
638         if(__isContactAppControlLaunched == true)
639         {
640                 if(__pEndCallEventTimer != null)
641                 {
642                         __pEndCallEventTimer->Start(2000);
643                 }
644                 if (__pContactNumber != null && __pContactNumber->IsEmpty() == false)
645                 {
646                         AppCallInfo* ActiveCallInfo = new (std::nothrow) AppCallInfo();
647                         ActiveCallInfo->SetContactNumber(*__pContactNumber);
648                         Contact* pContact = __pCallPresentor->GetContactN(*__pContactNumber);
649                         if (pContact != null)
650                         {
651                                 ActiveCallInfo->SetContactInfo(*pContact);
652                         }
653                         //before setting check if the contact is deleted
654                         if(pContact != null)
655                         {
656
657                                 ShowViewContactButton();
658                                 delete pContact;
659                                 pContact = null;
660                         }
661                         else
662                         {
663                                 ShowAddContactButton();
664                         }
665                         ShowPersonDetails(*__pContactNumber, IDC_CALLER1_LABEL, IDC_CALLER1_BIGPHOTO_LABEL,ActiveCallInfo);
666                         delete ActiveCallInfo;
667                 }
668
669                 //notify app control completed
670                 __isContactAppControlLaunched = false;
671                 __pCallPresentor->AppControlRequestCompleted();
672         }
673         else if (__isMsgAppControlLaunched == true)
674         {
675                 //Message AppControl request completed.
676                 if(__pEndCallEventTimer != null)
677                 {
678                         __pEndCallEventTimer->Start(2000);
679                 }
680                 __isMsgAppControlLaunched = false;
681                 __pCallPresentor->AppControlRequestCompleted();
682         }
683         else if(__pCallPresentor->IsAppControlRunning() == true)
684         {
685                 if(__pEndCallEventTimer != null)
686                 {
687                         __pEndCallEventTimer->Start(2000);
688                 }
689                 __pCallPresentor->AppControlRequestCompleted();
690         }
691         //Enable all buttons
692         Button* pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON,true));
693         pButton->SetEnabled(true);
694         pButton->Invalidate(true);
695         pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON,true));
696         pButton->SetEnabled(true);
697         pButton->Invalidate(true);
698         pButton = static_cast<Button*>(GetControl(IDC_ADD_TO_CONTACT_BUTTON,true));
699         if(pButton->GetShowState() == true)
700         {
701                 pButton->SetEnabled(true);
702                 pButton->Invalidate(true);
703         }
704         pButton = static_cast<Button*>(GetControl(IDC_MSG_BUTTON,true));
705         pButton->SetEnabled(true);
706         pButton->Invalidate(true);
707         AppLogDebug("Exit");
708 }
709
710 void
711 EndCallForm::OnBackground(void)
712 {
713         AppLogDebug("Enter");
714 }
715
716 void
717 EndCallForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
718 {
719         AppLogDebug("Enter");
720         if (__pCallButtonsPanel != null)
721         {
722                 //update position of call buttons panel
723                 Label* pKeysBgLbl = static_cast<Label*>(GetControl(IDC_KEY_BG_LABEL, true));
724                 __pCallButtonsPanel->SetBounds(pKeysBgLbl->GetBounds());
725                 //bring button on top
726                 __pCallButtonsPanel->SetButtonPosition();
727                 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetPortraitLayoutN());
728                 if (pRelativeLayout != null)
729                 {
730                         //pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_TOP_TO_TOP);
731                 }
732                 pRelativeLayout = dynamic_cast<RelativeLayout*>(GetLandscapeLayoutN());
733                 if (pRelativeLayout != null)
734                 {
735                         pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_LEFT_TO_LEFT);
736                         pRelativeLayout->SetRelation(*__pCallButtonsPanel, *this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
737                 }
738         }
739 }