From 6dbed827a7ba7386006f26e7397fbea4c73f1c57 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Mon, 11 Nov 2013 10:59:15 -0300 Subject: [PATCH] [Android] Fixes Bug 2031 - Backspace Not Sending Events From On-Screen Keyboard Thanks Joe LeVeque! --- android-project/src/org/libsdl/app/SDLActivity.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index d1292ddef9fe3..7c7d63c811cb1 100755 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -825,6 +825,17 @@ public boolean setComposingText(CharSequence text, int newCursorPosition) { public native void nativeSetComposingText(String text, int newCursorPosition); + @Override + public boolean deleteSurroundingText(int beforeLength, int afterLength) { + // Workaround to capture backspace key. Ref: http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection + if (beforeLength == 1 && afterLength == 0) { + // backspace + return super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)) + && super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)); + } + + return super.deleteSurroundingText(beforeLength, afterLength); + } } /* A null joystick handler for API level < 12 devices (the accelerometer is handled separately) */