From 267b9174eb147615785bb97669403cf8bc1bee24 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 13:28:55 +0200 Subject: [PATCH] Show the soft keyboard provided by Android without a text field for pure text input for editing the name of the savegame. --- project/java/MainActivity.java | 6 ++++++ project/java/Video.java | 15 +++++++++++++++ .../jni/application/opentyrian/src/mainint.cpp | 9 ++++++++- project/jni/sdl-1.2/include/SDL_screenkeyboard.h | 3 +++ .../sdl-1.3/src/video/android/SDL_androidvideo.c | 7 +++++++ .../sdl-1.3/src/video/android/SDL_androidvideo.h | 1 + 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 60e3b2e81..3272a75ef 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -307,6 +307,12 @@ public class MainActivity extends Activity { System.exit(0); } + public void togglePlainAndroidSoftKeyboardInput() + { + InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + public void showScreenKeyboard(final String oldText, boolean sendBackspace) { if(Globals.CompatibilityHacksTextInputEmulatesHwKeyboard) diff --git a/project/java/Video.java b/project/java/Video.java index 040ffe5ea..c47ca947d 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -524,6 +524,21 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer return 1; } + public void togglePlainAndroidSoftKeyboardInput() // Called from native code + { + class Callback implements Runnable + { + public MainActivity parent; + public void run() + { + parent.togglePlainAndroidSoftKeyboardInput(); + } + } + Callback cb = new Callback(); + cb.parent = context; + context.runOnUiThread(cb); + } + public void showScreenKeyboard(final String oldText, int sendBackspace) // Called from native code { class Callback implements Runnable diff --git a/project/jni/application/opentyrian/src/mainint.cpp b/project/jni/application/opentyrian/src/mainint.cpp index fd227731f..ef5206503 100644 --- a/project/jni/application/opentyrian/src/mainint.cpp +++ b/project/jni/application/opentyrian/src/mainint.cpp @@ -48,6 +48,8 @@ #include "vga256d.h" #include "video.h" +#include "SDL_screenkeyboard.h" + #include #include @@ -2398,7 +2400,9 @@ void JE_operation( JE_byte slot ) wait_noinput(false, true, false); JE_barShade(VGAScreen, 65, 55, 255, 155); - +#ifdef ANDROID + SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput(); +#endif bool quit = false; while (!quit) { @@ -2510,6 +2514,9 @@ void JE_operation( JE_byte slot ) case SDLK_RETURN: case SDLK_SPACE: quit = true; +#ifdef ANDROID + SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput(); +#endif JE_saveGame(slot, stemp); JE_playSampleNum(S_SELECT); break; diff --git a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h index 2cc3aa7c3..016a0abf9 100644 --- a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h +++ b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h @@ -105,6 +105,9 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBu /* Whether user redefined on-screen keyboard layout via SDL menu, app should not enforce it's own layout in that case */ extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardRedefinedByUser(); +/* Show only the bare Android on-screen keyboard without any text input field */ +extern DECLSPEC void SDLCALL SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput(); + #ifdef __cplusplus } #endif diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c index 4271c3bb0..0db87265d 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c @@ -61,6 +61,7 @@ static jclass JavaRendererClass = NULL; static jobject JavaRenderer = NULL; static jmethodID JavaSwapBuffers = NULL; static jmethodID JavaShowScreenKeyboard = NULL; +static jmethodID JavaTogglePlainAndroidSoftKeyboardInput = NULL; static int glContextLost = 0; static int showScreenKeyboardDeferred = 0; static const char * showScreenKeyboardOldText = ""; @@ -225,6 +226,11 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeGlContextRecreated) ( JNIEnv* env, jobject #endif } +void SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput() +{ + (*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaTogglePlainAndroidSoftKeyboardInput ); +} + volatile static textInputFinished = 0; void SDL_ANDROID_TextInputFinished() { @@ -283,6 +289,7 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject t JavaRendererClass = (*JavaEnv)->GetObjectClass(JavaEnv, thiz); JavaSwapBuffers = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "swapBuffers", "()I"); JavaShowScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showScreenKeyboard", "(Ljava/lang/String;I)V"); + JavaTogglePlainAndroidSoftKeyboardInput = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "togglePlainAndroidSoftKeyboardInput", "()V"); ANDROID_InitOSKeymap(); } diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h index bca181dce..57216978e 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h @@ -68,6 +68,7 @@ extern void SDL_ANDROID_ProcessDeferredEvents(); extern void SDL_ANDROID_WarpMouse(int x, int y); extern void SDL_ANDROID_DrawMouseCursor(int x, int y, int size, int alpha); extern void SDL_ANDROID_DrawMouseCursorIfNeeded(); +extern void SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput(); #if SDL_VERSION_ATLEAST(1,3,0)