DALi Version 2.2.17
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / android / android-framework-impl.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/adaptor/android/android-framework-impl.h>
20
21 namespace Dali
22 {
23 namespace Internal
24 {
25 namespace Adaptor
26 {
27 namespace
28 {
29 AndroidFramework* gAndroidFramework = nullptr; // raw specific pointer to allow AndroidFramework::Get
30 }
31
32 Dali::Integration::AndroidFramework& AndroidFramework::New()
33 {
34   Dali::Integration::AndroidFramework* androidFramework = new Dali::Integration::AndroidFramework;
35   AndroidFramework*                    impl             = new AndroidFramework(androidFramework);
36   androidFramework->mImpl                               = impl;
37   return *androidFramework;
38 }
39
40 void AndroidFramework::Delete()
41 {
42   DALI_ASSERT_ALWAYS(gAndroidFramework != nullptr && "Cannot delete already deleted AndroidFramework.");
43
44   delete gAndroidFramework->mAndroidFramework;
45   gAndroidFramework = nullptr;
46 }
47
48 void AndroidFramework::SetNativeApplication(android_app* application)
49 {
50   mNativeApplication = application;
51 }
52
53 android_app* AndroidFramework::GetNativeApplication() const
54 {
55   return mNativeApplication;
56 }
57
58 void AndroidFramework::SetJVM(JavaVM* jvm)
59 {
60   mJVM = jvm;
61 }
62
63 JavaVM* AndroidFramework::GetJVM() const
64 {
65   return mJVM;
66 }
67
68 void AndroidFramework::SetApplicationAssets(AAssetManager* assets)
69 {
70   mAssets = assets;
71 }
72
73 AAssetManager* AndroidFramework::GetApplicationAssets() const
74 {
75   return mAssets;
76 }
77
78 void AndroidFramework::SetInternalDataPath(const std::string& path)
79 {
80   mInternalDataPath = path;
81 }
82
83 std::string AndroidFramework::GetInternalDataPath() const
84 {
85   return mInternalDataPath;
86 }
87
88 void AndroidFramework::SetApplicationConfiguration(AConfiguration* configuration)
89 {
90   mConfiguration = configuration;
91 }
92
93 AConfiguration* AndroidFramework::GetApplicationConfiguration() const
94 {
95   return mConfiguration;
96 }
97
98 void AndroidFramework::SetApplicationWindow(ANativeWindow* window)
99 {
100   mWindow = window;
101 }
102
103 ANativeWindow* AndroidFramework::GetApplicationWindow() const
104 {
105   return mWindow;
106 }
107
108 void AndroidFramework::OnTerminate()
109 {
110   mFramework->AppStatusHandler(APP_DESTROYED, nullptr);
111 }
112
113 void AndroidFramework::OnPause()
114 {
115   mFramework->AppStatusHandler(APP_PAUSE, nullptr);
116 }
117
118 void AndroidFramework::OnResume()
119 {
120   mFramework->AppStatusHandler(APP_RESUME, nullptr);
121 }
122
123 void AndroidFramework::OnWindowCreated(ANativeWindow* window)
124 {
125   mFramework->AppStatusHandler(APP_WINDOW_CREATED, window);
126 }
127
128 void AndroidFramework::OnWindowDestroyed(ANativeWindow* window)
129 {
130   mFramework->AppStatusHandler(APP_WINDOW_DESTROYED, window);
131 }
132
133 Dali::Integration::AndroidFramework& AndroidFramework::Get()
134 {
135   DALI_ASSERT_ALWAYS(gAndroidFramework != nullptr && "AndroidFramework not instantiated");
136
137   return *gAndroidFramework->mAndroidFramework;
138 }
139
140 AndroidFramework::AndroidFramework(Dali::Integration::AndroidFramework* androidFramework)
141 : mAndroidFramework(androidFramework),
142   mFramework(nullptr),
143   mNativeApplication(nullptr),
144   mWindow(nullptr),
145   mAssets(nullptr),
146   mConfiguration(nullptr),
147   mJVM(nullptr)
148 {
149   DALI_ASSERT_ALWAYS(gAndroidFramework == nullptr && "Cannot create more than one AndroidFramework.");
150
151   gAndroidFramework = this;
152 }
153
154 AndroidFramework::~AndroidFramework()
155 {
156   gAndroidFramework = nullptr;
157 }
158
159 } // namespace Adaptor
160
161 } // namespace Internal
162
163 } // namespace Dali