todos and unused code

show debug settings in the original place in advanced settings
This commit is contained in:
Helium314 2023-09-10 21:39:56 +02:00
parent bc9150b007
commit 8840411039
11 changed files with 39 additions and 188 deletions

View file

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="english_ime_settings">
<PreferenceScreen
android:fragment="org.dslul.openboard.inputmethod.latin.settings.LanguageFakeSettingsFragment"
android:title="@string/language_selection_title"
android:key="screen_languages"
android:icon="@drawable/ic_settings_languages"/>
<PreferenceScreen
android:fragment="org.dslul.openboard.inputmethod.latin.settings.PreferencesSettingsFragment"
android:title="@string/settings_screen_preferences"
android:key="screen_preferences"
android:icon="@drawable/ic_settings_preferences"/>
<PreferenceScreen
android:fragment="org.dslul.openboard.inputmethod.latin.settings.AppearanceSettingsFragment"
android:title="@string/settings_screen_appearance"
android:key="screen_appearance"
android:icon="@drawable/ic_settings_appearance"/>
<PreferenceScreen
android:fragment="org.dslul.openboard.inputmethod.latin.settings.GestureSettingsFragment"
android:title="@string/settings_screen_gesture"
android:key="screen_gesture"
android:icon="@drawable/ic_settings_gesture"/>
<PreferenceScreen
android:fragment="org.dslul.openboard.inputmethod.latin.settings.CorrectionSettingsFragment"
android:title="@string/settings_screen_correction"
android:key="screen_correction"
android:icon="@drawable/ic_settings_correction"/>
<PreferenceScreen
android:fragment="org.dslul.openboard.inputmethod.latin.settings.AdvancedSettingsFragment"
android:title="@string/settings_screen_advanced"
android:key="screen_advanced"
android:icon="@drawable/ic_settings_advanced"/>
<PreferenceScreen
android:fragment="org.dslul.openboard.inputmethod.latin.settings.AboutFragment"
android:title="@string/settings_screen_about"
android:key="screen_about"
android:icon="@drawable/ic_settings_about"/>
<PreferenceScreen
android:fragment="org.dslul.openboard.inputmethod.latin.settings.DebugSettingsFragment"
android:title="Debug Settings"
android:key="screen_debug"/>
</PreferenceScreen>

View file

@ -136,13 +136,6 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
* A group of dictionaries that work together for a single language. * A group of dictionaries that work together for a single language.
*/ */
private static class DictionaryGroup { private static class DictionaryGroup {
// TODO: Add null analysis annotations.
// TODO: Run evaluation to determine a reasonable value for these constants. The current
// values are ad-hoc and chosen without any particular care or methodology.
public static final float WEIGHT_FOR_MOST_PROBABLE_LANGUAGE = 1.0f;
public static final float WEIGHT_FOR_GESTURING_IN_NOT_MOST_PROBABLE_LANGUAGE = 0.95f;
public static final float WEIGHT_FOR_TYPING_IN_NOT_MOST_PROBABLE_LANGUAGE = 0.6f;
private static final int MAX_CONFIDENCE = 2; private static final int MAX_CONFIDENCE = 2;
private static final int MIN_CONFIDENCE = 0; private static final int MIN_CONFIDENCE = 0;
@ -186,26 +179,25 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
} }
} }
// TODO: might need some more tuning, maybe more confidence steps // todo: might need some more tuning, maybe more confidence steps
private void updateWeights() { private void updateWeights() {
mWeightForTypingInLocale = 1f - 0.15f * (MAX_CONFIDENCE - mConfidence); mWeightForTypingInLocale = 1f - 0.15f * (MAX_CONFIDENCE - mConfidence);
mWeightForGesturingInLocale = 1f - 0.05f * (MAX_CONFIDENCE - mConfidence); mWeightForGesturingInLocale = 1f - 0.05f * (MAX_CONFIDENCE - mConfidence);
} }
public float mWeightForTypingInLocale = WEIGHT_FOR_MOST_PROBABLE_LANGUAGE; public float mWeightForTypingInLocale = 1f;
public float mWeightForGesturingInLocale = WEIGHT_FOR_MOST_PROBABLE_LANGUAGE; public float mWeightForGesturingInLocale = 1f;
public final ConcurrentHashMap<String, ExpandableBinaryDictionary> mSubDictMap = public final ConcurrentHashMap<String, ExpandableBinaryDictionary> mSubDictMap =
new ConcurrentHashMap<>(); new ConcurrentHashMap<>();
public DictionaryGroup() { public DictionaryGroup() {
this(null /* locale */, null /* mainDict */, null /* account */, this(null /* locale */, null /* mainDict */, null /* account */, Collections.emptyMap() /* subDicts */);
Collections.<String, ExpandableBinaryDictionary>emptyMap() /* subDicts */);
} }
public DictionaryGroup(@Nullable final Locale locale, public DictionaryGroup(@Nullable final Locale locale,
@Nullable final Dictionary mainDict, @Nullable final Dictionary mainDict,
@Nullable final String account, @Nullable final String account,
final Map<String, ExpandableBinaryDictionary> subDicts) { @NonNull final Map<String, ExpandableBinaryDictionary> subDicts) {
mLocale = locale; mLocale = locale;
mAccount = account; mAccount = account;
// The main dictionary can be asynchronously loaded. // The main dictionary can be asynchronously loaded.
@ -215,13 +207,11 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
} }
} }
private void setSubDict(final String dictType, final ExpandableBinaryDictionary dict) { private void setSubDict(@NonNull final String dictType, @NonNull final ExpandableBinaryDictionary dict) {
if (dict != null) { mSubDictMap.put(dictType, dict);
mSubDictMap.put(dictType, dict);
}
} }
public void setMainDict(final Dictionary mainDict) { public void setMainDict(@Nullable final Dictionary mainDict) {
// Close old dictionary if exists. Main dictionary can be assigned multiple times. // Close old dictionary if exists. Main dictionary can be assigned multiple times.
final Dictionary oldDict = mMainDict; final Dictionary oldDict = mMainDict;
mMainDict = mainDict; mMainDict = mainDict;
@ -230,18 +220,18 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
} }
} }
public Dictionary getDict(final String dictType) { public @Nullable Dictionary getDict(@NonNull final String dictType) {
if (Dictionary.TYPE_MAIN.equals(dictType)) { if (Dictionary.TYPE_MAIN.equals(dictType)) {
return mMainDict; return mMainDict;
} }
return getSubDict(dictType); return getSubDict(dictType);
} }
public ExpandableBinaryDictionary getSubDict(final String dictType) { public @Nullable ExpandableBinaryDictionary getSubDict(@NonNull final String dictType) {
return mSubDictMap.get(dictType); return mSubDictMap.get(dictType);
} }
public boolean hasDict(final String dictType, @Nullable final String account) { public boolean hasDict(@NonNull final String dictType, @Nullable final String account) {
if (Dictionary.TYPE_MAIN.equals(dictType)) { if (Dictionary.TYPE_MAIN.equals(dictType)) {
return mMainDict != null; return mMainDict != null;
} }
@ -255,7 +245,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
return mSubDictMap.containsKey(dictType); return mSubDictMap.containsKey(dictType);
} }
public void closeDict(final String dictType) { public void closeDict(@NonNull final String dictType) {
final Dictionary dict; final Dictionary dict;
if (Dictionary.TYPE_MAIN.equals(dictType)) { if (Dictionary.TYPE_MAIN.equals(dictType)) {
dict = mMainDict; dict = mMainDict;
@ -480,13 +470,8 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
final List<Locale> locales, final DictionaryInitializationListener listener) { final List<Locale> locales, final DictionaryInitializationListener listener) {
final CountDownLatch latchForWaitingLoadingMainDictionary = new CountDownLatch(1); final CountDownLatch latchForWaitingLoadingMainDictionary = new CountDownLatch(1);
mLatchForWaitingLoadingMainDictionaries = latchForWaitingLoadingMainDictionary; mLatchForWaitingLoadingMainDictionaries = latchForWaitingLoadingMainDictionary;
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(new Runnable() { ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(() ->
@Override doReloadUninitializedMainDictionaries(context, locales, listener, latchForWaitingLoadingMainDictionary));
public void run() {
doReloadUninitializedMainDictionaries(
context, locales, listener, latchForWaitingLoadingMainDictionary);
}
});
} }
void doReloadUninitializedMainDictionaries(final Context context, final List<Locale> locales, void doReloadUninitializedMainDictionaries(final Context context, final List<Locale> locales,
@ -704,13 +689,9 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
if (userDict != null && userHistoryDict.isInDictionary(suggestion)) { if (userDict != null && userHistoryDict.isInDictionary(suggestion)) {
if (userDict.isInDictionary(suggestion)) // is this check necessary? if (userDict.isInDictionary(suggestion)) // is this check necessary?
return; return;
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(new Runnable() { ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(() ->
@Override
public void run() {
UserDictionary.Words.addWord(userDict.mContext, suggestion, UserDictionary.Words.addWord(userDict.mContext, suggestion,
250 /*FREQUENCY_FOR_USER_DICTIONARY_ADDS*/, null, dictionaryGroup.mLocale); 250 /*FREQUENCY_FOR_USER_DICTIONARY_ADDS*/, null, dictionaryGroup.mLocale));
}
});
} }
} }
@ -828,6 +809,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
// TODO: Revise the way to fusion suggestion results. // TODO: Revise the way to fusion suggestion results.
@Override @Override
@SuppressWarnings("unchecked")
@NonNull public SuggestionResults getSuggestionResults(ComposedData composedData, @NonNull public SuggestionResults getSuggestionResults(ComposedData composedData,
NgramContext ngramContext, @NonNull final Keyboard keyboard, NgramContext ngramContext, @NonNull final Keyboard keyboard,
SettingsValuesForSuggestion settingsValuesForSuggestion, int sessionId, SettingsValuesForSuggestion settingsValuesForSuggestion, int sessionId,
@ -888,12 +870,12 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
int sessionId, long proximityInfoHandle, float[] weightOfLangModelVsSpatialModel, int sessionId, long proximityInfoHandle, float[] weightOfLangModelVsSpatialModel,
DictionaryGroup dictGroup) { DictionaryGroup dictGroup) {
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>(); final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>();
final float weightForLocale = composedData.mIsBatchMode
? dictGroup.mWeightForGesturingInLocale
: dictGroup.mWeightForTypingInLocale;
for (final String dictType : ALL_DICTIONARY_TYPES) { for (final String dictType : ALL_DICTIONARY_TYPES) {
final Dictionary dictionary = dictGroup.getDict(dictType); final Dictionary dictionary = dictGroup.getDict(dictType);
if (null == dictionary) continue; if (null == dictionary) continue;
final float weightForLocale = composedData.mIsBatchMode
? dictGroup.mWeightForGesturingInLocale
: dictGroup.mWeightForTypingInLocale;
final ArrayList<SuggestedWordInfo> dictionarySuggestions = final ArrayList<SuggestedWordInfo> dictionarySuggestions =
dictionary.getSuggestions(composedData, ngramContext, dictionary.getSuggestions(composedData, ngramContext,
proximityInfoHandle, settingsValuesForSuggestion, sessionId, proximityInfoHandle, settingsValuesForSuggestion, sessionId,

View file

@ -752,7 +752,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mInputLogic.mSuggest.setAutoCorrectionThreshold( mInputLogic.mSuggest.setAutoCorrectionThreshold(
settingsValues.mAutoCorrectionThreshold); settingsValues.mAutoCorrectionThreshold);
} }
mInputLogic.mSuggest.setPlausibilityThreshold(settingsValues.mPlausibilityThreshold);
} }
/** /**
@ -1068,8 +1067,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
suggest.setAutoCorrectionThreshold( suggest.setAutoCorrectionThreshold(
currentSettingsValues.mAutoCorrectionThreshold); currentSettingsValues.mAutoCorrectionThreshold);
} }
suggest.setPlausibilityThreshold(currentSettingsValues.mPlausibilityThreshold);
switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(), switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(),
getCurrentRecapitalizeState()); getCurrentRecapitalizeState());
if (needToCallLoadKeyboardLater) { if (needToCallLoadKeyboardLater) {

View file

@ -87,15 +87,6 @@ public final class Suggest {
mAutoCorrectionThreshold = threshold; mAutoCorrectionThreshold = threshold;
} }
/**
* Set the normalized-score threshold for what we consider a "plausible" suggestion, in
* the same dimension as the auto-correction threshold.
* @param threshold the threshold
*/
public void setPlausibilityThreshold(final float threshold) {
mPlausibilityThreshold = threshold;
}
public interface OnGetSuggestedWordsCallback { public interface OnGetSuggestedWordsCallback {
void onGetSuggestedWords(final SuggestedWords suggestedWords); void onGetSuggestedWords(final SuggestedWords suggestedWords);
} }

View file

@ -23,12 +23,14 @@ import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Process;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference; import androidx.preference.Preference;
import org.dslul.openboard.inputmethod.keyboard.KeyboardLayoutSet; import org.dslul.openboard.inputmethod.keyboard.KeyboardLayoutSet;
import org.dslul.openboard.inputmethod.latin.AudioAndHapticFeedbackManager; import org.dslul.openboard.inputmethod.latin.AudioAndHapticFeedbackManager;
import org.dslul.openboard.inputmethod.latin.BuildConfig;
import org.dslul.openboard.inputmethod.latin.R; import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.SystemBroadcastReceiver; import org.dslul.openboard.inputmethod.latin.SystemBroadcastReceiver;
import org.dslul.openboard.inputmethod.latin.common.FileUtils; import org.dslul.openboard.inputmethod.latin.common.FileUtils;
@ -63,9 +65,7 @@ public final class AdvancedSettingsFragment extends SubScreenFragment {
// initialization method of these classes here. See {@link LatinIME#onCreate()}. // initialization method of these classes here. See {@link LatinIME#onCreate()}.
AudioAndHapticFeedbackManager.init(context); AudioAndHapticFeedbackManager.init(context);
final SharedPreferences prefs = getSharedPreferences(); if (!BuildConfig.DEBUG) {
if (!Settings.isInternal(prefs)) {
removePreference(Settings.SCREEN_DEBUG); removePreference(Settings.SCREEN_DEBUG);
} }
@ -112,7 +112,7 @@ public final class AdvancedSettingsFragment extends SubScreenFragment {
FileUtils.copyStreamToNewFile(in, libfile); FileUtils.copyStreamToNewFile(in, libfile);
Runtime.getRuntime().exit(0); // exit will restart the app, so library will be loaded Runtime.getRuntime().exit(0); // exit will restart the app, so library will be loaded
} catch (IOException e) { } catch (IOException e) {
// todo: should inform user // should inform user, but probably the issues will only come when reading the library
} }
} }
} }

View file

@ -19,7 +19,6 @@ package org.dslul.openboard.inputmethod.latin.settings;
import static org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager.get; import static org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager.get;
import android.Manifest; import android.Manifest;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -112,7 +111,7 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
private void refreshEnabledSettings() { private void refreshEnabledSettings() {
setPreferenceVisible(Settings.PREF_AUTO_CORRECTION_CONFIDENCE, setPreferenceVisible(Settings.PREF_AUTO_CORRECTION_CONFIDENCE,
Settings.readAutoCorrectEnabled(getSharedPreferences(), getResources())); Settings.readAutoCorrectEnabled(getSharedPreferences()));
setPreferenceVisible(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, getSharedPreferences().getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true)); setPreferenceVisible(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, getSharedPreferences().getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true));
turnOffLookupContactsIfNoPermission(); turnOffLookupContactsIfNoPermission();
} }

View file

@ -58,7 +58,7 @@ public final class DebugSettingsFragment extends SubScreenFragment
removePreference(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI); removePreference(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI);
} }
final PreferenceGroup dictDumpPreferenceGroup = (PreferenceGroup)findPreference(PREF_KEY_DUMP_DICTS); final PreferenceGroup dictDumpPreferenceGroup = findPreference(PREF_KEY_DUMP_DICTS);
for (final String dictName : DictionaryFacilitatorImpl.DICT_TYPE_TO_CLASS.keySet()) { for (final String dictName : DictionaryFacilitatorImpl.DICT_TYPE_TO_CLASS.keySet()) {
final Preference pref = new DictDumpPreference(getActivity(), dictName); final Preference pref = new DictDumpPreference(getActivity(), dictName);
pref.setOnPreferenceClickListener(this); pref.setOnPreferenceClickListener(this);
@ -83,7 +83,7 @@ public final class DebugSettingsFragment extends SubScreenFragment
defaultKeyPreviewDismissEndScale); defaultKeyPreviewDismissEndScale);
mServiceNeedsRestart = false; mServiceNeedsRestart = false;
mDebugMode = (TwoStatePreference) findPreference(DebugSettings.PREF_DEBUG_MODE); mDebugMode = findPreference(DebugSettings.PREF_DEBUG_MODE);
updateDebugMode(); updateDebugMode();
} }
@ -116,7 +116,7 @@ public final class DebugSettingsFragment extends SubScreenFragment
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
if (mServiceNeedsRestart) { if (mServiceNeedsRestart) {
Process.killProcess(Process.myPid()); Runtime.getRuntime().exit(0);
} }
} }
@ -147,7 +147,7 @@ public final class DebugSettingsFragment extends SubScreenFragment
private void setupKeyPreviewAnimationScale(final String prefKey, final float defaultValue) { private void setupKeyPreviewAnimationScale(final String prefKey, final float defaultValue) {
final SharedPreferences prefs = getSharedPreferences(); final SharedPreferences prefs = getSharedPreferences();
final Resources res = getResources(); final Resources res = getResources();
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey); final SeekBarDialogPreference pref = findPreference(prefKey);
if (pref == null) { if (pref == null) {
return; return;
} }
@ -199,7 +199,7 @@ public final class DebugSettingsFragment extends SubScreenFragment
private void setupKeyPreviewAnimationDuration(final String prefKey, final int defaultValue) { private void setupKeyPreviewAnimationDuration(final String prefKey, final int defaultValue) {
final SharedPreferences prefs = getSharedPreferences(); final SharedPreferences prefs = getSharedPreferences();
final Resources res = getResources(); final Resources res = getResources();
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey); final SeekBarDialogPreference pref = findPreference(prefKey);
if (pref == null) { if (pref == null) {
return; return;
} }

View file

@ -76,16 +76,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_THEME_USER_DARK_COLOR_BACKGROUND = "theme_dark_color_background"; public static final String PREF_THEME_USER_DARK_COLOR_BACKGROUND = "theme_dark_color_background";
public static final String PREF_THEME_USER_DARK_COLOR_KEYS = "theme_dark_color_keys"; public static final String PREF_THEME_USER_DARK_COLOR_KEYS = "theme_dark_color_keys";
public static final String PREF_THEME_USER_DARK_COLOR_ACCENT = "theme_dark_color_accent"; public static final String PREF_THEME_USER_DARK_COLOR_ACCENT = "theme_dark_color_accent";
// PREF_VOICE_MODE_OBSOLETE is obsolete. Use PREF_VOICE_INPUT_KEY instead.
public static final String PREF_VOICE_MODE_OBSOLETE = "voice_mode";
public static final String PREF_VOICE_INPUT_KEY = "pref_voice_input_key"; public static final String PREF_VOICE_INPUT_KEY = "pref_voice_input_key";
public static final String PREF_CLIPBOARD_CLIPBOARD_KEY = "pref_clipboard_clipboard_key";
public static final String PREF_EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary"; public static final String PREF_EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary";
public static final String PREF_ADD_DICTIONARY = "add_dictionary";
public static final String PREF_AUTO_CORRECTION = "pref_key_auto_correction"; public static final String PREF_AUTO_CORRECTION = "pref_key_auto_correction";
public static final String PREF_AUTO_CORRECTION_CONFIDENCE = "pref_key_auto_correction_confidence"; public static final String PREF_AUTO_CORRECTION_CONFIDENCE = "pref_key_auto_correction_confidence";
// PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE is obsolete. Use PREF_SHOW_SUGGESTIONS instead.
public static final String PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE = "show_suggestions_setting";
public static final String PREF_SHOW_SUGGESTIONS = "show_suggestions"; public static final String PREF_SHOW_SUGGESTIONS = "show_suggestions";
public static final String PREF_KEY_USE_PERSONALIZED_DICTS = "pref_key_use_personalized_dicts"; public static final String PREF_KEY_USE_PERSONALIZED_DICTS = "pref_key_use_personalized_dicts";
public static final String PREF_KEY_USE_DOUBLE_SPACE_PERIOD = "pref_key_use_double_space_period"; public static final String PREF_KEY_USE_DOUBLE_SPACE_PERIOD = "pref_key_use_double_space_period";
@ -116,8 +110,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_ONE_HANDED_MODE = "pref_one_handed_mode_enabled"; public static final String PREF_ONE_HANDED_MODE = "pref_one_handed_mode_enabled";
public static final String PREF_ONE_HANDED_GRAVITY = "pref_one_handed_mode_gravity"; public static final String PREF_ONE_HANDED_GRAVITY = "pref_one_handed_mode_gravity";
public static final String PREF_KEY_IS_INTERNAL = "pref_key_is_internal";
public static final String PREF_SHOW_NUMBER_ROW = "pref_show_number_row"; public static final String PREF_SHOW_NUMBER_ROW = "pref_show_number_row";
public static final String PREF_SHOW_HINTS = "pref_show_hints"; public static final String PREF_SHOW_HINTS = "pref_show_hints";
@ -234,10 +226,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return mSettingsValues; return mSettingsValues;
} }
public boolean isInternal() {
return mSettingsValues.mIsInternal;
}
public static int readScreenMetrics(final Resources res) { public static int readScreenMetrics(final Resources res) {
return res.getInteger(R.integer.config_screen_metrics); return res.getInteger(R.integer.config_screen_metrics);
} }
@ -245,8 +233,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
// Accessed from the settings interface, hence public // Accessed from the settings interface, hence public
public static boolean readKeypressSoundEnabled(final SharedPreferences prefs, public static boolean readKeypressSoundEnabled(final SharedPreferences prefs,
final Resources res) { final Resources res) {
return prefs.getBoolean(PREF_SOUND_ON, return prefs.getBoolean(PREF_SOUND_ON, res.getBoolean(R.bool.config_default_sound_enabled));
res.getBoolean(R.bool.config_default_sound_enabled));
} }
public static boolean readVibrationEnabled(final SharedPreferences prefs, public static boolean readVibrationEnabled(final SharedPreferences prefs,
@ -256,8 +243,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
res.getBoolean(R.bool.config_default_vibration_enabled)); res.getBoolean(R.bool.config_default_vibration_enabled));
} }
public static boolean readAutoCorrectEnabled(final SharedPreferences prefs, public static boolean readAutoCorrectEnabled(final SharedPreferences prefs) {
final Resources res) {
return prefs.getBoolean(PREF_AUTO_CORRECTION, true); return prefs.getBoolean(PREF_AUTO_CORRECTION, true);
} }
@ -267,10 +253,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
res.getString(R.string.auto_correction_threshold_mode_index_modest)); res.getString(R.string.auto_correction_threshold_mode_index_modest));
} }
public static float readPlausibilityThreshold(final Resources res) {
return Float.parseFloat(res.getString(R.string.plausibility_threshold));
}
public static boolean readBlockPotentiallyOffensive(final SharedPreferences prefs, public static boolean readBlockPotentiallyOffensive(final SharedPreferences prefs,
final Resources res) { final Resources res) {
return prefs.getBoolean(PREF_BLOCK_POTENTIALLY_OFFENSIVE, return prefs.getBoolean(PREF_BLOCK_POTENTIALLY_OFFENSIVE,
@ -393,10 +375,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static int readDefaultClipboardHistoryRetentionTime(final Resources res) { public static int readDefaultClipboardHistoryRetentionTime(final Resources res) {
return res.getInteger(R.integer.config_clipboard_history_retention_time); return res.getInteger(R.integer.config_clipboard_history_retention_time);
} }
public static boolean readShowsNumberRow(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_SHOW_NUMBER_ROW, false);
}
public static float readKeyboardHeight(final SharedPreferences prefs, public static float readKeyboardHeight(final SharedPreferences prefs,
final float defaultValue) { final float defaultValue) {
@ -459,10 +437,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
&& conf.hardKeyboardHidden != Configuration.HARDKEYBOARDHIDDEN_YES; && conf.hardKeyboardHidden != Configuration.HARDKEYBOARDHIDDEN_YES;
} }
public static boolean isInternal(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_KEY_IS_INTERNAL, false);
}
public void writeLastUsedPersonalizationToken(byte[] token) { public void writeLastUsedPersonalizationToken(byte[] token) {
if (token == null) { if (token == null) {
mPrefs.edit().remove(PREF_LAST_USED_PERSONALIZATION_TOKEN).apply(); mPrefs.edit().remove(PREF_LAST_USED_PERSONALIZATION_TOKEN).apply();

View file

@ -110,6 +110,7 @@ public class SettingsValues {
public final boolean mAddToPersonalDictionary; public final boolean mAddToPersonalDictionary;
public final boolean mUseContactsDictionary; public final boolean mUseContactsDictionary;
public final boolean mCustomNavBarColor; public final boolean mCustomNavBarColor;
public final float mKeyboardHeightScale;
// From the input box // From the input box
@NonNull @NonNull
@ -121,7 +122,6 @@ public class SettingsValues {
private final boolean mAutoCorrectEnabled; private final boolean mAutoCorrectEnabled;
public final float mAutoCorrectionThreshold; public final float mAutoCorrectionThreshold;
public final int mScoreLimitForAutocorrect; public final int mScoreLimitForAutocorrect;
public final float mPlausibilityThreshold;
public final boolean mAutoCorrectionEnabledPerUserSettings; public final boolean mAutoCorrectionEnabledPerUserSettings;
private final boolean mSuggestionsEnabledPerUserSettings; private final boolean mSuggestionsEnabledPerUserSettings;
public final SettingsValuesForSuggestion mSettingsValuesForSuggestion; public final SettingsValuesForSuggestion mSettingsValuesForSuggestion;
@ -132,9 +132,7 @@ public class SettingsValues {
public final Colors mColors; public final Colors mColors;
// Debug settings // Debug settings
public final boolean mIsInternal;
public final boolean mHasCustomKeyPreviewAnimationParams; public final boolean mHasCustomKeyPreviewAnimationParams;
public final float mKeyboardHeightScale;
public final int mKeyPreviewShowUpDuration; public final int mKeyPreviewShowUpDuration;
public final int mKeyPreviewDismissDuration; public final int mKeyPreviewDismissDuration;
public final float mKeyPreviewShowUpStartXScale; public final float mKeyPreviewShowUpStartXScale;
@ -163,7 +161,7 @@ public class SettingsValues {
mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res); mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);
mSlidingKeyInputPreviewEnabled = prefs.getBoolean( mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, true); DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, true);
mShowsVoiceInputKey = needsToShowVoiceInputKey(prefs, res) && mInputAttributes.mShouldShowVoiceInputKey; mShowsVoiceInputKey = needsToShowVoiceInputKey(prefs) && mInputAttributes.mShouldShowVoiceInputKey;
final String languagePref = prefs.getString(Settings.PREF_LANGUAGE_SWITCH_KEY, "off"); final String languagePref = prefs.getString(Settings.PREF_LANGUAGE_SWITCH_KEY, "off");
mLanguageSwitchKeyToOtherImes = languagePref.equals("input_method") || languagePref.equals("both"); mLanguageSwitchKeyToOtherImes = languagePref.equals("input_method") || languagePref.equals("both");
mLanguageSwitchKeyToOtherSubtypes = languagePref.equals("internal") || languagePref.equals("both"); mLanguageSwitchKeyToOtherSubtypes = languagePref.equals("internal") || languagePref.equals("both");
@ -176,7 +174,7 @@ public class SettingsValues {
mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true) mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true)
&& inputAttributes.mIsGeneralTextInput; && inputAttributes.mIsGeneralTextInput;
mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res); mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res);
mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(prefs, res); mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(prefs);
mAutoCorrectionThreshold = mAutoCorrectEnabled mAutoCorrectionThreshold = mAutoCorrectEnabled
? readAutoCorrectionThreshold(res, prefs) ? readAutoCorrectionThreshold(res, prefs)
: AUTO_CORRECTION_DISABLED_THRESHOLD; : AUTO_CORRECTION_DISABLED_THRESHOLD;
@ -198,7 +196,6 @@ public class SettingsValues {
Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, true); Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, true);
mShowAppIcon = Settings.readShowSetupWizardIcon(prefs, context); mShowAppIcon = Settings.readShowSetupWizardIcon(prefs, context);
mIsShowAppIconSettingInPreferences = prefs.contains(Settings.PREF_SHOW_SETUP_WIZARD_ICON); mIsShowAppIconSettingInPreferences = prefs.contains(Settings.PREF_SHOW_SETUP_WIZARD_ICON);
mPlausibilityThreshold = Settings.readPlausibilityThreshold(res);
mGestureInputEnabled = Settings.readGestureInputEnabled(prefs, res); mGestureInputEnabled = Settings.readGestureInputEnabled(prefs, res);
mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true); mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true);
mCloudSyncEnabled = prefs.getBoolean(LocalSettingsConstants.PREF_ENABLE_CLOUD_SYNC, false); mCloudSyncEnabled = prefs.getBoolean(LocalSettingsConstants.PREF_ENABLE_CLOUD_SYNC, false);
@ -212,7 +209,6 @@ public class SettingsValues {
readSuggestionsEnabled(prefs); readSuggestionsEnabled(prefs);
mIncognitoModeEnabled = Settings.readAlwaysIncognitoMode(prefs) || mInputAttributes.mNoLearning mIncognitoModeEnabled = Settings.readAlwaysIncognitoMode(prefs) || mInputAttributes.mNoLearning
|| mInputAttributes.mIsPasswordField; || mInputAttributes.mIsPasswordField;
mIsInternal = Settings.isInternal(prefs);
mHasCustomKeyPreviewAnimationParams = prefs.getBoolean(DebugSettings.PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS, false); mHasCustomKeyPreviewAnimationParams = prefs.getBoolean(DebugSettings.PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS, false);
mKeyboardHeightScale = Settings.readKeyboardHeight(prefs, DEFAULT_SIZE_SCALE); mKeyboardHeightScale = Settings.readKeyboardHeight(prefs, DEFAULT_SIZE_SCALE);
mKeyPreviewShowUpDuration = Settings.readKeyPreviewAnimationDuration( mKeyPreviewShowUpDuration = Settings.readKeyPreviewAnimationDuration(
@ -335,17 +331,7 @@ public class SettingsValues {
return mDisplayOrientation == configuration.orientation; return mDisplayOrientation == configuration.orientation;
} }
private static final String SUGGESTIONS_VISIBILITY_HIDE_VALUE_OBSOLETE = "2";
private static boolean readSuggestionsEnabled(final SharedPreferences prefs) { private static boolean readSuggestionsEnabled(final SharedPreferences prefs) {
if (prefs.contains(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE)) {
final boolean alwaysHide = SUGGESTIONS_VISIBILITY_HIDE_VALUE_OBSOLETE.equals(
prefs.getString(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE, null));
prefs.edit()
.remove(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE)
.putBoolean(Settings.PREF_SHOW_SUGGESTIONS, !alwaysHide)
.apply();
}
return prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true); return prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true);
} }
@ -387,21 +373,7 @@ public class SettingsValues {
return autoCorrectionThreshold; return autoCorrectionThreshold;
} }
private static boolean needsToShowVoiceInputKey(final SharedPreferences prefs, private static boolean needsToShowVoiceInputKey(final SharedPreferences prefs) {
final Resources res) {
// Migrate preference from {@link Settings#PREF_VOICE_MODE_OBSOLETE} to
// {@link Settings#PREF_VOICE_INPUT_KEY}.
if (prefs.contains(Settings.PREF_VOICE_MODE_OBSOLETE)) {
final String voiceModeMain = res.getString(R.string.voice_mode_main);
final String voiceMode = prefs.getString(
Settings.PREF_VOICE_MODE_OBSOLETE, voiceModeMain);
final boolean shouldShowVoiceInputKey = voiceModeMain.equals(voiceMode);
prefs.edit()
.putBoolean(Settings.PREF_VOICE_INPUT_KEY, shouldShowVoiceInputKey)
// Remove the obsolete preference if exists.
.remove(Settings.PREF_VOICE_MODE_OBSOLETE)
.apply();
}
return prefs.getBoolean(Settings.PREF_VOICE_INPUT_KEY, true); return prefs.getBoolean(Settings.PREF_VOICE_INPUT_KEY, true);
} }
@ -464,8 +436,6 @@ public class SettingsValues {
sb.append("\n mAppWorkarounds = "); sb.append("\n mAppWorkarounds = ");
final AppWorkaroundsUtils awu = mAppWorkarounds.get(null, 0); final AppWorkaroundsUtils awu = mAppWorkarounds.get(null, 0);
sb.append("" + (null == awu ? "null" : awu.toString())); sb.append("" + (null == awu ? "null" : awu.toString()));
sb.append("\n mIsInternal = ");
sb.append("" + mIsInternal);
sb.append("\n mKeyPreviewShowUpDuration = "); sb.append("\n mKeyPreviewShowUpDuration = ");
sb.append("" + mKeyPreviewShowUpDuration); sb.append("" + mKeyPreviewShowUpDuration);
sb.append("\n mKeyPreviewDismissDuration = "); sb.append("\n mKeyPreviewDismissDuration = ");

View file

@ -55,7 +55,9 @@ public final class AutoCorrectionUtils {
// the normalized score of the second suggestion, behave less aggressive. // the normalized score of the second suggestion, behave less aggressive.
final float normalizedScore; final float normalizedScore;
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT == 0) if (BuildConfig.DEBUG && Build.VERSION.SDK_INT == 0)
normalizedScore = calcNormalizedScore(StringUtils.toCodePointArray(consideredWord), StringUtils.toCodePointArray(suggestion.mWord), autoCorrectionSuggestionScore, editDistance(consideredWord, suggestion.mWord)); normalizedScore = calcNormalizedScore(StringUtils.toCodePointArray(consideredWord),
StringUtils.toCodePointArray(suggestion.mWord), autoCorrectionSuggestionScore,
editDistance(consideredWord, suggestion.mWord));
else else
normalizedScore = BinaryDictionaryUtils.calcNormalizedScore( normalizedScore = BinaryDictionaryUtils.calcNormalizedScore(
consideredWord, suggestion.mWord, autoCorrectionSuggestionScore); consideredWord, suggestion.mWord, autoCorrectionSuggestionScore);

View file

@ -32,12 +32,6 @@
<item>floatNegativeInfinity</item> <item>floatNegativeInfinity</item>
</string-array> </string-array>
<!-- Chosen to be slightly less than the "aggressive" threshold. This is the threshold for
a mildly plausible suggestion given the input; if no "plausible" suggestion is present
for a language, it's a strong indicator the user is not typing in this language, so we
may be more forgiving of whitelist entries in another language. -->
<string name="plausibility_threshold" translatable="false">0.065</string>
<!-- The index of the auto correction threshold values array. --> <!-- The index of the auto correction threshold values array. -->
<string name="auto_correction_threshold_mode_index_modest" translatable="false">0</string> <string name="auto_correction_threshold_mode_index_modest" translatable="false">0</string>
<string name="auto_correction_threshold_mode_index_aggressive" translatable="false">1</string> <string name="auto_correction_threshold_mode_index_aggressive" translatable="false">1</string>