mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-23 15:01:50 +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")
|
@Suppress("unused")
|
||||||
fun vibrateDevice(index : Int, timing : LongArray, amplitude : IntArray) {
|
fun vibrateDevice(index : Int, timing : LongArray, amplitude : IntArray) {
|
||||||
val vibrator = if (vibrators[index] != null) {
|
val vibrator = if (vibrators[index] != null) {
|
||||||
vibrators[index]!!
|
vibrators[index]
|
||||||
} else {
|
} else {
|
||||||
inputManager.controllers[index]!!.rumbleDeviceDescriptor?.let {
|
inputManager.controllers[index]!!.rumbleDeviceDescriptor?.let {
|
||||||
if (it == "builtin") {
|
if (it == Controller.BuiltinRumbleDeviceDescriptor) {
|
||||||
val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
val vibratorManager = getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
val vibratorManager = getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
||||||
vibratorManager.defaultVibrator
|
vibratorManager.defaultVibrator
|
||||||
@ -496,12 +496,15 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
return@let vibrator
|
return@let vibrator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return@let null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} as Vibrator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vibrator?.let {
|
||||||
val effect = VibrationEffect.createWaveform(timing, amplitude, 0)
|
val effect = VibrationEffect.createWaveform(timing, amplitude, 0)
|
||||||
vibrator.vibrate(effect)
|
it.vibrate(effect)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
|
@ -48,6 +48,11 @@ open class Controller(val id : Int, var type : ControllerType, var rumbleDeviceD
|
|||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private val serialVersionUID = 6529685098267757690L
|
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.adapter.controller.ControllerGeneralViewItem
|
||||||
import emu.skyline.databinding.RumbleDialogBinding
|
import emu.skyline.databinding.RumbleDialogBinding
|
||||||
import emu.skyline.di.getInputManager
|
import emu.skyline.di.getInputManager
|
||||||
|
import emu.skyline.input.Controller
|
||||||
import emu.skyline.input.ControllerActivity
|
import emu.skyline.input.ControllerActivity
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +74,7 @@ class RumbleDialog @JvmOverloads constructor(val item : ControllerGeneralViewIte
|
|||||||
if (!vibrator.hasVibrator())
|
if (!vibrator.hasVibrator())
|
||||||
binding.rumbleBuiltin.isEnabled = false
|
binding.rumbleBuiltin.isEnabled = false
|
||||||
binding.rumbleBuiltin.setOnClickListener {
|
binding.rumbleBuiltin.setOnClickListener {
|
||||||
controller.rumbleDeviceDescriptor = "builtin"
|
controller.rumbleDeviceDescriptor = Controller.BuiltinRumbleDeviceDescriptor
|
||||||
controller.rumbleDeviceName = getString(R.string.builtin_vibrator)
|
controller.rumbleDeviceName = getString(R.string.builtin_vibrator)
|
||||||
item.update()
|
item.update()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user