Merge pull request #695 from Pkshields/auto-correction-confidence

Add Auto-correction Confidence settings
This commit is contained in:
Majeur 2022-12-17 14:01:09 +01:00 committed by GitHub
commit c3772cd56e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 40 deletions

View file

@ -16,7 +16,6 @@
package org.dslul.openboard.inputmethod.latin.settings; package org.dslul.openboard.inputmethod.latin.settings;
import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -25,12 +24,8 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; 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.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.UserDictionaryList;
import org.dslul.openboard.inputmethod.latin.userdictionary.UserDictionarySettings; import org.dslul.openboard.inputmethod.latin.userdictionary.UserDictionarySettings;
@ -44,6 +39,7 @@ import java.util.TreeSet;
* - Add-on dictionaries * - Add-on dictionaries
* - Block offensive words * - Block offensive words
* - Auto-correction * - Auto-correction
* - Auto-correction confidence
* - Show correction suggestions * - Show correction suggestions
* - Personalized suggestions * - Personalized suggestions
* - Suggest Contact names * - Suggest Contact names
@ -73,6 +69,18 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
if (ri == null) { if (ri == null) {
overwriteUserDictionaryPreference(editPersonalDictionary); 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) { private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) {

View file

@ -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_VOICE_INPUT_KEY = "pref_voice_input_key";
public static final String PREF_CLIPBOARD_CLIPBOARD_KEY = "pref_clipboard_clipboard_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";
// 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 = "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. // 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_SETTING_OBSOLETE = "show_suggestions_setting";
public static final String PREF_SHOW_SUGGESTIONS = "show_suggestions"; public static final String PREF_SHOW_SUGGESTIONS = "show_suggestions";
@ -173,7 +171,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
mRes = context.getResources(); mRes = context.getResources();
mPrefs = DeviceProtectedUtils.getSharedPreferences(context); mPrefs = DeviceProtectedUtils.getSharedPreferences(context);
mPrefs.registerOnSharedPreferenceChangeListener(this); mPrefs.registerOnSharedPreferenceChangeListener(this);
upgradeAutocorrectionSettings(mPrefs, mRes);
} }
public void onDestroy() { public void onDestroy() {
@ -247,6 +244,12 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return prefs.getBoolean(PREF_AUTO_CORRECTION, true); 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) { public static float readPlausibilityThreshold(final Resources res) {
return Float.parseFloat(res.getString(R.string.plausibility_threshold)); 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) { final SharedPreferences prefs, final int defValue) {
return prefs.getInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID, 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();
}
}
} }

View file

@ -53,6 +53,7 @@ public class SettingsValues {
private static final String FLOAT_NEGATIVE_INFINITY_MARKER_STRING = "floatNegativeInfinity"; private static final String FLOAT_NEGATIVE_INFINITY_MARKER_STRING = "floatNegativeInfinity";
private static final int TIMEOUT_TO_GET_TARGET_PACKAGE = 5; // seconds 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 DEFAULT_SIZE_SCALE = 1.0f; // 100%
public static final float AUTO_CORRECTION_DISABLED_THRESHOLD = Float.MAX_VALUE;
// From resources: // From resources:
public final SpacingAndPunctuations mSpacingAndPunctuations; public final SpacingAndPunctuations mSpacingAndPunctuations;
@ -163,9 +164,9 @@ public class SettingsValues {
&& inputAttributes.mIsGeneralTextInput; && inputAttributes.mIsGeneralTextInput;
mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res); mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res);
mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(prefs, res); mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(prefs, res);
final String autoCorrectionThresholdRawValue = mAutoCorrectEnabled mAutoCorrectionThreshold = mAutoCorrectEnabled
? res.getString(R.string.auto_correction_threshold_mode_index_modest) ? readAutoCorrectionThreshold(res, prefs)
: res.getString(R.string.auto_correction_threshold_mode_index_off); : AUTO_CORRECTION_DISABLED_THRESHOLD;
mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res); mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);
mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout);
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration()); mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
@ -183,8 +184,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);
mAutoCorrectionThreshold = readAutoCorrectionThreshold(res,
autoCorrectionThresholdRawValue);
mPlausibilityThreshold = Settings.readPlausibilityThreshold(res); 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);
@ -331,7 +330,8 @@ public class SettingsValues {
} }
private static float readAutoCorrectionThreshold(final Resources res, 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( final String[] autoCorrectionThresholdValues = res.getStringArray(
R.array.auto_correction_threshold_values); R.array.auto_correction_threshold_values);
// When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off. // When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off.

View file

@ -21,8 +21,6 @@
<resources> <resources>
<!-- The array of auto correction threshold values. --> <!-- The array of auto correction threshold values. -->
<string-array name="auto_correction_threshold_values" translatable="false"> <string-array name="auto_correction_threshold_values" translatable="false">
<!-- Off, When auto correction setting is Off, this value is not used. -->
<item>floatMaxValue</item>
<!-- Modest : Suggestion whose normalized score is greater than this value <!-- Modest : Suggestion whose normalized score is greater than this value
will be subject to auto-correction. --> will be subject to auto-correction. -->
<item>0.185</item> <item>0.185</item>
@ -41,21 +39,18 @@
<string name="plausibility_threshold" translatable="false">0.065</string> <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_off" translatable="false">0</string> <string name="auto_correction_threshold_mode_index_modest" translatable="false">0</string>
<string name="auto_correction_threshold_mode_index_modest" translatable="false">1</string> <string name="auto_correction_threshold_mode_index_aggressive" translatable="false">1</string>
<string name="auto_correction_threshold_mode_index_aggressive" translatable="false">2</string> <string name="auto_correction_threshold_mode_index_very_aggressive" translatable="false">2</string>
<string name="auto_correction_threshold_mode_index_very_aggressive" translatable="false">3</string>
<!-- The array of the auto correction threshold settings values. --> <!-- The array of the auto correction threshold settings values. -->
<string-array name="auto_correction_threshold_mode_indexes" translatable="false"> <string-array name="auto_correction_threshold_mode_indexes" translatable="false">
<item>@string/auto_correction_threshold_mode_index_off</item>
<item>@string/auto_correction_threshold_mode_index_modest</item> <item>@string/auto_correction_threshold_mode_index_modest</item>
<item>@string/auto_correction_threshold_mode_index_aggressive</item> <item>@string/auto_correction_threshold_mode_index_aggressive</item>
<item>@string/auto_correction_threshold_mode_index_very_aggressive</item> <item>@string/auto_correction_threshold_mode_index_very_aggressive</item>
</string-array> </string-array>
<!-- The array of the human readable auto correction threshold settings entries. --> <!-- The array of the human readable auto correction threshold settings entries. -->
<string-array name="auto_correction_threshold_modes" translatable="false"> <string-array name="auto_correction_threshold_modes" translatable="false">
<item>@string/auto_correction_threshold_mode_off</item>
<item>@string/auto_correction_threshold_mode_modest</item> <item>@string/auto_correction_threshold_mode_modest</item>
<item>@string/auto_correction_threshold_mode_aggressive</item> <item>@string/auto_correction_threshold_mode_aggressive</item>
<item>@string/auto_correction_threshold_mode_very_aggressive</item> <item>@string/auto_correction_threshold_mode_very_aggressive</item>

View file

@ -140,6 +140,8 @@
<string name="auto_correction">Auto-correction</string> <string name="auto_correction">Auto-correction</string>
<!-- Description for auto correction [CHAR LIMIT=65 (two lines) or 30 (fits on one line, preferable)] --> <!-- Description for auto correction [CHAR LIMIT=65 (two lines) or 30 (fits on one line, preferable)] -->
<string name="auto_correction_summary">Spacebar and punctuation automatically correct mistyped words</string> <string name="auto_correction_summary">Spacebar and punctuation automatically correct mistyped words</string>
<!-- Option to change the confidence level of the auto correction [CHAR LIMIT=20] -->
<string name="auto_correction_confidence">Auto-correction confidence</string>
<!-- Option to disable auto correction. [CHAR LIMIT=20] --> <!-- Option to disable auto correction. [CHAR LIMIT=20] -->
<string name="auto_correction_threshold_mode_off">Off</string> <string name="auto_correction_threshold_mode_off">Off</string>
<!-- Option to suggest auto correction suggestions modestly. Auto-corrects only to a word which has small edit distance from typed word. [CHAR LIMIT=20] --> <!-- Option to suggest auto correction suggestions modestly. Auto-corrects only to a word which has small edit distance from typed word. [CHAR LIMIT=20] -->

View file

@ -41,6 +41,14 @@
android:defaultValue="true" android:defaultValue="true"
android:persistent="true" /> android:persistent="true" />
<ListPreference
android:key="pref_key_auto_correction_confidence"
android:title="@string/auto_correction_confidence"
android:summary="%s"
android:entries="@array/auto_correction_threshold_modes"
android:entryValues="@array/auto_correction_threshold_mode_indexes"
android:defaultValue="@string/auto_correction_threshold_mode_index_modest" />
<CheckBoxPreference <CheckBoxPreference
android:key="auto_cap" android:key="auto_cap"
android:title="@string/auto_cap" android:title="@string/auto_cap"