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 PhnEndCallForm.cpp
19 * @brief End Call form implementation
24 #include "PhnPhoneApp.h"
25 #include "PhnAppUtility.h"
26 #include "PhnEndCallForm.h"
27 #include "PhnCallButtonsPanel.h"
28 #include "PhnCallPresentationModel.h"
29 #include "PhnSceneRegister.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;
42 const int IDI_APP_END_TIMER = 3000;
43 const int W_PHOTO_LABEL = 720;
44 const int H_PHOTO_LABEL = 720;
45 const int X_PHOTO_LBL = 166;
46 const int Y_PHOTO_LBL = 232;
47 const int W_PHOTO_LBL = 388;
48 const int H_PHOTO_LBL = 388;
49 static const wchar_t* IDL_END_CALL_FORM = L"IDL_END_CALL_FORM";
50 static const wchar_t* IDC_ADD_TO_CONTACT_BUTTON = L"IDC_ADD_TO_CONTACT_BUTTON";
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_CALLER1_BIGPHOTO_LABEL = L"IDC_CALLER1_BIGPHOTO_LABEL";
54 static const wchar_t* IDB_END_CALL_DEFAULT_ICON = L"C01-1_end call_default_caller ID_720x720.png";
56 EndCallForm::EndCallForm(void)
57 : BaseForm(FORMTYPE_ENDCALL)
59 __pCallButtonsPanel = null;
60 __pContactNumber = null;
61 __pEndCallEventTimer = null;
62 __pSmallPhotoLabel = null;
63 __isMsgAppControlLaunched = false;
64 __isContactAppControlLaunched = false;
67 EndCallForm::~EndCallForm(void)
69 if (__pEndCallEventTimer != null)
71 __pEndCallEventTimer->Cancel();
72 delete __pEndCallEventTimer;
73 __pEndCallEventTimer = null;
75 if (__pSmallPhotoLabel != null)
77 RemoveControl(*__pSmallPhotoLabel);
78 __pSmallPhotoLabel = null;
83 EndCallForm::Initialize(void)
85 Construct(IDL_END_CALL_FORM);
86 //initialize keypad and buttons
87 InitializeCallButtonsPanel();
88 //set initial show state to false. Correct state set on OnSceneActivatedN
89 SetContactButtonState(false);
93 EndCallForm::OnInitializing(void)
97 AddKeyPadActionListener(IDC_ADD_TO_CONTACT_BUTTON, IDA_ADD_TO_CONTACTS);
99 __pEndCallEventTimer = new (std::nothrow) Tizen::Base::Runtime::Timer();
100 r = __pEndCallEventTimer->Construct(*this);
102 __pCallPresentor = CallPresentationModel::GetInstance();
107 EndCallForm::InitializeCallButtonsPanel(void)
109 __pCallButtonsPanel = new (std::nothrow) CallButtonsPanel();
110 __pCallButtonsPanel->ConstructPanel(this, FORMTYPE_ENDCALL);
111 AddControl(*__pCallButtonsPanel);
115 EndCallForm::AddKeyPadActionListener(const String& keyName, CommandIds cmdId)
117 Button* pButton = static_cast<Button*>(GetControl(keyName));
120 pButton->SetActionId(cmdId);
121 pButton->AddActionEventListener(*this);
126 EndCallForm::OnTerminating(void)
128 result r = E_SUCCESS;
130 if (__pCallPresentor)
132 __pCallPresentor = null;
138 EndCallForm::OnActionPerformed(const Control& source, int actionId)
140 SceneManager* pSceneManager = SceneManager::GetInstance();
141 AppAssert(pSceneManager);
147 //check if EndCallTimer is running, then cancel it
148 if(__pEndCallEventTimer != null)
150 __pEndCallEventTimer->Cancel();
152 //make an outgoing call with given number
153 String* contactTxt = new (std::nothrow) String(*__pContactNumber);
154 //switch to dialing outgoing call form
155 ArrayList* pContact = new (std::nothrow) ArrayList(SingleObjectDeleter);
156 pContact->Construct();
157 pContact->Add(contactTxt);
159 //Check if dialing a call is possible
160 bool isSimInitialized = __pCallPresentor->CheckSimInitializationIsCompleted();
161 if (isSimInitialized)
163 //Check if dialing an emergency call
164 bool isEmergencyCall = __pCallPresentor->IsEmergencyNumber(*contactTxt, true);
167 pSceneManager->GoForward( ForwardSceneTransition( IDSCN_SCENE_OUT_EMERGENCYCALL), pContact);
171 pSceneManager->GoForward( ForwardSceneTransition(IDSCN_SCENE_OUTCALL), pContact);
176 //Show error message Popup
177 HandleTelephonyError(ERROR_CODE_SIM_INITIALIZATION_FAILED);
188 if (__isMsgAppControlLaunched == true)
190 //AppControl already launched.
193 //launch message AppControl
194 __isMsgAppControlLaunched = true;
195 result r = E_SUCCESS;
197 extraData.Construct();
199 extraData.Add(new (std::nothrow) String(MESSAGE_TYPE), new (std::nothrow) String(MESSAGE_SMS_TYPE));
200 extraData.Add(new (std::nothrow) String(MESSAGE_TO), new (std::nothrow) String(*__pContactNumber));
202 AppControl* pAc = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE);
205 r = pAc->Start(null, null, &extraData, this);
208 //AppControl request failed, reset flag.
209 __isMsgAppControlLaunched = false;
211 else if (r == E_SUCCESS && __pEndCallEventTimer != null)
213 //cancel EndCallTimer, if AppControl request was successful.
214 __pEndCallEventTimer->Cancel();
219 extraData.RemoveAll(true);
223 case IDA_ADD_TO_CONTACTS:
225 if(__isContactAppControlLaunched == true)
227 //AppControl already launched.
230 //Launch Contact AppControl
231 __isContactAppControlLaunched = true;
232 result r = E_SUCCESS;
234 extraData.Construct();
236 extraData.Add(new (std::nothrow) String(INPUT_TYPE_PHONE), new (std::nothrow) String(*__pContactNumber));
237 AppControl* pAc = AppManager::FindAppControlN(PROVIDER_ID_CONTACTS, OPERATION_ID_ADD);
240 r = pAc->Start(null, null, &extraData, this);
243 //AppControl request failed, reset flag.
244 __isContactAppControlLaunched = false;
246 else if (r == E_SUCCESS && __pEndCallEventTimer != null)
248 //cancel EndCallTimer, if AppControl request was success.
249 __pEndCallEventTimer->Cancel();
251 //NOTE:- goto next scene if present and is either Call log or Dialer,
252 // Else forcefully goto Dialer scene.
253 //Because we do not get any Appcontrol Completed response from Contacts in this case.
254 SceneId nextScene = (static_cast<PhoneApp*>(UiApp::GetInstance()))->GetInitialScene();
255 if(nextScene != IDSCN_CALL_LOG)
257 nextScene = IDSCN_DIALER;
259 pSceneManager->GoForward( ForwardSceneTransition(nextScene,
260 SCENE_TRANSITION_ANIMATION_TYPE_NONE,
261 SCENE_HISTORY_OPTION_NO_HISTORY));
265 extraData.RemoveAll(true);
275 EndCallForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
277 //set itself as listener
278 __pCallPresentor->SetTelEventListener(this);
279 //listen to Foreground events
280 PhoneApp* pPhoneApp = static_cast<PhoneApp*>(PhoneApp::GetInstance());
281 pPhoneApp->AddAppStateChangeListener(*this);
282 __isMsgAppControlLaunched = false;
283 __isContactAppControlLaunched = false;
287 case FORMTYPE_ENDCALL:
289 //fetch ended call details
290 CallInfo* pEndCall = static_cast<CallInfo*>(pArgs->GetAt(0));
293 __pContactNumber = new (std::nothrow) String();
294 __pContactNumber->Append(pEndCall->GetContactNumber());
296 //Fetch & show contact person details
297 ShowPersonDetails(*__pContactNumber, IDC_CALLER1_LABEL, IDC_CALLER1_BIGPHOTO_LABEL,pEndCall);
298 //If call is hidden means no contact number is present,
299 //or if call is from known number, Then do NOT show "Add to Contact" button.
300 if (pEndCall->IsNumberPresent() == true || pEndCall->GetContactNumber().IsEmpty() == true)
302 SetContactButtonState(false);
306 SetContactButtonState(true);
309 //Check if call is Emergency call or Hidden call,
310 //then disable all button in Call button panel.
311 if (pEndCall->IsEmergency() == true || pEndCall->GetContactNumber().IsEmpty() == true)
313 __pCallButtonsPanel->SetEndCallPanelState(false);
317 __pCallButtonsPanel->SetEndCallPanelState(true);
326 if (__pEndCallEventTimer)
328 __pEndCallEventTimer->Start(IDI_APP_END_TIMER);
340 EndCallForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
342 if (__pContactNumber)
344 delete __pContactNumber;
345 __pContactNumber = null;
347 if (__pSmallPhotoLabel != null)
349 __pSmallPhotoLabel->SetShowState(false);
351 //remove itself as listener
352 PhoneApp* pPhoneApp = static_cast<PhoneApp*>(PhoneApp::GetInstance());
353 pPhoneApp->RemoveAppStateChangeListener(*this);
357 EndCallForm::OnDraw(void)
363 EndCallForm::SetContactButtonState(bool showState)
365 Button* pButton = static_cast<Button*>(GetControl(IDC_ADD_TO_CONTACT_BUTTON));
368 pButton->SetShowState(showState);
373 EndCallForm::ShowPhoneNumber(const String& phoneNumber, const String& lblName)
375 String formattedNumber = phoneNumber;
376 Label* pContactLbl = static_cast<Label*>(GetControl(lblName));
377 pContactLbl->SetText(formattedNumber);
381 EndCallForm::ShowPersonDetails(const String& phoneNumber, const String& nameLblName, const String& photoLblName, CallInfo* pCallInfo)
384 ShowPhoneNumber(phoneNumber, IDC_NUMBER1_LABEL);
386 Label* pNameLbl = static_cast<Label*>(GetControl(nameLblName));
387 Label* pPhotoLbl = static_cast<Label*>(GetControl(photoLblName));
389 //fetch contact details based on phone number
390 String* pDisplayName = pCallInfo->FetchCallerNameN();
391 Bitmap* pPhotoBitmap = pCallInfo->FetchCallerPhotoN();
393 //passing an empty string to SetText fails in label,
394 //if previously valid text has been set
395 if (pDisplayName != null && pDisplayName->IsEmpty() == true && pNameLbl->GetText().IsEmpty() == false)
397 pDisplayName->Append(L" ");
400 // show display name on name Label
401 if (pDisplayName != null)
403 pNameLbl->SetText(*pDisplayName);
406 // If record not found or no photo id present for user,
407 //fetch default bitmap.
408 if (pPhotoBitmap != null)
410 // show Thumbnail bitmap on photo Label
411 pPhotoLbl->SetBackgroundBitmap(*pPhotoBitmap);
412 pPhotoLbl->Invalidate(true);
418 Bitmap* pDefaultPhoto = AppUtility::GetBitmapFromResourcesN(IDB_END_CALL_DEFAULT_ICON,W_PHOTO_LABEL,H_PHOTO_LABEL);
419 if (pDefaultPhoto != null)
421 pPhotoLbl->SetBackgroundBitmap(*pDefaultPhoto);
422 pPhotoLbl->Invalidate(true);
423 delete pDefaultPhoto;
436 EndCallForm::ShowCallersPhotoThumbnail(const Bitmap& pPhotoId)
438 if (__pSmallPhotoLabel != null)
440 RemoveControl(*__pSmallPhotoLabel);
441 __pSmallPhotoLabel = null;
443 //Draw Small Photo and show on small photo label
444 __pSmallPhotoLabel = new (std::nothrow) Label();//static_cast<Label*>(GetControl(IDC_SMALL_PHOTO_LABEL));
445 __pSmallPhotoLabel->Construct(Rectangle(X_PHOTO_LBL, Y_PHOTO_LBL, W_PHOTO_LBL, H_PHOTO_LBL), L"");
446 __pSmallPhotoLabel->SetBackgroundColor(Color(0,0,0));
447 __pSmallPhotoLabel->SetBackgroundBitmap(pPhotoId);
448 // Add a Label to the Form
449 AddControl(*__pSmallPhotoLabel);
450 __pSmallPhotoLabel->Invalidate(true);
454 EndCallForm::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
456 //goto initial scene or close application, since this was last active call.
457 HandleLastCallCompletion();
461 EndCallForm::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
463 if (__isMsgAppControlLaunched == true)
465 //Message AppControl request completed.
466 __isMsgAppControlLaunched = false;
468 //AppControl completed, goto initial scene if present
470 HandleLastCallCompletion();
474 EndCallForm::HandleLastCallCompletion(void)
476 //switch back to Dialer tab, based on starting state of call.
477 SceneManager* pSceneManager = SceneManager::GetInstance();
478 PhoneApp* pPhoneApp = (static_cast<PhoneApp*>(UiApp::GetInstance()));
479 SceneId nextSceneId = pPhoneApp->GetInitialScene();
480 if (pSceneManager->GetCurrentScene()->GetSceneId() == IDSCN_SCENE_ENDCALL)
482 if(nextSceneId == IDSCN_DIALER || nextSceneId == IDSCN_CALL_LOG)
484 pSceneManager->GoForward( ForwardSceneTransition(nextSceneId, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
485 SCENE_HISTORY_OPTION_NO_HISTORY));
489 pPhoneApp->Terminate();
495 EndCallForm::OnForeground(void)
497 AppLogDebug("Enter");
498 //If Contact app control was launched
499 //as we do not know if it success or failed.
500 __isContactAppControlLaunched = false;
504 EndCallForm::OnBackground(void)
506 AppLogDebug("Enter");