Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Merge branch 'skmp/android-msgbox' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
skmp committed Feb 1, 2020
2 parents 436c0b9 + 3308aec commit 77b6b97
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 7 deletions.
25 changes: 24 additions & 1 deletion libswirl/android/Android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ static jobject g_activity;
static jmethodID VJoyStartEditingMID;
static jmethodID VJoyStopEditingMID;
static jmethodID VJoyResetEditingMID;
static jmethodID MsgboxMID;

JNIEXPORT void JNICALL Java_com_reicast_emulator_BaseGLActivity_register(JNIEnv *env, jobject obj, jobject activity)
{
Expand All @@ -651,11 +652,13 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_BaseGLActivity_register(JNIEnv
env->DeleteGlobalRef(g_activity);
g_activity = NULL;
}

if (activity != NULL) {
g_activity = env->NewGlobalRef(activity);
VJoyStartEditingMID = env->GetMethodID(env->GetObjectClass(activity), "VJoyStartEditing", "()V");
VJoyStopEditingMID = env->GetMethodID(env->GetObjectClass(activity), "VJoyStopEditing", "(Z)V");
VJoyResetEditingMID = env->GetMethodID(env->GetObjectClass(activity), "VJoyResetEditing", "()V");
MsgboxMID = env->GetMethodID(env->GetObjectClass(activity), "Msgbox", "(Ljava/lang/String;I)I");
}
}

Expand Down Expand Up @@ -694,4 +697,24 @@ bool os_gl_swap()
void os_gl_term()
{
return egl_Term();
}
}

#if defined(_ANDROID)
int msgboxf(const wchar* text, unsigned int type, ...) {
va_list args;

wchar temp[2048];
va_start(args, type);
vsnprintf(temp, sizeof(temp), text, args);
va_end(args);
printf("msgbox(%d) %s\n", type, temp);

auto jstr = jvm_attacher.getEnv()->NewStringUTF(temp);

auto rv = jvm_attacher.getEnv()->CallIntMethod(g_activity, MsgboxMID, jstr, type);

jvm_attacher.getEnv()->DeleteLocalRef(jstr);

return rv;
}
#endif
5 changes: 3 additions & 2 deletions libswirl/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ GUI* GUI::Create() {
return new ReicastUI_impl();
}


#if !defined(_ANDROID)
int msgboxf(const wchar* text, unsigned int type, ...) {
va_list args;

Expand All @@ -1057,4 +1057,5 @@ int msgboxf(const wchar* text, unsigned int type, ...) {
g_GUI->DisplayNotification(temp, 2000);

return 1;
}
}
#endif
2 changes: 1 addition & 1 deletion libswirl/linux/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extern "C" u8* generic_fault_handler ()
}
else
{
fault_printf("generic_fault_handler: not in handled SIGSEGV pc: %lx addr:%p\n", ctx.pc, (void*)trap_si_addr);
fault_printf("generic_fault_handler: not in handled SIGSEGV pc: %lx addr:%p here %p\n", ctx.pc, (void*)trap_si_addr, (void*)generic_fault_handler);
trap_handled = false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.reicast.emulator;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
Expand Down Expand Up @@ -46,13 +49,13 @@ public boolean isSurfaceReady() {
}

// Called from native code
private void VJoyStartEditing() {
public void VJoyStartEditing() {
vjoy_d_cached = VJoy.readCustomVjoyValues(getApplicationContext());
JNIdc.show_osd();
((NativeGLView)mView).setEditVjoyMode(true);
}
// Called from native code
private void VJoyResetEditing() {
public void VJoyResetEditing() {
VJoy.resetCustomVjoyValues(getApplicationContext());
((NativeGLView)mView).readCustomVjoyValues();
((NativeGLView)mView).resetEditMode();
Expand All @@ -68,9 +71,53 @@ public void run() {
});
}
// Called from native code
private void VJoyStopEditing(boolean canceled) {
public void VJoyStopEditing(boolean canceled) {
if (canceled)
((NativeGLView)mView).restoreCustomVjoyValues(vjoy_d_cached);
((NativeGLView)mView).setEditVjoyMode(false);
}

class ReadyState { public boolean value = false; }

public int Msgbox(final String text, final int type) {

final ReadyState ready = new ReadyState();

final Activity activity = this;

new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);

String msg = text;

if ((type & 0x10) != 0) { /* MBX_ICONERROR */
msg += "\n" + R.string.msgbox_please_report;
}

builder.setMessage(msg).setPositiveButton(R.string.msgbox_okay, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
synchronized (ready) {
ready.value = true;
ready.notify();
}
}
});
builder.create().show();
}
});

try
{
synchronized (ready) {
while (!ready.value)
ready.wait();
}
} catch(InterruptedException is) {

}

return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="msgbox_please_report">Please send a screenshot of this to the Reicast Team</string>
<string name="msgbox_okay">Okay</string>
</resources>

0 comments on commit 77b6b97

Please sign in to comment.