Skip to content

Commit efd7d53

Browse files
authored
Option to customize start lag for gestures during fast typing (#894)
fixes #882
1 parent 4aac813 commit efd7d53

File tree

8 files changed

+72
-3
lines changed

8 files changed

+72
-3
lines changed

Diff for: app/src/main/java/helium314/keyboard/keyboard/internal/GestureStrokeRecognitionParams.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class GestureStrokeRecognitionParams {
4040

4141
private GestureStrokeRecognitionParams() {
4242
// These parameter values are default and intended for testing.
43-
mStaticTimeThresholdAfterFastTyping = 350; // msec
43+
mStaticTimeThresholdAfterFastTyping = 500; // msec
4444
mDetectFastMoveSpeedThreshold = 1.5f; // keyWidth/sec
4545
mDynamicThresholdDecayDuration = 450; // msec
4646
mDynamicTimeThresholdFrom = 300; // msec

Diff for: app/src/main/java/helium314/keyboard/keyboard/internal/GestureStrokeRecognitionPoints.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package helium314.keyboard.keyboard.internal;
88

9+
import helium314.keyboard.latin.settings.Settings;
910
import helium314.keyboard.latin.utils.Log;
1011

1112
import helium314.keyboard.latin.common.Constants;
@@ -104,7 +105,7 @@ public int getLength() {
104105
public void addDownEventPoint(final int x, final int y, final int elapsedTimeSinceFirstDown,
105106
final int elapsedTimeSinceLastTyping) {
106107
reset();
107-
if (elapsedTimeSinceLastTyping < mRecognitionParams.mStaticTimeThresholdAfterFastTyping) {
108+
if (elapsedTimeSinceLastTyping < Settings.getInstance().getCurrent().mGestureFastTypingCooldown) {
108109
mAfterFastTyping = true;
109110
}
110111
if (DEBUG) {

Diff for: app/src/main/java/helium314/keyboard/latin/settings/GestureSettingsFragment.java

+43
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package helium314.keyboard.latin.settings;
88

99
import android.content.SharedPreferences;
10+
import android.content.res.Resources;
1011
import android.os.Bundle;
1112

1213
import helium314.keyboard.latin.R;
@@ -25,6 +26,7 @@ public final class GestureSettingsFragment extends SubScreenFragment {
2526
public void onCreate(final Bundle icicle) {
2627
super.onCreate(icicle);
2728
addPreferencesFromResource(R.xml.prefs_screen_gesture);
29+
setupGestureFastTypingCooldownPref();
2830
refreshSettingsEnablement();
2931
}
3032

@@ -38,5 +40,46 @@ private void refreshSettingsEnablement() {
3840
setPreferenceVisible(Settings.PREF_GESTURE_PREVIEW_TRAIL, Settings.readGestureInputEnabled(prefs));
3941
setPreferenceVisible(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, Settings.readGestureInputEnabled(prefs));
4042
setPreferenceVisible(Settings.PREF_GESTURE_SPACE_AWARE, Settings.readGestureInputEnabled(prefs));
43+
setPreferenceVisible(Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, Settings.readGestureInputEnabled(prefs));
44+
}
45+
46+
private void setupGestureFastTypingCooldownPref() {
47+
final SeekBarDialogPreference pref = findPreference(
48+
Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN);
49+
if (pref == null) return;
50+
final SharedPreferences prefs = getSharedPreferences();
51+
final Resources res = getResources();
52+
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
53+
@Override
54+
public void writeValue(final int value, final String key) {
55+
prefs.edit().putInt(key, value).apply();
56+
}
57+
58+
@Override
59+
public void writeDefaultValue(final String key) {
60+
prefs.edit().remove(key).apply();
61+
}
62+
63+
@Override
64+
public int readValue(final String key) {
65+
return Settings.readGestureFastTypingCooldown(prefs, res);
66+
}
67+
68+
@Override
69+
public int readDefaultValue(final String key) {
70+
return Settings.readDefaultGestureFastTypingCooldown(res);
71+
}
72+
73+
@Override
74+
public String getValueText(final int value) {
75+
if (value == 0) {
76+
return res.getString(R.string.gesture_fast_typing_cooldown_instant);
77+
}
78+
return res.getString(R.string.abbreviation_unit_milliseconds, String.valueOf(value));
79+
}
80+
81+
@Override
82+
public void feedbackValue(final int value) {}
83+
});
4184
}
4285
}

Diff for: app/src/main/java/helium314/keyboard/latin/settings/Settings.java

+12
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
115115
public static final String PREF_GESTURE_PREVIEW_TRAIL = "gesture_preview_trail";
116116
public static final String PREF_GESTURE_FLOATING_PREVIEW_TEXT = "gesture_floating_preview_text";
117117
public static final String PREF_GESTURE_SPACE_AWARE = "gesture_space_aware";
118+
public static final String PREF_GESTURE_FAST_TYPING_COOLDOWN = "gesture_fast_typing_cooldown";
118119
public static final String PREF_SHOW_SETUP_WIZARD_ICON = "show_setup_wizard_icon";
119120
public static final String PREF_USE_CONTACTS = "use_contacts";
120121
public static final String PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD = "long_press_symbols_for_numpad";
@@ -364,6 +365,17 @@ public static int readDefaultClipboardHistoryRetentionTime(final Resources res)
364365
return res.getInteger(R.integer.config_clipboard_history_retention_time);
365366
}
366367

368+
public static int readGestureFastTypingCooldown(final SharedPreferences prefs, final Resources res) {
369+
final int milliseconds = prefs.getInt(
370+
PREF_GESTURE_FAST_TYPING_COOLDOWN, UNDEFINED_PREFERENCE_VALUE_INT);
371+
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
372+
: readDefaultGestureFastTypingCooldown(res);
373+
}
374+
375+
public static int readDefaultGestureFastTypingCooldown(final Resources res) {
376+
return res.getInteger(R.integer.config_gesture_static_time_threshold_after_fast_typing);
377+
}
378+
367379
public static int readHorizontalSpaceSwipe(final SharedPreferences prefs) {
368380
return switch (prefs.getString(PREF_SPACE_HORIZONTAL_SWIPE, "none")) {
369381
case "move_cursor" -> KeyboardActionListener.SWIPE_MOVE_CURSOR;

Diff for: app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public class SettingsValues {
9595
public final boolean mGestureInputEnabled;
9696
public final boolean mGestureTrailEnabled;
9797
public final boolean mGestureFloatingPreviewTextEnabled;
98+
public final int mGestureFastTypingCooldown;
9899
public final boolean mSlidingKeyInputPreviewEnabled;
99100
public final int mKeyLongpressTimeout;
100101
public final boolean mEnableEmojiAltPhysicalKey;
@@ -199,6 +200,7 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina
199200
mAccount = null; // remove? or can it be useful somewhere?
200201
mGestureFloatingPreviewTextEnabled = !mInputAttributes.mDisableGestureFloatingPreviewText
201202
&& prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true);
203+
mGestureFastTypingCooldown = Settings.readGestureFastTypingCooldown(prefs, res);
202204
mOverrideShowingSuggestions = mInputAttributes.mMayOverrideShowingSuggestions && readSuggestionsOverrideEnabled(prefs);
203205
mSuggestionsEnabledPerUserSettings = (mInputAttributes.mShouldShowSuggestions && readSuggestionsEnabled(prefs))
204206
|| mOverrideShowingSuggestions;

Diff for: app/src/main/res/values/config-common.xml

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<integer name="config_gesture_trail_update_interval">20</integer>
5858
<!-- Static threshold for gesture after fast typing (msec) -->
5959
<integer name="config_gesture_static_time_threshold_after_fast_typing">500</integer>
60+
<integer name="config_gesture_fast_typing_cooldown_step">10</integer>
6061
<!-- Static threshold for starting gesture detection (keyWidth%/sec) -->
6162
<fraction name="config_gesture_detect_fast_move_speed_threshold">150%</fraction>
6263
<!-- Dynamic threshold for gesture after fast typing (msec) -->

Diff for: app/src/main/res/values/strings.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@
146146
<string name="gesture_floating_preview_text_summary">See the suggested word while gesturing</string>
147147
<!-- Option to enable space aware gesture input. The user can input multiple words by gliding through the space key during a gesture input. [CHAR LIMIT=30]-->
148148
<string name="gesture_space_aware">Phrase gesture</string>
149-
<!-- Description for "gesture_space_aware" option. The user can input multiple words by gliding through the space key during a gesture input.[CHAR LIMIT=65]-->
149+
<!-- Description for "gesture_space_aware" option. The user can input multiple words by gliding through the space key during a gesture input. [CHAR LIMIT=65]-->
150150
<string name="gesture_space_aware_summary">Input spaces during gestures by gliding to the space key</string>
151+
<!-- Title of the setting to adjust the fast-typing gesture cooldown [CHAR LIMIT=35]-->
152+
<string name="gesture_fast_typing_cooldown">Rapid typing cooldown</string>
153+
<!-- The text that represents no cooldown [CHAR LIMIT=25]-->
154+
<string name="gesture_fast_typing_cooldown_instant">Always start instantly</string>
151155
<!-- Preferences item for enabling clipboard history -->
152156
<string name="enable_clipboard_history">Enable clipboard history</string>
153157
<!-- Description for enabling/disabling clipboard history mentioning that if disabled, clipboard content is pasted -->

Diff for: app/src/main/res/xml/prefs_screen_gesture.xml

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
-->
77
<PreferenceScreen
88
xmlns:android="http://schemas.android.com/apk/res/android"
9+
xmlns:latin="http://schemas.android.com/apk/res-auto"
910
android:title="@string/settings_screen_gesture"
1011
android:key="screen_gesture">
1112
<SwitchPreference
@@ -31,4 +32,9 @@
3132
android:summary="@string/gesture_space_aware_summary"
3233
android:defaultValue="false"
3334
android:persistent="true" />
35+
<helium314.keyboard.latin.settings.SeekBarDialogPreference
36+
android:key="gesture_fast_typing_cooldown"
37+
android:title="@string/gesture_fast_typing_cooldown"
38+
latin:maxValue="@integer/config_gesture_static_time_threshold_after_fast_typing"
39+
latin:stepValue="@integer/config_gesture_fast_typing_cooldown_step" />
3440
</PreferenceScreen>

0 commit comments

Comments
 (0)