2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/adaptor/common/framework.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/integration-api/adaptor-framework/adaptor.h>
24 #include <dali/integration-api/adaptor-framework/android/android-framework.h>
25 #include <dali/public-api/adaptor-framework/application.h>
26 #include <dali/devel-api/adaptor-framework/application-devel.h>
29 #include <dali/internal/adaptor/common/application-impl.h>
30 #include <dali/internal/adaptor/android/android-framework-impl.h>
31 #include <dali/internal/system/common/callback-manager.h>
45 * Impl to hide android data members
47 struct Framework::Impl
51 Impl( Framework* framework )
52 : mAbortCallBack( nullptr ),
53 mCallbackManager( CallbackManager::New() ),
54 mLanguage( "NOT_SUPPORTED" ),
55 mRegion( "NOT_SUPPORTED" )
57 AndroidFramework::GetImplementation( AndroidFramework::Get() ).SetFramework( framework );
62 AndroidFramework::GetImplementation( AndroidFramework::Get() ).SetFramework( nullptr );
64 delete mAbortCallBack;
65 mAbortCallBack = nullptr;
67 // we're quiting the main loop so
68 // mCallbackManager->RemoveAllCallBacks() does not need to be called
69 // to delete our abort handler
70 delete mCallbackManager;
71 mCallbackManager = nullptr;
74 std::string GetLanguage() const
79 std::string GetRegion() const
84 CallbackBase* mAbortCallBack;
85 CallbackManager* mCallbackManager;
86 std::string mLanguage;
90 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )
91 : mObserver( observer ),
92 mInitialised( false ),
99 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
102 mImpl = new Impl( this );
105 Framework::~Framework()
116 void Framework::Run()
118 AndroidFramework::GetImplementation( AndroidFramework::Get() ).SetFramework( this );
122 unsigned int Framework::AddIdle( int timeout, void* data, bool ( *callback )( void *data ) )
124 JNIEnv *env = nullptr;
125 JavaVM* javaVM = AndroidFramework::Get().GetJVM();
126 if( javaVM == nullptr || javaVM->GetEnv( reinterpret_cast<void **>( &env ), JNI_VERSION_1_6 ) != JNI_OK )
128 DALI_LOG_ERROR("Couldn't get JNI env.");
132 jclass clazz = env->FindClass( "com/sec/daliview/DaliView" );
135 DALI_LOG_ERROR("Couldn't find com.sec.daliview.DaliView.");
139 jmethodID addIdle = env->GetStaticMethodID( clazz, "addIdle", "(JJJ)I" );
142 DALI_LOG_ERROR("Couldn't find com.sec.daliview.DaliView.addIdle.");
146 jint id = env->CallStaticIntMethod( clazz, addIdle, reinterpret_cast<jlong>( callback ), reinterpret_cast<jlong>( data ), static_cast<jlong>( timeout ) );
147 return static_cast<unsigned int>( id );
150 void Framework::RemoveIdle( unsigned int id )
152 JNIEnv *env = nullptr;
153 JavaVM* javaVM = AndroidFramework::Get().GetJVM();
154 if( javaVM == nullptr || javaVM->GetEnv( reinterpret_cast<void **>( &env ), JNI_VERSION_1_6 ) != JNI_OK )
156 DALI_LOG_ERROR("Couldn't get JNI env.");
160 jclass clazz = env->FindClass( "com/sec/daliview/DaliView" );
163 DALI_LOG_ERROR("Couldn't find com.sec.daliview.DaliView.");
167 jmethodID removeIdle = env->GetStaticMethodID( clazz, "removeIdle", "(I)V" );
170 DALI_LOG_ERROR("Couldn't find com.sec.daliview.DaliView.removeIdle.");
174 env->CallStaticVoidMethod( clazz, removeIdle, static_cast<jint>( id ) );
177 void Framework::Quit()
179 DALI_LOG_ERROR("Quit does nothing for DaliView!");
182 bool Framework::IsMainLoopRunning()
187 void Framework::AddAbortCallback( CallbackBase* callback )
189 mImpl->mAbortCallBack = callback;
192 std::string Framework::GetBundleName() const
197 void Framework::SetBundleName(const std::string& name)
202 std::string Framework::GetBundleId() const
207 std::string Framework::GetResourcePath()
209 return DALI_DATA_RO_DIR;
212 std::string Framework::GetDataPath()
217 void Framework::SetBundleId(const std::string& id)
222 void Framework::AbortCallback( )
224 // if an abort call back has been installed run it.
225 if (mImpl->mAbortCallBack)
227 CallbackBase::Execute( *mImpl->mAbortCallBack );
235 bool Framework::AppStatusHandler(int type, void* data)
237 Dali::Adaptor* adaptor = nullptr;
240 case APP_WINDOW_CREATED:
247 mObserver.OnSurfaceCreated( data );
250 case APP_WINDOW_DESTROYED:
251 mObserver.OnSurfaceDestroyed( data );
259 mObserver.OnResume();
260 adaptor = &Dali::Adaptor::Get();
265 adaptor = &Dali::Adaptor::Get();
270 case APP_LANGUAGE_CHANGE:
271 mObserver.OnLanguageChanged();
275 mObserver.OnTerminate();
278 mInitialised = false;
288 void Framework::InitThreads()
292 std::string Framework::GetLanguage() const
294 return mImpl->GetLanguage();
297 std::string Framework::GetRegion() const
299 return mImpl->GetRegion();
302 } // namespace Adaptor
304 } // namespace Internal