[Android] Update Android bridge for notification

This commit is contained in:
zilmar 2016-08-11 20:43:51 +10:00
parent c39937f63c
commit a277fc0a60
4 changed files with 98 additions and 49 deletions

View File

@ -15,7 +15,7 @@
#ifdef ANDROID #ifdef ANDROID
JavaBridge::JavaBridge(JavaVM* vm) : JavaBridge::JavaBridge(JavaVM* vm) :
m_vm(vm) m_vm(vm)
{ {
JNIEnv *env = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
jclass GalleryActivityClass = env->FindClass("emu/project64/GalleryActivity"); jclass GalleryActivityClass = env->FindClass("emu/project64/GalleryActivity");
@ -34,13 +34,13 @@ void JavaBridge::GfxThreadInit()
{ {
WriteTrace(TraceUserInterface, TraceDebug, "Start"); WriteTrace(TraceUserInterface, TraceDebug, "Start");
JNIEnv *env = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
if (g_GLThread != NULL && env != NULL) if (g_GLThread != NULL && env != NULL)
{ {
jclass GLThreadClass = env->GetObjectClass(g_GLThread); jclass GLThreadClass = env->GetObjectClass(g_GLThread);
jmethodID midThreadStarting = env->GetMethodID(GLThreadClass, "ThreadStarting", "()V"); jmethodID midThreadStarting = env->GetMethodID(GLThreadClass, "ThreadStarting", "()V");
env->CallVoidMethod(g_GLThread, midThreadStarting); env->CallVoidMethod(g_GLThread, midThreadStarting);
env->DeleteLocalRef(GLThreadClass); env->DeleteLocalRef(GLThreadClass);
} }
WriteTrace(TraceUserInterface, TraceDebug, "Done"); WriteTrace(TraceUserInterface, TraceDebug, "Done");
} }
@ -48,14 +48,14 @@ void JavaBridge::GfxThreadDone()
{ {
WriteTrace(TraceUserInterface, TraceDebug, "Start"); WriteTrace(TraceUserInterface, TraceDebug, "Start");
JNIEnv *env = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
if (g_GLThread != NULL && env != NULL) if (g_GLThread != NULL && env != NULL)
{ {
WriteTrace(TraceUserInterface, TraceDebug, "calling java GLThread::ThreadExiting"); WriteTrace(TraceUserInterface, TraceDebug, "calling java GLThread::ThreadExiting");
jclass GLThreadClass = env->GetObjectClass(g_GLThread); jclass GLThreadClass = env->GetObjectClass(g_GLThread);
jmethodID midThreadExiting = env->GetMethodID(GLThreadClass, "ThreadExiting", "()V"); jmethodID midThreadExiting = env->GetMethodID(GLThreadClass, "ThreadExiting", "()V");
env->CallVoidMethod(g_GLThread, midThreadExiting); env->CallVoidMethod(g_GLThread, midThreadExiting);
env->DeleteLocalRef(GLThreadClass); env->DeleteLocalRef(GLThreadClass);
} }
WriteTrace(TraceUserInterface, TraceDebug, "Done"); WriteTrace(TraceUserInterface, TraceDebug, "Done");
} }
@ -63,7 +63,7 @@ void JavaBridge::SwapWindow()
{ {
JNIEnv *env = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
if (g_GLThread != NULL && env != NULL) if (g_GLThread != NULL && env != NULL)
{ {
jclass GLThreadClass = env->GetObjectClass(g_GLThread); jclass GLThreadClass = env->GetObjectClass(g_GLThread);
jmethodID midSwapBuffers = env->GetMethodID(GLThreadClass, "SwapBuffers", "()V"); jmethodID midSwapBuffers = env->GetMethodID(GLThreadClass, "SwapBuffers", "()V");
env->CallVoidMethod(g_GLThread, midSwapBuffers); env->CallVoidMethod(g_GLThread, midSwapBuffers);
@ -134,11 +134,23 @@ void JavaBridge::DisplayMessage(const char * Message)
} }
} }
void JavaBridge::DisplayMessage2(const char * Message)
{
JNIEnv *env = Android_JNI_GetEnv();
if (env)
{
jstring j_Message = env->NewStringUTF(Message);
jmethodID midShowToast = env->GetStaticMethodID(m_NotifierClass, "showToast", "(Landroid/app/Activity;Ljava/lang/String;)V");
env->CallStaticVoidMethod(m_NotifierClass, midShowToast,g_Activity,j_Message);
env->DeleteLocalRef(j_Message);
}
}
void JavaBridge::EmulationStopped(void) void JavaBridge::EmulationStopped(void)
{ {
JNIEnv *env = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
if (g_Activity != NULL && env != NULL) if (g_Activity != NULL && env != NULL)
{ {
jmethodID midEmulationStopped = env->GetStaticMethodID(m_NotifierClass, "EmulationStopped", "(Landroid/app/Activity;)V"); jmethodID midEmulationStopped = env->GetStaticMethodID(m_NotifierClass, "EmulationStopped", "(Landroid/app/Activity;)V");
env->CallStaticVoidMethod(m_NotifierClass, midEmulationStopped, g_Activity); env->CallStaticVoidMethod(m_NotifierClass, midEmulationStopped, g_Activity);
} }

View File

@ -5,14 +5,14 @@
#include <Project64-core/Plugins/PluginClass.h> #include <Project64-core/Plugins/PluginClass.h>
#include <jni.h> #include <jni.h>
class JavaBridge : class JavaBridge :
public RenderWindow public RenderWindow
{ {
public: public:
JavaBridge (JavaVM* vm); JavaBridge (JavaVM* vm);
//Render window functions //Render window functions
void GfxThreadInit(); void GfxThreadInit();
void GfxThreadDone(); void GfxThreadDone();
void SwapWindow(); void SwapWindow();
@ -24,14 +24,15 @@ public:
//Notification //Notification
void DisplayError(const char * Message); void DisplayError(const char * Message);
void DisplayMessage(const char * Message); void DisplayMessage(const char * Message);
void DisplayMessage2(const char * Message);
void EmulationStopped(void); void EmulationStopped(void);
private: private:
JavaBridge(void); // Disable default constructor JavaBridge(void); // Disable default constructor
JavaBridge(const JavaBridge&); // Disable copy constructor JavaBridge(const JavaBridge&); // Disable copy constructor
JavaBridge& operator=(const JavaBridge&); // Disable assignment JavaBridge& operator=(const JavaBridge&); // Disable assignment
JavaVM* m_vm; JavaVM* m_vm;
jclass m_GalleryActivityClass; jclass m_GalleryActivityClass;
jclass m_NotifierClass; jclass m_NotifierClass;
}; };

View File

@ -80,25 +80,23 @@ void CNotificationImp::DisplayMessage(int DisplayTime, LanguageStringID StringID
void CNotificationImp::DisplayMessage(int DisplayTime, const char * Message) const void CNotificationImp::DisplayMessage(int DisplayTime, const char * Message) const
{ {
#ifdef ANDROID #ifdef ANDROID
__android_log_print(ANDROID_LOG_VERBOSE, "PJ64-Bridge", "%s", Message);
if (g_JavaBridge == NULL) { return; } if (g_JavaBridge == NULL) { return; }
/*if (m_NextMsg > 0 || DisplayTime > 0) /*if (m_NextMsg > 0 || DisplayTime > 0)
{ {
time_t Now = time(NULL); time_t Now = time(NULL);
if (DisplayTime == 0 && Now < m_NextMsg) if (DisplayTime == 0 && Now < m_NextMsg)
{ {
return; return;
} }
if (DisplayTime > 0) if (DisplayTime > 0)
{ {
m_NextMsg = Now + DisplayTime; m_NextMsg = Now + DisplayTime;
} }
if (m_NextMsg == 0) if (m_NextMsg == 0)
{ {
m_NextMsg = 0; m_NextMsg = 0;
} }
}*/ }*/
g_JavaBridge->DisplayMessage(Message); g_JavaBridge->DisplayMessage(Message);
@ -109,8 +107,16 @@ void CNotificationImp::DisplayMessage(int DisplayTime, const char * Message) con
#endif #endif
} }
void CNotificationImp::DisplayMessage2(const char * /*Message*/) const void CNotificationImp::DisplayMessage2(const char * Message) const
{ {
#ifdef ANDROID
if (g_JavaBridge == NULL) { return; }
g_JavaBridge->DisplayMessage2(Message);
#else
// ignore warning usage
Message = Message;
#endif
} }
// Ask a Yes/No Question to the user, yes = true, no = false // Ask a Yes/No Question to the user, yes = true, no = false
@ -128,7 +134,7 @@ void CNotificationImp::BreakPoint(const char * FileName, int32_t LineNumber)
else else
{ {
FatalError("Fatal Error: Emulation stopped"); FatalError("Fatal Error: Emulation stopped");
} }
} }
void CNotificationImp::AppInitDone(void) void CNotificationImp::AppInitDone(void)

View File

@ -21,6 +21,7 @@
#include "jniBridge.h" #include "jniBridge.h"
#include "jniBridgeSettings.h" #include "jniBridgeSettings.h"
#include "JavaBridge.h" #include "JavaBridge.h"
#include "SyncBridge.h"
#include "UISettings.h" #include "UISettings.h"
#include "JavaRomList.h" #include "JavaRomList.h"
@ -58,6 +59,7 @@ AndroidLogger * g_Logger = NULL;
static pthread_key_t g_ThreadKey; static pthread_key_t g_ThreadKey;
static JavaVM* g_JavaVM = NULL; static JavaVM* g_JavaVM = NULL;
JavaBridge * g_JavaBridge = NULL; JavaBridge * g_JavaBridge = NULL;
SyncBridge * g_SyncBridge = NULL;
jobject g_Activity = NULL; jobject g_Activity = NULL;
jobject g_GLThread = NULL; jobject g_GLThread = NULL;
@ -120,7 +122,7 @@ void GameCpuRunning(void * /*NotUsed*/)
} }
env->DeleteGlobalRef(g_GLThread); env->DeleteGlobalRef(g_GLThread);
g_GLThread = NULL; g_GLThread = NULL;
} }
else else
{ {
WriteTrace(TraceUserInterface, TraceError, "Failed to get java environment"); WriteTrace(TraceUserInterface, TraceError, "Failed to get java environment");
@ -155,12 +157,13 @@ EXPORT jboolean CALL Java_emu_project64_jni_NativeExports_appInit(JNIEnv* env, j
const char *baseDir = env->GetStringUTFChars(BaseDir, 0); const char *baseDir = env->GetStringUTFChars(BaseDir, 0);
bool res = AppInit(&Notify(), baseDir, 0, NULL); bool res = AppInit(&Notify(), baseDir, 0, NULL);
env->ReleaseStringUTFChars(BaseDir, baseDir); env->ReleaseStringUTFChars(BaseDir, baseDir);
if (res) if (res)
{ {
g_JavaBridge = new JavaBridge(g_JavaVM); g_JavaBridge = new JavaBridge(g_JavaVM);
g_Plugins->SetRenderWindows(g_JavaBridge, NULL); g_SyncBridge = new SyncBridge(g_JavaBridge);
g_Plugins->SetRenderWindows(g_JavaBridge, g_SyncBridge);
JniBridegSettings = new CJniBridegSettings(); JniBridegSettings = new CJniBridegSettings();
@ -183,6 +186,7 @@ EXPORT void CALL Java_emu_project64_jni_NativeExports_SettingsSaveBool(JNIEnv* e
{ {
WriteTrace(TraceUserInterface, TraceDebug, "Saving %d value: %s",Type,Value ? "true" : "false"); WriteTrace(TraceUserInterface, TraceDebug, "Saving %d value: %s",Type,Value ? "true" : "false");
g_Settings->SaveBool((SettingID)Type, Value); g_Settings->SaveBool((SettingID)Type, Value);
CSettings::FlushSettings(g_Settings);
WriteTrace(TraceUserInterface, TraceDebug, "Saved"); WriteTrace(TraceUserInterface, TraceDebug, "Saved");
} }
@ -190,6 +194,7 @@ EXPORT void CALL Java_emu_project64_jni_NativeExports_SettingsSaveDword(JNIEnv*
{ {
WriteTrace(TraceUserInterface, TraceDebug, "Saving %d value: 0x%X",Type,Value); WriteTrace(TraceUserInterface, TraceDebug, "Saving %d value: 0x%X",Type,Value);
g_Settings->SaveDword((SettingID)Type, Value); g_Settings->SaveDword((SettingID)Type, Value);
CSettings::FlushSettings(g_Settings);
WriteTrace(TraceUserInterface, TraceDebug, "Saved"); WriteTrace(TraceUserInterface, TraceDebug, "Saved");
} }
@ -198,6 +203,7 @@ EXPORT void CALL Java_emu_project64_jni_NativeExports_SettingsSaveString(JNIEnv*
const char *value = env->GetStringUTFChars(Buffer, 0); const char *value = env->GetStringUTFChars(Buffer, 0);
WriteTrace(TraceUserInterface, TraceDebug, "Saving %d value: %s",Type,value); WriteTrace(TraceUserInterface, TraceDebug, "Saving %d value: %s",Type,value);
g_Settings->SaveString((SettingID)Type, value); g_Settings->SaveString((SettingID)Type, value);
CSettings::FlushSettings(g_Settings);
WriteTrace(TraceUserInterface, TraceDebug, "Saved"); WriteTrace(TraceUserInterface, TraceDebug, "Saved");
env->ReleaseStringUTFChars(Buffer, value); env->ReleaseStringUTFChars(Buffer, value);
} }
@ -281,9 +287,21 @@ EXPORT void CALL Java_emu_project64_jni_NativeExports_ExternalEvent(JNIEnv* env,
EXPORT void CALL Java_emu_project64_jni_NativeExports_onSurfaceCreated(JNIEnv * env, jclass cls) EXPORT void CALL Java_emu_project64_jni_NativeExports_onSurfaceCreated(JNIEnv * env, jclass cls)
{ {
WriteTrace(TraceUserInterface, TraceDebug, "Start"); WriteTrace(TraceUserInterface, TraceDebug, "Start");
if (g_Plugins != NULL && g_Plugins->Gfx() != NULL && g_Plugins->Gfx()->SurfaceCreated) if (g_BaseSystem != NULL && g_BaseSystem->GetPlugins() != NULL && g_BaseSystem->GetPlugins()->Gfx() != NULL)
{ {
g_Plugins->Gfx()->SurfaceCreated(); CGfxPlugin * GfxPlugin = g_BaseSystem->GetPlugins()->Gfx();
if (GfxPlugin->SurfaceCreated != NULL)
{
GfxPlugin->SurfaceCreated();
}
}
if (g_SyncSystem != NULL && g_SyncSystem->GetPlugins() != NULL && g_SyncSystem->GetPlugins()->Gfx() != NULL)
{
CGfxPlugin * GfxPlugin = g_SyncSystem->GetPlugins()->Gfx();
if (GfxPlugin->SurfaceCreated != NULL)
{
GfxPlugin->SurfaceCreated();
}
} }
WriteTrace(TraceUserInterface, TraceDebug, "Done"); WriteTrace(TraceUserInterface, TraceDebug, "Done");
} }
@ -291,9 +309,21 @@ EXPORT void CALL Java_emu_project64_jni_NativeExports_onSurfaceCreated(JNIEnv *
EXPORT void CALL Java_emu_project64_jni_NativeExports_onSurfaceChanged(JNIEnv * env, jclass cls, jint width, jint height) EXPORT void CALL Java_emu_project64_jni_NativeExports_onSurfaceChanged(JNIEnv * env, jclass cls, jint width, jint height)
{ {
WriteTrace(TraceUserInterface, TraceDebug, "Start"); WriteTrace(TraceUserInterface, TraceDebug, "Start");
if (g_Plugins != NULL && g_Plugins->Gfx() != NULL && g_Plugins->Gfx()->SurfaceChanged) if (g_BaseSystem != NULL && g_BaseSystem->GetPlugins() != NULL && g_BaseSystem->GetPlugins()->Gfx() != NULL)
{ {
g_Plugins->Gfx()->SurfaceChanged(width,height); CGfxPlugin * GfxPlugin = g_BaseSystem->GetPlugins()->Gfx();
if (GfxPlugin->SurfaceChanged != NULL)
{
GfxPlugin->SurfaceChanged(width,height);
}
}
if (g_SyncSystem != NULL && g_SyncSystem->GetPlugins() != NULL && g_SyncSystem->GetPlugins()->Gfx() != NULL)
{
CGfxPlugin * GfxPlugin = g_SyncSystem->GetPlugins()->Gfx();
if (GfxPlugin->SurfaceChanged != NULL)
{
GfxPlugin->SurfaceChanged(width,height);
}
} }
WriteTrace(TraceUserInterface, TraceDebug, "Done"); WriteTrace(TraceUserInterface, TraceDebug, "Done");
} }
@ -341,7 +371,7 @@ EXPORT void CALL Java_emu_project64_jni_NativeExports_StartEmulation(JNIEnv* env
EXPORT void CALL Java_emu_project64_jni_NativeExports_CloseSystem(JNIEnv* env, jclass cls) EXPORT void CALL Java_emu_project64_jni_NativeExports_CloseSystem(JNIEnv* env, jclass cls)
{ {
WriteTrace(TraceUserInterface, TraceDebug, "Start"); WriteTrace(TraceUserInterface, TraceDebug, "Start");
CN64System::CloseSystem(); g_BaseSystem->EndEmulation();
WriteTrace(TraceUserInterface, TraceDebug, "Done"); WriteTrace(TraceUserInterface, TraceDebug, "Done");
} }