From 0ae60405d7c13924af36323a4a582261b7730a65 Mon Sep 17 00:00:00 2001 From: Paul Shields Date: Mon, 29 Aug 2022 21:59:53 +0100 Subject: [PATCH 1/2] Added in an Auto-correction Confidence option to the Text Correction settings view. --- .../settings/CorrectionSettingsFragment.java | 18 ++++++++---- .../inputmethod/latin/settings/Settings.java | 28 +++++-------------- .../latin/settings/SettingsValues.java | 2 +- .../config-auto-correction-thresholds.xml | 2 -- app/src/main/res/values/strings.xml | 2 ++ .../main/res/xml/prefs_screen_correction.xml | 8 ++++++ 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java index 3ba15d1a6..7a73457d4 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java @@ -16,7 +16,6 @@ package org.dslul.openboard.inputmethod.latin.settings; -import android.Manifest; import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -25,12 +24,8 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.preference.Preference; -import android.preference.SwitchPreference; -import android.text.TextUtils; import org.dslul.openboard.inputmethod.latin.R; -import org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager; -import org.dslul.openboard.inputmethod.latin.permissions.PermissionsUtil; import org.dslul.openboard.inputmethod.latin.userdictionary.UserDictionaryList; import org.dslul.openboard.inputmethod.latin.userdictionary.UserDictionarySettings; @@ -44,6 +39,7 @@ import java.util.TreeSet; * - Add-on dictionaries * - Block offensive words * - Auto-correction + * - Auto-correction confidence * - Show correction suggestions * - Personalized suggestions * - Suggest Contact names @@ -73,6 +69,18 @@ public final class CorrectionSettingsFragment extends SubScreenFragment if (ri == null) { overwriteUserDictionaryPreference(editPersonalDictionary); } + + refreshEnabledSettings(); + } + + @Override + public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) { + refreshEnabledSettings(); + } + + private void refreshEnabledSettings() { + setPreferenceEnabled(Settings.PREF_AUTO_CORRECTION_CONFIDENCE, + Settings.readAutoCorrectEnabled(getSharedPreferences(), getResources())); } private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) { diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java index 135c6ceab..52647b444 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java @@ -65,10 +65,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang 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"; - // PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE is obsolete. Use PREF_AUTO_CORRECTION instead. - public static final String PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE = - "auto_correction_threshold"; public static final String PREF_AUTO_CORRECTION = "pref_key_auto_correction"; + 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"; @@ -173,7 +171,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang mRes = context.getResources(); mPrefs = DeviceProtectedUtils.getSharedPreferences(context); mPrefs.registerOnSharedPreferenceChangeListener(this); - upgradeAutocorrectionSettings(mPrefs, mRes); } public void onDestroy() { @@ -247,6 +244,12 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang return prefs.getBoolean(PREF_AUTO_CORRECTION, true); } + public static String readAutoCorrectConfidence(final SharedPreferences prefs, + final Resources res) { + return prefs.getString(PREF_AUTO_CORRECTION_CONFIDENCE, + 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)); } @@ -513,21 +516,4 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang final SharedPreferences prefs, final int defValue) { return prefs.getInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID, defValue); } - - private void upgradeAutocorrectionSettings(final SharedPreferences prefs, final Resources res) { - final String thresholdSetting = - prefs.getString(PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE, null); - if (thresholdSetting != null) { - SharedPreferences.Editor editor = prefs.edit(); - editor.remove(PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE); - final String autoCorrectionOff = - res.getString(R.string.auto_correction_threshold_mode_index_off); - if (thresholdSetting.equals(autoCorrectionOff)) { - editor.putBoolean(PREF_AUTO_CORRECTION, false); - } else { - editor.putBoolean(PREF_AUTO_CORRECTION, true); - } - editor.commit(); - } - } } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java index e639a6e3d..93c5a9534 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java @@ -164,7 +164,7 @@ public class SettingsValues { mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res); mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(prefs, res); final String autoCorrectionThresholdRawValue = mAutoCorrectEnabled - ? res.getString(R.string.auto_correction_threshold_mode_index_modest) + ? Settings.readAutoCorrectConfidence(prefs, res) : res.getString(R.string.auto_correction_threshold_mode_index_off); mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res); mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); diff --git a/app/src/main/res/values/config-auto-correction-thresholds.xml b/app/src/main/res/values/config-auto-correction-thresholds.xml index fc701c7ff..5c474e9b1 100644 --- a/app/src/main/res/values/config-auto-correction-thresholds.xml +++ b/app/src/main/res/values/config-auto-correction-thresholds.xml @@ -48,14 +48,12 @@ - @string/auto_correction_threshold_mode_index_off @string/auto_correction_threshold_mode_index_modest @string/auto_correction_threshold_mode_index_aggressive @string/auto_correction_threshold_mode_index_very_aggressive - @string/auto_correction_threshold_mode_off @string/auto_correction_threshold_mode_modest @string/auto_correction_threshold_mode_aggressive @string/auto_correction_threshold_mode_very_aggressive diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c6fd5fa0d..6ef73fc30 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -140,6 +140,8 @@ Auto-correction Spacebar and punctuation automatically correct mistyped words + + Auto-correction confidence Off diff --git a/app/src/main/res/xml/prefs_screen_correction.xml b/app/src/main/res/xml/prefs_screen_correction.xml index 350a8951a..286b14691 100644 --- a/app/src/main/res/xml/prefs_screen_correction.xml +++ b/app/src/main/res/xml/prefs_screen_correction.xml @@ -41,6 +41,14 @@ android:defaultValue="true" android:persistent="true" /> + + Date: Wed, 14 Dec 2022 21:48:36 +0000 Subject: [PATCH 2/2] Removing the "off" value from the auto_correction_threshold_values array. Making required code changes to auto correct threshold code based on this change. --- .../inputmethod/latin/settings/SettingsValues.java | 12 ++++++------ .../res/values/config-auto-correction-thresholds.xml | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java index 93c5a9534..e4986f7df 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java @@ -53,6 +53,7 @@ public class SettingsValues { private static final String FLOAT_NEGATIVE_INFINITY_MARKER_STRING = "floatNegativeInfinity"; private static final int TIMEOUT_TO_GET_TARGET_PACKAGE = 5; // seconds public static final float DEFAULT_SIZE_SCALE = 1.0f; // 100% + public static final float AUTO_CORRECTION_DISABLED_THRESHOLD = Float.MAX_VALUE; // From resources: public final SpacingAndPunctuations mSpacingAndPunctuations; @@ -163,9 +164,9 @@ public class SettingsValues { && inputAttributes.mIsGeneralTextInput; mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res); mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(prefs, res); - final String autoCorrectionThresholdRawValue = mAutoCorrectEnabled - ? Settings.readAutoCorrectConfidence(prefs, res) - : res.getString(R.string.auto_correction_threshold_mode_index_off); + mAutoCorrectionThreshold = mAutoCorrectEnabled + ? readAutoCorrectionThreshold(res, prefs) + : AUTO_CORRECTION_DISABLED_THRESHOLD; mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res); mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration()); @@ -183,8 +184,6 @@ public class SettingsValues { Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, true); mShowAppIcon = Settings.readShowSetupWizardIcon(prefs, context); mIsShowAppIconSettingInPreferences = prefs.contains(Settings.PREF_SHOW_SETUP_WIZARD_ICON); - mAutoCorrectionThreshold = readAutoCorrectionThreshold(res, - autoCorrectionThresholdRawValue); mPlausibilityThreshold = Settings.readPlausibilityThreshold(res); mGestureInputEnabled = Settings.readGestureInputEnabled(prefs, res); mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true); @@ -331,7 +330,8 @@ public class SettingsValues { } private static float readAutoCorrectionThreshold(final Resources res, - final String currentAutoCorrectionSetting) { + final SharedPreferences prefs) { + final String currentAutoCorrectionSetting = Settings.readAutoCorrectConfidence(prefs, res); 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. diff --git a/app/src/main/res/values/config-auto-correction-thresholds.xml b/app/src/main/res/values/config-auto-correction-thresholds.xml index 5c474e9b1..028a46baf 100644 --- a/app/src/main/res/values/config-auto-correction-thresholds.xml +++ b/app/src/main/res/values/config-auto-correction-thresholds.xml @@ -21,8 +21,6 @@ - - floatMaxValue 0.185 @@ -41,10 +39,9 @@ 0.065 - 0 - 1 - 2 - 3 + 0 + 1 + 2