3 // Open Service Platform
4 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 // All rights reserved.
7 // This software contains confidential and proprietary information
8 // of Samsung Electronics Co., Ltd.
9 // The user of this software agrees not to disclose, disseminate or copy such
10 // Confidential Information and shall use the software only in accordance with
11 // the terms of the license agreement the user entered into with Samsung.
14 #include "QrCodeRecognizerSample.h"
15 #include "CameraTools.h"
18 using namespace Tizen::App;
19 using namespace Tizen::Ui::Controls;
20 using namespace Tizen::System;
22 QrCodeRecognizer::QrCodeRecognizer()
25 , __pControlManager(0)
30 QrCodeRecognizer::~QrCodeRecognizer()
36 QrCodeRecognizer::CreateInstance(void)
38 // Create the instance through the constructor.
39 return new QrCodeRecognizer();
44 QrCodeRecognizer::OnAppInitializing(AppRegistry& appRegistry)
46 PowerManager::SetScreenEventListener(*this);
47 PowerManager::KeepScreenOnState(true, false);
52 QrCodeRecognizer::OnAppInitialized(void)
54 Frame* pAppFrame = new Frame();
55 pAppFrame->Construct();
58 //pAppFrame->SetOrientation(Tizen::Ui::ORIENTATION_PORTRAIT);
60 // Creates an instance of Popup
61 __pPopup = new Tizen::Ui::Controls::Popup();
62 __pPopup->Construct(true, Tizen::Graphics::Dimension(570, 250));
64 __pForm = new TouchForm();
65 __pForm->Initialize(this, this);
66 pAppFrame->AddControl(*__pForm);
67 GLtools::initGL(__pForm);
68 __pForm->SendUserEvent(TouchForm::REQUEST_ACTIVATE, null);
70 __pTracker = new Tracker();
72 if(CameraTools::StartCamera(*__pTracker, Tracker::DESIRED_CAMERA_WIDTH, Tracker::DESIRED_CAMERA_HEIGHT))
74 __pTracker->Init(__pForm);
77 __pPopup->SetTitleText(L"Exit application?");
79 // Creates an instance of Button to close the popup.
80 Button* pYesButton = new Button();
81 pYesButton->Construct(Tizen::Graphics::Rectangle(10, 50, 250, 80), L"Yes");
82 pYesButton->SetActionId(ID_BUTTON_YES);
83 pYesButton->AddActionEventListener(*this);
85 Button* pNoButton = new Button();
86 pNoButton->Construct(Tizen::Graphics::Rectangle(270, 50, 250, 80), L"No");
87 pNoButton->SetActionId(ID_BUTTON_NO);
88 pNoButton->AddActionEventListener(*this);
90 // Adds the button to the popup
91 __pPopup->AddControl(*pYesButton);
92 __pPopup->AddControl(*pNoButton);
98 QrCodeRecognizer::OnAppWillTerminate(void)
104 QrCodeRecognizer::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
106 CameraTools::StopCamera();
107 GLtools::destroyGL();
110 __pTracker->DoRendering(false);
118 QrCodeRecognizer::OnForeground(void)
120 PowerManager::KeepScreenOnState(true, false);
122 if(CameraTools::Restart() == false)
124 if(__pTracker != null)
132 msgBox.Construct("Warning","No Camera. Terminating App.", MSGBOX_STYLE_NONE, 3000);
133 msgBox.ShowAndWait(result);
137 case MSGBOX_RESULT_CLOSE:
138 Tizen::App::Application::GetInstance()->Terminate();
147 // Called when application is moved to background
149 QrCodeRecognizer::OnBackground(void)
151 CameraTools::Suspend();
155 QrCodeRecognizer::OnLowMemory(void)
160 QrCodeRecognizer::OnBatteryLevelChanged(BatteryLevel batteryLevel)
165 QrCodeRecognizer::OnScreenOn (void)
167 PowerManager::KeepScreenOnState(true, false);
168 CameraTools::Restart();
172 QrCodeRecognizer::OnScreenOff (void)
174 CameraTools::Suspend();
178 QrCodeRecognizer::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
182 case TouchForm::ID_BUTTON_EXECUTE:
186 ExecuteQr(__pTracker->GetTextMessage());
193 //Crushing application without this
200 __pTracker->Terminate();
204 Tizen::App::Application::GetInstance()->Terminate();
209 __pPopup->SetShowState(false);
217 QrCodeRecognizer::ExecuteQr(Tizen::Base::String text)
221 ControlManager* cMan = ControlManager::GetInstance();
223 if (text.StartsWith(L"http://", 0) ||
224 text.StartsWith("ftp://", 0) ||
225 text.StartsWith("ftps://", 0) ||
226 text.StartsWith("sftp://", 0) ||
227 text.StartsWith("https://", 0)
232 else if (text.StartsWith(L"sms:", 0))
234 Tizen::Base::String _number;
235 Tizen::Base::String _body;
237 int _numberStartIndex = 4; // message starting with "sms:" substring with length = 4
238 int _numberFinishIndex;
239 int _messageStartIndex;
240 text.IndexOf(L"?", _numberStartIndex, _numberFinishIndex);
241 text.SubString(_numberStartIndex, _numberFinishIndex - _numberStartIndex, _number);
242 text.IndexOf(L"body=", _numberStartIndex, _messageStartIndex);
243 text.SubString(_messageStartIndex + 5, _body);
245 cMan->ShowSms(_number, _body);
247 else if (text.StartsWith(L"BEGIN:VCARD", 0))
249 cMan->ShowContact(text);
253 cMan->ShowText(text);
259 QrCodeRecognizer::OnFormBackRequested(Tizen::Ui::Controls::Form &source)
261 __pPopup->SetShowState(true);