mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-22 20:39:20 +01:00
Add a rudimentary OSC button vibration setting
This commit is contained in:
parent
2afd33b305
commit
cfd3bfecba
@ -265,6 +265,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
isGone = controllerType == ControllerType.None || !preferenceSettings.onScreenControl
|
isGone = controllerType == ControllerType.None || !preferenceSettings.onScreenControl
|
||||||
setOnButtonStateChangedListener(::onButtonStateChanged)
|
setOnButtonStateChangedListener(::onButtonStateChanged)
|
||||||
setOnStickStateChangedListener(::onStickStateChanged)
|
setOnStickStateChangedListener(::onStickStateChanged)
|
||||||
|
hapticFeedback = preferenceSettings.onScreenControl && preferenceSettings.onScreenControlFeedback
|
||||||
recenterSticks = preferenceSettings.onScreenControlRecenterSticks
|
recenterSticks = preferenceSettings.onScreenControlRecenterSticks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +91,11 @@ class ControllerActivity : AppCompatActivity() {
|
|||||||
adapter.notifyItemChanged(position)
|
adapter.notifyItemChanged(position)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_feedback), "", preferenceSettings.onScreenControlFeedback) { item, position ->
|
||||||
|
preferenceSettings.onScreenControlFeedback = item.checked
|
||||||
|
adapter.notifyItemChanged(position)
|
||||||
|
})
|
||||||
|
|
||||||
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_recenter_sticks), "", preferenceSettings.onScreenControlRecenterSticks) { item, position ->
|
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_recenter_sticks), "", preferenceSettings.onScreenControlRecenterSticks) { item, position ->
|
||||||
preferenceSettings.onScreenControlRecenterSticks = item.checked
|
preferenceSettings.onScreenControlRecenterSticks = item.checked
|
||||||
adapter.notifyItemChanged(position)
|
adapter.notifyItemChanged(position)
|
||||||
|
@ -74,6 +74,8 @@ abstract class OnScreenButton(
|
|||||||
|
|
||||||
var isPressed = false
|
var isPressed = false
|
||||||
|
|
||||||
|
var hapticFeedback = false
|
||||||
|
|
||||||
var isEditing = false
|
var isEditing = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
@ -9,8 +9,14 @@ import android.animation.Animator
|
|||||||
import android.animation.AnimatorListenerAdapter
|
import android.animation.AnimatorListenerAdapter
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Context.VIBRATOR_MANAGER_SERVICE
|
||||||
|
import android.content.Context.VIBRATOR_SERVICE
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.PointF
|
import android.graphics.PointF
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.VibrationEffect
|
||||||
|
import android.os.Vibrator
|
||||||
|
import android.os.VibratorManager
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -55,6 +61,11 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
|
|||||||
field = value
|
field = value
|
||||||
controls.joysticks.forEach { it.recenterSticks = recenterSticks }
|
controls.joysticks.forEach { it.recenterSticks = recenterSticks }
|
||||||
}
|
}
|
||||||
|
var hapticFeedback = false
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
(controls.circularButtons + controls.rectangularButtons + controls.triggerButtons).forEach { it.hapticFeedback = hapticFeedback }
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDraw(canvas : Canvas) {
|
override fun onDraw(canvas : Canvas) {
|
||||||
super.onDraw(canvas)
|
super.onDraw(canvas)
|
||||||
@ -73,6 +84,16 @@ 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 ->
|
private val playingTouchHandler = OnTouchListener { _, event ->
|
||||||
var handled = false
|
var handled = false
|
||||||
val actionIndex = event.actionIndex
|
val actionIndex = event.actionIndex
|
||||||
@ -102,6 +123,7 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
|
|||||||
if (button.config.enabled && button.isTouched(x, y)) {
|
if (button.config.enabled && button.isTouched(x, y)) {
|
||||||
button.touchPointerId = pointerId
|
button.touchPointerId = pointerId
|
||||||
button.onFingerDown(x, y)
|
button.onFingerDown(x, y)
|
||||||
|
if (hapticFeedback) vibrate()
|
||||||
performClick()
|
performClick()
|
||||||
onButtonStateChangedListener?.invoke(button.buttonId, ButtonState.Pressed)
|
onButtonStateChangedListener?.invoke(button.buttonId, ButtonState.Pressed)
|
||||||
handled = true
|
handled = true
|
||||||
|
@ -51,6 +51,7 @@ class PreferenceSettings @Inject constructor(@ApplicationContext private val con
|
|||||||
|
|
||||||
// Input
|
// Input
|
||||||
var onScreenControl by sharedPreferences(context, true)
|
var onScreenControl by sharedPreferences(context, true)
|
||||||
|
var onScreenControlFeedback by sharedPreferences(context, true)
|
||||||
var onScreenControlRecenterSticks by sharedPreferences(context, true)
|
var onScreenControlRecenterSticks by sharedPreferences(context, true)
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
|
@ -110,6 +110,7 @@
|
|||||||
<string name="osc_enable">Enable On-Screen Controls</string>
|
<string name="osc_enable">Enable On-Screen Controls</string>
|
||||||
<string name="osc_not_shown">On-Screen Controls won\'t be shown</string>
|
<string name="osc_not_shown">On-Screen Controls won\'t be shown</string>
|
||||||
<string name="osc_shown">On-Screen Controls will be shown</string>
|
<string name="osc_shown">On-Screen Controls will be shown</string>
|
||||||
|
<string name="osc_feedback">Enable Haptic Feedback</string>
|
||||||
<string name="osc_edit">Edit On-Screen Controls layout</string>
|
<string name="osc_edit">Edit On-Screen Controls layout</string>
|
||||||
<string name="setup_guide">Setup Guide</string>
|
<string name="setup_guide">Setup Guide</string>
|
||||||
<string name="setup_guide_description">Sequentially map every stick and button</string>
|
<string name="setup_guide_description">Sequentially map every stick and button</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user