Android: Make vibration length variable

Previously we would vibrate for 100 ms on every vibration, which was
especially annoying if a game was doing a bunch of vibrations that were
supposed to be much shorter than that. Now we tell Android to vibrate
for 10 s, then cancel the vibration as soon as the game turns the
vibration off.
This commit is contained in:
JosJuice
2026-07-09 21:05:10 +02:00
parent aaeb6e5dc1
commit b67188cc44
2 changed files with 17 additions and 3 deletions
@@ -186,7 +186,7 @@ object ControllerInterface {
private fun vibrate(vibrator: Vibrator) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
vibrator.vibrate(
VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE),
VibrationEffect.createOneShot(10000, VibrationEffect.DEFAULT_AMPLITUDE),
VibrationAttributes.Builder().setUsage(VibrationAttributes.USAGE_MEDIA).build()
)
} else {
@@ -194,16 +194,22 @@ object ControllerInterface {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@Suppress("DEPRECATION")
vibrator.vibrate(
VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE),
VibrationEffect.createOneShot(10000, VibrationEffect.DEFAULT_AMPLITUDE),
attributes
)
} else {
@Suppress("DEPRECATION")
vibrator.vibrate(100, attributes)
vibrator.vibrate(10000, attributes)
}
}
}
@Keep
@JvmStatic
private fun cancelVibration(vibrator: Vibrator) {
vibrator.cancel()
}
private class InputDeviceListener : InputManager.InputDeviceListener {
override external fun onInputDeviceAdded(deviceId: Int)