mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-08-09 05:50:04 -05:00
Merge pull request #14702 from JosJuice/android-vibration-usage
Android: Set USAGE_MEDIA for rumble
This commit is contained in:
commit
2e07d3b4a8
|
|
@ -4,10 +4,12 @@ package org.dolphinemu.dolphinemu.features.input.model
|
|||
|
||||
import android.content.Context
|
||||
import android.hardware.input.InputManager
|
||||
import android.media.AudioAttributes
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.Looper
|
||||
import android.os.VibrationAttributes
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
import android.os.VibratorManager
|
||||
|
|
@ -158,6 +160,7 @@ object ControllerInterface {
|
|||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
DolphinVibratorManagerPassthrough(device.vibratorManager)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
DolphinVibratorManagerCompat(device.vibrator)
|
||||
}
|
||||
}
|
||||
|
|
@ -172,6 +175,7 @@ object ControllerInterface {
|
|||
return DolphinVibratorManagerPassthrough(vibratorManager)
|
||||
}
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
val vibrator = DolphinApplication.getAppContext()
|
||||
.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
return DolphinVibratorManagerCompat(vibrator)
|
||||
|
|
@ -180,10 +184,23 @@ object ControllerInterface {
|
|||
@Keep
|
||||
@JvmStatic
|
||||
private fun vibrate(vibrator: Vibrator) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
vibrator.vibrate(VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE))
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
vibrator.vibrate(
|
||||
VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE),
|
||||
VibrationAttributes.Builder().setUsage(VibrationAttributes.USAGE_MEDIA).build()
|
||||
)
|
||||
} else {
|
||||
vibrator.vibrate(100)
|
||||
val attributes = AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
@Suppress("DEPRECATION")
|
||||
vibrator.vibrate(
|
||||
VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE),
|
||||
attributes
|
||||
)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
vibrator.vibrate(100, attributes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user