2019-12-31 18:19:35 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
2023-10-17 13:44:01 +02:00
|
|
|
* modified
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
2019-12-31 18:19:35 +01:00
|
|
|
*/
|
|
|
|
|
2024-01-31 18:32:43 +01:00
|
|
|
package helium314.keyboard.latin.settings;
|
2019-12-31 18:19:35 +01:00
|
|
|
|
2024-05-11 17:40:49 +02:00
|
|
|
import android.Manifest;
|
2019-12-31 18:19:35 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
2023-09-10 00:20:21 +02:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2019-12-31 18:19:35 +01:00
|
|
|
|
2023-09-01 08:08:36 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2024-03-06 20:55:47 +01:00
|
|
|
import androidx.core.util.TypedValueCompat;
|
2023-09-01 08:08:36 +02:00
|
|
|
|
2024-01-31 18:32:43 +01:00
|
|
|
import helium314.keyboard.compat.ConfigurationCompatKt;
|
2025-02-23 16:24:59 +01:00
|
|
|
import helium314.keyboard.keyboard.KeyboardTheme;
|
2024-02-14 11:08:44 +01:00
|
|
|
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyboardInfosKt;
|
2024-01-31 18:32:43 +01:00
|
|
|
import helium314.keyboard.latin.InputAttributes;
|
|
|
|
import helium314.keyboard.latin.R;
|
|
|
|
import helium314.keyboard.latin.RichInputMethodManager;
|
|
|
|
import helium314.keyboard.latin.common.Colors;
|
2024-05-11 17:40:49 +02:00
|
|
|
import helium314.keyboard.latin.permissions.PermissionsUtil;
|
2024-01-31 18:32:43 +01:00
|
|
|
import helium314.keyboard.latin.utils.InputTypeUtils;
|
2025-02-09 19:01:57 +01:00
|
|
|
import helium314.keyboard.latin.utils.JniUtils;
|
2024-01-31 18:32:43 +01:00
|
|
|
import helium314.keyboard.latin.utils.ScriptUtils;
|
2025-02-16 12:49:19 +01:00
|
|
|
import helium314.keyboard.latin.utils.SubtypeSettings;
|
2025-02-19 23:00:58 +01:00
|
|
|
import helium314.keyboard.latin.utils.SubtypeUtilsKt;
|
2019-12-31 18:19:35 +01:00
|
|
|
|
2023-08-11 00:58:33 +02:00
|
|
|
import java.util.List;
|
2019-12-31 18:19:35 +01:00
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When you call the constructor of this class, you may want to change the current system locale by
|
2024-01-31 18:32:43 +01:00
|
|
|
* using {@link helium314.keyboard.latin.utils.RunInLocaleKt}.
|
2019-12-31 18:19:35 +01:00
|
|
|
*/
|
|
|
|
// Non-final for testing via mock library.
|
|
|
|
public class SettingsValues {
|
|
|
|
public static final float DEFAULT_SIZE_SCALE = 1.0f; // 100%
|
|
|
|
|
|
|
|
// From resources:
|
|
|
|
public final SpacingAndPunctuations mSpacingAndPunctuations;
|
|
|
|
public final long mDoubleSpacePeriodTimeout;
|
|
|
|
// From configuration:
|
|
|
|
public final Locale mLocale;
|
|
|
|
public final boolean mHasHardwareKeyboard;
|
|
|
|
public final int mDisplayOrientation;
|
2024-04-07 10:03:08 +02:00
|
|
|
// From preferences
|
2019-12-31 18:19:35 +01:00
|
|
|
public final boolean mAutoCap;
|
|
|
|
public final boolean mVibrateOn;
|
2025-01-12 20:28:23 +01:00
|
|
|
public final boolean mVibrateInDndMode;
|
2019-12-31 18:19:35 +01:00
|
|
|
public final boolean mSoundOn;
|
|
|
|
public final boolean mKeyPreviewPopupOn;
|
|
|
|
public final boolean mShowsVoiceInputKey;
|
2023-09-09 08:29:06 +02:00
|
|
|
public final boolean mLanguageSwitchKeyToOtherImes;
|
|
|
|
public final boolean mLanguageSwitchKeyToOtherSubtypes;
|
2024-06-01 22:27:41 +02:00
|
|
|
private final boolean mShowsLanguageSwitchKey;
|
2020-09-11 16:59:15 +02:00
|
|
|
public final boolean mShowsNumberRow;
|
2023-11-27 15:50:06 +01:00
|
|
|
public final boolean mLocalizedNumberRow;
|
2025-01-31 23:53:08 +02:00
|
|
|
public final boolean mShowNumberRowHints;
|
2021-04-29 14:58:59 -04:00
|
|
|
public final boolean mShowsHints;
|
2023-09-23 13:02:56 +02:00
|
|
|
public final boolean mShowsPopupHints;
|
2021-10-24 17:17:48 +05:30
|
|
|
public final boolean mSpaceForLangChange;
|
2020-09-30 16:11:13 +02:00
|
|
|
public final boolean mShowsEmojiKey;
|
2024-03-27 07:04:59 +02:00
|
|
|
public final boolean mVarToolbarDirection;
|
2019-12-31 18:19:35 +01:00
|
|
|
public final boolean mUsePersonalizedDicts;
|
|
|
|
public final boolean mUseDoubleSpacePeriod;
|
|
|
|
public final boolean mBlockPotentiallyOffensive;
|
2024-03-12 01:42:25 +04:00
|
|
|
public final int mSpaceSwipeHorizontal;
|
|
|
|
public final int mSpaceSwipeVertical;
|
2025-02-03 02:46:11 +06:00
|
|
|
public final int mLanguageSwipeDistance;
|
2020-01-18 16:26:22 +01:00
|
|
|
public final boolean mDeleteSwipeEnabled;
|
2022-03-21 15:09:39 +01:00
|
|
|
public final boolean mAutospaceAfterPunctuationEnabled;
|
2022-02-18 21:08:29 +01:00
|
|
|
public final boolean mClipboardHistoryEnabled;
|
|
|
|
public final long mClipboardHistoryRetentionTime;
|
2022-02-20 16:14:12 +01:00
|
|
|
public final boolean mOneHandedModeEnabled;
|
|
|
|
public final int mOneHandedModeGravity;
|
2023-12-18 17:30:53 +01:00
|
|
|
public final float mOneHandedModeScale;
|
2023-08-14 19:16:43 +02:00
|
|
|
public final boolean mNarrowKeyGaps;
|
2025-02-17 15:55:31 +01:00
|
|
|
public final String mShowMorePopupKeys;
|
2024-02-05 09:33:06 +01:00
|
|
|
public final List<String> mPopupKeyTypes;
|
|
|
|
public final List<String> mPopupKeyLabelSources;
|
2023-08-11 00:58:33 +02:00
|
|
|
public final List<Locale> mSecondaryLocales;
|
2024-04-07 10:03:08 +02:00
|
|
|
public final boolean mBigramPredictionEnabled;// Use bigrams to predict the next word when there is no input for it yet
|
2024-05-01 00:33:57 -04:00
|
|
|
public final boolean mCenterSuggestionTextToEnter;
|
2019-12-31 18:19:35 +01:00
|
|
|
public final boolean mGestureInputEnabled;
|
|
|
|
public final boolean mGestureTrailEnabled;
|
|
|
|
public final boolean mGestureFloatingPreviewTextEnabled;
|
2024-07-24 23:08:50 -06:00
|
|
|
public final boolean mGestureFloatingPreviewDynamicEnabled;
|
2024-06-26 13:00:06 -06:00
|
|
|
public final int mGestureFastTypingCooldown;
|
2024-07-24 23:08:50 -06:00
|
|
|
public final int mGestureTrailFadeoutDuration;
|
2019-12-31 18:19:35 +01:00
|
|
|
public final boolean mSlidingKeyInputPreviewEnabled;
|
|
|
|
public final int mKeyLongpressTimeout;
|
|
|
|
public final boolean mEnableEmojiAltPhysicalKey;
|
|
|
|
public final boolean mIsSplitKeyboardEnabled;
|
2023-12-19 23:32:30 +01:00
|
|
|
public final float mSplitKeyboardSpacerRelativeWidth;
|
2024-05-27 20:34:26 +02:00
|
|
|
public final boolean mQuickPinToolbarKeys;
|
2019-12-31 18:19:35 +01:00
|
|
|
public final int mScreenMetrics;
|
2023-06-28 21:18:41 +02:00
|
|
|
public final boolean mAddToPersonalDictionary;
|
2023-06-29 10:56:17 +02:00
|
|
|
public final boolean mUseContactsDictionary;
|
2023-07-21 17:13:14 +02:00
|
|
|
public final boolean mCustomNavBarColor;
|
2023-09-10 21:39:56 +02:00
|
|
|
public final float mKeyboardHeightScale;
|
2023-09-20 19:10:01 +02:00
|
|
|
public final boolean mUrlDetectionEnabled;
|
2023-11-03 14:24:43 +01:00
|
|
|
public final float mBottomPaddingScale;
|
2025-01-26 17:31:23 +01:00
|
|
|
public final float mSidePaddingScale;
|
2024-06-01 15:32:12 +03:00
|
|
|
public final boolean mAutoShowToolbar;
|
|
|
|
public final boolean mAutoHideToolbar;
|
2024-07-10 17:23:10 +02:00
|
|
|
public final boolean mAlphaAfterEmojiInEmojiView;
|
|
|
|
public final boolean mAlphaAfterClipHistoryEntry;
|
|
|
|
public final boolean mAlphaAfterSymbolAndSpace;
|
2024-07-13 09:13:14 +02:00
|
|
|
public final boolean mRemoveRedundantPopups;
|
2024-08-28 22:08:00 +02:00
|
|
|
public final String mSpaceBarText;
|
2025-01-26 09:27:48 +01:00
|
|
|
public final float mFontSizeMultiplier;
|
|
|
|
public final float mFontSizeMultiplierEmoji;
|
2019-12-31 18:19:35 +01:00
|
|
|
|
|
|
|
// From the input box
|
2023-09-01 08:08:36 +02:00
|
|
|
@NonNull
|
2019-12-31 18:19:35 +01:00
|
|
|
public final InputAttributes mInputAttributes;
|
|
|
|
|
|
|
|
// Deduced settings
|
|
|
|
public final int mKeypressVibrationDuration;
|
|
|
|
public final float mKeypressSoundVolume;
|
2024-01-23 12:29:14 +01:00
|
|
|
public final boolean mAutoCorrectionEnabledPerUserSettings;
|
|
|
|
public final boolean mAutoCorrectEnabled;
|
2019-12-31 18:19:35 +01:00
|
|
|
public final float mAutoCorrectionThreshold;
|
2023-09-10 19:45:03 +02:00
|
|
|
public final int mScoreLimitForAutocorrect;
|
2025-01-14 22:19:44 +01:00
|
|
|
public final boolean mAutoCorrectShortcuts;
|
2019-12-31 18:19:35 +01:00
|
|
|
private final boolean mSuggestionsEnabledPerUserSettings;
|
2024-01-21 19:02:40 +01:00
|
|
|
private final boolean mOverrideShowingSuggestions;
|
2024-07-06 00:14:54 +03:00
|
|
|
public final boolean mSuggestClipboardContent;
|
2023-09-10 16:29:29 +02:00
|
|
|
public final SettingsValuesForSuggestion mSettingsValuesForSuggestion;
|
2020-09-07 12:44:39 +02:00
|
|
|
public final boolean mIncognitoModeEnabled;
|
2024-04-07 10:03:08 +02:00
|
|
|
public final boolean mLongPressSymbolsForNumpad;
|
2025-01-12 21:08:20 +01:00
|
|
|
public final int mEmojiMaxSdk;
|
2019-12-31 18:19:35 +01:00
|
|
|
|
2023-06-28 18:54:23 +02:00
|
|
|
// User-defined colors
|
2023-07-26 11:01:58 +02:00
|
|
|
public final Colors mColors;
|
2023-06-28 18:54:23 +02:00
|
|
|
|
2020-04-23 20:29:26 +04:00
|
|
|
@Nullable
|
2024-04-07 10:03:08 +02:00
|
|
|
public final String mAccount; // todo: always null, remove?
|
2019-12-31 18:19:35 +01:00
|
|
|
|
2023-12-29 12:08:32 +01:00
|
|
|
// creation of Colors and SpacingAndPunctuations are the slowest parts in here, but still ok
|
2019-12-31 18:19:35 +01:00
|
|
|
public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
|
2023-09-01 08:08:36 +02:00
|
|
|
@NonNull final InputAttributes inputAttributes) {
|
2024-01-28 10:42:42 +01:00
|
|
|
mLocale = ConfigurationCompatKt.locale(res.getConfiguration());
|
2025-02-09 05:32:16 -05:00
|
|
|
mDisplayOrientation = res.getConfiguration().orientation;
|
2025-02-19 23:00:58 +01:00
|
|
|
final InputMethodSubtype selectedSubtype = SubtypeSettings.INSTANCE.getSelectedSubtype(prefs);
|
2019-12-31 18:19:35 +01:00
|
|
|
|
|
|
|
// Store the input attributes
|
|
|
|
mInputAttributes = inputAttributes;
|
|
|
|
|
|
|
|
// Get the settings preferences
|
2025-02-09 19:01:57 +01:00
|
|
|
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, Defaults.PREF_AUTO_CAP) && ScriptUtils.scriptSupportsUppercase(mLocale);
|
|
|
|
mVibrateOn = Settings.readVibrationEnabled(prefs);
|
|
|
|
mVibrateInDndMode = prefs.getBoolean(Settings.PREF_VIBRATE_IN_DND_MODE, Defaults.PREF_VIBRATE_IN_DND_MODE);
|
|
|
|
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON, Defaults.PREF_SOUND_ON);
|
|
|
|
mKeyPreviewPopupOn = prefs.getBoolean(Settings.PREF_POPUP_ON, Defaults.PREF_POPUP_ON);
|
2019-12-31 18:19:35 +01:00
|
|
|
mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
|
2025-02-09 19:01:57 +01:00
|
|
|
DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, Defaults.PREF_SLIDING_KEY_INPUT_PREVIEW);
|
2023-09-24 21:31:37 +02:00
|
|
|
mShowsVoiceInputKey = mInputAttributes.mShouldShowVoiceInputKey;
|
2025-02-09 19:01:57 +01:00
|
|
|
final String languagePref = prefs.getString(Settings.PREF_LANGUAGE_SWITCH_KEY, Defaults.PREF_LANGUAGE_SWITCH_KEY);
|
2023-09-09 08:29:06 +02:00
|
|
|
mLanguageSwitchKeyToOtherImes = languagePref.equals("input_method") || languagePref.equals("both");
|
|
|
|
mLanguageSwitchKeyToOtherSubtypes = languagePref.equals("internal") || languagePref.equals("both");
|
2025-02-09 19:01:57 +01:00
|
|
|
mShowsLanguageSwitchKey = prefs.getBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, Defaults.PREF_SHOW_LANGUAGE_SWITCH_KEY);
|
|
|
|
mShowsNumberRow = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, Defaults.PREF_SHOW_NUMBER_ROW);
|
2025-02-19 23:00:58 +01:00
|
|
|
mLocalizedNumberRow = SubtypeUtilsKt.getHasLocalizedNumberRow(selectedSubtype, prefs);
|
2025-02-09 19:01:57 +01:00
|
|
|
mShowNumberRowHints = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW_HINTS, Defaults.PREF_SHOW_NUMBER_ROW_HINTS);
|
|
|
|
mShowsHints = prefs.getBoolean(Settings.PREF_SHOW_HINTS, Defaults.PREF_SHOW_HINTS);
|
|
|
|
mShowsPopupHints = prefs.getBoolean(Settings.PREF_SHOW_POPUP_HINTS, Defaults.PREF_SHOW_POPUP_HINTS);
|
|
|
|
mSpaceForLangChange = prefs.getBoolean(Settings.PREF_SPACE_TO_CHANGE_LANG, Defaults.PREF_SPACE_TO_CHANGE_LANG);
|
|
|
|
mShowsEmojiKey = prefs.getBoolean(Settings.PREF_SHOW_EMOJI_KEY, Defaults.PREF_SHOW_EMOJI_KEY);
|
|
|
|
mVarToolbarDirection = prefs.getBoolean(Settings.PREF_VARIABLE_TOOLBAR_DIRECTION, Defaults.PREF_VARIABLE_TOOLBAR_DIRECTION);
|
|
|
|
mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, Defaults.PREF_KEY_USE_PERSONALIZED_DICTS);
|
|
|
|
mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, Defaults.PREF_KEY_USE_DOUBLE_SPACE_PERIOD)
|
2019-12-31 18:19:35 +01:00
|
|
|
&& inputAttributes.mIsGeneralTextInput;
|
2025-02-09 19:01:57 +01:00
|
|
|
mBlockPotentiallyOffensive = prefs.getBoolean(Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE, Defaults.PREF_BLOCK_POTENTIALLY_OFFENSIVE);
|
|
|
|
mUrlDetectionEnabled = prefs.getBoolean(Settings.PREF_URL_DETECTION, Defaults.PREF_URL_DETECTION);
|
|
|
|
mAutoCorrectionEnabledPerUserSettings = prefs.getBoolean(Settings.PREF_AUTO_CORRECTION, Defaults.PREF_AUTO_CORRECTION);
|
2024-01-23 12:29:14 +01:00
|
|
|
mAutoCorrectEnabled = mAutoCorrectionEnabledPerUserSettings
|
2025-02-09 19:01:57 +01:00
|
|
|
&& (mInputAttributes.mInputTypeShouldAutoCorrect || prefs.getBoolean(Settings.PREF_MORE_AUTO_CORRECTION, Defaults.PREF_MORE_AUTO_CORRECTION))
|
2024-01-23 12:29:14 +01:00
|
|
|
&& (mUrlDetectionEnabled || !InputTypeUtils.isUriOrEmailType(mInputAttributes.mInputType));
|
2025-02-09 19:01:57 +01:00
|
|
|
mCenterSuggestionTextToEnter = prefs.getBoolean(Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER, Defaults.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER);
|
2022-12-14 21:48:36 +00:00
|
|
|
mAutoCorrectionThreshold = mAutoCorrectEnabled
|
2025-03-02 07:28:37 +01:00
|
|
|
? prefs.getFloat(Settings.PREF_AUTO_CORRECT_THRESHOLD, Defaults.PREF_AUTO_CORRECT_THRESHOLD)
|
|
|
|
: Float.MAX_VALUE;
|
2023-09-10 19:45:03 +02:00
|
|
|
mScoreLimitForAutocorrect = (mAutoCorrectionThreshold < 0) ? 600000 // very aggressive
|
|
|
|
: (mAutoCorrectionThreshold < 0.07 ? 800000 : 950000); // aggressive or modest
|
2025-02-09 19:01:57 +01:00
|
|
|
mAutoCorrectShortcuts = prefs.getBoolean(Settings.PREF_AUTOCORRECT_SHORTCUTS, Defaults.PREF_AUTOCORRECT_SHORTCUTS);
|
|
|
|
mBigramPredictionEnabled = prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, Defaults.PREF_BIGRAM_PREDICTIONS);
|
|
|
|
mSuggestClipboardContent = prefs.getBoolean(Settings.PREF_SUGGEST_CLIPBOARD_CONTENT, Defaults.PREF_SUGGEST_CLIPBOARD_CONTENT);
|
|
|
|
mDoubleSpacePeriodTimeout = 1100; // ms
|
2019-12-31 18:19:35 +01:00
|
|
|
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
|
2025-02-09 05:32:16 -05:00
|
|
|
final boolean isLandscape = mDisplayOrientation == Configuration.ORIENTATION_LANDSCAPE;
|
2024-03-06 20:55:47 +01:00
|
|
|
final float displayWidthDp = TypedValueCompat.pxToDp(res.getDisplayMetrics().widthPixels, res.getDisplayMetrics());
|
2025-02-09 05:32:16 -05:00
|
|
|
mIsSplitKeyboardEnabled = Settings.readSplitKeyboardEnabled(prefs, isLandscape);
|
2023-11-03 12:28:00 +01:00
|
|
|
// determine spacerWidth from display width and scale setting
|
2023-12-19 23:32:30 +01:00
|
|
|
mSplitKeyboardSpacerRelativeWidth = mIsSplitKeyboardEnabled
|
2025-02-09 05:32:16 -05:00
|
|
|
? Math.min(Math.max((displayWidthDp - 600) / 600f + 0.15f, 0.15f), 0.35f) * Settings.readSplitSpacerScale(prefs, isLandscape)
|
2023-11-03 12:28:00 +01:00
|
|
|
: 0f;
|
2025-02-09 19:01:57 +01:00
|
|
|
mQuickPinToolbarKeys = prefs.getBoolean(Settings.PREF_QUICK_PIN_TOOLBAR_KEYS, Defaults.PREF_QUICK_PIN_TOOLBAR_KEYS);
|
2019-12-31 18:19:35 +01:00
|
|
|
mScreenMetrics = Settings.readScreenMetrics(res);
|
|
|
|
|
|
|
|
// Compute other readable settings
|
2025-02-09 19:01:57 +01:00
|
|
|
mKeyLongpressTimeout = prefs.getInt(Settings.PREF_KEY_LONGPRESS_TIMEOUT, Defaults.PREF_KEY_LONGPRESS_TIMEOUT);
|
|
|
|
mKeypressVibrationDuration = prefs.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, Defaults.PREF_VIBRATION_DURATION_SETTINGS);
|
|
|
|
mKeypressSoundVolume = prefs.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, Defaults.PREF_KEYPRESS_SOUND_VOLUME);
|
|
|
|
mEnableEmojiAltPhysicalKey = prefs.getBoolean(Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, Defaults.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY);
|
|
|
|
mGestureInputEnabled = JniUtils.sHaveGestureLib && prefs.getBoolean(Settings.PREF_GESTURE_INPUT, Defaults.PREF_GESTURE_INPUT);
|
|
|
|
mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, Defaults.PREF_GESTURE_PREVIEW_TRAIL);
|
2019-12-31 18:19:35 +01:00
|
|
|
mGestureFloatingPreviewTextEnabled = !mInputAttributes.mDisableGestureFloatingPreviewText
|
2025-02-09 19:01:57 +01:00
|
|
|
&& prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, Defaults.PREF_GESTURE_FLOATING_PREVIEW_TEXT);
|
|
|
|
mGestureFloatingPreviewDynamicEnabled = Settings.readGestureDynamicPreviewEnabled(prefs);
|
|
|
|
mGestureFastTypingCooldown = prefs.getInt(Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, Defaults.PREF_GESTURE_FAST_TYPING_COOLDOWN);
|
|
|
|
mGestureTrailFadeoutDuration = prefs.getInt(Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION, Defaults.PREF_GESTURE_TRAIL_FADEOUT_DURATION);
|
2024-07-24 23:08:50 -06:00
|
|
|
mAccount = null; // remove? or can it be useful somewhere?
|
2025-02-09 19:01:57 +01:00
|
|
|
mOverrideShowingSuggestions = mInputAttributes.mMayOverrideShowingSuggestions && prefs.getBoolean(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, Defaults.PREF_ALWAYS_SHOW_SUGGESTIONS);
|
|
|
|
final boolean suggestionsEnabled = prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, Defaults.PREF_SHOW_SUGGESTIONS);
|
|
|
|
mSuggestionsEnabledPerUserSettings = (mInputAttributes.mShouldShowSuggestions && suggestionsEnabled)
|
2024-01-21 19:02:40 +01:00
|
|
|
|| mOverrideShowingSuggestions;
|
2025-02-09 19:01:57 +01:00
|
|
|
mIncognitoModeEnabled = prefs.getBoolean(Settings.PREF_ALWAYS_INCOGNITO_MODE, Defaults.PREF_ALWAYS_INCOGNITO_MODE) || mInputAttributes.mNoLearning
|
2021-11-22 08:20:12 -05:00
|
|
|
|| mInputAttributes.mIsPasswordField;
|
2025-02-09 19:01:57 +01:00
|
|
|
mKeyboardHeightScale = prefs.getFloat(Settings.PREF_KEYBOARD_HEIGHT_SCALE, Defaults.PREF_KEYBOARD_HEIGHT_SCALE);
|
2024-03-12 01:42:25 +04:00
|
|
|
mSpaceSwipeHorizontal = Settings.readHorizontalSpaceSwipe(prefs);
|
|
|
|
mSpaceSwipeVertical = Settings.readVerticalSpaceSwipe(prefs);
|
2025-02-09 19:01:57 +01:00
|
|
|
mLanguageSwipeDistance = prefs.getInt(Settings.PREF_LANGUAGE_SWIPE_DISTANCE, Defaults.PREF_LANGUAGE_SWIPE_DISTANCE);
|
|
|
|
mDeleteSwipeEnabled = prefs.getBoolean(Settings.PREF_DELETE_SWIPE, Defaults.PREF_DELETE_SWIPE);
|
|
|
|
mAutospaceAfterPunctuationEnabled = prefs.getBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, Defaults.PREF_AUTOSPACE_AFTER_PUNCTUATION);
|
|
|
|
mClipboardHistoryEnabled = prefs.getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY);
|
|
|
|
mClipboardHistoryRetentionTime = prefs.getInt(Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, Defaults.PREF_CLIPBOARD_HISTORY_RETENTION_TIME);
|
2023-12-18 17:30:53 +01:00
|
|
|
|
2025-02-09 13:36:25 +01:00
|
|
|
mOneHandedModeEnabled = Settings.readOneHandedModeEnabled(prefs, isLandscape);
|
|
|
|
mOneHandedModeGravity = Settings.readOneHandedModeGravity(prefs, isLandscape);
|
2023-12-18 17:30:53 +01:00
|
|
|
if (mOneHandedModeEnabled) {
|
|
|
|
final float baseScale = res.getFraction(R.fraction.config_one_handed_mode_width, 1, 1);
|
2025-02-09 13:36:25 +01:00
|
|
|
final float extraScale = Settings.readOneHandedModeScale(prefs, isLandscape);
|
2023-12-18 17:30:53 +01:00
|
|
|
mOneHandedModeScale = 1 - (1 - baseScale) * extraScale;
|
|
|
|
} else
|
|
|
|
mOneHandedModeScale = 1f;
|
2025-02-19 23:00:58 +01:00
|
|
|
mSecondaryLocales = SubtypeUtilsKt.getSecondaryLocales(selectedSubtype.getExtraValue());
|
2024-02-05 09:33:06 +01:00
|
|
|
mShowMorePopupKeys = selectedSubtype.isAsciiCapable()
|
2025-02-19 23:00:58 +01:00
|
|
|
? SubtypeUtilsKt.getMoreKeys(selectedSubtype, prefs)
|
2024-02-14 11:08:44 +01:00
|
|
|
: LocaleKeyboardInfosKt.POPUP_KEYS_NORMAL;
|
2025-02-23 16:24:59 +01:00
|
|
|
mColors = KeyboardTheme.getColorsForCurrentTheme(context);
|
2023-06-28 21:18:41 +02:00
|
|
|
|
2025-02-19 23:00:58 +01:00
|
|
|
mPopupKeyTypes = SubtypeUtilsKt.getPopupKeyTypes(selectedSubtype, prefs);
|
|
|
|
mPopupKeyLabelSources = SubtypeUtilsKt.getPopupKeyLabelSources(selectedSubtype, prefs);
|
2025-02-09 19:01:57 +01:00
|
|
|
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, Defaults.PREF_ADD_TO_PERSONAL_DICTIONARY);
|
2024-05-11 17:40:49 +02:00
|
|
|
mUseContactsDictionary = SettingsValues.readUseContactsEnabled(prefs, context);
|
2025-02-09 19:01:57 +01:00
|
|
|
mCustomNavBarColor = prefs.getBoolean(Settings.PREF_NAVBAR_COLOR, Defaults.PREF_NAVBAR_COLOR);
|
|
|
|
mNarrowKeyGaps = prefs.getBoolean(Settings.PREF_NARROW_KEY_GAPS, Defaults.PREF_NARROW_KEY_GAPS);
|
2023-09-10 16:29:29 +02:00
|
|
|
mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(
|
|
|
|
mBlockPotentiallyOffensive,
|
2025-02-09 19:01:57 +01:00
|
|
|
prefs.getBoolean(Settings.PREF_GESTURE_SPACE_AWARE, Defaults.PREF_GESTURE_SPACE_AWARE)
|
2023-09-10 16:29:29 +02:00
|
|
|
);
|
2023-09-25 10:10:56 +02:00
|
|
|
mSpacingAndPunctuations = new SpacingAndPunctuations(res, mUrlDetectionEnabled);
|
2025-02-09 13:36:25 +01:00
|
|
|
mBottomPaddingScale = Settings.readBottomPaddingScale(prefs, isLandscape);
|
|
|
|
mSidePaddingScale = Settings.readSidePaddingScale(prefs, isLandscape);
|
2025-02-09 19:01:57 +01:00
|
|
|
mLongPressSymbolsForNumpad = prefs.getBoolean(Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD, Defaults.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD);
|
|
|
|
mAutoShowToolbar = prefs.getBoolean(Settings.PREF_AUTO_SHOW_TOOLBAR, Defaults.PREF_AUTO_SHOW_TOOLBAR);
|
|
|
|
mAutoHideToolbar = suggestionsEnabled && prefs.getBoolean(Settings.PREF_AUTO_HIDE_TOOLBAR, Defaults.PREF_AUTO_HIDE_TOOLBAR);
|
|
|
|
mAlphaAfterEmojiInEmojiView = prefs.getBoolean(Settings.PREF_ABC_AFTER_EMOJI, Defaults.PREF_ABC_AFTER_EMOJI);
|
|
|
|
mAlphaAfterClipHistoryEntry = prefs.getBoolean(Settings.PREF_ABC_AFTER_CLIP, Defaults.PREF_ABC_AFTER_CLIP);
|
|
|
|
mAlphaAfterSymbolAndSpace = prefs.getBoolean(Settings.PREF_ABC_AFTER_SYMBOL_SPACE, Defaults.PREF_ABC_AFTER_SYMBOL_SPACE);
|
|
|
|
mRemoveRedundantPopups = prefs.getBoolean(Settings.PREF_REMOVE_REDUNDANT_POPUPS, Defaults.PREF_REMOVE_REDUNDANT_POPUPS);
|
|
|
|
mSpaceBarText = prefs.getString(Settings.PREF_SPACE_BAR_TEXT, Defaults.PREF_SPACE_BAR_TEXT);
|
|
|
|
mEmojiMaxSdk = prefs.getInt(Settings.PREF_EMOJI_MAX_SDK, Defaults.PREF_EMOJI_MAX_SDK);
|
|
|
|
mFontSizeMultiplier = prefs.getFloat(Settings.PREF_FONT_SCALE, Defaults.PREF_FONT_SCALE);
|
|
|
|
mFontSizeMultiplierEmoji = prefs.getFloat(Settings.PREF_EMOJI_FONT_SCALE, Defaults.PREF_EMOJI_FONT_SCALE);
|
2019-12-31 18:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isApplicationSpecifiedCompletionsOn() {
|
|
|
|
return mInputAttributes.mApplicationSpecifiedCompletionOn;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean needsToLookupSuggestions() {
|
2024-01-21 19:02:40 +01:00
|
|
|
return (mInputAttributes.mShouldShowSuggestions || mOverrideShowingSuggestions)
|
2024-01-23 12:29:14 +01:00
|
|
|
&& (mAutoCorrectEnabled || isSuggestionsEnabledPerUserSettings());
|
2019-12-31 18:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSuggestionsEnabledPerUserSettings() {
|
|
|
|
return mSuggestionsEnabledPerUserSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isWordSeparator(final int code) {
|
|
|
|
return mSpacingAndPunctuations.isWordSeparator(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isWordConnector(final int code) {
|
|
|
|
return mSpacingAndPunctuations.isWordConnector(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isWordCodePoint(final int code) {
|
|
|
|
return Character.isLetter(code) || isWordConnector(code)
|
|
|
|
|| Character.COMBINING_SPACING_MARK == Character.getType(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isUsuallyPrecededBySpace(final int code) {
|
|
|
|
return mSpacingAndPunctuations.isUsuallyPrecededBySpace(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isUsuallyFollowedBySpace(final int code) {
|
|
|
|
return mSpacingAndPunctuations.isUsuallyFollowedBySpace(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean shouldInsertSpacesAutomatically() {
|
|
|
|
return mInputAttributes.mShouldInsertSpacesAutomatically;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isLanguageSwitchKeyEnabled() {
|
2024-06-01 22:27:41 +02:00
|
|
|
if (!mShowsLanguageSwitchKey) {
|
2019-12-31 18:19:35 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final RichInputMethodManager imm = RichInputMethodManager.getInstance();
|
2023-09-09 08:29:06 +02:00
|
|
|
if (!mLanguageSwitchKeyToOtherSubtypes) {
|
2019-12-31 18:19:35 +01:00
|
|
|
return imm.hasMultipleEnabledIMEsOrSubtypes(false /* include aux subtypes */);
|
|
|
|
}
|
2023-09-09 08:29:06 +02:00
|
|
|
if (!mLanguageSwitchKeyToOtherImes) {
|
|
|
|
return imm.hasMultipleEnabledSubtypesInThisIme(false /* include aux subtypes */);
|
|
|
|
}
|
|
|
|
return imm.hasMultipleEnabledSubtypesInThisIme(false /* include aux subtypes */)
|
|
|
|
|| imm.hasMultipleEnabledIMEsOrSubtypes(false /* include aux subtypes */);
|
2019-12-31 18:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSameInputType(final EditorInfo editorInfo) {
|
|
|
|
return mInputAttributes.isSameInputType(editorInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasSameOrientation(final Configuration configuration) {
|
|
|
|
return mDisplayOrientation == configuration.orientation;
|
|
|
|
}
|
|
|
|
|
2024-05-11 17:40:49 +02:00
|
|
|
private static boolean readUseContactsEnabled(final SharedPreferences prefs, final Context context) {
|
2025-02-09 19:01:57 +01:00
|
|
|
final boolean setting = prefs.getBoolean(Settings.PREF_USE_CONTACTS, Defaults.PREF_USE_CONTACTS);
|
2025-02-09 13:27:55 +01:00
|
|
|
if (!setting) return false;
|
|
|
|
if (PermissionsUtil.checkAllPermissionsGranted(context, Manifest.permission.READ_CONTACTS))
|
|
|
|
return true;
|
|
|
|
// disable if permission not granted
|
|
|
|
prefs.edit().putBoolean(Settings.PREF_USE_CONTACTS, false).apply();
|
|
|
|
return false;
|
2024-05-11 17:40:49 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 18:19:35 +01:00
|
|
|
public String dump() {
|
|
|
|
final StringBuilder sb = new StringBuilder("Current settings :");
|
|
|
|
sb.append("\n mSpacingAndPunctuations = ");
|
|
|
|
sb.append("" + mSpacingAndPunctuations.dump());
|
|
|
|
sb.append("\n mAutoCap = ");
|
|
|
|
sb.append("" + mAutoCap);
|
|
|
|
sb.append("\n mVibrateOn = ");
|
|
|
|
sb.append("" + mVibrateOn);
|
|
|
|
sb.append("\n mSoundOn = ");
|
|
|
|
sb.append("" + mSoundOn);
|
|
|
|
sb.append("\n mKeyPreviewPopupOn = ");
|
|
|
|
sb.append("" + mKeyPreviewPopupOn);
|
|
|
|
sb.append("\n mShowsVoiceInputKey = ");
|
|
|
|
sb.append("" + mShowsVoiceInputKey);
|
2023-09-09 08:29:06 +02:00
|
|
|
sb.append("\n mLanguageSwitchKeyToOtherImes = ");
|
|
|
|
sb.append("" + mLanguageSwitchKeyToOtherImes);
|
|
|
|
sb.append("\n mLanguageSwitchKeyToOtherSubtypes = ");
|
|
|
|
sb.append("" + mLanguageSwitchKeyToOtherSubtypes);
|
2019-12-31 18:19:35 +01:00
|
|
|
sb.append("\n mUsePersonalizedDicts = ");
|
|
|
|
sb.append("" + mUsePersonalizedDicts);
|
|
|
|
sb.append("\n mUseDoubleSpacePeriod = ");
|
|
|
|
sb.append("" + mUseDoubleSpacePeriod);
|
|
|
|
sb.append("\n mBlockPotentiallyOffensive = ");
|
|
|
|
sb.append("" + mBlockPotentiallyOffensive);
|
|
|
|
sb.append("\n mBigramPredictionEnabled = ");
|
|
|
|
sb.append("" + mBigramPredictionEnabled);
|
|
|
|
sb.append("\n mGestureInputEnabled = ");
|
|
|
|
sb.append("" + mGestureInputEnabled);
|
|
|
|
sb.append("\n mGestureTrailEnabled = ");
|
|
|
|
sb.append("" + mGestureTrailEnabled);
|
|
|
|
sb.append("\n mGestureFloatingPreviewTextEnabled = ");
|
|
|
|
sb.append("" + mGestureFloatingPreviewTextEnabled);
|
|
|
|
sb.append("\n mSlidingKeyInputPreviewEnabled = ");
|
|
|
|
sb.append("" + mSlidingKeyInputPreviewEnabled);
|
|
|
|
sb.append("\n mKeyLongpressTimeout = ");
|
|
|
|
sb.append("" + mKeyLongpressTimeout);
|
|
|
|
sb.append("\n mLocale = ");
|
|
|
|
sb.append("" + mLocale);
|
|
|
|
sb.append("\n mInputAttributes = ");
|
|
|
|
sb.append("" + mInputAttributes);
|
|
|
|
sb.append("\n mKeypressVibrationDuration = ");
|
|
|
|
sb.append("" + mKeypressVibrationDuration);
|
|
|
|
sb.append("\n mKeypressSoundVolume = ");
|
|
|
|
sb.append("" + mKeypressSoundVolume);
|
|
|
|
sb.append("\n mAutoCorrectEnabled = ");
|
|
|
|
sb.append("" + mAutoCorrectEnabled);
|
|
|
|
sb.append("\n mAutoCorrectionThreshold = ");
|
|
|
|
sb.append("" + mAutoCorrectionThreshold);
|
|
|
|
sb.append("\n mAutoCorrectionEnabledPerUserSettings = ");
|
|
|
|
sb.append("" + mAutoCorrectionEnabledPerUserSettings);
|
|
|
|
sb.append("\n mSuggestionsEnabledPerUserSettings = ");
|
|
|
|
sb.append("" + mSuggestionsEnabledPerUserSettings);
|
|
|
|
sb.append("\n mDisplayOrientation = ");
|
|
|
|
sb.append("" + mDisplayOrientation);
|
|
|
|
sb.append("\n mAppWorkarounds = ");
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
}
|