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 AddOrientationEventListener(*this);
369 EndCallForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
371 if (__pEndCallEventTimer != null)
373 __pEndCallEventTimer->Cancel();
375 if (__pContactNumber)
377 delete __pContactNumber;
378 __pContactNumber = null;
380 if (__pSmallPhotoLabel != null)
382 __pSmallPhotoLabel->SetShowState(false);
384 //remove itself as listener
385 CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
386 pPhoneApp->RemoveAppStateChangeListener(*this);
387 RemoveOrientationEventListener(*this);
391 EndCallForm::OnDraw(void)
397 EndCallForm::ShowViewContactButton(void)
399 __pCallButtonsPanel->ShowViewContactButton();
403 EndCallForm::ShowAddContactButton(void)
405 __pCallButtonsPanel->ShowAddContactButton();
409 EndCallForm::ShowPhoneNumber(const String& phoneNumber, const String& lblName)
411 String formattedNumber = phoneNumber;
412 Label* pContactLbl = static_cast<Label*>(GetControl(lblName));
413 pContactLbl->SetText(formattedNumber);
417 EndCallForm::ShowPersonDetails(const String& phoneNumber, const String& nameLblName, const String& photoLblName, AppCallInfo* pCallInfo)
420 ShowPhoneNumber(phoneNumber, IDC_NUMBER1_LABEL);
422 Label* pNameLbl = static_cast<Label*>(GetControl(nameLblName));
423 Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLblName));
425 //fetch contact details based on phone number
426 String* pDisplayName = pCallInfo->FetchCallerNameN();
427 Bitmap* pPhotoBitmap = pCallInfo->FetchCallerPhotoN();
429 //passing an empty string to SetText fails in label,
430 //if previously valid text has been set
431 if (pDisplayName != null && pDisplayName->IsEmpty() == true && pNameLbl->GetText().IsEmpty() == false)
433 pDisplayName->Append(L" ");
436 // show display name on name Label
437 if (pDisplayName != null)
439 pNameLbl->SetText(*pDisplayName);
442 // If record not found or no photo id present for user,
443 //fetch default bitmap.
444 if (pPhotoBitmap != null)
446 if(pPhotoBitmap->GetHeight() <= H_SMALL_PHOTO
447 && pPhotoBitmap->GetWidth() <= W_SMALL_PHOTO)
449 ShowThumbnailImage(pPhotoBitmap,photoLblName);
453 Canvas* pCanvas = new (std::nothrow) Canvas;
454 Rectangle canvasRect(Rectangle(0, 0, pPhotoLbl->GetBounds().width, pPhotoLbl->GetBounds().height));
455 pCanvas->Construct(canvasRect);
456 //draw the contact bitmap
457 pCanvas->DrawBitmap(canvasRect,*pPhotoBitmap);
458 Bitmap* pNewPhotoId = new Bitmap();
459 pNewPhotoId->Construct(*pCanvas, pCanvas->GetBounds());
462 pPhotoLbl->SetBackgroundBitmap(*pNewPhotoId);
463 pPhotoLbl->Invalidate(true);
470 Bitmap* pDefaultPhoto = AppUtility::GetBitmapFromResourcesN(IDB_END_CALL_DEFAULT_ICON,W_PHOTO_LABEL,H_PHOTO_LABEL);
471 if (pDefaultPhoto != null)
473 pPhotoLbl->SetBackgroundBitmap(*pDefaultPhoto);
474 pPhotoLbl->Invalidate(true);
475 delete pDefaultPhoto;
493 EndCallForm::ShowThumbnailImage(const Bitmap* pPhotoId,const String& photoLabel)
495 Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLabel));
497 if (pPhotoLbl != null && pPhotoId != null)
499 Canvas* pCanvas = new (std::nothrow) Canvas;
500 Bitmap* pBackground = AppUtility::GetBitmapFromResourcesN(IDB_CALL_THUMBNAIL_BACKGROUND,W_CALL_THUMBNAIL,H_CALL_THUMBNAIL);
501 Bitmap* pShadow = AppUtility::GetBitmapFromResourcesN(IDB_CALL_THUMBNAIL_SHADOW,W_CALL_THUMBNAIL_SHADOW,H_CALL_THUMBNAIL_SHADOW);
502 Rectangle canvasRect(Rectangle(0, 0, pPhotoLbl->GetBounds().width, pPhotoLbl->GetBounds().height));
503 pCanvas->Construct(canvasRect);
504 //draw the back ground
505 pCanvas->DrawBitmap(canvasRect,*pBackground);
506 //draw shadow (to be enabled after correct shadow image is provided )
507 //pCanvas->DrawBitmap(Rectangle((pPhotoLbl->GetBounds().width/2)-(W_CALL_THUMBNAIL_SHADOW/2),
508 // (pPhotoLbl->GetBounds().height/2)-(H_CALL_THUMBNAIL_SHADOW/2),W_CALL_THUMBNAIL_SHADOW,H_CALL_THUMBNAIL_SHADOW),*pShadow);
509 //draw the contact bitmap
510 pCanvas->DrawBitmap(Rectangle((pPhotoLbl->GetBounds().width/2)-(W_SMALL_PHOTO/2),
511 (pPhotoLbl->GetBounds().height/2)-(H_SMALL_PHOTO/2),W_SMALL_PHOTO,H_SMALL_PHOTO),*pPhotoId);
512 Bitmap* pNewPhotoId = new Bitmap();
513 pNewPhotoId->Construct(*pCanvas, pCanvas->GetBounds());
516 pPhotoLbl->SetBackgroundBitmap(*pNewPhotoId);
517 pPhotoLbl->Invalidate(true);
525 EndCallForm::ShowCallersPhotoThumbnail(const Bitmap& pPhotoId)
527 if (__pSmallPhotoLabel != null)
529 RemoveControl(*__pSmallPhotoLabel);
530 __pSmallPhotoLabel = null;
532 //Draw Small Photo and show on small photo label
533 __pSmallPhotoLabel = new (std::nothrow) Label();//static_cast<Label*>(GetControl(IDC_SMALL_PHOTO_LABEL));
534 __pSmallPhotoLabel->Construct(Rectangle(X_PHOTO_LBL, Y_PHOTO_LBL, W_PHOTO_LBL, H_PHOTO_LBL), L"");
535 __pSmallPhotoLabel->SetBackgroundColor(Color(0,0,0));
536 __pSmallPhotoLabel->SetBackgroundBitmap(pPhotoId);
537 // Add a Label to the Form
538 AddControl(*__pSmallPhotoLabel);
539 __pSmallPhotoLabel->Invalidate(true);
543 EndCallForm::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
545 //goto initial scene or close application, since this was last active call.
546 HandleLastCallCompletion();
550 EndCallForm::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
552 AppLogDebug("Enter");
553 if (__isMsgAppControlLaunched == true)
555 //Message AppControl request completed.
556 __isMsgAppControlLaunched = false;
557 __pCallPresentor->AppControlRequestCompleted();
559 if(__isContactAppControlLaunched == true)
561 //notify app control completed
562 __isContactAppControlLaunched = false;
563 __pCallPresentor->AppControlRequestCompleted();
565 //AppControl completed, goto initial scene if present
567 HandleLastCallCompletion();
571 EndCallForm::HandleLastCallCompletion(void)
573 CallApp* pPhoneApp = (static_cast<CallApp*>(UiApp::GetInstance()));
574 pPhoneApp->Terminate();
578 EndCallForm::OnForeground(void)
580 AppLogDebug("Enter");
581 //If Contact app control was launched
582 //as we do not know if it success or failed.
583 if(__isContactAppControlLaunched == true)
585 if(__pEndCallEventTimer != null)
587 __pEndCallEventTimer->Start(2000);
589 if (__pContactNumber != null && __pContactNumber->IsEmpty() == false)
591 AppCallInfo* ActiveCallInfo = new (std::nothrow) AppCallInfo();
592 ActiveCallInfo->SetContactNumber(*__pContactNumber);
593 Contact* pContact = __pCallPresentor->GetContactN(*__pContactNumber);
594 if (pContact != null)
596 ActiveCallInfo->SetContactInfo(*pContact);
598 //before setting check if the contact is deleted
602 ShowViewContactButton();
608 ShowAddContactButton();
610 ShowPersonDetails(*__pContactNumber, IDC_CALLER1_LABEL, IDC_CALLER1_BIGPHOTO_LABEL,ActiveCallInfo);
611 delete ActiveCallInfo;
614 //notify app control completed
615 __isContactAppControlLaunched = false;
616 __pCallPresentor->AppControlRequestCompleted();
618 else if (__isMsgAppControlLaunched == true)
620 //Message AppControl request completed.
621 if(__pEndCallEventTimer != null)
623 __pEndCallEventTimer->Start(2000);
625 __isMsgAppControlLaunched = false;
626 __pCallPresentor->AppControlRequestCompleted();
628 else if(__pCallPresentor->IsAppControlRunning() == true)
630 if(__pEndCallEventTimer != null)
632 __pEndCallEventTimer->Start(2000);
634 __pCallPresentor->AppControlRequestCompleted();
640 EndCallForm::OnBackground(void)
642 AppLogDebug("Enter");
646 EndCallForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
648 AppLogDebug("Enter");
649 if (__pCallButtonsPanel != null)
651 //update position of call buttons panel
652 Label* pKeysBgLbl = static_cast<Label*>(GetControl(IDC_KEY_BG_LABEL, true));
653 __pCallButtonsPanel->SetBounds(pKeysBgLbl->GetBounds());
654 //bring button on top
655 __pCallButtonsPanel->SetButtonPosition();
656 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetPortraitLayoutN());
657 if (pRelativeLayout != null)
659 //pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_TOP_TO_TOP);
661 pRelativeLayout = dynamic_cast<RelativeLayout*>(GetLandscapeLayoutN());
662 if (pRelativeLayout != null)
664 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_LEFT_TO_LEFT);
665 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);