26
26
#pragma once
27
27
28
28
#include < memory>
29
+ #include < mutex>
29
30
30
31
#include < android_native_app_glue.h>
32
+ #include < FlagEnum.h>
31
33
#include " AppBase.hpp"
32
34
33
35
#include " NDKHelper.h"
@@ -38,62 +40,92 @@ namespace Diligent
38
40
{
39
41
40
42
// / Base class for Android applications.
41
- class AndroidAppBase : public AppBase
42
- {
43
- public:
44
- int InitDisplay ();
45
- void SetState (android_app* state, const char * native_activity_class_name);
46
- void InitSensors ();
47
- void ProcessSensors (int32_t id);
48
- virtual void DrawFrame ();
49
- bool IsReady ();
50
- virtual void TrimMemory () = 0;
51
- virtual void TermDisplay () = 0;
52
- static int32_t HandleInput (android_app* app, AInputEvent* event);
53
- static void HandleCmd (android_app* app, int32_t cmd);
54
-
55
- protected:
56
- virtual void Initialize ()
57
- {
58
- }
59
-
60
- virtual int Resume (ANativeWindow* window) = 0;
61
-
62
- virtual int32_t HandleInput (AInputEvent* event) { return 0 ; }
63
-
64
- virtual void LoadResources ()
65
- {
66
- // renderer_.Init();
67
- // renderer_.Bind( &tap_camera_ );
68
- }
69
-
70
- virtual void UnloadResources ()
71
- {
72
- // renderer_.Unload();
73
- }
74
-
75
- ndk_helper::DoubletapDetector doubletap_detector_;
76
- ndk_helper::PinchDetector pinch_detector_;
77
- ndk_helper::DragDetector drag_detector_;
78
- ndk_helper::PerfMonitor monitor_;
79
-
80
- // ndk_helper::TapCamera tap_camera_;
81
- android_app* app_ = nullptr ;
82
- std::string native_activity_class_name_;
83
-
84
- private:
85
- void UpdatePosition (AInputEvent* event, int32_t iIndex, float & fX , float & fY );
86
- void SuspendSensors ();
87
- void ResumeSensors ();
88
- void ShowUI ();
89
- void UpdateFPS (float fFPS );
90
-
91
- bool initialized_resources_ = false ;
92
- bool has_focus_ = false ;
93
-
94
- ASensorManager* sensor_manager_ = nullptr ;
95
- const ASensor* accelerometer_sensor_ = nullptr ;
96
- ASensorEventQueue* sensor_event_queue_ = nullptr ;
97
- };
43
+ class AndroidAppBase : public AppBase {
44
+ public:
45
+ int InitDisplay ();
46
+
47
+ void SetState (android_app *state, const char *native_activity_class_name);
48
+
49
+ void InitSensors ();
50
+
51
+ void ProcessSensors (int32_t id);
52
+
53
+ virtual void DrawFrame ();
54
+
55
+ bool IsReady ();
56
+
57
+ virtual void TrimMemory () = 0;
58
+
59
+ virtual void TermDisplay () = 0;
60
+
61
+ static int32_t HandleInput (android_app *app, AInputEvent *event);
62
+
63
+ static void HandleCmd (android_app *app, int32_t cmd);
64
+
65
+ enum APP_STATUS_FLAGS {
66
+ APP_STATUS_FLAG_NONE = 0x00000000 ,
67
+ // Android lifecycle status flags. Not app-specific
68
+ // Set between onCreate and onDestroy
69
+ APP_STATUS_FLAG_RUNNING = 0x00000001 ,
70
+ // Set between onResume and onPause
71
+ APP_STATUS_FLAG_ACTIVE = 0x00000002 ,
72
+ // Set between onWindowFocusChanged(true) and (false)
73
+ APP_STATUS_FLAG_FOCUSED = 0x00000004 ,
74
+ // Set when the app's SurfaceHolder points to a
75
+ // valid, nonzero-sized surface
76
+ APP_STATUS_FLAG_HAS_REAL_SURFACE = 0x00000008 ,
77
+ };
78
+
79
+ APP_STATUS_FLAGS app_status_ = APP_STATUS_FLAG_NONE;
80
+ protected:
81
+ virtual void Initialize () {
82
+ }
83
+
84
+ virtual int Resume (ANativeWindow *window) = 0;
85
+
86
+ virtual int32_t HandleInput (AInputEvent *event) { return 0 ; }
87
+
88
+ virtual void LoadResources () {
89
+ // renderer_.Init();
90
+ // renderer_.Bind( &tap_camera_ );
91
+ }
92
+
93
+ virtual void UnloadResources () {
94
+ // renderer_.Unload();
95
+ }
96
+
97
+ ndk_helper::DoubletapDetector doubletap_detector_;
98
+ ndk_helper::PinchDetector pinch_detector_;
99
+ ndk_helper::DragDetector drag_detector_;
100
+ ndk_helper::PerfMonitor monitor_;
101
+
102
+ // ndk_helper::TapCamera tap_camera_;
103
+ android_app *app_ = nullptr ;
104
+ std::string native_activity_class_name_;
105
+
106
+ std::mutex mutex;
107
+
108
+ private:
109
+ void UpdatePosition (AInputEvent *event, int32_t iIndex, float &fX , float &fY );
110
+
111
+ void SuspendSensors ();
112
+
113
+ void ResumeSensors ();
114
+
115
+ void ShowUI ();
116
+
117
+ void UpdateFPS (float fFPS );
118
+
119
+ bool initialized_resources_ = false ;
120
+
121
+ int32_t window_width_ = 0 ;
122
+ int32_t window_height_ = 0 ;
123
+
124
+ ASensorManager* sensor_manager_ = nullptr ;
125
+ const ASensor* accelerometer_sensor_ = nullptr ;
126
+ ASensorEventQueue* sensor_event_queue_ = nullptr ;
127
+ };
128
+
129
+ DEFINE_FLAG_ENUM_OPERATORS (AndroidAppBase::APP_STATUS_FLAGS)
98
130
99
131
} // namespace Diligent
0 commit comments