2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file CallEndCallForm.cpp
19 * @brief End Call form implementation
25 #include "CallAppUtility.h"
26 #include "CallEndCallForm.h"
27 #include "CallButtonsPanel.h"
28 #include "CallPresentationModel.h"
29 #include "CallSceneRegister.h"
30 #include "CallTypes.h"
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;
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";
58 EndCallForm::EndCallForm(void)
59 : BaseForm(FORMTYPE_ENDCALL)
61 __pCallButtonsPanel = null;
62 __pContactNumber = null;
63 __pEndCallEventTimer = null;
64 __pSmallPhotoLabel = null;
65 __isMsgAppControlLaunched = false;
66 __isContactAppControlLaunched = false;
69 EndCallForm::~EndCallForm(void)
71 if (__pEndCallEventTimer != null)
73 __pEndCallEventTimer->Cancel();
74 delete __pEndCallEventTimer;
75 __pEndCallEventTimer = null;
77 if (__pSmallPhotoLabel != null)
79 __pSmallPhotoLabel = null;
84 EndCallForm::Initialize(void)
86 Construct(IDL_END_CALL_FORM);
90 EndCallForm::OnInitializing(void)
94 //initialize keypad and buttons
95 InitializeCallButtonsPanel();
97 __pEndCallEventTimer = new (std::nothrow) Tizen::Base::Runtime::Timer();
98 r = __pEndCallEventTimer->Construct(*this);
100 __pCallPresentor = CallPresentationModel::GetInstance();
105 EndCallForm::InitializeCallButtonsPanel(void)
107 Label* pKeysBgLbl = static_cast<Label*>(GetControl(IDC_KEY_BG_LABEL, true));
108 Bitmap* pBgBitmap = AppUtility::GetBitmapFromResourcesN(IDB_BACKGROUND_BITMAP, pKeysBgLbl->GetWidth(), pKeysBgLbl->GetHeight());
109 if (pBgBitmap != null)
111 pKeysBgLbl->SetBackgroundBitmap(*pBgBitmap);
113 if (__pCallButtonsPanel == null)
115 __pCallButtonsPanel = new (std::nothrow) CallButtonsPanel();
116 __pCallButtonsPanel->ConstructPanel(this, FORMTYPE_ENDCALL);
117 __pCallButtonsPanel->SetBounds(pKeysBgLbl->GetBounds());
118 AddControl(*__pCallButtonsPanel);
121 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetPortraitLayoutN());
122 if (pRelativeLayout != null)
124 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
126 pRelativeLayout = dynamic_cast<RelativeLayout*>(GetLandscapeLayoutN());
127 if (pRelativeLayout != null)
129 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_LEFT_TO_LEFT);
130 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
135 EndCallForm::AddKeyPadActionListener(const String& keyName, CommandIds cmdId)
137 Button* pButton = static_cast<Button*>(GetControl(keyName));
140 pButton->SetActionId(cmdId);
141 pButton->AddActionEventListener(*this);
146 EndCallForm::OnTerminating(void)
148 result r = E_SUCCESS;
150 if (__pCallPresentor)
152 __pCallPresentor = null;
158 EndCallForm::OnActionPerformed(const Control& source, int actionId)
160 SceneManager* pSceneManager = SceneManager::GetInstance();
161 AppAssert(pSceneManager);
167 //check if EndCallTimer is running, then cancel it
168 if(__pEndCallEventTimer != null)
170 __pEndCallEventTimer->Cancel();
172 //make an outgoing call with given number
173 String* contactTxt = new (std::nothrow) String(*__pContactNumber);
174 //switch to dialing outgoing call form
175 ArrayList* pContact = new (std::nothrow) ArrayList(SingleObjectDeleter);
176 pContact->Construct();
177 pContact->Add(contactTxt);
179 //Check if dialing a call is possible
180 bool isSimInitialized = __pCallPresentor->CheckSimInitializationIsCompleted();
181 if (isSimInitialized)
183 //Check if dialing an emergency call
184 bool isEmergencyCall = __pCallPresentor->IsEmergencyNumber(*contactTxt, true);
187 pSceneManager->GoForward( ForwardSceneTransition( IDSCN_SCENE_OUT_EMERGENCYCALL), pContact);
191 pSceneManager->GoForward( ForwardSceneTransition(IDSCN_SCENE_OUTCALL), pContact);
196 //Show error message Popup
197 HandleTelephonyError(ERROR_CODE_SIM_INITIALIZATION_FAILED);
208 if (__isMsgAppControlLaunched == true)
210 //AppControl already launched.
213 //launch message AppControl
214 __isMsgAppControlLaunched = __pCallPresentor->LaunchComposeMessageAppControl(*__pContactNumber, this);
215 if (__isMsgAppControlLaunched == true && __pEndCallEventTimer != null)
217 //cancel EndCallTimer, if AppControl request was successful.
218 __pEndCallEventTimer->Cancel();
223 case IDA_ADD_TO_CONTACTS:
225 if(__isContactAppControlLaunched == true)
227 //AppControl already launched.
228 AppLogDebug("__isContactAppControlLaunched == true");
231 HandleAddToContacts();
241 EndCallForm::HandleAddToContacts(void)
243 AppLogDebug("Enter");
245 Contact* pContact = __pCallPresentor->GetContactN(*__pContactNumber);
246 //Launch Contact AppControl
247 String requestParameter;
248 if (pContact != null)
251 requestParameter.Append(pContact->GetRecordId());
252 __isContactAppControlLaunched = __pCallPresentor->LaunchViewContactAppControl(requestParameter, this);
259 requestParameter.Append(*__pContactNumber);
260 __isContactAppControlLaunched = __pCallPresentor->LaunchAddContactAppControl(requestParameter, this);
263 if (__isContactAppControlLaunched == true && __pEndCallEventTimer != null)
265 //cancel EndCallTimer, if AppControl request was success.
266 __pEndCallEventTimer->Cancel();
271 EndCallForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
273 //set itself as listener
274 __pCallPresentor->SetTelEventListener(this);
275 //listen to Foreground events
276 CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
277 pPhoneApp->AddAppStateChangeListener(*this);
278 __isMsgAppControlLaunched = false;
279 __isContactAppControlLaunched = false;
283 case FORMTYPE_ENDCALL:
285 //fetch ended call details
286 AppCallInfo* pEndCall = static_cast<AppCallInfo*>(pArgs->GetAt(0));
289 __pContactNumber = new (std::nothrow) String();
290 if(pEndCall->GetContactNumber().IsEmpty() == false)
292 __pContactNumber->Append(pEndCall->GetContactNumber());
296 __pContactNumber->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
299 //Fetch & show contact person details
300 ShowPersonDetails(*__pContactNumber, IDC_CALLER1_LABEL, IDC_CALLER1_BIGPHOTO_LABEL,pEndCall);
301 //If call is hidden means contact number is empty,
302 //or if call is from known number(i.e present in contacts db), Then do NOT show "Add to Contact" button.
303 if (pEndCall->GetContactInfo() != null)
305 //Check if contact is deleted in mean time.
306 Contact* pContact = __pCallPresentor->GetContactN(pEndCall->GetContactNumber());
307 //before setting check if the contact is deleted
310 ShowViewContactButton();
316 ShowAddContactButton();
322 ShowAddContactButton();
325 //Check if call is Emergency call or Hidden call,
326 //then disable all button in Call button panel.
327 if (pEndCall->IsEmergency() == true || pEndCall->GetContactNumber().IsEmpty() == true)
329 __pCallButtonsPanel->SetEndCallPanelState(false);
333 __pCallButtonsPanel->SetEndCallPanelState(true);
336 //check if we reached the end call form of an outgoing call then don't show add to contacts
337 if(pEndCall->GetCalllogType() == CALL_LOG_TYPE_VOICE_OUTGOING)
339 __pCallButtonsPanel->ShowOrHideAddtoContactsButton(false);
341 else if(pEndCall->GetCalllogType() == CALL_LOG_TYPE_VOICE_INCOMING)
343 __pCallButtonsPanel->ShowOrHideAddtoContactsButton(true);
353 //Before starting end call timer check if messaging appcontrol was launched during incoming call
354 if (__pEndCallEventTimer && __pCallPresentor->IsAppControlRunning() == false)
356 __pEndCallEventTimer->Start(IDI_APP_END_TIMER);
365 CallApp* pCallApp = static_cast<CallApp*>(CallApp::GetInstance());
366 pCallApp->SetTopMostWindow(false);
367 AddOrientationEventListener(*this);
371 EndCallForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
373 if (__pEndCallEventTimer != null)
375 __pEndCallEventTimer->Cancel();
377 if (__pContactNumber)
379 delete __pContactNumber;
380 __pContactNumber = null;
382 if (__pSmallPhotoLabel != null)
384 __pSmallPhotoLabel->SetShowState(false);
386 //remove itself as listener
387 CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
388 pPhoneApp->RemoveAppStateChangeListener(*this);
389 RemoveOrientationEventListener(*this);
393 EndCallForm::OnDraw(void)
399 EndCallForm::ShowViewContactButton(void)
401 __pCallButtonsPanel->ShowViewContactButton();
405 EndCallForm::ShowAddContactButton(void)
407 __pCallButtonsPanel->ShowAddContactButton();
411 EndCallForm::ShowPhoneNumber(const String& phoneNumber, const String& lblName)
413 String formattedNumber = phoneNumber;
414 Label* pContactLbl = static_cast<Label*>(GetControl(lblName));
415 pContactLbl->SetText(formattedNumber);
419 EndCallForm::ShowPersonDetails(const String& phoneNumber, const String& nameLblName, const String& photoLblName, AppCallInfo* pCallInfo)
422 ShowPhoneNumber(phoneNumber, IDC_NUMBER1_LABEL);
424 Label* pNameLbl = static_cast<Label*>(GetControl(nameLblName));
425 Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLblName));
427 //fetch contact details based on phone number
428 String* pDisplayName = pCallInfo->FetchCallerNameN();
429 Bitmap* pPhotoBitmap = pCallInfo->FetchCallerPhotoN();
431 //passing an empty string to SetText fails in label,
432 //if previously valid text has been set
433 if (pDisplayName != null && pDisplayName->IsEmpty() == true && pNameLbl->GetText().IsEmpty() == false)
435 pDisplayName->Append(L" ");
438 // show display name on name Label
439 if (pDisplayName != null)
441 pNameLbl->SetText(*pDisplayName);
444 // If record not found or no photo id present for user,
445 //fetch default bitmap.
446 if (pPhotoBitmap != null)
448 if(pPhotoBitmap->GetHeight() <= H_SMALL_PHOTO
449 && pPhotoBitmap->GetWidth() <= W_SMALL_PHOTO)
451 ShowThumbnailImage(pPhotoBitmap,photoLblName);
455 Canvas* pCanvas = new (std::nothrow) Canvas;
456 Rectangle canvasRect(Rectangle(0, 0, pPhotoLbl->GetBounds().width, pPhotoLbl->GetBounds().height));
457 pCanvas->Construct(canvasRect);
458 //draw the contact bitmap
459 pCanvas->DrawBitmap(canvasRect,*pPhotoBitmap);
460 Bitmap* pNewPhotoId = new Bitmap();
461 pNewPhotoId->Construct(*pCanvas, pCanvas->GetBounds());
464 pPhotoLbl->SetBackgroundBitmap(*pNewPhotoId);
465 pPhotoLbl->Invalidate(true);
472 Bitmap* pDefaultPhoto = AppUtility::GetBitmapFromResourcesN(IDB_END_CALL_DEFAULT_ICON,W_PHOTO_LABEL,H_PHOTO_LABEL);
473 if (pDefaultPhoto != null)
475 pPhotoLbl->SetBackgroundBitmap(*pDefaultPhoto);
476 pPhotoLbl->Invalidate(true);
477 delete pDefaultPhoto;
495 EndCallForm::ShowThumbnailImage(const Bitmap* pPhotoId,const String& photoLabel)
497 Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLabel));
499 if (pPhotoLbl != null && pPhotoId != null)
501 Canvas* pCanvas = new (std::nothrow) Canvas;
502 Bitmap* pBackground = AppUtility::GetBitmapFromResourcesN(IDB_CALL_THUMBNAIL_BACKGROUND,W_CALL_THUMBNAIL,H_CALL_THUMBNAIL);
503 Bitmap* pShadow = AppUtility::GetBitmapFromResourcesN(IDB_CALL_THUMBNAIL_SHADOW,W_CALL_THUMBNAIL_SHADOW,H_CALL_THUMBNAIL_SHADOW);
504 Rectangle canvasRect(Rectangle(0, 0, pPhotoLbl->GetBounds().width, pPhotoLbl->GetBounds().height));
505 pCanvas->Construct(canvasRect);
506 //draw the back ground
507 pCanvas->DrawBitmap(canvasRect,*pBackground);
508 //draw shadow (to be enabled after correct shadow image is provided )
509 //pCanvas->DrawBitmap(Rectangle((pPhotoLbl->GetBounds().width/2)-(W_CALL_THUMBNAIL_SHADOW/2),
510 // (pPhotoLbl->GetBounds().height/2)-(H_CALL_THUMBNAIL_SHADOW/2),W_CALL_THUMBNAIL_SHADOW,H_CALL_THUMBNAIL_SHADOW),*pShadow);
511 //draw the contact bitmap
512 pCanvas->DrawBitmap(Rectangle((pPhotoLbl->GetBounds().width/2)-(W_SMALL_PHOTO/2),
513 (pPhotoLbl->GetBounds().height/2)-(H_SMALL_PHOTO/2),W_SMALL_PHOTO,H_SMALL_PHOTO),*pPhotoId);
514 Bitmap* pNewPhotoId = new Bitmap();
515 pNewPhotoId->Construct(*pCanvas, pCanvas->GetBounds());
518 pPhotoLbl->SetBackgroundBitmap(*pNewPhotoId);
519 pPhotoLbl->Invalidate(true);
527 EndCallForm::ShowCallersPhotoThumbnail(const Bitmap& pPhotoId)
529 if (__pSmallPhotoLabel != null)
531 RemoveControl(*__pSmallPhotoLabel);
532 __pSmallPhotoLabel = null;
534 //Draw Small Photo and show on small photo label
535 __pSmallPhotoLabel = new (std::nothrow) Label();//static_cast<Label*>(GetControl(IDC_SMALL_PHOTO_LABEL));
536 __pSmallPhotoLabel->Construct(Rectangle(X_PHOTO_LBL, Y_PHOTO_LBL, W_PHOTO_LBL, H_PHOTO_LBL), L"");
537 __pSmallPhotoLabel->SetBackgroundColor(Color(0,0,0));
538 __pSmallPhotoLabel->SetBackgroundBitmap(pPhotoId);
539 // Add a Label to the Form
540 AddControl(*__pSmallPhotoLabel);
541 __pSmallPhotoLabel->Invalidate(true);
545 EndCallForm::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
547 //goto initial scene or close application, since this was last active call.
548 HandleLastCallCompletion();
552 EndCallForm::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
554 AppLogDebug("Enter");
555 if (__isMsgAppControlLaunched == true)
557 //Message AppControl request completed.
558 __isMsgAppControlLaunched = false;
559 __pCallPresentor->AppControlRequestCompleted();
561 if(__isContactAppControlLaunched == true)
563 //notify app control completed
564 __isContactAppControlLaunched = false;
565 __pCallPresentor->AppControlRequestCompleted();
567 //AppControl completed, goto initial scene if present
569 HandleLastCallCompletion();
573 EndCallForm::HandleLastCallCompletion(void)
575 CallApp* pPhoneApp = (static_cast<CallApp*>(UiApp::GetInstance()));
576 pPhoneApp->Terminate();
580 EndCallForm::OnForeground(void)
582 AppLogDebug("Enter");
583 //If Contact app control was launched
584 //as we do not know if it success or failed.
585 if(__isContactAppControlLaunched == true)
587 if(__pEndCallEventTimer != null)
589 __pEndCallEventTimer->Start(2000);
591 if (__pContactNumber != null && __pContactNumber->IsEmpty() == false)
593 AppCallInfo* ActiveCallInfo = new (std::nothrow) AppCallInfo();
594 ActiveCallInfo->SetContactNumber(*__pContactNumber);
595 Contact* pContact = __pCallPresentor->GetContactN(*__pContactNumber);
596 if (pContact != null)
598 ActiveCallInfo->SetContactInfo(*pContact);
600 //before setting check if the contact is deleted
604 ShowViewContactButton();
610 ShowAddContactButton();
612 ShowPersonDetails(*__pContactNumber, IDC_CALLER1_LABEL, IDC_CALLER1_BIGPHOTO_LABEL,ActiveCallInfo);
613 delete ActiveCallInfo;
616 //notify app control completed
617 __isContactAppControlLaunched = false;
618 __pCallPresentor->AppControlRequestCompleted();
620 else if (__isMsgAppControlLaunched == true)
622 //Message AppControl request completed.
623 if(__pEndCallEventTimer != null)
625 __pEndCallEventTimer->Start(2000);
627 __isMsgAppControlLaunched = false;
628 __pCallPresentor->AppControlRequestCompleted();
630 else if(__pCallPresentor->IsAppControlRunning() == true)
632 if(__pEndCallEventTimer != null)
634 __pEndCallEventTimer->Start(2000);
636 __pCallPresentor->AppControlRequestCompleted();
642 EndCallForm::OnBackground(void)
644 AppLogDebug("Enter");
648 EndCallForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
650 AppLogDebug("Enter");
651 if (__pCallButtonsPanel != null)
653 //update position of call buttons panel
654 Label* pKeysBgLbl = static_cast<Label*>(GetControl(IDC_KEY_BG_LABEL, true));
655 __pCallButtonsPanel->SetBounds(pKeysBgLbl->GetBounds());
656 //bring button on top
657 __pCallButtonsPanel->SetButtonPosition();
658 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetPortraitLayoutN());
659 if (pRelativeLayout != null)
661 //pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_TOP_TO_TOP);
663 pRelativeLayout = dynamic_cast<RelativeLayout*>(GetLandscapeLayoutN());
664 if (pRelativeLayout != null)
666 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_LEFT_TO_LEFT);
667 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);