From 64f64552a91a697f414cb828dff503315576f5c3 Mon Sep 17 00:00:00 2001 From: Time Date: Fri, 29 Nov 2024 18:32:19 +0800 Subject: [PATCH 1/4] Add some vibration --- .../fcitx5/android/input/keyboard/BaseKeyboard.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt b/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt index fa9ef3351..1769d4f41 100644 --- a/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt +++ b/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt @@ -162,7 +162,7 @@ abstract class BaseKeyboard( swipeRepeatEnabled = true swipeThresholdX = selectionSwipeThreshold swipeThresholdY = disabledSwipeThreshold - onGestureListener = OnGestureListener { _, event -> + onGestureListener = OnGestureListener { view, event -> when (event.type) { GestureType.Move -> when (val count = event.countX) { 0 -> false @@ -172,6 +172,7 @@ abstract class BaseKeyboard( val action = KeyAction.SymAction(KeySym(sym), KeyStates.Empty) repeat(count.absoluteValue) { onAction(action) + InputFeedbacks.hapticFeedback(view) } true } @@ -184,12 +185,13 @@ abstract class BaseKeyboard( swipeRepeatEnabled = true swipeThresholdX = selectionSwipeThreshold swipeThresholdY = disabledSwipeThreshold - onGestureListener = OnGestureListener { _, event -> + onGestureListener = OnGestureListener { view, event -> when (event.type) { GestureType.Move -> { val count = event.countX if (count != 0) { onAction(KeyAction.MoveSelectionAction(count)) + InputFeedbacks.hapticFeedback(view) true } else false } @@ -216,9 +218,10 @@ abstract class BaseKeyboard( } is KeyDef.Behavior.Repeat -> { repeatEnabled = true - onRepeatListener = { _ -> + onRepeatListener = if (def is BackspaceKey) { view -> onAction(it.action) - } + InputFeedbacks.hapticFeedback(view) + } else { _ -> onAction(it.action) } } is KeyDef.Behavior.Swipe -> { swipeEnabled = true From 0aa79468421b6f30a3c944feb4a8bfdb09a41fb9 Mon Sep 17 00:00:00 2001 From: Time Date: Fri, 29 Nov 2024 19:57:32 +0800 Subject: [PATCH 2/4] add switch --- .../fcitx5/android/data/prefs/AppPrefs.kt | 2 ++ .../android/input/FcitxInputMethodService.kt | 2 ++ .../android/input/keyboard/BaseKeyboard.kt | 19 +++++++++++++++---- .../android/input/keyboard/KeyboardWindow.kt | 4 ++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt b/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt index ef20c79fe..afbf00d5e 100644 --- a/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt +++ b/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt @@ -83,6 +83,8 @@ class AppPrefs(private val sharedPreferences: SharedPreferences) { buttonLongPressVibrationMilliseconds = secondary } + val hapticFeedback = switch(R.string.haptic_feedback, "haptic_feedback", false) + val buttonPressVibrationAmplitude: ManagedPreference.PInt val buttonLongPressVibrationAmplitude: ManagedPreference.PInt diff --git a/app/src/main/java/org/fcitx/fcitx5/android/input/FcitxInputMethodService.kt b/app/src/main/java/org/fcitx/fcitx5/android/input/FcitxInputMethodService.kt index f00a79fd7..dc2811ed2 100644 --- a/app/src/main/java/org/fcitx/fcitx5/android/input/FcitxInputMethodService.kt +++ b/app/src/main/java/org/fcitx/fcitx5/android/input/FcitxInputMethodService.kt @@ -126,6 +126,7 @@ class FcitxInputMethodService : LifecycleInputMethodService() { prefs.keyboard.expandKeypressArea, prefs.advanced.disableAnimation, prefs.advanced.ignoreSystemWindowInsets, + prefs.keyboard.hapticFeedback, ) private fun replaceInputView(theme: Theme): InputView { @@ -927,6 +928,7 @@ class FcitxInputMethodService : LifecycleInputMethodService() { override fun onFinishInputView(finishingInput: Boolean) { Timber.d("onFinishInputView: finishingInput=$finishingInput") + inputView?.updateSelection(0, 0) decorLocationUpdated = false inputDeviceMgr.onFinishInputView() currentInputConnection?.apply { diff --git a/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt b/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt index 1769d4f41..234dde3cd 100644 --- a/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt +++ b/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt @@ -21,6 +21,7 @@ import org.fcitx.fcitx5.android.data.InputFeedbacks import org.fcitx.fcitx5.android.data.prefs.AppPrefs import org.fcitx.fcitx5.android.data.prefs.ManagedPreference import org.fcitx.fcitx5.android.data.theme.Theme +import org.fcitx.fcitx5.android.input.cursor.CursorRange import org.fcitx.fcitx5.android.input.keyboard.CustomGestureView.GestureType import org.fcitx.fcitx5.android.input.keyboard.CustomGestureView.OnGestureListener import org.fcitx.fcitx5.android.input.popup.PopupAction @@ -67,6 +68,8 @@ abstract class BaseKeyboard( private val vivoKeypressWorkaround by prefs.advanced.vivoKeypressWorkaround + private val hapticFeedback by prefs.keyboard.hapticFeedback + var popupActionListener: PopupActionListener? = null private val selectionSwipeThreshold = dp(10f) @@ -156,6 +159,9 @@ abstract class BaseKeyboard( is ReturnKey -> InputFeedbacks.SoundEffect.Return else -> InputFeedbacks.SoundEffect.Standard } + val vibration: ((View, Boolean) -> Unit)? = if (hapticFeedback) { view, extraConditions -> + if (selection.end > 0 && selection.start > 0 && extraConditions) InputFeedbacks.hapticFeedback(view) + } else null if (def is SpaceKey) { spaceKeys.add(this) swipeEnabled = spaceSwipeMoveCursor.getValue() @@ -172,7 +178,7 @@ abstract class BaseKeyboard( val action = KeyAction.SymAction(KeySym(sym), KeyStates.Empty) repeat(count.absoluteValue) { onAction(action) - InputFeedbacks.hapticFeedback(view) + vibration?.invoke(view, selection.end >= selection.start) } true } @@ -191,7 +197,7 @@ abstract class BaseKeyboard( val count = event.countX if (count != 0) { onAction(KeyAction.MoveSelectionAction(count)) - InputFeedbacks.hapticFeedback(view) + vibration?.invoke(view, selection.end > selection.start) true } else false } @@ -218,9 +224,9 @@ abstract class BaseKeyboard( } is KeyDef.Behavior.Repeat -> { repeatEnabled = true - onRepeatListener = if (def is BackspaceKey) { view -> + onRepeatListener = if (hapticFeedback && def is BackspaceKey) { view -> onAction(it.action) - InputFeedbacks.hapticFeedback(view) + vibration?.invoke(view, selection.end >= selection.start) } else { _ -> onAction(it.action) } } is KeyDef.Behavior.Swipe -> { @@ -481,6 +487,11 @@ abstract class BaseKeyboard( return true } + private val selection = CursorRange() + fun onSelectionUpdate(start: Int, end: Int) { + selection.update(start, end) + } + open fun onAttach() { // do nothing by default } diff --git a/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/KeyboardWindow.kt b/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/KeyboardWindow.kt index 26dcded01..3090b3e65 100644 --- a/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/KeyboardWindow.kt +++ b/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/KeyboardWindow.kt @@ -159,6 +159,10 @@ class KeyboardWindow : InputWindow.SimpleInputWindow(), Essentia currentKeyboard?.onReturnDrawableUpdate(resourceId) } + override fun onSelectionUpdate(start: Int, end: Int) { + currentKeyboard?.onSelectionUpdate(start, end) + } + override fun onAttached() { currentKeyboard?.let { it.keyActionListener = keyActionListener diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 679a9a108..7cdb80769 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -283,4 +283,5 @@ Fcitx instance will be destroyed and reinitialized. Proceed? Ignore system WindowInsets Browse user data directory + Haptic feedback on key repeat From 3c946c353cf86cba5e9c3935d97c72257621d82e Mon Sep 17 00:00:00 2001 From: Time Date: Tue, 17 Dec 2024 09:19:38 +0800 Subject: [PATCH 3/4] Correction --- .../fcitx5/android/data/prefs/AppPrefs.kt | 2 +- .../android/input/FcitxInputMethodService.kt | 2 -- .../android/input/keyboard/BaseKeyboard.kt | 21 ++++++------------- .../android/input/keyboard/KeyboardWindow.kt | 4 ---- app/src/main/res/values/strings.xml | 2 +- 5 files changed, 8 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt b/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt index afbf00d5e..d64a8dbd0 100644 --- a/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt +++ b/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt @@ -83,7 +83,7 @@ class AppPrefs(private val sharedPreferences: SharedPreferences) { buttonLongPressVibrationMilliseconds = secondary } - val hapticFeedback = switch(R.string.haptic_feedback, "haptic_feedback", false) + val hapticOnRepeat = switch(R.string.haptic_on_repeat, "haptic_on_repeat", false) val buttonPressVibrationAmplitude: ManagedPreference.PInt val buttonLongPressVibrationAmplitude: ManagedPreference.PInt diff --git a/app/src/main/java/org/fcitx/fcitx5/android/input/FcitxInputMethodService.kt b/app/src/main/java/org/fcitx/fcitx5/android/input/FcitxInputMethodService.kt index dc2811ed2..f00a79fd7 100644 --- a/app/src/main/java/org/fcitx/fcitx5/android/input/FcitxInputMethodService.kt +++ b/app/src/main/java/org/fcitx/fcitx5/android/input/FcitxInputMethodService.kt @@ -126,7 +126,6 @@ class FcitxInputMethodService : LifecycleInputMethodService() { prefs.keyboard.expandKeypressArea, prefs.advanced.disableAnimation, prefs.advanced.ignoreSystemWindowInsets, - prefs.keyboard.hapticFeedback, ) private fun replaceInputView(theme: Theme): InputView { @@ -928,7 +927,6 @@ class FcitxInputMethodService : LifecycleInputMethodService() { override fun onFinishInputView(finishingInput: Boolean) { Timber.d("onFinishInputView: finishingInput=$finishingInput") - inputView?.updateSelection(0, 0) decorLocationUpdated = false inputDeviceMgr.onFinishInputView() currentInputConnection?.apply { diff --git a/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt b/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt index 234dde3cd..9bc8045ce 100644 --- a/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt +++ b/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/BaseKeyboard.kt @@ -21,7 +21,6 @@ import org.fcitx.fcitx5.android.data.InputFeedbacks import org.fcitx.fcitx5.android.data.prefs.AppPrefs import org.fcitx.fcitx5.android.data.prefs.ManagedPreference import org.fcitx.fcitx5.android.data.theme.Theme -import org.fcitx.fcitx5.android.input.cursor.CursorRange import org.fcitx.fcitx5.android.input.keyboard.CustomGestureView.GestureType import org.fcitx.fcitx5.android.input.keyboard.CustomGestureView.OnGestureListener import org.fcitx.fcitx5.android.input.popup.PopupAction @@ -68,7 +67,7 @@ abstract class BaseKeyboard( private val vivoKeypressWorkaround by prefs.advanced.vivoKeypressWorkaround - private val hapticFeedback by prefs.keyboard.hapticFeedback + private val hapticOnRepeat by prefs.keyboard.hapticOnRepeat var popupActionListener: PopupActionListener? = null @@ -159,9 +158,6 @@ abstract class BaseKeyboard( is ReturnKey -> InputFeedbacks.SoundEffect.Return else -> InputFeedbacks.SoundEffect.Standard } - val vibration: ((View, Boolean) -> Unit)? = if (hapticFeedback) { view, extraConditions -> - if (selection.end > 0 && selection.start > 0 && extraConditions) InputFeedbacks.hapticFeedback(view) - } else null if (def is SpaceKey) { spaceKeys.add(this) swipeEnabled = spaceSwipeMoveCursor.getValue() @@ -178,7 +174,7 @@ abstract class BaseKeyboard( val action = KeyAction.SymAction(KeySym(sym), KeyStates.Empty) repeat(count.absoluteValue) { onAction(action) - vibration?.invoke(view, selection.end >= selection.start) + if (hapticOnRepeat) InputFeedbacks.hapticFeedback(view) } true } @@ -197,7 +193,7 @@ abstract class BaseKeyboard( val count = event.countX if (count != 0) { onAction(KeyAction.MoveSelectionAction(count)) - vibration?.invoke(view, selection.end > selection.start) + if (hapticOnRepeat) InputFeedbacks.hapticFeedback(view) true } else false } @@ -224,10 +220,10 @@ abstract class BaseKeyboard( } is KeyDef.Behavior.Repeat -> { repeatEnabled = true - onRepeatListener = if (hapticFeedback && def is BackspaceKey) { view -> + onRepeatListener = { view -> onAction(it.action) - vibration?.invoke(view, selection.end >= selection.start) - } else { _ -> onAction(it.action) } + if (hapticOnRepeat) InputFeedbacks.hapticFeedback(view) + } } is KeyDef.Behavior.Swipe -> { swipeEnabled = true @@ -487,11 +483,6 @@ abstract class BaseKeyboard( return true } - private val selection = CursorRange() - fun onSelectionUpdate(start: Int, end: Int) { - selection.update(start, end) - } - open fun onAttach() { // do nothing by default } diff --git a/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/KeyboardWindow.kt b/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/KeyboardWindow.kt index 3090b3e65..26dcded01 100644 --- a/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/KeyboardWindow.kt +++ b/app/src/main/java/org/fcitx/fcitx5/android/input/keyboard/KeyboardWindow.kt @@ -159,10 +159,6 @@ class KeyboardWindow : InputWindow.SimpleInputWindow(), Essentia currentKeyboard?.onReturnDrawableUpdate(resourceId) } - override fun onSelectionUpdate(start: Int, end: Int) { - currentKeyboard?.onSelectionUpdate(start, end) - } - override fun onAttached() { currentKeyboard?.let { it.keyActionListener = keyActionListener diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7cdb80769..12bcee0a7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -283,5 +283,5 @@ Fcitx instance will be destroyed and reinitialized. Proceed? Ignore system WindowInsets Browse user data directory - Haptic feedback on key repeat + Haptic feedback on key repeat From 639832205202711b11c477ba6ff416c3306901fe Mon Sep 17 00:00:00 2001 From: Rocka Date: Mon, 23 Dec 2024 00:53:30 +0800 Subject: [PATCH 4/4] Tweak preference order --- .../main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt b/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt index d64a8dbd0..492d3057a 100644 --- a/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt +++ b/app/src/main/java/org/fcitx/fcitx5/android/data/prefs/AppPrefs.kt @@ -62,6 +62,8 @@ class AppPrefs(private val sharedPreferences: SharedPreferences) { "haptic_on_keyup", false ) { hapticOnKeyPress.getValue() != InputFeedbackMode.Disabled } + val hapticOnRepeat = switch(R.string.haptic_on_repeat, "haptic_on_repeat", false) + val buttonPressVibrationMilliseconds: ManagedPreference.PInt val buttonLongPressVibrationMilliseconds: ManagedPreference.PInt @@ -83,8 +85,6 @@ class AppPrefs(private val sharedPreferences: SharedPreferences) { buttonLongPressVibrationMilliseconds = secondary } - val hapticOnRepeat = switch(R.string.haptic_on_repeat, "haptic_on_repeat", false) - val buttonPressVibrationAmplitude: ManagedPreference.PInt val buttonLongPressVibrationAmplitude: ManagedPreference.PInt 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