mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-21 14:49:10 +00:00
Merge pull request #695 from Pkshields/auto-correction-confidence
Add Auto-correction Confidence settings
This commit is contained in:
commit
c3772cd56e
6 changed files with 39 additions and 40 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
? res.getString(R.string.auto_correction_threshold_mode_index_modest)
|
||||
: 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.
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
<resources>
|
||||
<!-- The array of auto correction threshold values. -->
|
||||
<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
|
||||
will be subject to auto-correction. -->
|
||||
<item>0.185</item>
|
||||
|
@ -41,21 +39,18 @@
|
|||
<string name="plausibility_threshold" translatable="false">0.065</string>
|
||||
|
||||
<!-- 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">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">3</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_very_aggressive" translatable="false">2</string>
|
||||
|
||||
<!-- The array of the auto correction threshold settings values. -->
|
||||
<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_aggressive</item>
|
||||
<item>@string/auto_correction_threshold_mode_index_very_aggressive</item>
|
||||
</string-array>
|
||||
<!-- The array of the human readable auto correction threshold settings entries. -->
|
||||
<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_aggressive</item>
|
||||
<item>@string/auto_correction_threshold_mode_very_aggressive</item>
|
||||
|
|
|
@ -140,6 +140,8 @@
|
|||
<string name="auto_correction">Auto-correction</string>
|
||||
<!-- 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>
|
||||
<!-- 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] -->
|
||||
<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] -->
|
||||
|
|
|
@ -41,6 +41,14 @@
|
|||
android:defaultValue="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
|
||||
android:key="auto_cap"
|
||||
android:title="@string/auto_cap"
|
||||
|
|
Loading…
Add table
Reference in a new issue