Fixed bug 2415 - Message Boxes aren't implemented on Android
Philipp Wiesemann I attached a patch for an incomplete implementation of the messagebox parts. It was not tested on lots of devices yet and features a very fragile workaround to block the calling SDL thread while the dialog is handled on Android's UI thread. Although it works for testmessage.c I assume there are lot of situations were it may fail (standby, device rotation and other changes). Also not all flags and colors are implemented. On the other hand most uses of the messagebox are to show an error on start and fragility (or working at all) may not matter there.
This commit is contained in:
parent
f464f677f2
commit
56f86cc81f
5 changed files with 351 additions and 0 deletions
|
@ -1342,6 +1342,85 @@ void Android_JNI_HideTextInput()
|
|||
Android_JNI_SendMessage(COMMAND_TEXTEDIT_HIDE, 0);
|
||||
}
|
||||
|
||||
int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||
{
|
||||
JNIEnv *env;
|
||||
jmethodID mid;
|
||||
jobject context;
|
||||
jstring title;
|
||||
jstring message;
|
||||
jintArray button_flags;
|
||||
jintArray button_ids;
|
||||
jobjectArray button_texts;
|
||||
jintArray colors;
|
||||
jint temp;
|
||||
int i;
|
||||
|
||||
env = Android_JNI_GetEnv();
|
||||
|
||||
/* convert parameters */
|
||||
|
||||
title = (*env)->NewStringUTF(env, messageboxdata->title);
|
||||
message = (*env)->NewStringUTF(env, messageboxdata->message);
|
||||
|
||||
button_flags = (*env)->NewIntArray(env, messageboxdata->numbuttons);
|
||||
button_ids = (*env)->NewIntArray(env, messageboxdata->numbuttons);
|
||||
button_texts = (*env)->NewObjectArray(env, messageboxdata->numbuttons,
|
||||
(*env)->FindClass(env, "java/lang/String"), NULL);
|
||||
for (i = 0; i < messageboxdata->numbuttons; ++i) {
|
||||
temp = messageboxdata->buttons[i].flags;
|
||||
(*env)->SetIntArrayRegion(env, button_flags, i, 1, &temp);
|
||||
temp = messageboxdata->buttons[i].buttonid;
|
||||
(*env)->SetIntArrayRegion(env, button_ids, i, 1, &temp);
|
||||
(*env)->SetObjectArrayElement(env, button_texts, i, (*env)->NewStringUTF(env, messageboxdata->buttons[i].text));
|
||||
}
|
||||
|
||||
if (messageboxdata->colorScheme) {
|
||||
colors = (*env)->NewIntArray(env, SDL_MESSAGEBOX_COLOR_MAX);
|
||||
for (i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; ++i) {
|
||||
temp = (0xFF << 24) |
|
||||
(messageboxdata->colorScheme->colors[i].r << 16) |
|
||||
(messageboxdata->colorScheme->colors[i].g << 8) |
|
||||
(messageboxdata->colorScheme->colors[i].b << 0);
|
||||
(*env)->SetIntArrayRegion(env, colors, i, 1, &temp);
|
||||
}
|
||||
} else {
|
||||
colors = NULL;
|
||||
}
|
||||
|
||||
/* call function */
|
||||
|
||||
mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;");
|
||||
|
||||
context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
|
||||
|
||||
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
|
||||
"messageboxShowMessageBox", "(ILjava/lang/String;Ljava/lang/String;[I[I[Ljava/lang/String;[I)I");
|
||||
*buttonid = (*env)->CallIntMethod(env, context, mid,
|
||||
messageboxdata->flags,
|
||||
title,
|
||||
message,
|
||||
button_flags,
|
||||
button_ids,
|
||||
button_texts,
|
||||
colors);
|
||||
|
||||
/* delete parameters */
|
||||
|
||||
(*env)->DeleteLocalRef(env, title);
|
||||
(*env)->DeleteLocalRef(env, message);
|
||||
(*env)->DeleteLocalRef(env, button_flags);
|
||||
(*env)->DeleteLocalRef(env, button_ids);
|
||||
for (i = 0; i < messageboxdata->numbuttons; ++i) {
|
||||
(*env)->DeleteLocalRef(env, (*env)->GetObjectArrayElement(env, button_texts, i));
|
||||
(*env)->SetObjectArrayElement(env, button_texts, i, NULL);
|
||||
}
|
||||
(*env)->DeleteLocalRef(env, button_texts);
|
||||
(*env)->DeleteLocalRef(env, colors);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
|
|
@ -3265,6 +3265,9 @@ SDL_IsScreenKeyboardShown(SDL_Window *window)
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
#if SDL_VIDEO_DRIVER_ANDROID
|
||||
#include "android/SDL_androidmessagebox.h"
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
#include "windows/SDL_windowsmessagebox.h"
|
||||
#endif
|
||||
|
@ -3329,6 +3332,12 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
}
|
||||
|
||||
/* It's completely fine to call this function before video is initialized */
|
||||
#if SDL_VIDEO_DRIVER_ANDROID
|
||||
if (retval == -1 &&
|
||||
Android_ShowMessageBox(messageboxdata, buttonid) == 0) {
|
||||
retval = 0;
|
||||
}
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
if (retval == -1 &&
|
||||
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINDOWS) &&
|
||||
|
|
37
src/video/android/SDL_androidmessagebox.c
Normal file
37
src/video/android/SDL_androidmessagebox.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_ANDROID
|
||||
|
||||
#include "SDL_messagebox.h"
|
||||
|
||||
int
|
||||
Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||
{
|
||||
int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
|
||||
|
||||
return Android_JNI_ShowMessageBox(messageboxdata, buttonid);
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_ANDROID */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
29
src/video/android/SDL_androidmessagebox.h
Normal file
29
src/video/android/SDL_androidmessagebox.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_ANDROID
|
||||
|
||||
extern int Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_ANDROID */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
Loading…
Add table
Add a link
Reference in a new issue