Skip to content

Commit 3529610

Browse files
MOldtimerocka
andauthored
Add option "Haptic feedback on key repeat" (#626)
Co-authored-by: Rocka <i@rocka.me>
1 parent e34a22f commit 3529610

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class AppPrefs(private val sharedPreferences: SharedPreferences) {
6262
"haptic_on_keyup",
6363
false
6464
) { hapticOnKeyPress.getValue() != InputFeedbackMode.Disabled }
65+
val hapticOnRepeat = switch(R.string.haptic_on_repeat, "haptic_on_repeat", false)
66+
6567
val buttonPressVibrationMilliseconds: ManagedPreference.PInt
6668
val buttonLongPressVibrationMilliseconds: ManagedPreference.PInt
6769

app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ abstract class BaseKeyboard(
6767

6868
private val vivoKeypressWorkaround by prefs.advanced.vivoKeypressWorkaround
6969

70+
private val hapticOnRepeat by prefs.keyboard.hapticOnRepeat
71+
7072
var popupActionListener: PopupActionListener? = null
7173

7274
private val selectionSwipeThreshold = dp(10f)
@@ -162,7 +164,7 @@ abstract class BaseKeyboard(
162164
swipeRepeatEnabled = true
163165
swipeThresholdX = selectionSwipeThreshold
164166
swipeThresholdY = disabledSwipeThreshold
165-
onGestureListener = OnGestureListener { _, event ->
167+
onGestureListener = OnGestureListener { view, event ->
166168
when (event.type) {
167169
GestureType.Move -> when (val count = event.countX) {
168170
0 -> false
@@ -172,6 +174,7 @@ abstract class BaseKeyboard(
172174
val action = KeyAction.SymAction(KeySym(sym), KeyStates.Empty)
173175
repeat(count.absoluteValue) {
174176
onAction(action)
177+
if (hapticOnRepeat) InputFeedbacks.hapticFeedback(view)
175178
}
176179
true
177180
}
@@ -184,12 +187,13 @@ abstract class BaseKeyboard(
184187
swipeRepeatEnabled = true
185188
swipeThresholdX = selectionSwipeThreshold
186189
swipeThresholdY = disabledSwipeThreshold
187-
onGestureListener = OnGestureListener { _, event ->
190+
onGestureListener = OnGestureListener { view, event ->
188191
when (event.type) {
189192
GestureType.Move -> {
190193
val count = event.countX
191194
if (count != 0) {
192195
onAction(KeyAction.MoveSelectionAction(count))
196+
if (hapticOnRepeat) InputFeedbacks.hapticFeedback(view)
193197
true
194198
} else false
195199
}
@@ -216,8 +220,9 @@ abstract class BaseKeyboard(
216220
}
217221
is KeyDef.Behavior.Repeat -> {
218222
repeatEnabled = true
219-
onRepeatListener = { _ ->
223+
onRepeatListener = { view ->
220224
onAction(it.action)
225+
if (hapticOnRepeat) InputFeedbacks.hapticFeedback(view)
221226
}
222227
}
223228
is KeyDef.Behavior.Swipe -> {

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,5 @@
283283
<string name="restart_fcitx_instance_confirm">Fcitx instance will be destroyed and reinitialized. Proceed?</string>
284284
<string name="ignore_system_window_insets">Ignore system WindowInsets</string>
285285
<string name="browse_user_data_dir">Browse user data directory</string>
286+
<string name="haptic_on_repeat">Haptic feedback on key repeat</string>
286287
</resources>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy