Provide haptic feedback when a game is picked.
This commit is contained in:
parent
12e6034ef1
commit
e4abd73151
|
@ -23,6 +23,7 @@ import org.dolphinemu.dolphinemu.databinding.CardGameBinding
|
|||
import org.dolphinemu.dolphinemu.dialogs.GamePropertiesDialog
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting
|
||||
import org.dolphinemu.dolphinemu.utils.CoilUtils
|
||||
import org.dolphinemu.dolphinemu.utils.HapticListener
|
||||
import java.util.ArrayList
|
||||
|
||||
class GameAdapter : RecyclerView.Adapter<GameViewHolder>(),
|
||||
|
@ -39,7 +40,7 @@ class GameAdapter : RecyclerView.Adapter<GameViewHolder>(),
|
|||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameViewHolder {
|
||||
val binding = CardGameBinding.inflate(LayoutInflater.from(parent.context))
|
||||
binding.root.apply {
|
||||
setOnClickListener(this@GameAdapter)
|
||||
setOnClickListener(HapticListener.wrapOnClickListener(this@GameAdapter))
|
||||
setOnLongClickListener(this@GameAdapter)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.dolphinemu.dolphinemu.utils
|
||||
|
||||
import android.view.View
|
||||
import android.widget.CompoundButton
|
||||
import androidx.core.view.HapticFeedbackConstantsCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
|
@ -10,6 +11,24 @@ import com.google.android.material.slider.Slider
|
|||
*/
|
||||
object HapticListener {
|
||||
|
||||
/**
|
||||
* Wraps a [View.OnClickListener] with haptic feedback.
|
||||
*
|
||||
* @param listener The [View.OnClickListener] to be wrapped. Can be null.
|
||||
* @param feedbackConstant The haptic feedback constant to be used for haptic feedback.
|
||||
* Defaults to [HapticFeedbackConstantsCompat.CONTEXT_CLICK] if not specified.
|
||||
* @return A new listener which wraps [listener] with haptic feedback.
|
||||
*/
|
||||
fun wrapOnClickListener(
|
||||
listener: View.OnClickListener?,
|
||||
feedbackConstant: Int = HapticFeedbackConstantsCompat.CONTEXT_CLICK
|
||||
): View.OnClickListener {
|
||||
return View.OnClickListener { view: View ->
|
||||
listener?.onClick(view)
|
||||
ViewCompat.performHapticFeedback(view, feedbackConstant)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a [Slider.OnChangeListener] with haptic feedback.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue