diff --git a/app/src/main/java/emu/skyline/EmulationActivity.kt b/app/src/main/java/emu/skyline/EmulationActivity.kt index 29f3b7f7..be1c0bec 100644 --- a/app/src/main/java/emu/skyline/EmulationActivity.kt +++ b/app/src/main/java/emu/skyline/EmulationActivity.kt @@ -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") diff --git a/app/src/main/java/emu/skyline/input/Controller.kt b/app/src/main/java/emu/skyline/input/Controller.kt index 4d4b3ba4..789d62c1 100644 --- a/app/src/main/java/emu/skyline/input/Controller.kt +++ b/app/src/main/java/emu/skyline/input/Controller.kt @@ -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" } } diff --git a/app/src/main/java/emu/skyline/input/dialog/RumbleDialog.kt b/app/src/main/java/emu/skyline/input/dialog/RumbleDialog.kt index cb43d89c..96ddef16 100644 --- a/app/src/main/java/emu/skyline/input/dialog/RumbleDialog.kt +++ b/app/src/main/java/emu/skyline/input/dialog/RumbleDialog.kt @@ -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()