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 PhnEmergencyDialForm.cpp
19 * @brief Base class for all Call forms
22 #include "PhnAppUtility.h"
23 #include "PhnCommonUtils.h"
24 #include "PhnCallPresentationModel.h"
25 #include "PhnDialerKeypad.h"
26 #include "PhnErrorMsgPopup.h"
27 #include "PhnEmergencyDialForm.h"
28 #include "PhnPhoneApp.h"
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::App;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
37 using namespace Tizen::Graphics;
40 const wchar_t* IDL_EMERGENCY_DIAL_FORM = L"IDL_EMERGENCY_DIAL_FORM";
41 const wchar_t* IDC_LABEL_EMERGENCY = L"IDC_LABEL_EMERGENCY";
42 const wchar_t* IDC_PANEL_EMERGENCY_DISPLAY_DATA = L"IDC_PANEL_EMERGENCY_DISPLAY_DATA";
43 const wchar_t* IDC_EDITFIELD_NUMBER = L"IDC_EDITFIELD_NUMBER";
45 const unsigned int COLOR_LABEL_BG = Color32<43, 107, 144>::Value;
46 const int MAX_NUMBER_WITH_SEPERATOR = 11;
47 const int MIN_NUMBER_WITH_TWO_SEPERATOR = 7;
48 const int MIN_NUMBER_WITH_ONE_SEPERATOR = 3;
49 const int MAX_TXT_LENGTH_WITH_SEPERATOR = 12;
50 const int MAX_VISIBLE_TXT_WITH_MIN_FONT = 18;
51 const int IDI_DELTA_FONT_SIZE = 5;
52 const int IDI_MAX_TXT_FONT = 94;
53 const int IDI_MIN_TXT_FONT = 67;
54 const int IDI_MAX_LIMIT_LENGTH = 18;
56 EmergencyDialForm::EmergencyDialForm(void)
59 __pErrorMsgPopup = null;
62 EmergencyDialForm::~EmergencyDialForm(void)
64 if(__pDialKeypad != null)
66 //RemoveControl() also deletes the child control.
67 RemoveControl(*__pDialKeypad);
73 EmergencyDialForm::Initialize(void)
75 Construct(IDL_EMERGENCY_DIAL_FORM);
80 EmergencyDialForm::OnInitializing(void)
88 EmergencyDialForm::ConstructKeypad(void)
91 //Construct Alpha numeric Keypad
92 if(__pDialKeypad == null)
94 __pDialKeypad = new (std::nothrow) DialerKeypad(DialerKeypad::DIALER_STATE_EMERGENCY_APPCONTROL);
95 __pDialKeypad->ConstructPanel(this, this);
96 AddControl(*__pDialKeypad);
103 EmergencyDialForm::ShowFormattedText(EditField* pEditField, int actionId)
105 AppLogDebug("ENTER");
106 String contactNumber = pEditField->GetText();
107 contactNumber.Replace(L"-",L"");
108 if(actionId == CLEAR_KEY)
110 contactNumber.Remove(contactNumber.GetLength() - 1, 1);
114 contactNumber.Append(DialUtil::ConvertDialedNumberToString(actionId));
117 int textLength = contactNumber.GetLength();
124 //Insert separator if required
125 if(textLength < MAX_NUMBER_WITH_SEPERATOR)
127 if(textLength > MIN_NUMBER_WITH_TWO_SEPERATOR)
129 contactNumber.Insert(L"-",MIN_NUMBER_WITH_TWO_SEPERATOR);
131 if(textLength > MIN_NUMBER_WITH_ONE_SEPERATOR)
133 contactNumber.Insert(L"-",MIN_NUMBER_WITH_ONE_SEPERATOR);
137 textLength = contactNumber.GetLength();
138 //need to change font to fit inside text box
139 //With size 94 -> 12 chars, 67 -> 18 chars
140 int fontSize = pEditField->GetTextSize();
141 if((actionId == CLEAR_KEY) && (textLength <= MAX_VISIBLE_TXT_WITH_MIN_FONT))
144 fontSize += IDI_DELTA_FONT_SIZE;
146 else if(textLength > MAX_TXT_LENGTH_WITH_SEPERATOR)
149 fontSize -= IDI_DELTA_FONT_SIZE;
152 if(fontSize > IDI_MAX_TXT_FONT)
154 fontSize = IDI_MAX_TXT_FONT;
156 if(fontSize < IDI_MIN_TXT_FONT)
158 fontSize = IDI_MIN_TXT_FONT;
160 pEditField->SetTextSize(fontSize);
161 //set text to edit field
162 pEditField->SetText(contactNumber);
169 EmergencyDialForm::OnActionPerformed(const Control& source, int actionId)
171 EditField* pEditField = static_cast<EditField*>(GetControl(IDC_EDITFIELD_NUMBER, true));
172 if (pEditField == null)
191 if(pEditField->GetTextLength() >= IDI_MAX_LIMIT_LENGTH && actionId != CLEAR_KEY)
193 //Maximum capacity reached, Don't append any more numbers.
197 //append / clear last character to contact
198 ShowFormattedText(pEditField, actionId);
204 if (pEditField->GetTextLength() > 0)
206 String contactNo = pEditField->GetText();
207 contactNo.Replace(L"-",L"");
208 SwitchToOutgoingCallScreen(contactNo);
216 pEditField->AppendText(L"*");
222 pEditField->AppendText(L"#");
234 PhoneApp* pApp = static_cast<PhoneApp*>(UiApp::GetInstance());
242 pEditField->Invalidate(false);
248 EmergencyDialForm::OnLongPressGestureDetected(TouchLongPressGestureDetector& gestureDetector)
250 if (gestureDetector.GetControl() != null)
252 Button* pButton = static_cast<Button*>(gestureDetector.GetControl());
253 int actionId = pButton->GetActionId();
258 EditField* pEditField = static_cast<EditField*>(GetControl(IDC_EDITFIELD_NUMBER, true));
259 if (pEditField != null && pEditField->GetTextLength() > 0)
262 pEditField->SetTextSize(IDI_MAX_TXT_FONT);
263 pEditField->Invalidate(false);
272 EmergencyDialForm::OnTerminating(void)
274 result r = E_SUCCESS;
279 EmergencyDialForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
284 EmergencyDialForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
289 EmergencyDialForm::SwitchToOutgoingCallScreen(const String& contactNumber)
291 AppLogDebug("ENTER");
292 SceneManager* pSceneManager = SceneManager::GetInstance();
293 AppAssert(pSceneManager);
295 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
296 //Check if dialing a call is possible
297 bool isSimInitialized = pCallPresentor->CheckSimInitializationIsCompleted();
298 if (isSimInitialized)
300 //make an outgoing call with given number
301 String* contactTxt = new (std::nothrow) String(contactNumber);
302 //switch to dialing outgoing call form
303 ArrayList* pContact = new (std::nothrow) ArrayList(SingleObjectDeleter);
304 pContact->Construct(1);
305 pContact->Add(contactTxt);
306 //Check if dialing an emergency call
307 bool isEmergencyCall = pCallPresentor->IsEmergencyNumber(*contactTxt, true);
310 pSceneManager->GoForward( ForwardSceneTransition( IDSCN_SCENE_OUT_EMERGENCYCALL), pContact);
314 //Show error message Popup
315 if (__pErrorMsgPopup == null)
317 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
319 __pErrorMsgPopup->ShowErrorMsgPopupN(ERROR_NOT_EMERGENCY_NUM);
324 //TODO: check what to do for SOS calls
325 //Show error message Popup
326 if (__pErrorMsgPopup == null)
328 __pErrorMsgPopup = new (std::nothrow) ErrorMsgPopup(this);
330 __pErrorMsgPopup->ShowErrorMsgPopupN(ERROR_CODE_SIM_INITIALIZATION_FAILED);
337 EmergencyDialForm::HandlePopupClosed(void)
339 EditField* pEditField = static_cast<EditField*>(GetControl(IDC_EDITFIELD_NUMBER, true));
343 delete __pErrorMsgPopup;
344 __pErrorMsgPopup = null;