[Android] Update Android bridge for notification
This commit is contained in:
parent
c39937f63c
commit
a277fc0a60
|
@ -15,7 +15,7 @@
|
|||
|
||||
#ifdef ANDROID
|
||||
JavaBridge::JavaBridge(JavaVM* vm) :
|
||||
m_vm(vm)
|
||||
m_vm(vm)
|
||||
{
|
||||
JNIEnv *env = Android_JNI_GetEnv();
|
||||
jclass GalleryActivityClass = env->FindClass("emu/project64/GalleryActivity");
|
||||
|
@ -34,13 +34,13 @@ void JavaBridge::GfxThreadInit()
|
|||
{
|
||||
WriteTrace(TraceUserInterface, TraceDebug, "Start");
|
||||
JNIEnv *env = Android_JNI_GetEnv();
|
||||
if (g_GLThread != NULL && env != NULL)
|
||||
{
|
||||
jclass GLThreadClass = env->GetObjectClass(g_GLThread);
|
||||
jmethodID midThreadStarting = env->GetMethodID(GLThreadClass, "ThreadStarting", "()V");
|
||||
if (g_GLThread != NULL && env != NULL)
|
||||
{
|
||||
jclass GLThreadClass = env->GetObjectClass(g_GLThread);
|
||||
jmethodID midThreadStarting = env->GetMethodID(GLThreadClass, "ThreadStarting", "()V");
|
||||
env->CallVoidMethod(g_GLThread, midThreadStarting);
|
||||
env->DeleteLocalRef(GLThreadClass);
|
||||
}
|
||||
env->DeleteLocalRef(GLThreadClass);
|
||||
}
|
||||
WriteTrace(TraceUserInterface, TraceDebug, "Done");
|
||||
}
|
||||
|
||||
|
@ -48,14 +48,14 @@ void JavaBridge::GfxThreadDone()
|
|||
{
|
||||
WriteTrace(TraceUserInterface, TraceDebug, "Start");
|
||||
JNIEnv *env = Android_JNI_GetEnv();
|
||||
if (g_GLThread != NULL && env != NULL)
|
||||
{
|
||||
if (g_GLThread != NULL && env != NULL)
|
||||
{
|
||||
WriteTrace(TraceUserInterface, TraceDebug, "calling java GLThread::ThreadExiting");
|
||||
jclass GLThreadClass = env->GetObjectClass(g_GLThread);
|
||||
jmethodID midThreadExiting = env->GetMethodID(GLThreadClass, "ThreadExiting", "()V");
|
||||
env->CallVoidMethod(g_GLThread, midThreadExiting);
|
||||
env->DeleteLocalRef(GLThreadClass);
|
||||
}
|
||||
jclass GLThreadClass = env->GetObjectClass(g_GLThread);
|
||||
jmethodID midThreadExiting = env->GetMethodID(GLThreadClass, "ThreadExiting", "()V");
|
||||
env->CallVoidMethod(g_GLThread, midThreadExiting);
|
||||
env->DeleteLocalRef(GLThreadClass);
|
||||
}
|
||||
WriteTrace(TraceUserInterface, TraceDebug, "Done");
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ void JavaBridge::SwapWindow()
|
|||
{
|
||||
JNIEnv *env = Android_JNI_GetEnv();
|
||||
if (g_GLThread != NULL && env != NULL)
|
||||
{
|
||||
{
|
||||
jclass GLThreadClass = env->GetObjectClass(g_GLThread);
|
||||
jmethodID midSwapBuffers = env->GetMethodID(GLThreadClass, "SwapBuffers", "()V");
|
||||
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)
|
||||
{
|
||||
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");
|
||||
env->CallStaticVoidMethod(m_NotifierClass, midEmulationStopped, g_Activity);
|
||||
}
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
#include <Project64-core/Plugins/PluginClass.h>
|
||||
#include <jni.h>
|
||||
|
||||
class JavaBridge :
|
||||
public RenderWindow
|
||||
class JavaBridge :
|
||||
public RenderWindow
|
||||
{
|
||||
public:
|
||||
JavaBridge (JavaVM* vm);
|
||||
JavaBridge (JavaVM* vm);
|
||||
|
||||
//Render window functions
|
||||
void GfxThreadInit();
|
||||
void GfxThreadInit();
|
||||
void GfxThreadDone();
|
||||
void SwapWindow();
|
||||
|
||||
|
@ -24,14 +24,15 @@ public:
|
|||
//Notification
|
||||
void DisplayError(const char * Message);
|
||||
void DisplayMessage(const char * Message);
|
||||
void DisplayMessage2(const char * Message);
|
||||
void EmulationStopped(void);
|
||||
|
||||
private:
|
||||
JavaBridge(void); // Disable default constructor
|
||||
JavaBridge(const JavaBridge&); // Disable copy constructor
|
||||
JavaBridge(void); // Disable default constructor
|
||||
JavaBridge(const JavaBridge&); // Disable copy constructor
|
||||
JavaBridge& operator=(const JavaBridge&); // Disable assignment
|
||||
|
||||
JavaVM* m_vm;
|
||||
JavaVM* m_vm;
|
||||
jclass m_GalleryActivityClass;
|
||||
jclass m_NotifierClass;
|
||||
};
|
||||
|
|
|
@ -80,25 +80,23 @@ void CNotificationImp::DisplayMessage(int DisplayTime, LanguageStringID StringID
|
|||
void CNotificationImp::DisplayMessage(int DisplayTime, const char * Message) const
|
||||
{
|
||||
#ifdef ANDROID
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, "PJ64-Bridge", "%s", Message);
|
||||
|
||||
if (g_JavaBridge == NULL) { return; }
|
||||
|
||||
/*if (m_NextMsg > 0 || DisplayTime > 0)
|
||||
{
|
||||
time_t Now = time(NULL);
|
||||
if (DisplayTime == 0 && Now < m_NextMsg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (DisplayTime > 0)
|
||||
{
|
||||
m_NextMsg = Now + DisplayTime;
|
||||
}
|
||||
if (m_NextMsg == 0)
|
||||
{
|
||||
m_NextMsg = 0;
|
||||
}
|
||||
time_t Now = time(NULL);
|
||||
if (DisplayTime == 0 && Now < m_NextMsg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (DisplayTime > 0)
|
||||
{
|
||||
m_NextMsg = Now + DisplayTime;
|
||||
}
|
||||
if (m_NextMsg == 0)
|
||||
{
|
||||
m_NextMsg = 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
g_JavaBridge->DisplayMessage(Message);
|
||||
|
@ -109,8 +107,16 @@ void CNotificationImp::DisplayMessage(int DisplayTime, const char * Message) con
|
|||
#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
|
||||
|
@ -128,7 +134,7 @@ void CNotificationImp::BreakPoint(const char * FileName, int32_t LineNumber)
|
|||
else
|
||||
{
|
||||
FatalError("Fatal Error: Emulation stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CNotificationImp::AppInitDone(void)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "jniBridge.h"
|
||||
#include "jniBridgeSettings.h"
|
||||
#include "JavaBridge.h"
|
||||
#include "SyncBridge.h"
|
||||
#include "UISettings.h"
|
||||
#include "JavaRomList.h"
|
||||
|
||||
|
@ -58,6 +59,7 @@ AndroidLogger * g_Logger = NULL;
|
|||
static pthread_key_t g_ThreadKey;
|
||||
static JavaVM* g_JavaVM = NULL;
|
||||
JavaBridge * g_JavaBridge = NULL;
|
||||
SyncBridge * g_SyncBridge = NULL;
|
||||
jobject g_Activity = NULL;
|
||||
jobject g_GLThread = NULL;
|
||||
|
||||
|
@ -120,7 +122,7 @@ void GameCpuRunning(void * /*NotUsed*/)
|
|||
}
|
||||
env->DeleteGlobalRef(g_GLThread);
|
||||
g_GLThread = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
bool res = AppInit(&Notify(), baseDir, 0, NULL);
|
||||
|
||||
|
||||
env->ReleaseStringUTFChars(BaseDir, baseDir);
|
||||
if (res)
|
||||
{
|
||||
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();
|
||||
|
||||
|
@ -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");
|
||||
g_Settings->SaveBool((SettingID)Type, Value);
|
||||
CSettings::FlushSettings(g_Settings);
|
||||
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);
|
||||
g_Settings->SaveDword((SettingID)Type, Value);
|
||||
CSettings::FlushSettings(g_Settings);
|
||||
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);
|
||||
WriteTrace(TraceUserInterface, TraceDebug, "Saving %d value: %s",Type,value);
|
||||
g_Settings->SaveString((SettingID)Type, value);
|
||||
CSettings::FlushSettings(g_Settings);
|
||||
WriteTrace(TraceUserInterface, TraceDebug, "Saved");
|
||||
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)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
WriteTrace(TraceUserInterface, TraceDebug, "Start");
|
||||
CN64System::CloseSystem();
|
||||
g_BaseSystem->EndEmulation();
|
||||
WriteTrace(TraceUserInterface, TraceDebug, "Done");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue