From 7672948ce8d5d72cf2f6775c00a83f93364d4938 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Thu, 21 Feb 2013 23:43:08 -0500 Subject: [PATCH] intents: add the very beginnings of an intents class Implemented as a singleton, this will eventually have functions for setting up receivers, callbacks, etc. Also, our broadcasting can move into here, to clean up some of the mess in XBMCApp. --- xbmc/android/activity/Intents.cpp | 55 +++++++++++++++++++++++++++++++ xbmc/android/activity/Intents.h | 35 ++++++++++++++++++++ xbmc/android/activity/Makefile.in | 1 + xbmc/android/activity/XBMCApp.h | 1 + 4 files changed, 92 insertions(+) create mode 100644 xbmc/android/activity/Intents.cpp create mode 100644 xbmc/android/activity/Intents.h diff --git a/xbmc/android/activity/Intents.cpp b/xbmc/android/activity/Intents.cpp new file mode 100644 index 0000000000000..d4623ed86bac5 --- /dev/null +++ b/xbmc/android/activity/Intents.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2013 Team XBMC + * http://www.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 "Intents.h" +#include "utils/log.h" +#include "XBMCApp.h" + +CAndroidIntents::CAndroidIntents() +{ +} + +void CAndroidIntents::ReceiveIntent(JNIEnv *env, const jobject &intent) +{ + std::string action = GetIntentAction(intent); + CLog::Log(LOGDEBUG,"CAndroidIntents::ReceiveIntent: %s", action.c_str()); +} + +std::string CAndroidIntents::GetIntentAction(const jobject &intent) +{ + std::string action; + JNIEnv *env; + + if (!intent) + return ""; + + CXBMCApp::AttachCurrentThread(&env, NULL); + jclass cIntent = env->GetObjectClass(intent); + + //action = intent.getAction() + jmethodID mgetAction = env->GetMethodID(cIntent, "getAction", "()Ljava/lang/String;"); + env->DeleteLocalRef(cIntent); + jstring sAction = (jstring)env->CallObjectMethod(intent, mgetAction); + const char *nativeString = env->GetStringUTFChars(sAction, 0); + action = std::string(nativeString); + + env->ReleaseStringUTFChars(sAction, nativeString); + CXBMCApp::DetachCurrentThread(); + return action; +} diff --git a/xbmc/android/activity/Intents.h b/xbmc/android/activity/Intents.h new file mode 100644 index 0000000000000..381c6eb9029fc --- /dev/null +++ b/xbmc/android/activity/Intents.h @@ -0,0 +1,35 @@ +#pragma once +/* + * Copyright (C) 2013 Team XBMC + * http://www.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 +#include + +class CAndroidIntents +{ +public: + void ReceiveIntent(JNIEnv *env, const jobject &intent); + static CAndroidIntents& getInstance() {static CAndroidIntents temp; return temp;}; + +private: + CAndroidIntents(); + CAndroidIntents(CAndroidIntents const&); + void operator=(CAndroidIntents const&); + std::string GetIntentAction(const jobject &intent); +}; diff --git a/xbmc/android/activity/Makefile.in b/xbmc/android/activity/Makefile.in index 1314505fe33e0..3a4d21764c857 100644 --- a/xbmc/android/activity/Makefile.in +++ b/xbmc/android/activity/Makefile.in @@ -17,6 +17,7 @@ SRCS += GraphicBuffer.cpp SRCS += EventLoop.cpp SRCS += XBMCApp.cpp SRCS += JNI.cpp +SRCS += Intents.cpp OBJS += $(APP_GLUE) $(CPU_OBJ) diff --git a/xbmc/android/activity/XBMCApp.h b/xbmc/android/activity/XBMCApp.h index 5a56152cc1336..f51709d1e6b7a 100644 --- a/xbmc/android/activity/XBMCApp.h +++ b/xbmc/android/activity/XBMCApp.h @@ -104,6 +104,7 @@ class CXBMCApp : public IActivityHandler friend class CAESinkAUDIOTRACK; friend class CAndroidFeatures; friend class CFileAndroidApp; + friend class CAndroidIntents; static int AttachCurrentThread(JNIEnv** p_env, void* thr_args = NULL); static int DetachCurrentThread();