mirror of
https://github.com/fcitx5-android/fcitx5-android.git
synced 2026-08-02 20:16:06 +08:00
add switch
This commit is contained in:
parent
64f64552a9
commit
0aa7946842
@ -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
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -159,6 +159,10 @@ class KeyboardWindow : InputWindow.SimpleInputWindow<KeyboardWindow>(), Essentia
|
||||
currentKeyboard?.onReturnDrawableUpdate(resourceId)
|
||||
}
|
||||
|
||||
override fun onSelectionUpdate(start: Int, end: Int) {
|
||||
currentKeyboard?.onSelectionUpdate(start, end)
|
||||
}
|
||||
|
||||
override fun onAttached() {
|
||||
currentKeyboard?.let {
|
||||
it.keyActionListener = keyActionListener
|
||||
|
||||
@ -283,4 +283,5 @@
|
||||
<string name="restart_fcitx_instance_confirm">Fcitx instance will be destroyed and reinitialized. Proceed?</string>
|
||||
<string name="ignore_system_window_insets">Ignore system WindowInsets</string>
|
||||
<string name="browse_user_data_dir">Browse user data directory</string>
|
||||
<string name="haptic_feedback">Haptic feedback on key repeat</string>
|
||||
</resources>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user