dealing with low battery
authorKyusung Cho <ks0128.cho@samsung.com>
Fri, 5 Apr 2013 08:59:12 +0000 (17:59 +0900)
committerKyusung Cho <ks0128.cho@samsung.com>
Fri, 5 Apr 2013 08:59:12 +0000 (17:59 +0900)
Change-Id: I411dd3f1d0c8f5e96abc431aeaebcd6459dfceb7
Signed-off-by: Kyusung Cho <ks0128.cho@samsung.com>
project/inc/QrCodeRecognizerSample.h
project/src/QrCodeRecognizerSample.cpp

index a76f965..0653d3f 100644 (file)
@@ -28,6 +28,7 @@ class QrCodeRecognizer
     , public Tizen::System::IScreenEventListener
     , public Tizen::Ui::IActionEventListener
     , public Tizen::Ui::Controls::IFormBackEventListener
+    , public Tizen::System::IDeviceEventListener
 {
 public:
     static Tizen::App::Application* CreateInstance(void);
@@ -71,6 +72,9 @@ public:
 
     void OnFormBackRequested(Tizen::Ui::Controls::Form &source);
 
+       // Called when device is connected or removed
+       virtual void OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state);
+
 private:
     Tracker*   __pTracker;
     TouchForm* __pForm;
index a557ea6..71ad4a7 100644 (file)
@@ -16,6 +16,7 @@
 #include "GLtools.h"
 
 using namespace Tizen::App;
+using namespace Tizen::Base;
 using namespace Tizen::Ui::Controls;
 using namespace Tizen::System;
 
@@ -28,6 +29,7 @@ QrCodeRecognizer::QrCodeRecognizer()
 
 QrCodeRecognizer::~QrCodeRecognizer()
 {
+       DeviceManager::RemoveDeviceEventListener(Charger,*this);
 }
 
 
@@ -64,6 +66,35 @@ QrCodeRecognizer::OnAppInitialized(void)
     __pForm->Initialize(this, this);
     pAppFrame->AddControl(*__pForm);
 
+    // dealing with low battery
+    DeviceManager::AddDeviceEventListener(Charger,*this);
+    bool isCharging = true;
+       Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"),isCharging);
+       if (isCharging == false)
+       {
+               BatteryLevel level = BATTERY_FULL;
+               Tizen::System::Battery::GetCurrentLevel(level);
+               if ((level == BATTERY_EMPTY) || (level == BATTERY_CRITICAL) || (level == BATTERY_LOW))
+               {
+                       MessageBox msgBox;
+                       int result = 0;
+
+                       msgBox.Construct("Warning", "Low battery. Terminating App.", MSGBOX_STYLE_NONE, 3000);
+                       msgBox.ShowAndWait(result);
+
+                       switch (result)
+                       {
+                               case MSGBOX_RESULT_CLOSE:
+                                       Tizen::App::Application::GetInstance()->Terminate();
+                                       return false;
+                                       break;
+
+                               default:
+                                       break;
+                       }
+               }
+       }
+
     if (!GLtools::initGL(__pForm))
     {
        MessageBox msgBox;
@@ -171,6 +202,25 @@ QrCodeRecognizer::OnLowMemory(void)
 void
 QrCodeRecognizer::OnBatteryLevelChanged(BatteryLevel batteryLevel)
 {
+       bool isCharging = true;
+       Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"),isCharging);
+       if (isCharging == false)
+       {
+               if ((batteryLevel == BATTERY_EMPTY) || (batteryLevel == BATTERY_CRITICAL) || (batteryLevel == BATTERY_LOW))
+               {
+                       MessageBox msgBox;
+                       int result = 0;
+
+                       msgBox.Construct("Warning","Low Battery.\nPlease charge to use.",MSGBOX_STYLE_OK);
+                       msgBox.ShowAndWait(result);
+
+                       if(result == MSGBOX_RESULT_OK)
+                       {
+                               Application::GetInstance()->Terminate();
+                               return;
+                       }
+               }
+       }
 }
 
 void
@@ -222,3 +272,14 @@ QrCodeRecognizer::OnFormBackRequested(Tizen::Ui::Controls::Form &source)
     __pPopup->SetShowState(true);
     __pPopup->Show();
 }
+
+void
+QrCodeRecognizer::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
+{
+    if (deviceType == Charger)
+    {
+       BatteryLevel level = BATTERY_FULL;
+       Tizen::System::Battery::GetCurrentLevel(level);
+       OnBatteryLevelChanged(level);
+    }
+}