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