summaryrefslogtreecommitdiffstats
path: root/platform/android/java/lib/src
diff options
context:
space:
mode:
authorFredia Huya-Kouadio <fhuya@meta.com>2023-08-23 08:40:24 -0700
committerFredia Huya-Kouadio <fhuya@meta.com>2023-08-23 09:57:00 -0700
commit87102e358d71a270ec8792a2aa6c711e9de3b91c (patch)
tree4c668e855c04a5f91a4a9efff163fcbb222bed5b /platform/android/java/lib/src
parent6758a7f8c07d1f4c8ec4f052ded6d26402967ebe (diff)
downloadredot-engine-87102e358d71a270ec8792a2aa6c711e9de3b91c.tar.gz
Fix Android input routing logic when using a hardware keyboard
When a hardware keyboard is connected, all key events come through so we can route them directly to the engine. This is not the case for soft keyboards, for which the current logic was designed as it requires extra processing.
Diffstat (limited to 'platform/android/java/lib/src')
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java
index a7064dfc1d..3070a8a207 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java
@@ -33,6 +33,7 @@ package org.godotengine.godot.input;
import org.godotengine.godot.*;
import android.content.Context;
+import android.content.res.Configuration;
import android.os.Handler;
import android.os.Message;
import android.text.InputFilter;
@@ -209,6 +210,13 @@ public class GodotEditText extends EditText {
mRenderView.getView().requestFocus();
}
+ // When a hardware keyboard is connected, all key events come through so we can route them
+ // directly to the engine.
+ // This is not the case when using a soft keyboard, requiring extra processing from this class.
+ if (hasHardwareKeyboard()) {
+ return mRenderView.getInputHandler().onKeyDown(keyCode, keyEvent);
+ }
+
// pass event to godot in special cases
if (needHandlingInGodot(keyCode, keyEvent) && mRenderView.getInputHandler().onKeyDown(keyCode, keyEvent)) {
return true;
@@ -219,6 +227,13 @@ public class GodotEditText extends EditText {
@Override
public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
+ // When a hardware keyboard is connected, all key events come through so we can route them
+ // directly to the engine.
+ // This is not the case when using a soft keyboard, requiring extra processing from this class.
+ if (hasHardwareKeyboard()) {
+ return mRenderView.getInputHandler().onKeyUp(keyCode, keyEvent);
+ }
+
if (needHandlingInGodot(keyCode, keyEvent) && mRenderView.getInputHandler().onKeyUp(keyCode, keyEvent)) {
return true;
} else {
@@ -235,10 +250,20 @@ public class GodotEditText extends EditText {
isModifiedKey;
}
+ boolean hasHardwareKeyboard() {
+ Configuration config = getResources().getConfiguration();
+ return config.keyboard != Configuration.KEYBOARD_NOKEYS &&
+ config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
+ }
+
// ===========================================================
// Methods
// ===========================================================
public void showKeyboard(String p_existing_text, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
+ if (hasHardwareKeyboard()) {
+ return;
+ }
+
int maxInputLength = (p_max_input_length <= 0) ? Integer.MAX_VALUE : p_max_input_length;
if (p_cursor_start == -1) { // cursor position not given
this.mOriginText = p_existing_text;
@@ -262,6 +287,10 @@ public class GodotEditText extends EditText {
}
public void hideKeyboard() {
+ if (hasHardwareKeyboard()) {
+ return;
+ }
+
final Message msg = new Message();
msg.what = HANDLER_CLOSE_IME_KEYBOARD;
msg.obj = this;