mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-04 05:40:17 +00:00
More visual options for gesture typing (#944)
This commit is contained in:
parent
28ba8a7a72
commit
83ae078cfa
95 changed files with 171 additions and 127 deletions
|
@ -10,6 +10,9 @@ import android.content.SharedPreferences;
|
|||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import helium314.keyboard.keyboard.KeyboardSwitcher;
|
||||
import helium314.keyboard.latin.R;
|
||||
|
||||
/**
|
||||
|
@ -22,14 +25,27 @@ import helium314.keyboard.latin.R;
|
|||
* - Phrase gesture
|
||||
*/
|
||||
public final class GestureSettingsFragment extends SubScreenFragment {
|
||||
private boolean needsReload = false;
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
addPreferencesFromResource(R.xml.prefs_screen_gesture);
|
||||
setupGestureDynamicPreviewPref();
|
||||
setupGestureFastTypingCooldownPref();
|
||||
setupGestureTrailFadeoutPref();
|
||||
refreshSettingsEnablement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (needsReload) {
|
||||
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext());
|
||||
needsReload = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
|
||||
refreshSettingsEnablement();
|
||||
|
@ -37,10 +53,34 @@ public final class GestureSettingsFragment extends SubScreenFragment {
|
|||
|
||||
private void refreshSettingsEnablement() {
|
||||
final SharedPreferences prefs = getSharedPreferences();
|
||||
setPreferenceVisible(Settings.PREF_GESTURE_PREVIEW_TRAIL, Settings.readGestureInputEnabled(prefs));
|
||||
setPreferenceVisible(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, Settings.readGestureInputEnabled(prefs));
|
||||
setPreferenceVisible(Settings.PREF_GESTURE_SPACE_AWARE, Settings.readGestureInputEnabled(prefs));
|
||||
setPreferenceVisible(Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, Settings.readGestureInputEnabled(prefs));
|
||||
final boolean gestureInputEnabled = Settings.readGestureInputEnabled(prefs);
|
||||
setPreferenceVisible(Settings.PREF_GESTURE_PREVIEW_TRAIL, gestureInputEnabled);
|
||||
setPreferenceVisible(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, gestureInputEnabled);
|
||||
final boolean gesturePreviewEnabled = gestureInputEnabled
|
||||
&& prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true);
|
||||
setPreferenceVisible(Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC, gesturePreviewEnabled);
|
||||
setPreferenceVisible(Settings.PREF_GESTURE_SPACE_AWARE, gestureInputEnabled);
|
||||
setPreferenceVisible(Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, gestureInputEnabled);
|
||||
final boolean gestureTrailEnabled = gestureInputEnabled
|
||||
&& prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true);
|
||||
// This setting also affects the preview linger duration, so it's visible if either setting is enabled.
|
||||
setPreferenceVisible(Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION, gestureTrailEnabled || gesturePreviewEnabled);
|
||||
}
|
||||
|
||||
private void setupGestureDynamicPreviewPref() {
|
||||
final SwitchPreference pref = findPreference(Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC);
|
||||
if (pref == null) return;
|
||||
final SharedPreferences prefs = getSharedPreferences();
|
||||
pref.setChecked(Settings.readGestureDynamicPreviewEnabled(prefs, requireContext()));
|
||||
pref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
// default value is based on system reduced motion
|
||||
final boolean defValue = Settings.readGestureDynamicPreviewDefault(requireContext());
|
||||
final boolean followingSystem = newValue.equals(defValue);
|
||||
// allow the default to be overridden
|
||||
prefs.edit().putBoolean(Settings.PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM, followingSystem).apply();
|
||||
needsReload = true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private void setupGestureFastTypingCooldownPref() {
|
||||
|
@ -82,4 +122,44 @@ public final class GestureSettingsFragment extends SubScreenFragment {
|
|||
public void feedbackValue(final int value) {}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupGestureTrailFadeoutPref() {
|
||||
final SeekBarDialogPreference pref = findPreference(Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION);
|
||||
if (pref == null) return;
|
||||
final SharedPreferences prefs = getSharedPreferences();
|
||||
final Resources res = getResources();
|
||||
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
|
||||
@Override
|
||||
public void writeValue(final int value, final String key) {
|
||||
prefs.edit().putInt(key, value).apply();
|
||||
needsReload = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDefaultValue(final String key) {
|
||||
prefs.edit().remove(key).apply();
|
||||
needsReload = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readValue(final String key) {
|
||||
return Settings.readGestureTrailFadeoutDuration(prefs, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readDefaultValue(final String key) {
|
||||
return Settings.readDefaultGestureTrailFadeoutDuration(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueText(final int value) {
|
||||
// fade-out has a constant start delay, value text is adjusted accordingly.
|
||||
final int adjustedValue = res.getInteger(R.integer.config_gesture_trail_fadeout_start_delay) + value;
|
||||
return res.getString(R.string.abbreviation_unit_milliseconds, String.valueOf(adjustedValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void feedbackValue(final int value) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,8 +115,11 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
public static final String PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY = "enable_emoji_alt_physical_key";
|
||||
public static final String PREF_GESTURE_PREVIEW_TRAIL = "gesture_preview_trail";
|
||||
public static final String PREF_GESTURE_FLOATING_PREVIEW_TEXT = "gesture_floating_preview_text";
|
||||
public static final String PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC = "gesture_floating_preview_dynamic";
|
||||
public static final String PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM = "gesture_dynamic_preview_follow_system";
|
||||
public static final String PREF_GESTURE_SPACE_AWARE = "gesture_space_aware";
|
||||
public static final String PREF_GESTURE_FAST_TYPING_COOLDOWN = "gesture_fast_typing_cooldown";
|
||||
public static final String PREF_GESTURE_TRAIL_FADEOUT_DURATION = "gesture_trail_fadeout_duration";
|
||||
public static final String PREF_SHOW_SETUP_WIZARD_ICON = "show_setup_wizard_icon";
|
||||
public static final String PREF_USE_CONTACTS = "use_contacts";
|
||||
public static final String PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD = "long_press_symbols_for_numpad";
|
||||
|
@ -311,6 +314,44 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
return JniUtils.sHaveGestureLib && prefs.getBoolean(PREF_GESTURE_INPUT, true);
|
||||
}
|
||||
|
||||
public static boolean readGestureDynamicPreviewEnabled(final SharedPreferences prefs, final Context context) {
|
||||
final boolean followSystem = prefs.getBoolean(PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM, true);
|
||||
final boolean defValue = readGestureDynamicPreviewDefault(context);
|
||||
final boolean curValue = prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC, defValue);
|
||||
return followSystem ? defValue : curValue;
|
||||
}
|
||||
|
||||
public static boolean readGestureDynamicPreviewDefault(final Context context) {
|
||||
// if transitions are disabled for the system (reduced motion), moving preview should be disabled
|
||||
return android.provider.Settings.System.getFloat(
|
||||
context.getContentResolver(),
|
||||
android.provider.Settings.Global.TRANSITION_ANIMATION_SCALE,
|
||||
1.0f
|
||||
) != 0.0f;
|
||||
}
|
||||
|
||||
public static int readGestureFastTypingCooldown(final SharedPreferences prefs, final Resources res) {
|
||||
final int milliseconds = prefs.getInt(
|
||||
PREF_GESTURE_FAST_TYPING_COOLDOWN, UNDEFINED_PREFERENCE_VALUE_INT);
|
||||
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
|
||||
: readDefaultGestureFastTypingCooldown(res);
|
||||
}
|
||||
|
||||
public static int readDefaultGestureFastTypingCooldown(final Resources res) {
|
||||
return res.getInteger(R.integer.config_gesture_static_time_threshold_after_fast_typing);
|
||||
}
|
||||
|
||||
public static int readGestureTrailFadeoutDuration(final SharedPreferences prefs, final Resources res) {
|
||||
final int milliseconds = prefs.getInt(
|
||||
PREF_GESTURE_TRAIL_FADEOUT_DURATION, UNDEFINED_PREFERENCE_VALUE_INT);
|
||||
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
|
||||
: readDefaultGestureTrailFadeoutDuration(res);
|
||||
}
|
||||
|
||||
public static int readDefaultGestureTrailFadeoutDuration(final Resources res) {
|
||||
return res.getInteger(R.integer.config_gesture_trail_fadeout_duration_default);
|
||||
}
|
||||
|
||||
public static boolean readKeyPreviewPopupEnabled(final SharedPreferences prefs, final Resources res) {
|
||||
final boolean defaultKeyPreviewPopup = res.getBoolean(R.bool.config_default_key_preview_popup);
|
||||
return prefs.getBoolean(PREF_POPUP_ON, defaultKeyPreviewPopup);
|
||||
|
@ -370,17 +411,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
return res.getInteger(R.integer.config_clipboard_history_retention_time);
|
||||
}
|
||||
|
||||
public static int readGestureFastTypingCooldown(final SharedPreferences prefs, final Resources res) {
|
||||
final int milliseconds = prefs.getInt(
|
||||
PREF_GESTURE_FAST_TYPING_COOLDOWN, UNDEFINED_PREFERENCE_VALUE_INT);
|
||||
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
|
||||
: readDefaultGestureFastTypingCooldown(res);
|
||||
}
|
||||
|
||||
public static int readDefaultGestureFastTypingCooldown(final Resources res) {
|
||||
return res.getInteger(R.integer.config_gesture_static_time_threshold_after_fast_typing);
|
||||
}
|
||||
|
||||
public static int readHorizontalSpaceSwipe(final SharedPreferences prefs) {
|
||||
return switch (prefs.getString(PREF_SPACE_HORIZONTAL_SWIPE, "none")) {
|
||||
case "move_cursor" -> KeyboardActionListener.SWIPE_MOVE_CURSOR;
|
||||
|
|
|
@ -95,7 +95,9 @@ public class SettingsValues {
|
|||
public final boolean mGestureInputEnabled;
|
||||
public final boolean mGestureTrailEnabled;
|
||||
public final boolean mGestureFloatingPreviewTextEnabled;
|
||||
public final boolean mGestureFloatingPreviewDynamicEnabled;
|
||||
public final int mGestureFastTypingCooldown;
|
||||
public final int mGestureTrailFadeoutDuration;
|
||||
public final boolean mSlidingKeyInputPreviewEnabled;
|
||||
public final int mKeyLongpressTimeout;
|
||||
public final boolean mEnableEmojiAltPhysicalKey;
|
||||
|
@ -203,10 +205,12 @@ public class SettingsValues {
|
|||
mEnableEmojiAltPhysicalKey = prefs.getBoolean(Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, true);
|
||||
mGestureInputEnabled = Settings.readGestureInputEnabled(prefs);
|
||||
mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true);
|
||||
mAccount = null; // remove? or can it be useful somewhere?
|
||||
mGestureFloatingPreviewTextEnabled = !mInputAttributes.mDisableGestureFloatingPreviewText
|
||||
&& prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true);
|
||||
mGestureFloatingPreviewDynamicEnabled = Settings.readGestureDynamicPreviewEnabled(prefs, context);
|
||||
mGestureFastTypingCooldown = Settings.readGestureFastTypingCooldown(prefs, res);
|
||||
mGestureTrailFadeoutDuration = Settings.readGestureTrailFadeoutDuration(prefs, res);
|
||||
mAccount = null; // remove? or can it be useful somewhere?
|
||||
mOverrideShowingSuggestions = mInputAttributes.mMayOverrideShowingSuggestions && readSuggestionsOverrideEnabled(prefs);
|
||||
mSuggestionsEnabledPerUserSettings = (mInputAttributes.mShouldShowSuggestions && readSuggestionsEnabled(prefs))
|
||||
|| mOverrideShowingSuggestions;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue