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;
67 __isContactPresent = false;
70 EndCallForm::~EndCallForm(void)
72 if (__pEndCallEventTimer != null)
74 __pEndCallEventTimer->Cancel();
75 delete __pEndCallEventTimer;
76 __pEndCallEventTimer = null;
78 if (__pSmallPhotoLabel != null)
80 __pSmallPhotoLabel = null;
85 EndCallForm::Initialize(void)
87 Construct(IDL_END_CALL_FORM);
91 EndCallForm::OnInitializing(void)
95 //initialize keypad and buttons
96 InitializeCallButtonsPanel();
98 __pEndCallEventTimer = new (std::nothrow) Tizen::Base::Runtime::Timer();
99 r = __pEndCallEventTimer->Construct(*this);
101 __pCallPresentor = CallPresentationModel::GetInstance();
106 EndCallForm::InitializeCallButtonsPanel(void)
108 Label* pKeysBgLbl = static_cast<Label*>(GetControl(IDC_KEY_BG_LABEL, true));
109 Bitmap* pBgBitmap = AppUtility::GetBitmapFromResourcesN(IDB_BACKGROUND_BITMAP, pKeysBgLbl->GetWidth(), pKeysBgLbl->GetHeight());
110 if (pBgBitmap != null)
112 pKeysBgLbl->SetBackgroundBitmap(*pBgBitmap);
114 if (__pCallButtonsPanel == null)
116 __pCallButtonsPanel = new (std::nothrow) CallButtonsPanel();
117 __pCallButtonsPanel->ConstructPanel(this, FORMTYPE_ENDCALL);
118 __pCallButtonsPanel->SetBounds(pKeysBgLbl->GetBounds());
119 AddControl(*__pCallButtonsPanel);
122 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetPortraitLayoutN());
123 if (pRelativeLayout != null)
125 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
127 pRelativeLayout = dynamic_cast<RelativeLayout*>(GetLandscapeLayoutN());
128 if (pRelativeLayout != null)
130 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_LEFT_TO_LEFT);
131 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
136 EndCallForm::AddKeyPadActionListener(const String& keyName, CommandIds cmdId)
138 Button* pButton = static_cast<Button*>(GetControl(keyName));
141 pButton->SetActionId(cmdId);
142 pButton->AddActionEventListener(*this);
147 EndCallForm::OnTerminating(void)
149 result r = E_SUCCESS;
151 if (__pCallPresentor)
153 __pCallPresentor = null;
159 EndCallForm::OnActionPerformed(const Control& source, int actionId)
161 SceneManager* pSceneManager = SceneManager::GetInstance();
162 AppAssert(pSceneManager);
168 //check if EndCallTimer is running, then cancel it
169 if(__pEndCallEventTimer != null)
171 __pEndCallEventTimer->Cancel();
173 //make an outgoing call with given number
174 String* contactTxt = new (std::nothrow) String(*__pContactNumber);
175 //switch to dialing outgoing call form
176 ArrayList* pContact = new (std::nothrow) ArrayList(SingleObjectDeleter);
177 pContact->Construct();
178 pContact->Add(contactTxt);
180 //Check if dialing a call is possible
181 bool isSimInitialized = __pCallPresentor->CheckSimInitializationIsCompleted();
182 if (isSimInitialized)
184 //Check if dialing an emergency call
185 bool isEmergencyCall = __pCallPresentor->IsEmergencyNumber(*contactTxt, true);
188 pSceneManager->GoForward( ForwardSceneTransition( IDSCN_SCENE_OUT_EMERGENCYCALL), pContact);
192 pSceneManager->GoForward( ForwardSceneTransition(IDSCN_SCENE_OUTCALL), pContact);
197 //Show error message Popup
198 HandleTelephonyError(ERROR_CODE_SIM_INITIALIZATION_FAILED);
209 if (__isMsgAppControlLaunched == true)
211 //AppControl already launched.
214 //launch message AppControl
215 __isMsgAppControlLaunched = true;
216 result r = E_SUCCESS;
218 extraData.Construct();
220 extraData.Add(new (std::nothrow) String(MESSAGE_TYPE), new (std::nothrow) String(MESSAGE_SMS_TYPE));
221 extraData.Add(new (std::nothrow) String(MESSAGE_TO), new (std::nothrow) String(*__pContactNumber));
223 AppControl* pAc = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE);
226 r = pAc->Start(null, null, &extraData, this);
229 //AppControl request failed, reset flag.
230 __isMsgAppControlLaunched = false;
232 else if (r == E_SUCCESS && __pEndCallEventTimer != null)
234 //cancel EndCallTimer, if AppControl request was successful.
235 __pEndCallEventTimer->Cancel();
240 extraData.RemoveAll(true);
244 case IDA_ADD_TO_CONTACTS:
246 if(__isContactAppControlLaunched == true)
248 //AppControl already launched.
249 AppLogDebug("__isContactAppControlLaunched == true");
252 HandleAddToContacts();
262 EndCallForm::HandleAddToContacts(void)
264 AppLogDebug("Enter");
265 //Launch Contact AppControl
266 __isContactAppControlLaunched = true;
267 Contact* pContact = __pCallPresentor->GetContactN(*__pContactNumber);
268 AppControl* pAc = null;
269 result r = E_SUCCESS;
271 extraData.Construct();
273 if (pContact != null)
275 AppLogDebug("View Contact");
278 idVal.Append(pContact->GetRecordId());
279 extraData.Add(new (std::nothrow) String(CONTACTS_VIEW_TYPE), new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT));
280 extraData.Add(new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT), new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT));
281 extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), new (std::nothrow) String(idVal));
282 extraData.Add(new (std::nothrow) String(CONTACTS_ID_KEY), new (std::nothrow) String(idVal));
283 extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_TYPE), new (std::nothrow) String(ITEM_TYPE_PERSON));
284 pAc = AppManager::FindAppControlN(PROVIDER_ID_CONTACTS, OPERATION_ID_VIEW);
289 AppLogDebug("Add Contact");
290 extraData.Add(new (std::nothrow) String(INPUT_TYPE_PHONE), new (std::nothrow) String(*__pContactNumber));
291 extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_TYPE), new (std::nothrow) String(ITEM_TYPE_CONTACT));
292 pAc = AppManager::FindAppControlN(PROVIDER_ID_CONTACTS, OPERATION_ID_ADD);
297 r = pAc->Start(null, null, &extraData, this);
300 //AppControl request failed, reset flag.
301 __isContactAppControlLaunched = false;
303 else if (r == E_SUCCESS && __pEndCallEventTimer != null)
305 //cancel EndCallTimer, if AppControl request was success.
306 __pEndCallEventTimer->Cancel();
312 __isContactAppControlLaunched = false;
314 extraData.RemoveAll(true);
318 EndCallForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
320 //set itself as listener
321 __pCallPresentor->SetTelEventListener(this);
322 //listen to Foreground events
323 CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
324 pPhoneApp->AddAppStateChangeListener(*this);
325 __isMsgAppControlLaunched = false;
326 __isContactAppControlLaunched = false;
330 case FORMTYPE_ENDCALL:
332 //fetch ended call details
333 AppCallInfo* pEndCall = static_cast<AppCallInfo*>(pArgs->GetAt(0));
336 __pContactNumber = new (std::nothrow) String();
337 if(pEndCall->GetContactNumber().IsEmpty() == false)
339 __pContactNumber->Append(pEndCall->GetContactNumber());
343 __pContactNumber->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
346 //Fetch & show contact person details
347 ShowPersonDetails(*__pContactNumber, IDC_CALLER1_LABEL, IDC_CALLER1_BIGPHOTO_LABEL,pEndCall);
348 //If call is hidden means contact number is empty,
349 //or if call is from known number(i.e present in contacts db), Then do NOT show "Add to Contact" button.
350 if (pEndCall->GetContactInfo() != null || pEndCall->GetContactNumber().IsEmpty() == true)
352 SetContactButtonState(false);
356 SetContactButtonState(true);
359 //Check if call is Emergency call or Hidden call,
360 //then disable all button in Call button panel.
361 if (pEndCall->IsEmergency() == true || pEndCall->GetContactNumber().IsEmpty() == true)
363 __pCallButtonsPanel->SetEndCallPanelState(false);
367 __pCallButtonsPanel->SetEndCallPanelState(true);
376 if (__pEndCallEventTimer)
378 __pEndCallEventTimer->Start(IDI_APP_END_TIMER);
387 AddOrientationEventListener(*this);
391 EndCallForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
393 if (__pEndCallEventTimer != null)
395 __pEndCallEventTimer->Cancel();
397 if (__pContactNumber)
399 delete __pContactNumber;
400 __pContactNumber = null;
402 if (__pSmallPhotoLabel != null)
404 __pSmallPhotoLabel->SetShowState(false);
406 //remove itself as listener
407 CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
408 pPhoneApp->RemoveAppStateChangeListener(*this);
409 RemoveOrientationEventListener(*this);
413 EndCallForm::OnDraw(void)
419 EndCallForm::SetContactButtonState(bool showState)
421 __pCallButtonsPanel->SetViewContactButtonStatus(showState);
422 __isContactPresent = !showState;
426 EndCallForm::IsContactPresent(void)
428 return __isContactPresent;
433 EndCallForm::ShowPhoneNumber(const String& phoneNumber, const String& lblName)
435 String formattedNumber = phoneNumber;
436 Label* pContactLbl = static_cast<Label*>(GetControl(lblName));
437 pContactLbl->SetText(formattedNumber);
441 EndCallForm::ShowPersonDetails(const String& phoneNumber, const String& nameLblName, const String& photoLblName, AppCallInfo* pCallInfo)
444 ShowPhoneNumber(phoneNumber, IDC_NUMBER1_LABEL);
446 Label* pNameLbl = static_cast<Label*>(GetControl(nameLblName));
447 Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLblName));
449 //fetch contact details based on phone number
450 String* pDisplayName = pCallInfo->FetchCallerNameN();
451 Bitmap* pPhotoBitmap = pCallInfo->FetchCallerPhotoN();
453 //passing an empty string to SetText fails in label,
454 //if previously valid text has been set
455 if (pDisplayName != null && pDisplayName->IsEmpty() == true && pNameLbl->GetText().IsEmpty() == false)
457 pDisplayName->Append(L" ");
460 // show display name on name Label
461 if (pDisplayName != null)
463 pNameLbl->SetText(*pDisplayName);
466 // If record not found or no photo id present for user,
467 //fetch default bitmap.
468 if (pPhotoBitmap != null)
470 if(pPhotoBitmap->GetHeight() <= H_SMALL_PHOTO
471 && pPhotoBitmap->GetWidth() <= W_SMALL_PHOTO)
473 ShowThumbnailImage(pPhotoBitmap,photoLblName);
477 Canvas* pCanvas = new (std::nothrow) Canvas;
478 Rectangle canvasRect(Rectangle(0, 0, pPhotoLbl->GetBounds().width, pPhotoLbl->GetBounds().height));
479 pCanvas->Construct(canvasRect);
480 //draw the contact bitmap
481 pCanvas->DrawBitmap(canvasRect,*pPhotoBitmap);
482 Bitmap* pNewPhotoId = new Bitmap();
483 pNewPhotoId->Construct(*pCanvas, pCanvas->GetBounds());
486 pPhotoLbl->SetBackgroundBitmap(*pNewPhotoId);
487 pPhotoLbl->Invalidate(true);
494 Bitmap* pDefaultPhoto = AppUtility::GetBitmapFromResourcesN(IDB_END_CALL_DEFAULT_ICON,W_PHOTO_LABEL,H_PHOTO_LABEL);
495 if (pDefaultPhoto != null)
497 pPhotoLbl->SetBackgroundBitmap(*pDefaultPhoto);
498 pPhotoLbl->Invalidate(true);
499 delete pDefaultPhoto;
517 EndCallForm::ShowThumbnailImage(const Bitmap* pPhotoId,const String& photoLabel)
519 Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLabel));
521 if (pPhotoLbl != null && pPhotoId != null)
523 Canvas* pCanvas = new (std::nothrow) Canvas;
524 Bitmap* pBackground = AppUtility::GetBitmapFromResourcesN(IDB_CALL_THUMBNAIL_BACKGROUND,W_CALL_THUMBNAIL,H_CALL_THUMBNAIL);
525 Bitmap* pShadow = AppUtility::GetBitmapFromResourcesN(IDB_CALL_THUMBNAIL_SHADOW,W_CALL_THUMBNAIL_SHADOW,H_CALL_THUMBNAIL_SHADOW);
526 Rectangle canvasRect(Rectangle(0, 0, pPhotoLbl->GetBounds().width, pPhotoLbl->GetBounds().height));
527 pCanvas->Construct(canvasRect);
528 //draw the back ground
529 pCanvas->DrawBitmap(canvasRect,*pBackground);
530 //draw shadow (to be enabled after correct shadow image is provided )
531 //pCanvas->DrawBitmap(Rectangle((pPhotoLbl->GetBounds().width/2)-(W_CALL_THUMBNAIL_SHADOW/2),
532 // (pPhotoLbl->GetBounds().height/2)-(H_CALL_THUMBNAIL_SHADOW/2),W_CALL_THUMBNAIL_SHADOW,H_CALL_THUMBNAIL_SHADOW),*pShadow);
533 //draw the contact bitmap
534 pCanvas->DrawBitmap(Rectangle((pPhotoLbl->GetBounds().width/2)-(W_SMALL_PHOTO/2),
535 (pPhotoLbl->GetBounds().height/2)-(H_SMALL_PHOTO/2),W_SMALL_PHOTO,H_SMALL_PHOTO),*pPhotoId);
536 Bitmap* pNewPhotoId = new Bitmap();
537 pNewPhotoId->Construct(*pCanvas, pCanvas->GetBounds());
540 pPhotoLbl->SetBackgroundBitmap(*pNewPhotoId);
541 pPhotoLbl->Invalidate(true);
550 EndCallForm::ShowCallersPhotoThumbnail(const Bitmap& pPhotoId)
552 if (__pSmallPhotoLabel != null)
554 RemoveControl(*__pSmallPhotoLabel);
555 __pSmallPhotoLabel = null;
557 //Draw Small Photo and show on small photo label
558 __pSmallPhotoLabel = new (std::nothrow) Label();//static_cast<Label*>(GetControl(IDC_SMALL_PHOTO_LABEL));
559 __pSmallPhotoLabel->Construct(Rectangle(X_PHOTO_LBL, Y_PHOTO_LBL, W_PHOTO_LBL, H_PHOTO_LBL), L"");
560 __pSmallPhotoLabel->SetBackgroundColor(Color(0,0,0));
561 __pSmallPhotoLabel->SetBackgroundBitmap(pPhotoId);
562 // Add a Label to the Form
563 AddControl(*__pSmallPhotoLabel);
564 __pSmallPhotoLabel->Invalidate(true);
568 EndCallForm::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
570 //goto initial scene or close application, since this was last active call.
571 HandleLastCallCompletion();
575 EndCallForm::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
577 AppLogDebug("Enter");
578 if (__isMsgAppControlLaunched == true)
580 //Message AppControl request completed.
581 __isMsgAppControlLaunched = false;
583 //AppControl completed, goto initial scene if present
585 HandleLastCallCompletion();
589 EndCallForm::HandleLastCallCompletion(void)
592 CallApp* pPhoneApp = (static_cast<CallApp*>(UiApp::GetInstance()));
593 pPhoneApp->Terminate();
598 EndCallForm::OnForeground(void)
600 AppLogDebug("Enter");
601 //If Contact app control was launched
602 //as we do not know if it success or failed.
603 if(__isContactAppControlLaunched == true)
605 CallApp* pPhoneApp = (static_cast<CallApp*>(UiApp::GetInstance()));
606 pPhoneApp->Terminate();
608 __isContactAppControlLaunched = false;
610 if (__isMsgAppControlLaunched == true)
612 //Message AppControl request completed.
613 CallApp* pPhoneApp = (static_cast<CallApp*>(UiApp::GetInstance()));
614 pPhoneApp->Terminate();
615 __isMsgAppControlLaunched = false;
621 EndCallForm::OnBackground(void)
623 AppLogDebug("Enter");
627 EndCallForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
629 AppLogDebug("Enter");
630 if (__pCallButtonsPanel != null)
632 //update position of call buttons panel
633 Label* pKeysBgLbl = static_cast<Label*>(GetControl(IDC_KEY_BG_LABEL, true));
634 __pCallButtonsPanel->SetBounds(pKeysBgLbl->GetBounds());
635 //bring button on top
636 __pCallButtonsPanel->SetButtonPosition();
637 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetPortraitLayoutN());
638 if (pRelativeLayout != null)
640 //pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_TOP_TO_TOP);
642 pRelativeLayout = dynamic_cast<RelativeLayout*>(GetLandscapeLayoutN());
643 if (pRelativeLayout != null)
645 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *pKeysBgLbl, RECT_EDGE_RELATION_LEFT_TO_LEFT);
646 pRelativeLayout->SetRelation(*__pCallButtonsPanel, *this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);