Fixed bug 2265 - Voice to text feature on Android repeats some text via SDL_TEXTINPUT
authorSam Lantinga <slouken@libsdl.org>
Sun, 27 Aug 2017 18:36:54 -0700
changeset 11354323fc605104f
parent 11353 598839965877
child 11355 6185fb86f046
Fixed bug 2265 - Voice to text feature on Android repeats some text via SDL_TEXTINPUT

Sylvain

Small patch for this issue. I tested it and it seems to work.

- it can send several backspaces (instead of only 1).
- it calls directly "sendKeyEvent()" instead of "super.sendKeyEvent()".
otherwise, it would go through the android internals, calling again "onKey()".
and then the "backspace" would arrive after the next "commitText()".
android-project/src/org/libsdl/app/SDLActivity.java
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Sat Aug 26 21:17:12 2017 -0700
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Sun Aug 27 18:36:54 2017 -0700
     1.3 @@ -1683,10 +1683,16 @@
     1.4      @Override
     1.5      public boolean deleteSurroundingText(int beforeLength, int afterLength) {
     1.6          // Workaround to capture backspace key. Ref: http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection
     1.7 -        if (beforeLength == 1 && afterLength == 0) {
     1.8 -            // backspace
     1.9 -            return super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
    1.10 -                && super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
    1.11 +        // and https://bugzilla.libsdl.org/show_bug.cgi?id=2265
    1.12 +        if (beforeLength > 0 && afterLength == 0) {
    1.13 +            boolean ret = true;
    1.14 +            // backspace(s)
    1.15 +            while (beforeLength-- > 0) {
    1.16 +               boolean ret_key = sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
    1.17 +                              && sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
    1.18 +               ret = ret && ret_key; 
    1.19 +            }
    1.20 +            return ret;
    1.21          }
    1.22  
    1.23          return super.deleteSurroundingText(beforeLength, afterLength);