e7e755fc92ff10b59a2dd17ea4e05a3fdb38e0e1
[platform/core/uifw/dali-adaptor.git] / dali / integration-api / adaptor-framework / android / android-framework.h
1 #ifndef DALI_INTEGRATION_ANDROID_FRAMEWORK_H
2 #define DALI_INTEGRATION_ANDROID_FRAMEWORK_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 #include <jni.h>
25 #include <android/asset_manager.h>
26 #include <android/asset_manager_jni.h>
27 #include <android/configuration.h>
28 #include <android/native_window.h>
29 #include <android/native_window_jni.h>
30
31 #ifndef _ANDROID_NATIVE_APP_GLUE_H
32 extern "C"
33 {
34 struct android_app;
35 }
36 #endif
37
38 #include <dali/public-api/common/dali-common.h>
39 #include <dali/public-api/dali-adaptor-common.h>
40
41 namespace Dali
42 {
43
44 namespace Internal DALI_INTERNAL
45 {
46
47 namespace Adaptor
48 {
49 class AndroidFramework;
50 }
51
52 }
53
54 namespace Integration
55 {
56
57 /**
58  * AndroidFramework provides setter/getter for Android native interfaces for Android DALi Adaptor.
59  * It is also used to pass Android application events to Android DALi Adaptor.
60  */
61 class DALI_ADAPTOR_API AndroidFramework
62 {
63 public:
64   /**
65    * @brief Create a new Android framework instance. Can be only one per application.
66    *
67    * @return a reference to the framework
68    */
69   static AndroidFramework& New();
70
71   /**
72    * @brief Delete an Android framework instance.
73    */
74   static void Delete();
75
76   /**
77    * @brief Sets the Android native application glue struct
78    * @param[in] application A pointer to the application glue struct
79    */
80   void SetNativeApplication( android_app* application );
81
82   /**
83    * @brief Gets the Android native application glue struct
84    * @return the native application glue struct
85    */
86   android_app* GetNativeApplication() const;
87
88   /**
89    * @brief Sets the Android JVM
90    * @param[in] jvm A pointer to Android JVM
91    */
92   void SetJVM( JavaVM* jvm );
93
94   /**
95    * @brief Sets the JVM
96    * @return A pointer to JVM
97    */
98   JavaVM* GetJVM() const;
99
100   /**
101    *  Sets the Android application assets manager.
102    *  @param[in] assets A pointer to assets manager
103    */
104   void SetApplicationAssets( AAssetManager* assets );
105
106   /**
107    * @brief Gets the Android application assets manager.
108    * @return The application assets manager
109    */
110   AAssetManager* GetApplicationAssets() const;
111
112   /**
113    *  Sets the Android application internal data path.
114    *  @param[in] path A path to the application data path
115    */
116   void SetInternalDataPath( const std::string& path );
117
118   /**
119    *  Gets the Android application internal data path.
120    *  @return The application data path
121    */
122   std::string GetInternalDataPath() const;
123
124   /**
125    * @brief Sets the Android application configuration
126    * @param[in] configuration A pointer to Android application configuration
127    */
128   void SetApplicationConfiguration( AConfiguration* configuration );
129
130   /**
131    * @brief Gets the Android application configuration
132    * @return A Android application configuration
133    */
134   AConfiguration* GetApplicationConfiguration() const;
135
136   /**
137    * @brief Sets the Android application native window
138    * @return A native window
139    */
140   void SetApplicationWindow( ANativeWindow* window );
141
142   /**
143    * @brief Gets the Android application native window
144    * @param[in] window A native window
145    */
146   ANativeWindow* GetApplicationWindow() const;
147
148   /**
149    * Invoked when the Android application is to be terminated.
150    */
151   void OnTerminate();
152
153   /**
154    * Invoked when the Android application is to be paused.
155    */
156   void OnPause();
157
158   /**
159    * Invoked when the Android application is to be resumed.
160    */
161   void OnResume();
162
163   /**
164    * Invoked when the Android application native window is created.
165    */
166   void OnWindowCreated( ANativeWindow* window );
167
168   /**
169    * Invoked when the Android application native window is deleted.
170    */
171   void OnWindowDestroyed( ANativeWindow* window );
172
173   /**
174    * @brief Returns a reference to the instance of the Android framework used by the current thread.
175    *
176    * @return A reference to the framework.
177    * @note This is only valid in the main thread.
178    */
179   static AndroidFramework& Get();
180
181   /**
182    * @brief Virtual Destructor.
183    */
184   virtual ~AndroidFramework();
185
186   // Not copyable or movable
187   AndroidFramework( const AndroidFramework& ) = delete; ///< Deleted copy constructor
188   AndroidFramework( AndroidFramework&& ) = delete; ///< Deleted move constructor
189   AndroidFramework& operator=( const AndroidFramework& ) = delete; ///< Deleted copy assignment operator
190   AndroidFramework& operator=( AndroidFramework&& ) = delete; ///< Deleted move assignment operator
191
192 private:
193
194   /**
195    * @brief Create an uninitialized AndroidFramework.
196    */
197   AndroidFramework();
198
199   Internal::Adaptor::AndroidFramework* mImpl; ///< Implementation object
200   friend class Internal::Adaptor::AndroidFramework;
201 };
202
203 } // namespace Integration
204
205 } // namespace Dali
206
207 #endif // DALI_INTEGRATION_ANDROID_FRAMEWORK_H
208