Add Android adaptor.
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / android / android-framework-impl.cpp
1 /*
2  * Copyright (c) 2019 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
24 namespace Internal
25 {
26
27 namespace Adaptor
28 {
29
30 namespace
31 {
32 AndroidFramework* gAndroidFramework = nullptr; // raw specific pointer to allow AndroidFramework::Get
33 }
34
35 Dali::Integration::AndroidFramework& AndroidFramework::New()
36 {
37   Dali::Integration::AndroidFramework* androidFramework = new Dali::Integration::AndroidFramework;
38   AndroidFramework* impl = new AndroidFramework( *androidFramework );
39   androidFramework->mImpl = impl;
40   return *androidFramework;
41 }
42
43 void AndroidFramework::SetNativeApplication( android_app* application )
44 {
45   mNativeApplication = application;
46 }
47
48 android_app* AndroidFramework::GetNativeApplication() const
49 {
50   return mNativeApplication;
51 }
52
53 void AndroidFramework::SetJVM( JavaVM* jvm )
54 {
55   mJVM = jvm;
56 }
57
58 JavaVM* AndroidFramework::GetJVM() const
59 {
60   return mJVM;
61 }
62
63 void AndroidFramework::SetApplicationAssets( AAssetManager* assets )
64 {
65   mAssets = assets;
66 }
67
68 AAssetManager* AndroidFramework::GetApplicationAssets() const
69 {
70   return mAssets;
71 }
72
73 void AndroidFramework::SetApplicationConfiguration( AConfiguration* configuration )
74 {
75   mConfiguration = configuration;
76 }
77
78 AConfiguration* AndroidFramework::GetApplicationConfiguration() const
79 {
80   return mConfiguration;
81 }
82
83 void AndroidFramework::SetApplicationWindow( ANativeWindow* window )
84 {
85   mWindow = window;
86 }
87
88 ANativeWindow* AndroidFramework::GetApplicationWindow() const
89 {
90   return mWindow;
91 }
92
93 void AndroidFramework::OnTerminate()
94 {
95   mFramework->AppStatusHandler( APP_DESTROYED, nullptr );
96 }
97
98 void AndroidFramework::OnPause()
99 {
100   mFramework->AppStatusHandler( APP_PAUSE, nullptr );
101 }
102
103 void AndroidFramework::OnResume()
104 {
105   mFramework->AppStatusHandler( APP_RESUME, nullptr );
106 }
107
108 void AndroidFramework::OnWindowCreated( ANativeWindow* window )
109 {
110   mFramework->AppStatusHandler( APP_WINDOW_CREATED, window );
111 }
112
113 void AndroidFramework::OnWindowDestroyed( ANativeWindow* window )
114 {
115   mFramework->AppStatusHandler( APP_WINDOW_DESTROYED, window );
116 }
117
118 Dali::Integration::AndroidFramework& AndroidFramework::Get()
119 {
120   DALI_ASSERT_ALWAYS( gAndroidFramework != nullptr && "AndroidFramework not instantiated" );
121
122   return gAndroidFramework->mAndroidFramework;
123 }
124
125 AndroidFramework::AndroidFramework( Dali::Integration::AndroidFramework& androidFramework )
126  : mAndroidFramework( androidFramework ),
127    mFramework( nullptr ),
128    mNativeApplication( nullptr ),
129    mWindow( nullptr ),
130    mAssets( nullptr ),
131    mConfiguration( nullptr ),
132    mJVM( nullptr )
133 {
134   DALI_ASSERT_ALWAYS( gAndroidFramework == nullptr && "Cannot create more than one AndroidFramework." );
135
136   gAndroidFramework = this;
137 }
138
139 AndroidFramework::~AndroidFramework()
140 {
141   gAndroidFramework = nullptr;
142 }
143
144 } // namespace Adaptor
145
146 } // namespace Internal
147
148 } // namespace Dali