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
|
|
|
|
|
|
|
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-01-31 18:32:43 +01:00
|
|
|
import helium314.keyboard.compat.ConfigurationCompatKt;
|
|
|
|
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyTextsKt;
|
|
|
|
import helium314.keyboard.latin.InputAttributes;
|
|
|
|
import helium314.keyboard.latin.R;
|
|
|
|
import helium314.keyboard.latin.RichInputMethodManager;
|
|
|
|
import helium314.keyboard.latin.common.Colors;
|
|
|
|
import helium314.keyboard.latin.utils.InputTypeUtils;
|
|
|
|
import helium314.keyboard.latin.utils.Log;
|
|
|
|
import helium314.keyboard.latin.utils.MoreKeysUtilsKt;
|
|
|
|
import helium314.keyboard.latin.utils.ScriptUtils;
|
|
|
|
import helium314.keyboard.latin.utils.SubtypeSettingsKt;
|
2019-12-31 18:19:35 +01:00
|
|
|
|
|
|
|
import java.util.Arrays;
|
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 {
|
|
|
|
private static final String TAG = SettingsValues.class.getSimpleName();
|
|
|
|
// "floatMaxValue" and "floatNegativeInfinity" are special marker strings for
|
|
|
|
// Float.NEGATIVE_INFINITE and Float.MAX_VALUE. Currently used for auto-correction settings.
|
|
|
|
private static final String FLOAT_MAX_VALUE_MARKER_STRING = "floatMaxValue";
|
|
|
|
private static final String FLOAT_NEGATIVE_INFINITY_MARKER_STRING = "floatNegativeInfinity";
|
|
|
|
public static final float DEFAULT_SIZE_SCALE = 1.0f; // 100%
|
2022-12-14 21:48:36 +00:00
|
|
|
public static final float AUTO_CORRECTION_DISABLED_THRESHOLD = Float.MAX_VALUE;
|
2019-12-31 18:19:35 +01:00
|
|
|
|
|
|
|
// From resources:
|
|
|
|
public final SpacingAndPunctuations mSpacingAndPunctuations;
|
|
|
|
public final long mDoubleSpacePeriodTimeout;
|
|
|
|
// From configuration:
|
|
|
|
public final Locale mLocale;
|
|
|
|
public final boolean mHasHardwareKeyboard;
|
|
|
|
public final int mDisplayOrientation;
|
|
|
|
// From preferences, in the same order as xml/prefs.xml:
|
|
|
|
public final boolean mAutoCap;
|
|
|
|
public final boolean mVibrateOn;
|
|
|
|
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;
|
2020-09-11 16:59:15 +02:00
|
|
|
public final boolean mShowsNumberRow;
|
2023-11-27 15:50:06 +01:00
|
|
|
public final boolean mLocalizedNumberRow;
|
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;
|
2023-09-12 22:53:14 +02:00
|
|
|
public final boolean mSpaceLanguageSlide;
|
2020-09-30 16:11:13 +02:00
|
|
|
public final boolean mShowsEmojiKey;
|
2019-12-31 18:19:35 +01:00
|
|
|
public final boolean mUsePersonalizedDicts;
|
|
|
|
public final boolean mUseDoubleSpacePeriod;
|
|
|
|
public final boolean mBlockPotentiallyOffensive;
|
2020-01-18 16:26:22 +01:00
|
|
|
public final boolean mSpaceTrackpadEnabled;
|
|
|
|
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;
|
2023-12-25 09:20:15 +01:00
|
|
|
public final int mShowMoreMoreKeys;
|
|
|
|
public final List<String> mMoreKeyTypes;
|
|
|
|
public final List<String> mMoreKeyLabelSources;
|
2023-08-11 00:58:33 +02:00
|
|
|
public final List<Locale> mSecondaryLocales;
|
2019-12-31 18:19:35 +01:00
|
|
|
// Use bigrams to predict the next word when there is no input for it yet
|
|
|
|
public final boolean mBigramPredictionEnabled;
|
|
|
|
public final boolean mGestureInputEnabled;
|
|
|
|
public final boolean mGestureTrailEnabled;
|
|
|
|
public final boolean mGestureFloatingPreviewTextEnabled;
|
|
|
|
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;
|
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;
|
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;
|
2019-12-31 18:19:35 +01:00
|
|
|
private final boolean mSuggestionsEnabledPerUserSettings;
|
2024-01-21 19:02:40 +01:00
|
|
|
private final boolean mOverrideShowingSuggestions;
|
2023-09-10 16:29:29 +02:00
|
|
|
public final SettingsValuesForSuggestion mSettingsValuesForSuggestion;
|
2020-09-07 12:44:39 +02:00
|
|
|
public final boolean mIncognitoModeEnabled;
|
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
|
|
|
|
public final String mAccount;
|
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());
|
2019-12-31 18:19:35 +01:00
|
|
|
|
|
|
|
// Store the input attributes
|
|
|
|
mInputAttributes = inputAttributes;
|
|
|
|
|
|
|
|
// Get the settings preferences
|
2023-08-29 12:22:39 +02:00
|
|
|
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true) && ScriptUtils.scriptSupportsUppercase(mLocale);
|
2019-12-31 18:19:35 +01:00
|
|
|
mVibrateOn = Settings.readVibrationEnabled(prefs, res);
|
|
|
|
mSoundOn = Settings.readKeypressSoundEnabled(prefs, res);
|
|
|
|
mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);
|
|
|
|
mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
|
|
|
|
DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, true);
|
2023-09-24 21:31:37 +02:00
|
|
|
mShowsVoiceInputKey = mInputAttributes.mShouldShowVoiceInputKey;
|
2023-09-09 08:29:06 +02:00
|
|
|
final String languagePref = prefs.getString(Settings.PREF_LANGUAGE_SWITCH_KEY, "off");
|
|
|
|
mLanguageSwitchKeyToOtherImes = languagePref.equals("input_method") || languagePref.equals("both");
|
|
|
|
mLanguageSwitchKeyToOtherSubtypes = languagePref.equals("internal") || languagePref.equals("both");
|
2020-09-11 16:59:15 +02:00
|
|
|
mShowsNumberRow = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, false);
|
2023-11-30 10:58:53 +01:00
|
|
|
mLocalizedNumberRow = prefs.getBoolean(Settings.PREF_LOCALIZED_NUMBER_ROW, true);
|
2021-04-29 14:58:59 -04:00
|
|
|
mShowsHints = prefs.getBoolean(Settings.PREF_SHOW_HINTS, true);
|
2023-09-23 13:02:56 +02:00
|
|
|
mShowsPopupHints = prefs.getBoolean(Settings.PREF_SHOW_POPUP_HINTS, false);
|
2021-10-24 17:17:48 +05:30
|
|
|
mSpaceForLangChange = prefs.getBoolean(Settings.PREF_SPACE_TO_CHANGE_LANG, true);
|
2023-09-12 22:53:14 +02:00
|
|
|
mSpaceLanguageSlide = prefs.getBoolean(Settings.PREF_SPACE_LANGUAGE_SLIDE, false);
|
2020-09-30 16:11:13 +02:00
|
|
|
mShowsEmojiKey = prefs.getBoolean(Settings.PREF_SHOW_EMOJI_KEY, false);
|
2019-12-31 18:19:35 +01:00
|
|
|
mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true);
|
|
|
|
mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true)
|
|
|
|
&& inputAttributes.mIsGeneralTextInput;
|
|
|
|
mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res);
|
2024-01-23 12:29:14 +01:00
|
|
|
mUrlDetectionEnabled = prefs.getBoolean(Settings.PREF_URL_DETECTION, false);
|
|
|
|
mAutoCorrectionEnabledPerUserSettings = Settings.readAutoCorrectEnabled(prefs);
|
|
|
|
mAutoCorrectEnabled = mAutoCorrectionEnabledPerUserSettings
|
|
|
|
&& (mInputAttributes.mInputTypeShouldAutoCorrect || Settings.readMoreAutoCorrectEnabled(prefs))
|
|
|
|
&& (mUrlDetectionEnabled || !InputTypeUtils.isUriOrEmailType(mInputAttributes.mInputType));
|
2022-12-14 21:48:36 +00:00
|
|
|
mAutoCorrectionThreshold = mAutoCorrectEnabled
|
|
|
|
? readAutoCorrectionThreshold(res, prefs)
|
|
|
|
: AUTO_CORRECTION_DISABLED_THRESHOLD;
|
2023-09-10 19:45:03 +02:00
|
|
|
mScoreLimitForAutocorrect = (mAutoCorrectionThreshold < 0) ? 600000 // very aggressive
|
|
|
|
: (mAutoCorrectionThreshold < 0.07 ? 800000 : 950000); // aggressive or modest
|
2019-12-31 18:19:35 +01:00
|
|
|
mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);
|
|
|
|
mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout);
|
|
|
|
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
|
2023-11-03 12:28:00 +01:00
|
|
|
final float displayWidthDp = res.getDisplayMetrics().widthPixels / res.getDisplayMetrics().density;
|
|
|
|
mIsSplitKeyboardEnabled = prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD, false) && displayWidthDp > 600; // require display width of 600 dp for split
|
|
|
|
// determine spacerWidth from display width and scale setting
|
2023-12-19 23:32:30 +01:00
|
|
|
mSplitKeyboardSpacerRelativeWidth = mIsSplitKeyboardEnabled
|
2023-11-03 12:28:00 +01:00
|
|
|
? Math.min(Math.max((displayWidthDp - 600) / 6000f + 0.15f, 0.15f), 0.25f) * prefs.getFloat(Settings.PREF_SPLIT_SPACER_SCALE, DEFAULT_SIZE_SCALE)
|
|
|
|
: 0f;
|
2019-12-31 18:19:35 +01:00
|
|
|
mScreenMetrics = Settings.readScreenMetrics(res);
|
|
|
|
|
|
|
|
// Compute other readable settings
|
|
|
|
mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res);
|
|
|
|
mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res);
|
|
|
|
mKeypressSoundVolume = Settings.readKeypressSoundVolume(prefs, res);
|
2023-12-29 12:08:32 +01:00
|
|
|
mEnableEmojiAltPhysicalKey = prefs.getBoolean(Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, true);
|
2023-09-16 22:18:31 +02:00
|
|
|
mGestureInputEnabled = Settings.readGestureInputEnabled(prefs);
|
2019-12-31 18:19:35 +01:00
|
|
|
mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true);
|
2023-12-29 12:08:32 +01:00
|
|
|
mAccount = null; // remove? or can it be useful somewhere?
|
2019-12-31 18:19:35 +01:00
|
|
|
mGestureFloatingPreviewTextEnabled = !mInputAttributes.mDisableGestureFloatingPreviewText
|
|
|
|
&& prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true);
|
2024-01-21 19:02:40 +01:00
|
|
|
mOverrideShowingSuggestions = mInputAttributes.mMayOverrideShowingSuggestions && readSuggestionsOverrideEnabled(prefs);
|
2024-01-17 09:09:33 +01:00
|
|
|
mSuggestionsEnabledPerUserSettings = (mInputAttributes.mShouldShowSuggestions && readSuggestionsEnabled(prefs))
|
2024-01-21 19:02:40 +01:00
|
|
|
|| mOverrideShowingSuggestions;
|
2021-11-22 08:20:12 -05:00
|
|
|
mIncognitoModeEnabled = Settings.readAlwaysIncognitoMode(prefs) || mInputAttributes.mNoLearning
|
|
|
|
|| mInputAttributes.mIsPasswordField;
|
2023-11-03 12:28:00 +01:00
|
|
|
mKeyboardHeightScale = prefs.getFloat(Settings.PREF_KEYBOARD_HEIGHT_SCALE, DEFAULT_SIZE_SCALE);
|
2019-12-31 18:19:35 +01:00
|
|
|
mDisplayOrientation = res.getConfiguration().orientation;
|
2020-01-18 16:26:22 +01:00
|
|
|
mSpaceTrackpadEnabled = Settings.readSpaceTrackpadEnabled(prefs);
|
|
|
|
mDeleteSwipeEnabled = Settings.readDeleteSwipeEnabled(prefs);
|
2022-03-21 15:09:39 +01:00
|
|
|
mAutospaceAfterPunctuationEnabled = Settings.readAutospaceAfterPunctuationEnabled(prefs);
|
2022-02-18 21:08:29 +01:00
|
|
|
mClipboardHistoryEnabled = Settings.readClipboardHistoryEnabled(prefs);
|
|
|
|
mClipboardHistoryRetentionTime = Settings.readClipboardHistoryRetentionTime(prefs, res);
|
2023-12-18 17:30:53 +01:00
|
|
|
|
|
|
|
mOneHandedModeEnabled = Settings.readOneHandedModeEnabled(prefs, mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT);
|
|
|
|
mOneHandedModeGravity = Settings.readOneHandedModeGravity(prefs, mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT);
|
|
|
|
if (mOneHandedModeEnabled) {
|
|
|
|
final float baseScale = res.getFraction(R.fraction.config_one_handed_mode_width, 1, 1);
|
|
|
|
final float extraScale = Settings.readOneHandedModeScale(prefs, mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT);
|
|
|
|
mOneHandedModeScale = 1 - (1 - baseScale) * extraScale;
|
|
|
|
} else
|
|
|
|
mOneHandedModeScale = 1f;
|
2023-09-10 00:20:21 +02:00
|
|
|
final InputMethodSubtype selectedSubtype = SubtypeSettingsKt.getSelectedSubtype(prefs);
|
2024-02-01 19:46:44 +01:00
|
|
|
mSecondaryLocales = Settings.getSecondaryLocales(prefs, mLocale);
|
2023-12-25 09:20:15 +01:00
|
|
|
mShowMoreMoreKeys = selectedSubtype.isAsciiCapable()
|
2023-11-19 21:16:23 +01:00
|
|
|
? Settings.readMoreMoreKeysPref(prefs)
|
|
|
|
: LocaleKeyTextsKt.MORE_KEYS_NORMAL;
|
2023-09-01 00:35:40 +02:00
|
|
|
mColors = Settings.getColorsForCurrentTheme(context, prefs);
|
2023-06-28 21:18:41 +02:00
|
|
|
|
2023-12-27 17:38:19 +01:00
|
|
|
// read locale-specific popup key settings, fall back to global settings
|
2024-01-31 16:54:31 +01:00
|
|
|
final String moreKeyTypesDefault = prefs.getString(Settings.PREF_POPUP_KEYS_ORDER, MoreKeysUtilsKt.MORE_KEYS_ORDER_DEFAULT);
|
2024-02-01 19:46:44 +01:00
|
|
|
mMoreKeyTypes = MoreKeysUtilsKt.getEnabledMoreKeys(prefs, Settings.PREF_POPUP_KEYS_ORDER + "_" + mLocale.toLanguageTag(), moreKeyTypesDefault);
|
2024-01-31 16:54:31 +01:00
|
|
|
final String moreKeyLabelDefault = prefs.getString(Settings.PREF_POPUP_KEYS_LABELS_ORDER, MoreKeysUtilsKt.MORE_KEYS_LABEL_DEFAULT);
|
2024-02-01 19:46:44 +01:00
|
|
|
mMoreKeyLabelSources = MoreKeysUtilsKt.getEnabledMoreKeys(prefs, Settings.PREF_POPUP_KEYS_LABELS_ORDER + "_" + mLocale.toLanguageTag(), moreKeyLabelDefault);
|
2023-12-27 17:38:19 +01:00
|
|
|
|
2023-06-28 21:18:41 +02:00
|
|
|
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false);
|
2024-02-01 08:51:17 +01:00
|
|
|
mUseContactsDictionary = prefs.getBoolean(Settings.PREF_USE_CONTACTS, false);
|
2023-07-21 17:13:14 +02:00
|
|
|
mCustomNavBarColor = prefs.getBoolean(Settings.PREF_NAVBAR_COLOR, false);
|
2023-08-14 19:16:43 +02:00
|
|
|
mNarrowKeyGaps = prefs.getBoolean(Settings.PREF_NARROW_KEY_GAPS, true);
|
2023-09-10 16:29:29 +02:00
|
|
|
mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(
|
|
|
|
mBlockPotentiallyOffensive,
|
|
|
|
prefs.getBoolean(Settings.PREF_GESTURE_SPACE_AWARE, false)
|
|
|
|
);
|
2023-09-25 10:10:56 +02:00
|
|
|
mSpacingAndPunctuations = new SpacingAndPunctuations(res, mUrlDetectionEnabled);
|
2023-11-03 14:24:43 +01:00
|
|
|
mBottomPaddingScale = prefs.getFloat(Settings.PREF_BOTTOM_PADDING_SCALE, DEFAULT_SIZE_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() {
|
2023-09-09 08:29:06 +02:00
|
|
|
if (!mLanguageSwitchKeyToOtherImes && !mLanguageSwitchKeyToOtherSubtypes) {
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean readSuggestionsEnabled(final SharedPreferences prefs) {
|
|
|
|
return prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true);
|
|
|
|
}
|
|
|
|
|
2024-01-17 09:09:33 +01:00
|
|
|
private static boolean readSuggestionsOverrideEnabled(final SharedPreferences prefs) {
|
|
|
|
return prefs.getBoolean(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, false);
|
|
|
|
}
|
|
|
|
|
2019-12-31 18:19:35 +01:00
|
|
|
private static boolean readBigramPredictionEnabled(final SharedPreferences prefs,
|
2020-04-23 20:29:26 +04:00
|
|
|
final Resources res) {
|
2019-12-31 18:19:35 +01:00
|
|
|
return prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, res.getBoolean(
|
|
|
|
R.bool.config_default_next_word_prediction));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static float readAutoCorrectionThreshold(final Resources res,
|
2022-12-14 21:48:36 +00:00
|
|
|
final SharedPreferences prefs) {
|
|
|
|
final String currentAutoCorrectionSetting = Settings.readAutoCorrectConfidence(prefs, res);
|
2019-12-31 18:19:35 +01:00
|
|
|
final String[] autoCorrectionThresholdValues = res.getStringArray(
|
|
|
|
R.array.auto_correction_threshold_values);
|
|
|
|
// When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off.
|
|
|
|
final float autoCorrectionThreshold;
|
|
|
|
try {
|
|
|
|
final int arrayIndex = Integer.parseInt(currentAutoCorrectionSetting);
|
|
|
|
if (arrayIndex >= 0 && arrayIndex < autoCorrectionThresholdValues.length) {
|
|
|
|
final String val = autoCorrectionThresholdValues[arrayIndex];
|
|
|
|
if (FLOAT_MAX_VALUE_MARKER_STRING.equals(val)) {
|
|
|
|
autoCorrectionThreshold = Float.MAX_VALUE;
|
|
|
|
} else if (FLOAT_NEGATIVE_INFINITY_MARKER_STRING.equals(val)) {
|
|
|
|
autoCorrectionThreshold = Float.NEGATIVE_INFINITY;
|
|
|
|
} else {
|
|
|
|
autoCorrectionThreshold = Float.parseFloat(val);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
autoCorrectionThreshold = Float.MAX_VALUE;
|
|
|
|
}
|
|
|
|
} catch (final NumberFormatException e) {
|
|
|
|
// Whenever the threshold settings are correct, never come here.
|
|
|
|
Log.w(TAG, "Cannot load auto correction threshold setting."
|
|
|
|
+ " currentAutoCorrectionSetting: " + currentAutoCorrectionSetting
|
|
|
|
+ ", autoCorrectionThresholdValues: "
|
|
|
|
+ Arrays.toString(autoCorrectionThresholdValues), e);
|
|
|
|
return Float.MAX_VALUE;
|
|
|
|
}
|
|
|
|
return autoCorrectionThreshold;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|