You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-16 14:00:40 +00:00
Implement amplitude to Input.vibrate_handheld
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Co-authored-by: m4gr3d <m4gr3d@users.noreply.github.com>
This commit is contained in:
@@ -894,16 +894,25 @@ class Godot(private val context: Context) : SensorEventListener {
|
||||
*/
|
||||
@SuppressLint("MissingPermission")
|
||||
@Keep
|
||||
private fun vibrate(durationMs: Int) {
|
||||
private fun vibrate(durationMs: Int, amplitude: Int) {
|
||||
if (durationMs > 0 && requestPermission("VIBRATE")) {
|
||||
val vibratorService = getActivity()?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator? ?: return
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
vibratorService.vibrate(
|
||||
VibrationEffect.createOneShot(
|
||||
durationMs.toLong(),
|
||||
VibrationEffect.DEFAULT_AMPLITUDE
|
||||
if (amplitude <= -1) {
|
||||
vibratorService.vibrate(
|
||||
VibrationEffect.createOneShot(
|
||||
durationMs.toLong(),
|
||||
VibrationEffect.DEFAULT_AMPLITUDE
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
vibratorService.vibrate(
|
||||
VibrationEffect.createOneShot(
|
||||
durationMs.toLong(),
|
||||
amplitude
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// deprecated in API 26
|
||||
vibratorService.vibrate(durationMs.toLong())
|
||||
|
||||
Reference in New Issue
Block a user