diff --git a/app/src/main/java/emu/skyline/input/ControllerActivity.kt b/app/src/main/java/emu/skyline/input/ControllerActivity.kt index 7169c171..be142a3b 100644 --- a/app/src/main/java/emu/skyline/input/ControllerActivity.kt +++ b/app/src/main/java/emu/skyline/input/ControllerActivity.kt @@ -91,7 +91,7 @@ class ControllerActivity : AppCompatActivity() { adapter.notifyItemChanged(position) }) - items.add(ControllerCheckBoxViewItem(getString(R.string.osc_feedback), "", preferenceSettings.onScreenControlFeedback) { item, position -> + items.add(ControllerCheckBoxViewItem(getString(R.string.osc_feedback), getString(R.string.osc_feedback_description), preferenceSettings.onScreenControlFeedback) { item, position -> preferenceSettings.onScreenControlFeedback = item.checked adapter.notifyItemChanged(position) }) diff --git a/app/src/main/java/emu/skyline/input/onscreen/OnScreenControllerView.kt b/app/src/main/java/emu/skyline/input/onscreen/OnScreenControllerView.kt index 0d83ac10..28904e27 100644 --- a/app/src/main/java/emu/skyline/input/onscreen/OnScreenControllerView.kt +++ b/app/src/main/java/emu/skyline/input/onscreen/OnScreenControllerView.kt @@ -66,6 +66,13 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs field = value (controls.circularButtons + controls.rectangularButtons + controls.triggerButtons).forEach { it.hapticFeedback = hapticFeedback } } + private val vibrator: Vibrator = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + (context.getSystemService(VIBRATOR_MANAGER_SERVICE) as VibratorManager).defaultVibrator + } else { + @Suppress("DEPRECATION") (context.getSystemService(VIBRATOR_SERVICE) as Vibrator) + } + private val effectClick = VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK) override fun onDraw(canvas : Canvas) { super.onDraw(canvas) @@ -84,16 +91,6 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs } } - private val vibrationEffect = VibrationEffect.createOneShot(20, VibrationEffect.DEFAULT_AMPLITUDE) - private val vibrate = { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - (context.getSystemService(VIBRATOR_MANAGER_SERVICE) as VibratorManager).defaultVibrator.vibrate(vibrationEffect) - } else { - @Suppress("DEPRECATION") - (context.getSystemService(VIBRATOR_SERVICE) as Vibrator).vibrate(vibrationEffect) - } - } - private val playingTouchHandler = OnTouchListener { _, event -> var handled = false val actionIndex = event.actionIndex @@ -123,7 +120,7 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs if (button.config.enabled && button.isTouched(x, y)) { button.touchPointerId = pointerId button.onFingerDown(x, y) - if (hapticFeedback) vibrate() + if (hapticFeedback) vibrator.vibrate(effectClick) performClick() onButtonStateChangedListener?.invoke(button.buttonId, ButtonState.Pressed) handled = true diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 913f167c..0f700036 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -111,6 +111,7 @@ On-Screen Controls won\'t be shown On-Screen Controls will be shown Enable Haptic Feedback + Excludes joysticks and hardware controls Edit On-Screen Controls layout Setup Guide Sequentially map every stick and button