Skip to content

Commit

Permalink
Merge pull request #6514 from koying/chgdroidactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins4kodi committed Mar 3, 2015
2 parents b7d1690 + 5093c79 commit 1e78a9b
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 26 deletions.
2 changes: 1 addition & 1 deletion xbmc/android/activity/XBMCApp.cpp
Expand Up @@ -94,7 +94,7 @@ std::vector<androidPackage> CXBMCApp::m_applications;


CXBMCApp::CXBMCApp(ANativeActivity* nativeActivity)
: CJNIContext(nativeActivity)
: CJNIApplicationMainActivity(nativeActivity)
, CJNIBroadcastReceiver("org/xbmc/kodi/XBMCBroadcastReceiver")
, m_wakeLock(NULL)
{
Expand Down
5 changes: 2 additions & 3 deletions xbmc/android/activity/XBMCApp.h
Expand Up @@ -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"

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/android/activity/android_main.cpp
Expand Up @@ -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);
}
Expand Down
69 changes: 69 additions & 0 deletions 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
* <http://www.gnu.org/licenses/>.
*
*/

#include "Activity.h"
#include "Intent.h"

#include "jutils/jutils-details.hpp"

#include <android/native_activity.h>

using namespace jni;

CJNIActivity::CJNIActivity(const ANativeActivity *nativeActivity) : CJNIContext(nativeActivity)
{
}

CJNIActivity::~CJNIActivity()
{
}

bool CJNIActivity::moveTaskToBack(bool nonRoot)
{
return call_method<jboolean>(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)));
}
57 changes: 57 additions & 0 deletions 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
* <http://www.gnu.org/licenses/>.
*
*/

#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;
};

3 changes: 2 additions & 1 deletion xbmc/android/jni/BroadcastReceiver.cpp
Expand Up @@ -21,6 +21,7 @@
#include "BroadcastReceiver.h"
#include "Intent.h"
#include "Context.h"
#include "Activity.h"
#include "ClassLoader.h"
#include "jutils/jutils-details.hpp"

Expand All @@ -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;

Expand Down
11 changes: 0 additions & 11 deletions xbmc/android/jni/Context.cpp
Expand Up @@ -51,20 +51,17 @@
using namespace jni;

jhobject CJNIContext::m_context(0);
CJNIContext* CJNIContext::m_appInstance(NULL);

CJNIContext::CJNIContext(const ANativeActivity *nativeActivity)
{
m_context.reset(nativeActivity->clazz);
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();
}

Expand Down Expand Up @@ -200,11 +197,3 @@ CJNIWindow CJNIContext::getWindow()
return call_method<jhobject>(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)));
}
10 changes: 2 additions & 8 deletions xbmc/android/jni/Context.h
Expand Up @@ -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;
};

1 change: 1 addition & 0 deletions xbmc/android/jni/Makefile.in
Expand Up @@ -50,6 +50,7 @@ SRCS += View.cpp
SRCS += Window.cpp
SRCS += Build.cpp
SRCS += KeyCharacterMap.cpp
SRCS += Activity.cpp

LIB = jni.a

Expand Down
3 changes: 2 additions & 1 deletion xbmc/android/jni/SurfaceTexture.cpp
Expand Up @@ -20,6 +20,7 @@

#include "JNIBase.h"
#include "Context.h"
#include "Activity.h"
#include "ClassLoader.h"
#include "SurfaceTexture.h"

Expand All @@ -36,7 +37,7 @@ CJNISurfaceTextureOnFrameAvailableListener* CJNISurfaceTextureOnFrameAvailableLi
CJNISurfaceTextureOnFrameAvailableListener::CJNISurfaceTextureOnFrameAvailableListener()
: CJNIBase("org/xbmc/kodi/XBMCOnFrameAvailableListener")
{
CJNIContext *appInstance = CJNIContext::GetAppInstance();
CJNIApplicationMainActivity *appInstance = CJNIApplicationMainActivity::GetAppInstance();
if (!appInstance)
return;

Expand Down

0 comments on commit 1e78a9b

Please sign in to comment.