only ignore TYPE_TEXT_FLAG_NO_SUGGESTIONS when user explicitly wants it

This commit is contained in:
Helium314 2024-01-17 09:09:33 +01:00
parent 9e94aa1143
commit e8e4354600
7 changed files with 27 additions and 24 deletions

View file

@ -89,7 +89,7 @@ public final class InputAttributes {
// TODO: Have a helper method in InputTypeUtils
// Make sure that passwords are not displayed in {@link SuggestionStripView}.
mShouldShowSuggestions = !mIsPasswordField;
mShouldShowSuggestions = !mIsPasswordField && !flagNoSuggestions;
mShouldInsertSpacesAutomatically = InputTypeUtils.isAutoSpaceFriendlyType(inputType);

View file

@ -844,7 +844,7 @@ public final class InputLogic {
|| mWordComposer.isComposingWord() // emoji will be part of the word in this case, better do nothing
|| !settingsValues.mBigramPredictionEnabled // this is only for next word suggestions, so they need to be enabled
|| settingsValues.mIncognitoModeEnabled
|| !settingsValues.mInputAttributes.mShouldShowSuggestions // see comment in performAdditionToUserHistoryDictionary
|| !settingsValues.isSuggestionsEnabledPerUserSettings() // see comment in performAdditionToUserHistoryDictionary
|| !StringUtilsKt.isEmoji(text)
) return;
if (mConnection.hasSlowInputConnection()) {
@ -1524,8 +1524,8 @@ public final class InputLogic {
// If correction is not enabled, we don't add words to the user history dictionary.
// That's to avoid unintended additions in some sensitive fields, or fields that
// expect to receive non-words.
// mInputTypeNoAutoCorrect changed to !mShouldShowSuggestions because this was cancelling learning way too often
if (!settingsValues.mInputAttributes.mShouldShowSuggestions || settingsValues.mIncognitoModeEnabled || TextUtils.isEmpty(suggestion))
// mInputTypeNoAutoCorrect changed to !isSuggestionsEnabledPerUserSettings because this was cancelling learning way too often
if (!settingsValues.isSuggestionsEnabledPerUserSettings() || settingsValues.mIncognitoModeEnabled || TextUtils.isEmpty(suggestion))
return;
final boolean wasAutoCapitalized = mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps();
final String word = stripWordSeparatorsFromEnd(suggestion, settingsValues);

View file

@ -29,20 +29,6 @@ import org.dslul.openboard.inputmethod.latin.userdictionary.UserDictionarySettin
import java.util.TreeSet;
/**
* "Text correction" settings sub screen.
*
* This settings sub screen handles the following text correction preferences.
* - Personal dictionary
* - Add-on dictionaries
* - Block offensive words
* - Auto-correction
* - Auto-correction confidence
* - Show correction suggestions
* - Personalized suggestions
* - Suggest Contact names
* - Next-word suggestions
*/
public final class CorrectionSettingsFragment extends SubScreenFragment
implements SharedPreferences.OnSharedPreferenceChangeListener,
PermissionsManager.PermissionsResultCallback {
@ -86,6 +72,8 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
.setPositiveButton(android.R.string.ok, null)
.setOnCancelListener(dialogInterface -> ((TwoStatePreference) findPreference(key)).setChecked(true))
.show();
} else if (Settings.PREF_SHOW_SUGGESTIONS.equals(key) && !prefs.getBoolean(key, true)) {
((TwoStatePreference)findPreference(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS)).setChecked(false);
}
refreshEnabledSettings();
}
@ -106,9 +94,9 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
}
private void refreshEnabledSettings() {
setPreferenceVisible(Settings.PREF_AUTO_CORRECTION_CONFIDENCE,
Settings.readAutoCorrectEnabled(getSharedPreferences()));
setPreferenceVisible(Settings.PREF_AUTO_CORRECTION_CONFIDENCE, Settings.readAutoCorrectEnabled(getSharedPreferences()));
setPreferenceVisible(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, getSharedPreferences().getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true));
setPreferenceVisible(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, getSharedPreferences().getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true));
turnOffLookupContactsIfNoPermission();
}

View file

@ -83,6 +83,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
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_SHOW_SUGGESTIONS = "show_suggestions";
public static final String PREF_ALWAYS_SHOW_SUGGESTIONS = "pref_always_show_suggestions";
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_BLOCK_POTENTIALLY_OFFENSIVE = "pref_key_block_potentially_offensive";

View file

@ -192,8 +192,8 @@ public class SettingsValues {
&& prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true);
mAutoCorrectionEnabledPerUserSettings = mAutoCorrectEnabled;
//&& !mInputAttributes.mInputTypeNoAutoCorrect; // follow that request or not?
mSuggestionsEnabledPerUserSettings = !mInputAttributes.mIsPasswordField &&
readSuggestionsEnabled(prefs);
mSuggestionsEnabledPerUserSettings = (mInputAttributes.mShouldShowSuggestions && readSuggestionsEnabled(prefs))
|| (!mInputAttributes.mIsPasswordField && readSuggestionsOverrideEnabled(prefs));
mIncognitoModeEnabled = Settings.readAlwaysIncognitoMode(prefs) || mInputAttributes.mNoLearning
|| mInputAttributes.mIsPasswordField;
mKeyboardHeightScale = prefs.getFloat(Settings.PREF_KEYBOARD_HEIGHT_SCALE, DEFAULT_SIZE_SCALE);
@ -252,8 +252,7 @@ public class SettingsValues {
}
public boolean needsToLookupSuggestions() {
return mInputAttributes.mShouldShowSuggestions
&& (mAutoCorrectionEnabledPerUserSettings || isSuggestionsEnabledPerUserSettings());
return mAutoCorrectionEnabledPerUserSettings || isSuggestionsEnabledPerUserSettings();
}
public boolean isSuggestionsEnabledPerUserSettings() {
@ -312,6 +311,10 @@ public class SettingsValues {
return prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true);
}
private static boolean readSuggestionsOverrideEnabled(final SharedPreferences prefs) {
return prefs.getBoolean(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, false);
}
private static boolean readBigramPredictionEnabled(final SharedPreferences prefs,
final Resources res) {
return prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, res.getBoolean(

View file

@ -101,6 +101,10 @@
<string name="prefs_show_suggestions">Show correction suggestions</string>
<!-- Description for show suggestions -->
<string name="prefs_show_suggestions_summary">Display suggested words while typing</string>
<!-- Option to override app flag to not show suggestions -->
<string name="prefs_always_show_suggestions">Always show suggestions</string>
<!-- Description for override app flag to not show suggestions -->
<string name="prefs_always_show_suggestions_summary">Ignore other apps request to disable suggestions</string>
<!-- Option to block potentially offensive words to be shown [CHAR_LIMIT=30] -->
<string name="prefs_block_potentially_offensive_title">Block offensive words</string>
<!-- Summary for option to block potentially offensive words to be shown [CHAR_LIMIT=80 (two lines) or 40 (fits on one line, preferable)] -->

View file

@ -71,6 +71,13 @@
android:defaultValue="true"
android:persistent="true" />
<SwitchPreferenceCompat
android:key="pref_always_show_suggestions"
android:title="@string/prefs_always_show_suggestions"
android:summary="@string/prefs_always_show_suggestions_summary"
android:defaultValue="false"
android:persistent="true" />
<SwitchPreferenceCompat
android:key="pref_key_use_personalized_dicts"
android:title="@string/use_personalized_dicts"