diff --git a/xbmc/android/activity/XBMCApp.cpp b/xbmc/android/activity/XBMCApp.cpp index 1cc1be5b57839..7d932e3e3e639 100644 --- a/xbmc/android/activity/XBMCApp.cpp +++ b/xbmc/android/activity/XBMCApp.cpp @@ -94,7 +94,7 @@ std::vector CXBMCApp::m_applications; CXBMCApp::CXBMCApp(ANativeActivity* nativeActivity) - : CJNIContext(nativeActivity) + : CJNIApplicationMainActivity(nativeActivity) , CJNIBroadcastReceiver("org/xbmc/kodi/XBMCBroadcastReceiver") , m_wakeLock(NULL) { diff --git a/xbmc/android/activity/XBMCApp.h b/xbmc/android/activity/XBMCApp.h index 3218be2acfa1b..cb9a357191a7e 100644 --- a/xbmc/android/activity/XBMCApp.h +++ b/xbmc/android/activity/XBMCApp.h @@ -30,7 +30,7 @@ #include "IInputHandler.h" #include "xbmc.h" -#include "android/jni/Context.h" +#include "android/jni/Activity.h" #include "android/jni/BroadcastReceiver.h" #include "threads/Event.h" @@ -52,8 +52,7 @@ struct androidPackage std::string packageLabel; }; - -class CXBMCApp : public IActivityHandler, public CJNIContext, public CJNIBroadcastReceiver +class CXBMCApp : public IActivityHandler, public CJNIApplicationMainActivity, public CJNIBroadcastReceiver { public: CXBMCApp(ANativeActivity *nativeActivity); diff --git a/xbmc/android/activity/android_main.cpp b/xbmc/android/activity/android_main.cpp index 2db5916e0f34b..426321c2d6d10 100644 --- a/xbmc/android/activity/android_main.cpp +++ b/xbmc/android/activity/android_main.cpp @@ -96,7 +96,7 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) JNINativeMethod mOnNewIntent = { "_onNewIntent", "(Landroid/content/Intent;)V", - (void*)&CJNIContext::_onNewIntent + (void*)&CJNIApplicationMainActivity::_onNewIntent }; env->RegisterNatives(cMain, &mOnNewIntent, 1); } diff --git a/xbmc/android/jni/Activity.cpp b/xbmc/android/jni/Activity.cpp new file mode 100644 index 0000000000000..6c4a33e20a060 --- /dev/null +++ b/xbmc/android/jni/Activity.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2014 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ + +#include "Activity.h" +#include "Intent.h" + +#include "jutils/jutils-details.hpp" + +#include + +using namespace jni; + +CJNIActivity::CJNIActivity(const ANativeActivity *nativeActivity) : CJNIContext(nativeActivity) +{ +} + +CJNIActivity::~CJNIActivity() +{ +} + +bool CJNIActivity::moveTaskToBack(bool nonRoot) +{ + return call_method(jhobject(m_context), + "moveTaskToBack", "(Z)Z", + nonRoot); +} + +///////////////////////////////////////////////// +/// \brief CJNIApplicationMainActivity::CJNIApplicationMainActivity +/// \param nativeActivity +/// + +CJNIApplicationMainActivity* CJNIApplicationMainActivity::m_appInstance(NULL); + +CJNIApplicationMainActivity::CJNIApplicationMainActivity(const ANativeActivity *nativeActivity) + : CJNIActivity(nativeActivity) +{ + m_appInstance = this; +} + +CJNIApplicationMainActivity::~CJNIApplicationMainActivity() +{ + m_appInstance = NULL; +} + +void CJNIApplicationMainActivity::_onNewIntent(JNIEnv *env, jobject context, jobject intent) +{ + (void)env; + (void)context; + if(m_appInstance) + m_appInstance->onNewIntent(CJNIIntent(jhobject(intent))); +} diff --git a/xbmc/android/jni/Activity.h b/xbmc/android/jni/Activity.h new file mode 100644 index 0000000000000..da92221c80acb --- /dev/null +++ b/xbmc/android/jni/Activity.h @@ -0,0 +1,57 @@ +#pragma once +/* + * Copyright (C) 2014 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ + +#include "JNIBase.h" +#include "Context.h" + +struct ANativeActivity; + +class CJNIActivity : public CJNIContext +{ +public: + CJNIActivity(const ANativeActivity *nativeActivity); + ~CJNIActivity(); + + static bool moveTaskToBack(bool nonRoot); + +private: + CJNIActivity(); +}; + +/////////////////////////////////// + +class CJNIApplicationMainActivity : public CJNIActivity +{ +public: + CJNIApplicationMainActivity(const ANativeActivity *nativeActivity); + ~CJNIApplicationMainActivity(); + + static CJNIApplicationMainActivity* GetAppInstance() { return m_appInstance; } + + static void _onNewIntent(JNIEnv *env, jobject context, jobject intent); + +private: + static CJNIApplicationMainActivity *m_appInstance; + +protected: + virtual void onNewIntent(CJNIIntent intent)=0; +}; + diff --git a/xbmc/android/jni/BroadcastReceiver.cpp b/xbmc/android/jni/BroadcastReceiver.cpp index b4929e14aec4f..cfd01fb1a8c24 100644 --- a/xbmc/android/jni/BroadcastReceiver.cpp +++ b/xbmc/android/jni/BroadcastReceiver.cpp @@ -21,6 +21,7 @@ #include "BroadcastReceiver.h" #include "Intent.h" #include "Context.h" +#include "Activity.h" #include "ClassLoader.h" #include "jutils/jutils-details.hpp" @@ -29,7 +30,7 @@ using namespace jni; CJNIBroadcastReceiver *CJNIBroadcastReceiver::m_receiverInstance(NULL); CJNIBroadcastReceiver::CJNIBroadcastReceiver(const std::string &className) : CJNIBase(className) { - CJNIContext *appInstance = CJNIContext::GetAppInstance(); + CJNIApplicationMainActivity *appInstance = CJNIApplicationMainActivity::GetAppInstance(); if (!appInstance || className.empty()) return; diff --git a/xbmc/android/jni/Context.cpp b/xbmc/android/jni/Context.cpp index b5afd0fd85dc5..513da17eb1117 100644 --- a/xbmc/android/jni/Context.cpp +++ b/xbmc/android/jni/Context.cpp @@ -51,7 +51,6 @@ using namespace jni; jhobject CJNIContext::m_context(0); -CJNIContext* CJNIContext::m_appInstance(NULL); CJNIContext::CJNIContext(const ANativeActivity *nativeActivity) { @@ -59,12 +58,10 @@ CJNIContext::CJNIContext(const ANativeActivity *nativeActivity) xbmc_jni_on_load(nativeActivity->vm, nativeActivity->env); CJNIBase::SetSDKVersion(nativeActivity->sdkVersion); PopulateStaticFields(); - m_appInstance = this; } CJNIContext::~CJNIContext() { - m_appInstance = NULL; xbmc_jni_on_unload(); } @@ -200,11 +197,3 @@ CJNIWindow CJNIContext::getWindow() return call_method(m_context, "getWindow", "()Landroid/view/Window;"); } - -void CJNIContext::_onNewIntent(JNIEnv *env, jobject context, jobject intent) -{ - (void)env; - (void)context; - if(m_appInstance) - m_appInstance->onNewIntent(CJNIIntent(jhobject(intent))); -} diff --git a/xbmc/android/jni/Context.h b/xbmc/android/jni/Context.h index 60c62c6387e07..b3e73d784b651 100644 --- a/xbmc/android/jni/Context.h +++ b/xbmc/android/jni/Context.h @@ -54,21 +54,15 @@ class CJNIContext static CJNIContentResolver getContentResolver(); static CJNIWindow getWindow(); - static CJNIContext* GetAppInstance() { return m_appInstance; }; - static void _onNewIntent(JNIEnv *env, jobject context, jobject intent); - protected: CJNIContext(const ANativeActivity *nativeActivity); ~CJNIContext(); - virtual void onNewIntent(CJNIIntent intent)=0; + static jni::jhobject m_context; -private: +protected: CJNIContext(); void PopulateStaticFields(); void operator=(CJNIContext const&){}; - static jni::jhobject m_context; - static CJNIContext *m_appInstance; }; - diff --git a/xbmc/android/jni/Makefile.in b/xbmc/android/jni/Makefile.in index 7354df6223033..60468782d8478 100644 --- a/xbmc/android/jni/Makefile.in +++ b/xbmc/android/jni/Makefile.in @@ -50,6 +50,7 @@ SRCS += View.cpp SRCS += Window.cpp SRCS += Build.cpp SRCS += KeyCharacterMap.cpp +SRCS += Activity.cpp LIB = jni.a diff --git a/xbmc/android/jni/SurfaceTexture.cpp b/xbmc/android/jni/SurfaceTexture.cpp index 8a40597ea36dd..6ee9b532d991e 100644 --- a/xbmc/android/jni/SurfaceTexture.cpp +++ b/xbmc/android/jni/SurfaceTexture.cpp @@ -20,6 +20,7 @@ #include "JNIBase.h" #include "Context.h" +#include "Activity.h" #include "ClassLoader.h" #include "SurfaceTexture.h" @@ -36,7 +37,7 @@ CJNISurfaceTextureOnFrameAvailableListener* CJNISurfaceTextureOnFrameAvailableLi CJNISurfaceTextureOnFrameAvailableListener::CJNISurfaceTextureOnFrameAvailableListener() : CJNIBase("org/xbmc/kodi/XBMCOnFrameAvailableListener") { - CJNIContext *appInstance = CJNIContext::GetAppInstance(); + CJNIApplicationMainActivity *appInstance = CJNIApplicationMainActivity::GetAppInstance(); if (!appInstance) return;