mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-04 23:55:08 +01:00
Fix EmulationActivity.vibrateDevice
assert due to null
Vibrator
`EmulationActivity.vibrateDevice` would assert when a `null` Vibrator is provided due to one not being set in the controller configuration. This has now been fixed by the code not playing a vibration when a vibration device isn't selected.
This commit is contained in:
parent
414c0104c3
commit
bed9fbf5e7
@ -469,10 +469,10 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
@Suppress("unused")
|
||||
fun vibrateDevice(index : Int, timing : LongArray, amplitude : IntArray) {
|
||||
val vibrator = if (vibrators[index] != null) {
|
||||
vibrators[index]!!
|
||||
vibrators[index]
|
||||
} else {
|
||||
inputManager.controllers[index]!!.rumbleDeviceDescriptor?.let {
|
||||
if (it == "builtin") {
|
||||
if (it == Controller.BuiltinRumbleDeviceDescriptor) {
|
||||
val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val vibratorManager = getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
||||
vibratorManager.defaultVibrator
|
||||
@ -496,12 +496,15 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
return@let vibrator
|
||||
}
|
||||
}
|
||||
return@let null
|
||||
}
|
||||
} as Vibrator
|
||||
}
|
||||
}
|
||||
|
||||
val effect = VibrationEffect.createWaveform(timing, amplitude, 0)
|
||||
vibrator.vibrate(effect)
|
||||
vibrator?.let {
|
||||
val effect = VibrationEffect.createWaveform(timing, amplitude, 0)
|
||||
it.vibrate(effect)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
|
@ -48,6 +48,11 @@ open class Controller(val id : Int, var type : ControllerType, var rumbleDeviceD
|
||||
companion object {
|
||||
@JvmStatic
|
||||
private val serialVersionUID = 6529685098267757690L
|
||||
|
||||
/**
|
||||
* The value of [rumbleDeviceDescriptor] when the built-in Vibrator should be utilized
|
||||
*/
|
||||
const val BuiltinRumbleDeviceDescriptor = "builtin"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import emu.skyline.R
|
||||
import emu.skyline.adapter.controller.ControllerGeneralViewItem
|
||||
import emu.skyline.databinding.RumbleDialogBinding
|
||||
import emu.skyline.di.getInputManager
|
||||
import emu.skyline.input.Controller
|
||||
import emu.skyline.input.ControllerActivity
|
||||
|
||||
/**
|
||||
@ -73,7 +74,7 @@ class RumbleDialog @JvmOverloads constructor(val item : ControllerGeneralViewIte
|
||||
if (!vibrator.hasVibrator())
|
||||
binding.rumbleBuiltin.isEnabled = false
|
||||
binding.rumbleBuiltin.setOnClickListener {
|
||||
controller.rumbleDeviceDescriptor = "builtin"
|
||||
controller.rumbleDeviceDescriptor = Controller.BuiltinRumbleDeviceDescriptor
|
||||
controller.rumbleDeviceName = getString(R.string.builtin_vibrator)
|
||||
item.update()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user