From 418ab79db8f139a21348347755bc0cc0ce59e4b6 Mon Sep 17 00:00:00 2001 From: pelya Date: Mon, 28 Feb 2011 11:16:47 +0000 Subject: [PATCH] Do not send Backspace keycode for text input invoked with SDL_ANDROID_GetScreenKeyboardTextInput() --- project/java/MainActivity.java | 18 ++++++------------ project/java/Video.java | 6 ++++-- .../ballfield/AndroidAppSettings.cfg | 2 +- .../src/video/android/SDL_androidvideo.c | 9 ++++++--- .../video/android/SDL_touchscreenkeyboard.c | 2 ++ 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 812e396cc..153d88df5 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -250,32 +250,26 @@ public class MainActivity extends Activity { mGLView.requestFocus(); }; - public void showScreenKeyboard(final String oldText) + public void showScreenKeyboard(final String oldText, boolean sendBackspace) { if(_screenKeyboard != null) return; class myKeyListener implements OnKeyListener { MainActivity _parent; - myKeyListener(MainActivity parent) { _parent = parent; }; + boolean sendBackspace; + myKeyListener(MainActivity parent, boolean sendBackspace) { _parent = parent; this.sendBackspace = sendBackspace; }; public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_UP) && ((keyCode == KeyEvent.KEYCODE_ENTER) || (keyCode == KeyEvent.KEYCODE_BACK))) { _parent.hideScreenKeyboard(); - if(keyCode == KeyEvent.KEYCODE_ENTER) - { - synchronized(textInput) - { - //DemoRenderer.nativeTextInput( 13, 13 ); // send return - } - } return true; } - if ((event.getAction() == KeyEvent.ACTION_UP) && (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_CLEAR)) + if ((sendBackspace && event.getAction() == KeyEvent.ACTION_UP) && (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_CLEAR)) { synchronized(textInput) { - DemoRenderer.nativeTextInput( 8, 8 ); + DemoRenderer.nativeTextInput( 8, 8 ); // Send backspace to native code } return false; // and proceed to delete text in keyboard input field } @@ -283,7 +277,7 @@ public class MainActivity extends Activity { } }; _screenKeyboard = new EditText(this); - _screenKeyboard.setOnKeyListener(new myKeyListener(this)); + _screenKeyboard.setOnKeyListener(new myKeyListener(this, sendBackspace)); _screenKeyboard.setHint(R.string.text_edit_click_here); _screenKeyboard.setText(oldText); _videoLayout.addView(_screenKeyboard); diff --git a/project/java/Video.java b/project/java/Video.java index e188d1d62..cfbc517bf 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -253,20 +253,22 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer { return 1; } - public void showScreenKeyboard(final String oldText) // Called from native code + public void showScreenKeyboard(final String oldText, int sendBackspace) // Called from native code { class Callback implements Runnable { public MainActivity parent; public String oldText; + public boolean sendBackspace; public void run() { - parent.showScreenKeyboard(oldText); + parent.showScreenKeyboard(oldText, sendBackspace); } } Callback cb = new Callback(); cb.parent = context; cb.oldText = oldText; + cb.sendBackspace = (sendBackspace != 0); context.runOnUiThread(cb); } diff --git a/project/jni/application/ballfield/AndroidAppSettings.cfg b/project/jni/application/ballfield/AndroidAppSettings.cfg index 0471859bd..bf049c5c7 100644 --- a/project/jni/application/ballfield/AndroidAppSettings.cfg +++ b/project/jni/application/ballfield/AndroidAppSettings.cfg @@ -2,7 +2,7 @@ AppSettingVersion=17 LibSdlVersion=1.2 AppName="Ballfield" -AppFullName=net.olofson.ballfield.v426 +AppFullName=net.olofson.ballfield ScreenOrientation=h InhibitSuspend=n AppDataDownloadUrl="Game data is 1 Mb|ballfield.zip" 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 986b6bb8b..afa913b58 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 @@ -64,6 +64,7 @@ static jmethodID JavaShowScreenKeyboard = NULL; static int glContextLost = 0; static int showScreenKeyboardDeferred = 0; static const char * showScreenKeyboardOldText = ""; +static int showScreenKeyboardSendBackspace = 0; int SDL_ANDROID_SmoothVideo = 0; int SDL_ANDROID_VideoMultithreaded = 0; @@ -118,7 +119,7 @@ int SDL_ANDROID_CallJavaSwapBuffers() if( showScreenKeyboardDeferred ) { showScreenKeyboardDeferred = 0; - (*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, (*JavaEnv)->NewStringUTF(JavaEnv, showScreenKeyboardOldText) ); + (*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, (*JavaEnv)->NewStringUTF(JavaEnv, showScreenKeyboardOldText), showScreenKeyboardSendBackspace ); } SDL_ANDROID_ProcessDeferredEvents(); return 1; @@ -229,6 +230,7 @@ void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, { showScreenKeyboardDeferred = 1; showScreenKeyboardOldText = oldText; + showScreenKeyboardSendBackspace = 1; // Move mouse by 1 pixel to force screen update int x, y; SDL_GetMouseState( &x, &y ); @@ -246,11 +248,12 @@ void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, // Dirty hack: we may call (*JavaEnv)->CallVoidMethod(...) only from video thread showScreenKeyboardDeferred = 1; showScreenKeyboardOldText = oldText; + showScreenKeyboardSendBackspace = 0; SDL_Flip(SDL_GetVideoSurface()); #endif } else - (*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, (*JavaEnv)->NewStringUTF(JavaEnv, oldText) ); + (*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, (*JavaEnv)->NewStringUTF(JavaEnv, oldText), 0 ); while( !textInputFinished ) SDL_Delay(100); @@ -266,7 +269,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;)V"); + JavaShowScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showScreenKeyboard", "(Ljava/lang/String;I)V"); ANDROID_InitOSKeymap(); diff --git a/project/jni/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c b/project/jni/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c index b49dc1a9e..2c7058aa0 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c @@ -789,6 +789,8 @@ int SDL_ANDROID_GetScreenKeyboardSize() int SDL_ANDROID_ToggleScreenKeyboardTextInput(const char * previousText) { static char textIn[255]; + if( previousText == NULL ) + previousText = ""; strncpy(textIn, previousText, sizeof(textIn)); textIn[sizeof(textIn)-1] = 0; SDL_ANDROID_CallJavaShowScreenKeyboard(textIn, NULL, 0);