Merge branch 'devel/master' into sandbox/dkdk/tizen
[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 <android/asset_manager.h>
25 #include <android/asset_manager_jni.h>
26 #include <android/configuration.h>
27 #include <android/native_window.h>
28 #include <android/native_window_jni.h>
29 #include <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 namespace Internal DALI_INTERNAL
44 {
45 namespace Adaptor
46 {
47 class AndroidFramework;
48 }
49
50 } // namespace DALI_INTERNAL
51
52 namespace Integration
53 {
54 /**
55  * AndroidFramework provides setter/getter for Android native interfaces for Android DALi Adaptor.
56  * It is also used to pass Android application events to Android DALi Adaptor.
57  */
58 class DALI_ADAPTOR_API AndroidFramework
59 {
60 public:
61   /**
62    * @brief Create a new Android framework instance. Can be only one per application.
63    *
64    * @return a reference to the framework
65    */
66   static AndroidFramework& New();
67
68   /**
69    * @brief Delete an Android framework instance.
70    */
71   static void Delete();
72
73   /**
74    * @brief Sets the Android native application glue struct
75    * @param[in] application A pointer to the application glue struct
76    */
77   void SetNativeApplication(android_app* application);
78
79   /**
80    * @brief Gets the Android native application glue struct
81    * @return the native application glue struct
82    */
83   android_app* GetNativeApplication() const;
84
85   /**
86    * @brief Sets the Android JVM
87    * @param[in] jvm A pointer to Android JVM
88    */
89   void SetJVM(JavaVM* jvm);
90
91   /**
92    * @brief Sets the JVM
93    * @return A pointer to JVM
94    */
95   JavaVM* GetJVM() const;
96
97   /**
98    *  Sets the Android application assets manager.
99    *  @param[in] assets A pointer to assets manager
100    */
101   void SetApplicationAssets(AAssetManager* assets);
102
103   /**
104    * @brief Gets the Android application assets manager.
105    * @return The application assets manager
106    */
107   AAssetManager* GetApplicationAssets() const;
108
109   /**
110    *  Sets the Android application internal data path.
111    *  @param[in] path A path to the application data path
112    */
113   void SetInternalDataPath(const std::string& path);
114
115   /**
116    *  Gets the Android application internal data path.
117    *  @return The application data path
118    */
119   std::string GetInternalDataPath() const;
120
121   /**
122    * @brief Sets the Android application configuration
123    * @param[in] configuration A pointer to Android application configuration
124    */
125   void SetApplicationConfiguration(AConfiguration* configuration);
126
127   /**
128    * @brief Gets the Android application configuration
129    * @return A Android application configuration
130    */
131   AConfiguration* GetApplicationConfiguration() const;
132
133   /**
134    * @brief Sets the Android application native window
135    * @return A native window
136    */
137   void SetApplicationWindow(ANativeWindow* window);
138
139   /**
140    * @brief Gets the Android application native window
141    * @param[in] window A native window
142    */
143   ANativeWindow* GetApplicationWindow() const;
144
145   /**
146    * Invoked when the Android application is to be terminated.
147    */
148   void OnTerminate();
149
150   /**
151    * Invoked when the Android application is to be paused.
152    */
153   void OnPause();
154
155   /**
156    * Invoked when the Android application is to be resumed.
157    */
158   void OnResume();
159
160   /**
161    * Invoked when the Android application native window is created.
162    */
163   void OnWindowCreated(ANativeWindow* window);
164
165   /**
166    * Invoked when the Android application native window is deleted.
167    */
168   void OnWindowDestroyed(ANativeWindow* window);
169
170   /**
171    * @brief Returns a reference to the instance of the Android framework used by the current thread.
172    *
173    * @return A reference to the framework.
174    * @note This is only valid in the main thread.
175    */
176   static AndroidFramework& Get();
177
178   /**
179    * @brief Virtual Destructor.
180    */
181   virtual ~AndroidFramework();
182
183   // Not copyable or movable
184   AndroidFramework(const AndroidFramework&) = delete;            ///< Deleted copy constructor
185   AndroidFramework(AndroidFramework&&)      = delete;            ///< Deleted move constructor
186   AndroidFramework& operator=(const AndroidFramework&) = delete; ///< Deleted copy assignment operator
187   AndroidFramework& operator=(AndroidFramework&&) = delete;      ///< Deleted move assignment operator
188
189 private:
190   /**
191    * @brief Create an uninitialized AndroidFramework.
192    */
193   AndroidFramework();
194
195   Internal::Adaptor::AndroidFramework* mImpl; ///< Implementation object
196   friend class Internal::Adaptor::AndroidFramework;
197 };
198
199 } // namespace Integration
200
201 } // namespace Dali
202
203 #endif // DALI_INTEGRATION_ANDROID_FRAMEWORK_H