1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Android: Hardware keyboard connection status callback

Adds a DisplayServer method to register hardware keyboard connection change callback.
This commit is contained in:
Anish Mishra
2025-04-04 16:16:24 +05:30
parent 8bd9cdeea6
commit b462db5adb
11 changed files with 51 additions and 10 deletions

View File

@@ -77,7 +77,6 @@ import org.godotengine.godot.xr.XRMode
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
import java.lang.Exception
import java.security.MessageDigest
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean

View File

@@ -268,6 +268,11 @@ public class GodotLib {
*/
public static native void onNightModeChanged();
/**
* Invoked on the hardware keyboard connected/disconnected.
*/
public static native void hardwareKeyboardConnected(boolean connected);
/**
* Invoked on the file picker closed.
*/

View File

@@ -265,13 +265,6 @@ public class GodotEditText extends EditText {
}
public boolean hasHardwareKeyboard() {
Configuration config = getResources().getConfiguration();
boolean hasHardwareKeyboardConfig = config.keyboard != Configuration.KEYBOARD_NOKEYS &&
config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
if (hasHardwareKeyboardConfig) {
return true;
}
return mRenderView.getInputHandler().hasHardwareKeyboard();
}

View File

@@ -90,6 +90,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
private int cachedRotation = -1;
private boolean overrideVolumeButtons = false;
private boolean hasHardwareKeyboardConfig = false;
public GodotInputHandler(Context context, Godot godot) {
this.godot = godot;
@@ -105,6 +106,9 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
this.scaleGestureDetector.setStylusScaleEnabled(true);
}
Configuration config = context.getResources().getConfiguration();
hasHardwareKeyboardConfig = config.keyboard != Configuration.KEYBOARD_NOKEYS &&
config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
}
/**
@@ -143,6 +147,9 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
}
boolean hasHardwareKeyboard() {
if (hasHardwareKeyboardConfig) {
return true;
}
return !mHardwareKeyboardIds.isEmpty();
}
@@ -797,5 +804,12 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
public void onConfigurationChanged(Configuration newConfig) {
updateCachedRotation();
boolean newHardwareKeyboardConfig = newConfig.keyboard != Configuration.KEYBOARD_NOKEYS &&
newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
if (hasHardwareKeyboardConfig != newHardwareKeyboardConfig) {
hasHardwareKeyboardConfig = newHardwareKeyboardConfig;
GodotLib.hardwareKeyboardConnected(hasHardwareKeyboard());
}
}
}