You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Android: enable support for volume button events
- Enable events KEY_VOLUMEUP and KEY_VOLUMEDOWN on Android. - Adds a project setting to override volume buttons. It would disable system volume changes when the buttons are used within the project.
This commit is contained in:
@@ -714,11 +714,13 @@ class Godot(private val context: Context) {
|
||||
val longPressEnabled = java.lang.Boolean.parseBoolean(GodotLib.getGlobal("input_devices/pointing/android/enable_long_press_as_right_click"))
|
||||
val panScaleEnabled = java.lang.Boolean.parseBoolean(GodotLib.getGlobal("input_devices/pointing/android/enable_pan_and_scale_gestures"))
|
||||
val rotaryInputAxisValue = GodotLib.getGlobal("input_devices/pointing/android/rotary_input_scroll_axis")
|
||||
val overrideVolumeButtons = java.lang.Boolean.parseBoolean(GodotLib.getGlobal("input_devices/pointing/android/override_volume_buttons"))
|
||||
|
||||
runOnUiThread {
|
||||
renderView?.inputHandler?.apply {
|
||||
enableLongPress(longPressEnabled)
|
||||
enablePanningAndScalingGestures(panScaleEnabled)
|
||||
setOverrideVolumeButtons(overrideVolumeButtons)
|
||||
try {
|
||||
setRotaryInputAxis(Integer.parseInt(rotaryInputAxisValue))
|
||||
} catch (e: NumberFormatException) {
|
||||
|
||||
@@ -88,6 +88,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
||||
private int rotaryInputAxis = ROTARY_INPUT_VERTICAL_AXIS;
|
||||
|
||||
private int cachedRotation = -1;
|
||||
private boolean overrideVolumeButtons = false;
|
||||
|
||||
public GodotInputHandler(Context context, Godot godot) {
|
||||
this.godot = godot;
|
||||
@@ -136,6 +137,10 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
||||
rotaryInputAxis = axis;
|
||||
}
|
||||
|
||||
public void setOverrideVolumeButtons(boolean value) {
|
||||
overrideVolumeButtons = value;
|
||||
}
|
||||
|
||||
boolean hasHardwareKeyboard() {
|
||||
return !mHardwareKeyboardIds.isEmpty();
|
||||
}
|
||||
@@ -157,10 +162,6 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
||||
}
|
||||
|
||||
public boolean onKeyUp(final int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int source = event.getSource();
|
||||
if (isKeyEventGameDevice(source)) {
|
||||
// Check if the device exists
|
||||
@@ -178,14 +179,14 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
||||
handleKeyEvent(physical_keycode, unicode, key_label, false, event.getRepeatCount() > 0);
|
||||
};
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
return overrideVolumeButtons;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onKeyDown(final int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int source = event.getSource();
|
||||
|
||||
final int deviceId = event.getDeviceId();
|
||||
@@ -206,6 +207,10 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
||||
handleKeyEvent(physical_keycode, unicode, key_label, true, event.getRepeatCount() > 0);
|
||||
}
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
return overrideVolumeButtons;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user