diff options
author | Artyom Palvelev <artyompp@google.com> | 2023-09-08 15:21:21 +0100 |
---|---|---|
committer | Artyom Palvelev <artyompp@google.com> | 2023-09-08 15:21:21 +0100 |
commit | d6782dca9bd861dd159eb3ccf760f0b746d0500a (patch) | |
tree | 7f6c9f8986b863f70e5690605cf1998cc7c5efe2 | |
parent | 6af5fd85f8d0069e9cd5cd96eb75a0ce07c6c8a6 (diff) | |
download | gamesdk-d6782dca9bd861dd159eb3ccf760f0b746d0500a.tar.gz |
make GameTextInput use default implementations from BaseInputConnection
Default versions of getSelectedText, getTextAfterCursor,
getTextBeforeCursor contain more safety checks, so we drop our custom
implementation of these functions in favor of default implementations.
Bug: 298945353
Test: build and run AGDKTunnel sample, test text input
Change-Id: I96340b0ae2475760898d83a1756f95e2f11c9ce6
-rw-r--r-- | game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java b/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java index 3d0f05a7..7d5d7c6d 100644 --- a/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java +++ b/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java @@ -322,27 +322,18 @@ public class InputConnection @Override public boolean deleteSurroundingText(int beforeLength, int afterLength) { Log.d(TAG, "deleteSurroundingText: " + beforeLength + ":" + afterLength); - Pair selection = this.getSelection(); - int shift = 0; - if (beforeLength > 0) { - this.mEditable.delete(Math.max(0, selection.first - beforeLength), selection.first); - shift = beforeLength; - } - - if (afterLength > 0) { - this.mEditable.delete(Math.max(0, selection.second - shift), - Math.min(this.mEditable.length(), selection.second - shift + afterLength)); - } - + boolean res = super.deleteSurroundingText(beforeLength, afterLength); this.stateUpdated(false); - return true; + return res; } // From BaseInputConnection @Override public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) { Log.d(TAG, "deleteSurroundingTextInCodePoints: " + beforeLength + ":" + afterLength); - return super.deleteSurroundingTextInCodePoints(beforeLength, afterLength); + boolean res = super.deleteSurroundingTextInCodePoints(beforeLength, afterLength); + this.stateUpdated(false); + return res; } // From BaseInputConnection @@ -358,37 +349,30 @@ public class InputConnection // From BaseInputConnection @Override public CharSequence getSelectedText(int flags) { - Pair selection = this.getSelection(); - return selection.first == -1 ? (CharSequence) "" - : this.mEditable.subSequence(selection.first, selection.second); + Log.d(TAG, "getSelectedText: " + flags); + return super.getSelectedText(flags); } // From BaseInputConnection @Override public CharSequence getTextAfterCursor(int length, int flags) { Log.d(TAG, "getTextAfterCursor: " + length + ":" + flags); - Pair selection = this.getSelection(); - if (selection.first == -1) { - return (CharSequence) ""; - } else { - int n = Math.min(selection.second + length, this.mEditable.length()); - CharSequence seq = this.mEditable.subSequence(selection.second, n); - return (CharSequence) seq.toString(); + if (length < 0) { + Log.i(TAG, "getTextAfterCursor: returning null to due to an invalid length=" + length); + return null; } + return super.getTextAfterCursor(length, flags); } // From BaseInputConnection @Override public CharSequence getTextBeforeCursor(int length, int flags) { Log.d(TAG, "getTextBeforeCursor: " + length + ", flags=" + flags); - Pair selection = this.getSelection(); - if (selection.first == -1) { - return (CharSequence) ""; - } else { - int start = Math.max(selection.first - length, 0); - CharSequence seq = this.mEditable.subSequence(start, selection.first); - return (CharSequence) seq.toString(); + if (length < 0) { + Log.i(TAG, "getTextBeforeCursor: returning null to due to an invalid length=" + length); + return null; } + return super.getTextBeforeCursor(length, flags); } // From BaseInputConnection |