diff --git a/java/res/values/strings-uix.xml b/java/res/values/strings-uix.xml index d69782d46d..72f50310e6 100644 --- a/java/res/values/strings-uix.xml +++ b/java/res/values/strings-uix.xml @@ -425,6 +425,10 @@ additional characters, alt keys, symbols, popup keys Long Press Duration How long a key needs to be pressed to be considered a long-press + Flick sensitivity + Adjust how far you need to swipe to trigger a flick action. Lower values make flick easier to trigger. + Default + flick, swipe, gesture, sensitivity, threshold, distance Backspace Hold to delete words diff --git a/java/src/org/futo/inputmethod/keyboard/Key.kt b/java/src/org/futo/inputmethod/keyboard/Key.kt index 96ce406fb2..cc210c38a4 100644 --- a/java/src/org/futo/inputmethod/keyboard/Key.kt +++ b/java/src/org/futo/inputmethod/keyboard/Key.kt @@ -554,7 +554,7 @@ data class Key( val dirs = computeDirectionsFromDeltaPos( dx = dx.toDouble(), dy = dy.toDouble(), - threshold = (width / 3).toDouble() + threshold = (width * flickThresholdRatio).toDouble() ) dirs.firstOrNull { flickKeys.contains(it) } } @@ -569,6 +569,10 @@ data class Key( get() = mFlickDirection companion object { + @Volatile + @JvmStatic + var flickThresholdRatio: Float = 1.0f / 3.0f + @JvmStatic fun removeRedundantMoreKeys( key: Key, diff --git a/java/src/org/futo/inputmethod/latin/LatinIME.kt b/java/src/org/futo/inputmethod/latin/LatinIME.kt index 0924d9460e..8ea1d45aa4 100644 --- a/java/src/org/futo/inputmethod/latin/LatinIME.kt +++ b/java/src/org/futo/inputmethod/latin/LatinIME.kt @@ -59,6 +59,7 @@ import org.futo.inputmethod.accessibility.AccessibilityUtils import org.futo.inputmethod.engine.ExpandableSuggestionBarConfiguration import org.futo.inputmethod.engine.IMEManager import org.futo.inputmethod.engine.general.WordLearner +import org.futo.inputmethod.keyboard.Key import org.futo.inputmethod.latin.SuggestedWords.SuggestedWordInfo import org.futo.inputmethod.latin.common.Constants import org.futo.inputmethod.latin.settings.Settings @@ -86,6 +87,8 @@ import org.futo.inputmethod.latin.uix.getSettingFlow import org.futo.inputmethod.latin.uix.isDirectBootUnlocked import org.futo.inputmethod.latin.uix.safeKeyboardPadding import org.futo.inputmethod.latin.uix.setSetting +import org.futo.inputmethod.latin.uix.settings.pages.FLICK_THRESHOLD_DEFAULT +import org.futo.inputmethod.latin.uix.settings.pages.flickThresholdSetting import org.futo.inputmethod.latin.uix.theme.ThemeOption import org.futo.inputmethod.latin.uix.theme.applyWindowColors import org.futo.inputmethod.latin.uix.theme.getThemeOption @@ -440,6 +443,16 @@ class LatinIME : InputMethodServiceCompose(), LatinIMELegacy.SuggestionStripCont } } + val toFlickThresholdRatio: (Int) -> Float = { + if(it < 0) FLICK_THRESHOLD_DEFAULT else it / 100.0f + } + Key.flickThresholdRatio = toFlickThresholdRatio(getSettingBlocking(flickThresholdSetting)) + launchJob { + getSettingFlow(flickThresholdSetting).collect { + Key.flickThresholdRatio = toFlickThresholdRatio(it) + } + } + launchJob { val onNewSubtype: suspend (String) -> Unit = { val activeSubtype = it.ifEmpty { diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Typing.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Typing.kt index 0218653c24..df089c6690 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Typing.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Typing.kt @@ -145,6 +145,15 @@ val keySoundVolumeSetting = SettingsKey( 0.0f ) +// Percentage of the key width a swipe has to cover to trigger a flick. +// -1 means "use the built-in default", see FLICK_THRESHOLD_DEFAULT. +val flickThresholdSetting = SettingsKey( + intPreferencesKey("flick_threshold_percent"), + -1 +) + +const val FLICK_THRESHOLD_DEFAULT = 1.0f / 3.0f + val ActionBarDisplayedSetting = SettingsKey( booleanPreferencesKey("enable_action_bar"), true @@ -663,6 +672,29 @@ val LongPressMenu = UserSettingsMenu( steps = 23 ) }, + + UserSetting( + name = R.string.morekey_settings_flick_threshold, + subtitle = R.string.morekey_settings_flick_threshold_subtitle, + searchTags = R.string.morekey_settings_flick_threshold_tags, + ) { + val resources = LocalResources.current + SettingSlider( + title = stringResource(R.string.morekey_settings_flick_threshold), + subtitle = stringResource(R.string.morekey_settings_flick_threshold_subtitle), + setting = flickThresholdSetting, + range = -1.0f .. 100.0f, + hardRange = -1.0f .. 100.0f, + transform = { if(it < 1.0f) -1 else it.roundToInt() }, + indicator = { + if(it < 0) { + resources.getString(R.string.morekey_settings_flick_threshold_default) + } else { + "$it%" + } + } + ) + }, ) )