[Android] Fixes Bug 2031 - Backspace Not Sending Events From On-Screen Keyboard
authorGabriel Jacobo <gabomdq@gmail.com>
Mon, 11 Nov 2013 10:59:15 -0300
changeset 7958 b8f431cd7819
parent 7957 5d9563c4f4b6
child 7959 fb3307cd5609
[Android] Fixes Bug 2031 - Backspace Not Sending Events From On-Screen Keyboard Thanks Joe LeVeque!
android-project/src/org/libsdl/app/SDLActivity.java
--- a/android-project/src/org/libsdl/app/SDLActivity.java	Mon Nov 11 10:49:48 2013 -0300
+++ b/android-project/src/org/libsdl/app/SDLActivity.java	Mon Nov 11 10:59:15 2013 -0300
@@ -825,6 +825,17 @@
 
     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) */