Tizen 2.1 base
[apps/native/sample/FaceTracker.git] / project / src / FaceTracker.cpp
1 //
2 // Tizen C++ SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (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
8 //
9 //     http://www.tizenopensource.org/license
10 //
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.
16 //
17
18 #include "FaceTracker.h"
19 #include "FaceTrackerFrame.h"
20 #include "FaceTrackerForm.h"
21
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;
27
28 FaceTrackerApp::FaceTrackerApp(void)
29 {
30 }
31
32 FaceTrackerApp::~FaceTrackerApp(void)
33 {
34         DeviceManager::RemoveDeviceEventListener(Charger,*this);
35 }
36
37 UiApp*
38 FaceTrackerApp::CreateInstance(void)
39 {
40         return new (std::nothrow) FaceTrackerApp();
41 }
42
43 bool
44 FaceTrackerApp::OnAppInitializing(AppRegistry& appRegistry)
45 {
46         return true;
47 }
48
49 bool
50 FaceTrackerApp::OnAppInitialized(void)
51 {
52         DeviceManager::AddDeviceEventListener(Charger,*this);
53
54         FaceTrackerFrame* pFaceTrackerFrame = new (std::nothrow) FaceTrackerFrame();
55         TryReturn(pFaceTrackerFrame != null, false, "Failed to create FaceTrackerFrame");
56         result r = pFaceTrackerFrame->Construct();
57         TryReturn(r == E_SUCCESS, false, "Failed to construct FaceTrackerFrame");
58         pFaceTrackerFrame->SetName(L"FaceTracker");
59         AddFrame(*pFaceTrackerFrame);
60
61         return true;
62 }
63
64 bool
65 FaceTrackerApp::OnAppWillTerminate(void)
66 {
67         return true;
68 }
69
70
71 bool
72 FaceTrackerApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
73 {
74         return true;
75 }
76
77 void
78 FaceTrackerApp::OnForeground(void)
79 {
80         FaceTrackerForm *pFaceTrackerForm = (FaceTrackerForm *)(GetFrame(L"FaceTracker")->GetCurrentForm());
81         pFaceTrackerForm->StartCamera();        
82 }
83
84 void
85 FaceTrackerApp::OnBackground(void)
86 {
87         FaceTrackerForm *pFaceTrackerForm = (FaceTrackerForm *)(GetFrame(L"FaceTracker")->GetCurrentForm());
88         pFaceTrackerForm->StopCamera();
89 }
90
91 void
92 FaceTrackerApp::OnLowMemory(void)
93 {
94 }
95
96 void
97 FaceTrackerApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
98 {
99         bool isCharging = false;
100
101         Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"),isCharging);
102
103         if (isCharging)
104         {
105                 return;
106         }
107
108         if ((batteryLevel == BATTERY_LEVEL_LOW) || (batteryLevel == BATTERY_LEVEL_CRITICAL) || (batteryLevel == BATTERY_LEVEL_EMPTY))
109         {
110                 MessageBox msgBox;
111                 int modalResult = 0;
112                 result r = msgBox.Construct("Warning","Battery is low. Terminating App.",MSGBOX_STYLE_NONE,4000);
113                 TryReturn(r == E_SUCCESS, , "Failed to construct MessageBox");
114                 msgBox.ShowAndWait(modalResult);
115
116                 Application::GetInstance()->Terminate();
117         }
118 }
119
120 void
121 FaceTrackerApp::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
122 {
123         BatteryLevel level = BATTERY_FULL;
124
125         if (deviceType == Charger)
126         {
127                 Tizen::System::Battery::GetCurrentLevel(level);
128                 OnBatteryLevelChanged(level);
129         }
130 }
131
132 void
133 FaceTrackerApp::OnScreenOn(void)
134 {
135 }
136
137 void
138 FaceTrackerApp::OnScreenOff(void)
139 {
140 }