Skip to content

Commit

Permalink
Disable vibration strength preference
Browse files Browse the repository at this point in the history
Perform haptic feedback on virtual button release
  • Loading branch information
rafaelvcaetano committed Feb 28, 2025
1 parent 23cc6a9 commit 00119a3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package me.magnum.melonds.ui.emulator.input

import android.view.HapticFeedbackConstants
import android.view.View
import me.magnum.melonds.common.vibration.TouchVibrator

abstract class FeedbackInputHandler(inputListener: IInputListener, private val enableHapticFeedback: Boolean, private val touchVibrator: TouchVibrator) : BaseInputHandler(inputListener) {
protected fun performHapticFeedback() {

enum class HapticFeedbackType {
KEY_PRESS,
KEY_RELEASE
}

protected fun performHapticFeedback(view: View, type: HapticFeedbackType) {
if (enableHapticFeedback) {
touchVibrator.performTouchHapticFeedback()
val feedbackType = when (type) {
HapticFeedbackType.KEY_PRESS -> HapticFeedbackConstants.KEYBOARD_TAP
HapticFeedbackType.KEY_RELEASE -> HapticFeedbackConstants.CLOCK_TICK
}
view.performHapticFeedback(feedbackType)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ abstract class MultiButtonInputHandler(inputListener: IInputListener, enableHapt
inputListener.onKeyReleased(it)
}

if (tempInputList.isNotEmpty()) {
performHapticFeedback(v, HapticFeedbackType.KEY_RELEASE)
}

tempInputList.clear()
newPressedInputs.filterNotTo(tempInputList) {
it in pressedInputs
Expand All @@ -48,7 +52,7 @@ abstract class MultiButtonInputHandler(inputListener: IInputListener, enableHapt
}

if (tempInputList.isNotEmpty()) {
performHapticFeedback()
performHapticFeedback(v, HapticFeedbackType.KEY_PRESS)
}

pressedInputs.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ class SingleButtonInputHandler(inputListener: IInputListener, private val input:
when (event.action) {
MotionEvent.ACTION_DOWN -> {
inputListener.onKeyPress(input)
performHapticFeedback()
performHapticFeedback(v, HapticFeedbackType.KEY_PRESS)
}
MotionEvent.ACTION_UP -> {
inputListener.onKeyReleased(input)
performHapticFeedback(v, HapticFeedbackType.KEY_RELEASE)
}
MotionEvent.ACTION_UP -> inputListener.onKeyReleased(input)
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class InputPreferencesFragment : PreferenceFragmentCompat(), PreferenceFragmentT

if (!vibrator.supportsVibration()) {
touchVibratePreference.isVisible = false
vibrationStrengthPreference.isVisible = false
}
vibrationStrengthPreference.isVisible = false

vibrationStrengthPreference.setOnPreferenceChangeListener { _, newValue ->
val strength = newValue as Int
Expand Down

1 comment on commit 00119a3

@FATCatAndroid12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the vibaration strength follow the device settings
I mean if I set to light, medium or strong vaibration on my device. Melonds vibration would be the same

Please sign in to comment.