aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtyom Palvelev <artyompp@google.com>2024-04-02 14:47:16 +0100
committerArtyom Palvelev <artyompp@google.com>2024-04-02 14:47:16 +0100
commitea1a3965f1d9e662e3ea03a0f306931ffbdcb440 (patch)
tree6dd4f1ed38222db7a8ff1416001fa3439f3a9eba
parentfeac0cf0fc08a685b43219306bd383d2a51077d1 (diff)
downloadgamesdk-master.tar.gz
add error handling in GameTextInputHEADmastermain
With some IMEs window insets might be null sometimes, so we have to take this into account. Fix: 314924320 Test: build and run AGDKTunnel Change-Id: I3f8edb39f1c4cb4a0a5cc61a8dfc4e4fb52015a8
-rw-r--r--game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java18
1 files changed, 18 insertions, 0 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 70527626..2de0f9d5 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
@@ -601,7 +601,16 @@ public class InputConnection
* @return The current IME insets
*/
public Insets getImeInsets() {
+ if (this.targetView == null) {
+ return Insets.NONE;
+ }
+
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(this.targetView);
+
+ if (insets == null) {
+ return Insets.NONE;
+ }
+
return insets.getInsets(WindowInsetsCompat.Type.ime());
}
@@ -611,7 +620,16 @@ public class InputConnection
* @return whether software IME is visible or not.
*/
public boolean isSoftwareKeyboardVisible() {
+ if (this.targetView == null) {
+ return false;
+ }
+
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(this.targetView);
+
+ if (insets == null) {
+ return false;
+ }
+
return insets.isVisible(WindowInsetsCompat.Type.ime());
}