3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include "QrCodeRecognizerSample.h"
19 #include "CameraTools.h"
22 using namespace Tizen::App;
23 using namespace Tizen::Base;
24 using namespace Tizen::System;
25 using namespace Tizen::Ui;
26 using namespace Tizen::Ui::Controls;
28 const char* pTagApp = "QrCodeRecognizer";
30 QrCodeRecognizer::QrCodeRecognizer()
36 QrCodeRecognizer::~QrCodeRecognizer()
38 DeviceManager::RemoveDeviceEventListener(Charger,*this);
43 QrCodeRecognizer::CreateInstance(void)
45 // Create the instance through the constructor.
46 return new QrCodeRecognizer();
50 QrCodeRecognizer::OnAppInitializing(AppRegistry& appRegistry)
52 PowerManager::KeepScreenOnState(true, false);
57 QrCodeRecognizer::OnAppInitialized(void)
59 Frame* pAppFrame = new Frame();
60 pAppFrame->Construct();
63 __pForm = new TouchForm();
64 __pForm->Initialize(this, this);
65 pAppFrame->AddControl(__pForm);
67 // dealing with low battery
68 DeviceManager::AddDeviceEventListener(Charger,*this);
69 bool isCharging = true;
70 Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"),isCharging);
71 if (isCharging == false)
73 BatteryLevel level = BATTERY_FULL;
74 Tizen::System::Battery::GetCurrentLevel(level);
75 if ((level == BATTERY_EMPTY) || (level == BATTERY_CRITICAL) || (level == BATTERY_LOW))
80 msgBox.Construct("Warning", "Low battery. Terminating App.", MSGBOX_STYLE_NONE, 3000);
81 msgBox.ShowAndWait(result);
82 Tizen::App::Application::GetInstance()->Terminate();
87 if (!GLtools::initGL(__pForm))
92 msgBox.Construct("Warning", "Cannot init OpenGL. Terminating App.", MSGBOX_STYLE_NONE, 3000);
93 msgBox.ShowAndWait(result);
94 Tizen::App::Application::GetInstance()->Terminate();
98 __pTracker = new Tracker();
99 __pForm->SendUserEvent(TouchForm::REQUEST_ACTIVATE, null);
101 if (!CameraTools::InitCamera(*__pTracker, Tracker::DESIRED_CAMERA_WIDTH, Tracker::DESIRED_CAMERA_HEIGHT))
106 msgBox.Construct("Warning","Cannot init camera. Terminating App.", MSGBOX_STYLE_NONE, 3000);
107 msgBox.ShowAndWait(result);
108 Tizen::App::Application::GetInstance()->Terminate();
112 __pTracker->Init(__pForm);
118 QrCodeRecognizer::OnAppWillTerminate(void)
124 QrCodeRecognizer::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
128 __pTracker->DoRendering(false);
133 GLtools::destroyGL();
134 CameraTools::StopCamera();
140 QrCodeRecognizer::OnForeground(void)
142 AppSecureLogTag(pTagApp, "OnForeground");
143 PowerManager::KeepScreenOnState(true, false);
144 if (!CameraTools::StartCamera())
149 msgBox.Construct("Warning", "Cannot restart camera. Terminating App.", MSGBOX_STYLE_NONE, 3000);
150 msgBox.ShowAndWait(result);
151 Tizen::App::Application::GetInstance()->Terminate();
155 // Called when application is moved to background
157 QrCodeRecognizer::OnBackground(void)
159 CameraTools::StopCamera();
163 QrCodeRecognizer::OnLowMemory(void)
168 QrCodeRecognizer::OnBatteryLevelChanged(BatteryLevel batteryLevel)
170 bool isCharging = true;
171 Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"),isCharging);
172 if (isCharging == false)
174 if ((batteryLevel == BATTERY_EMPTY) || (batteryLevel == BATTERY_CRITICAL) || (batteryLevel == BATTERY_LOW))
179 msgBox.Construct("Warning","Low Battery.\nTerminating App.",MSGBOX_STYLE_NONE,8000);
180 msgBox.ShowAndWait(result);
181 Application::GetInstance()->Terminate();
187 QrCodeRecognizer::OnKeyPressed (Control &source, const KeyEventInfo &keyEventInfo)
193 QrCodeRecognizer::OnKeyReleased (Control &source, const KeyEventInfo &keyEventInfo)
199 QrCodeRecognizer::OnPreviewKeyPressed (Control &source, const KeyEventInfo &keyEventInfo)
205 QrCodeRecognizer::OnPreviewKeyReleased (Control &source, const KeyEventInfo &keyEventInfo)
211 QrCodeRecognizer::TranslateKeyEventInfo (Control &source, KeyEventInfo &keyEventInfo)
217 QrCodeRecognizer::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
223 QrCodeRecognizer::OnFormBackRequested(Tizen::Ui::Controls::Form &source)
225 if (__pTracker && (CameraTools::GetCamera()->GetState() == Tizen::Media::CAMERA_STATE_PREVIEW || CameraTools::GetCamera()->GetState() == Tizen::Media::CAMERA_STATE_AUTO_FOCUSING))
227 __pTracker->Terminate();
231 Tizen::App::Application::GetInstance()->Terminate();
236 QrCodeRecognizer::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
238 if (deviceType == Charger)
240 BatteryLevel level = BATTERY_FULL;
241 Tizen::System::Battery::GetCurrentLevel(level);
242 OnBatteryLevelChanged(level);