aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkleidis <kleidis1@protonmail.com>2025-11-13 03:45:41 +0100
committercrueter <crueter@eden-emu.dev>2025-11-13 03:45:41 +0100
commitf51d61e4a41218780815bfa7d2c13ccc5e2744b5 (patch)
tree7e21d98781b2a5763494162c577dea2b524426d7 /src
parentba9e03a612f4d4d50ad619ab3135bcb04b0fc29d (diff)
[android] Use spinbox setting type for CPU_TICKS (#2952)
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2952 Reviewed-by: crueter <crueter@eden-emu.dev> Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: Caio Oliveira <caiooliveirafarias0@gmail.com> Co-authored-by: kleidis <kleidis1@protonmail.com> Co-committed-by: kleidis <kleidis1@protonmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt3
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsDialogFragment.kt51
2 files changed, 53 insertions, 1 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt
index 6dc5d66c7b..bbcfe3da45 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt
@@ -667,10 +667,11 @@ abstract class SettingsItem(
)
)
put(
- SliderSetting(
+ SpinBoxSetting(
IntSetting.CPU_TICKS,
titleId = R.string.cpu_ticks,
descriptionId = 0,
+ valueHint = R.string.cpu_ticks,
min = 77,
max = 65535
)
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsDialogFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsDialogFragment.kt
index 2a97f15892..eb1b0a4257 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsDialogFragment.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsDialogFragment.kt
@@ -14,6 +14,9 @@ import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.view.MotionEvent
+import android.os.Handler
+import android.os.Looper
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import androidx.fragment.app.DialogFragment
@@ -197,6 +200,54 @@ class SettingsDialogFragment : DialogFragment(), DialogInterface.OnClickListener
updateValidity(newValue)
}
+ fun attachRepeat(button: View, delta: Int) {
+ val handler = Handler(Looper.getMainLooper())
+ var runnable: Runnable? = null
+ val initialDelay = 400L
+ val minDelay = 40L
+ val accelerationFactor = 0.75f
+
+ button.setOnTouchListener { v, event ->
+ when (event.action) {
+ MotionEvent.ACTION_DOWN -> {
+ val current = spinboxBinding.editValue.text.toString().toIntOrNull() ?: currentValue
+ val newValue = (current + delta)
+ spinboxBinding.editValue.setText(newValue.toString())
+ updateValidity(newValue)
+
+ var delay = initialDelay
+ runnable = object : Runnable {
+ override fun run() {
+ val curr = spinboxBinding.editValue.text.toString().toIntOrNull() ?: currentValue
+ val next = curr + delta
+ spinboxBinding.editValue.setText(next.toString())
+ updateValidity(next)
+ // accelerate
+ delay = (delay * accelerationFactor).toLong().coerceAtLeast(minDelay)
+ handler.postDelayed(this, delay)
+ }
+ }
+ handler.postDelayed(runnable!!, initialDelay)
+ true
+ }
+
+ MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
+ if (runnable != null) {
+ handler.removeCallbacks(runnable!!)
+ runnable = null
+ }
+ v.performClick()
+ true
+ }
+
+ else -> false
+ }
+ }
+ }
+
+ attachRepeat(spinboxBinding.buttonDecrement, -1)
+ attachRepeat(spinboxBinding.buttonIncrement, 1)
+
spinboxBinding.editValue.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}