Handle the case where no spell checker is selected.
This follows up to a previous CL [1] that fixed Bug 26685795 that the
Settings app crashes when no spell checker is selected, but introduced
another Bug 26686710 that the user cannot re-select the spell checker
once the device has fallen into that state because the button to select
new spell checker is disabled.
This CL tries to deal with such a case more carefully and gracefully, by
adding more null checking and by showing a meaningful text
("Not selected" for English) to users when no spell checker is currently
selected.
[1]: I65e6d269572e064aa6897807b6611ef947d90211
093a646772
Bug: 26108333
Bug: 26685795
Bug: 26686710
Change-Id: I0ed71bbb580e3547d97e321799ac2b77b1f284a3
This commit is contained in:
@@ -7238,6 +7238,9 @@
|
|||||||
<!-- [CHAR LIMIT=30] Title for dialog for setting to control the default spell checker -->
|
<!-- [CHAR LIMIT=30] Title for dialog for setting to control the default spell checker -->
|
||||||
<string name="choose_spell_checker">Choose spell checker</string>
|
<string name="choose_spell_checker">Choose spell checker</string>
|
||||||
|
|
||||||
|
<!-- [CHAR LIMIT=30] Label for the placeholder of the current spell checker name. Used when no spell checker is currently selected. -->
|
||||||
|
<string name="spell_checker_not_selected">Not selected</string>
|
||||||
|
|
||||||
<!-- Notification log debug tool: missing title -->
|
<!-- Notification log debug tool: missing title -->
|
||||||
<string name="notification_log_no_title">(none)</string>
|
<string name="notification_log_no_title">(none)</string>
|
||||||
<!-- Notification log debug tool: delimiter between header and field data -->
|
<!-- Notification log debug tool: delimiter between header and field data -->
|
||||||
|
@@ -261,12 +261,16 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
|||||||
if (spellChecker != null) {
|
if (spellChecker != null) {
|
||||||
final TextServicesManager tsm = (TextServicesManager) getSystemService(
|
final TextServicesManager tsm = (TextServicesManager) getSystemService(
|
||||||
Context.TEXT_SERVICES_MANAGER_SERVICE);
|
Context.TEXT_SERVICES_MANAGER_SERVICE);
|
||||||
final SpellCheckerInfo sci = tsm.getCurrentSpellChecker();
|
if (!tsm.isSpellCheckerEnabled()) {
|
||||||
spellChecker.setEnabled(sci != null);
|
spellChecker.setEnabled(false);
|
||||||
if (tsm.isSpellCheckerEnabled() && sci != null) {
|
|
||||||
spellChecker.setSummary(sci.loadLabel(getPackageManager()));
|
|
||||||
} else {
|
|
||||||
spellChecker.setSummary(R.string.switch_off_text);
|
spellChecker.setSummary(R.string.switch_off_text);
|
||||||
|
} else {
|
||||||
|
final SpellCheckerInfo sci = tsm.getCurrentSpellChecker();
|
||||||
|
if (sci != null) {
|
||||||
|
spellChecker.setSummary(sci.loadLabel(getPackageManager()));
|
||||||
|
} else {
|
||||||
|
spellChecker.setSummary(R.string.spell_checker_not_selected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -73,19 +73,17 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void populatePreferenceScreen() {
|
private void populatePreferenceScreen() {
|
||||||
final PreferenceScreen screen = getPreferenceScreen();
|
|
||||||
final Context context = getActivity();
|
|
||||||
final int count = (mEnabledScis == null) ? 0 : mEnabledScis.length;
|
|
||||||
|
|
||||||
for (int index = 0; index < count; ++index) {
|
|
||||||
final SpellCheckerInfo sci = mEnabledScis[index];
|
|
||||||
}
|
|
||||||
final SpellCheckerPreference pref = new SpellCheckerPreference(getPrefContext(),
|
final SpellCheckerPreference pref = new SpellCheckerPreference(getPrefContext(),
|
||||||
mEnabledScis);
|
mEnabledScis);
|
||||||
pref.setTitle(R.string.default_spell_checker);
|
pref.setTitle(R.string.default_spell_checker);
|
||||||
pref.setSummary("%s");
|
final int count = (mEnabledScis == null) ? 0 : mEnabledScis.length;
|
||||||
|
if (count > 0) {
|
||||||
|
pref.setSummary("%s");
|
||||||
|
} else {
|
||||||
|
pref.setSummary(R.string.spell_checker_not_selected);
|
||||||
|
}
|
||||||
pref.setOnPreferenceChangeListener(this);
|
pref.setOnPreferenceChangeListener(this);
|
||||||
screen.addPreference(pref);
|
getPreferenceScreen().addPreference(pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,8 +112,13 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
|
|||||||
final boolean isSpellCheckerEnabled = mTsm.isSpellCheckerEnabled();
|
final boolean isSpellCheckerEnabled = mTsm.isSpellCheckerEnabled();
|
||||||
mSwitchBar.setChecked(isSpellCheckerEnabled);
|
mSwitchBar.setChecked(isSpellCheckerEnabled);
|
||||||
|
|
||||||
final SpellCheckerSubtype currentScs = mTsm.getCurrentSpellCheckerSubtype(
|
final SpellCheckerSubtype currentScs;
|
||||||
false /* allowImplicitlySelectedSubtype */);
|
if (mCurrentSci == null) {
|
||||||
|
currentScs = mTsm.getCurrentSpellCheckerSubtype(
|
||||||
|
false /* allowImplicitlySelectedSubtype */);
|
||||||
|
} else {
|
||||||
|
currentScs = null;
|
||||||
|
}
|
||||||
mSpellCheckerLanaguagePref.setSummary(getSpellCheckerSubtypeLabel(mCurrentSci, currentScs));
|
mSpellCheckerLanaguagePref.setSummary(getSpellCheckerSubtypeLabel(mCurrentSci, currentScs));
|
||||||
|
|
||||||
final PreferenceScreen screen = getPreferenceScreen();
|
final PreferenceScreen screen = getPreferenceScreen();
|
||||||
@@ -128,12 +131,13 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
|
|||||||
pref.setSelected(mCurrentSci);
|
pref.setSelected(mCurrentSci);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mSpellCheckerLanaguagePref.setEnabled(isSpellCheckerEnabled && mCurrentSci != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence getSpellCheckerSubtypeLabel(final SpellCheckerInfo sci,
|
private CharSequence getSpellCheckerSubtypeLabel(final SpellCheckerInfo sci,
|
||||||
final SpellCheckerSubtype subtype) {
|
final SpellCheckerSubtype subtype) {
|
||||||
if (sci == null) {
|
if (sci == null) {
|
||||||
return null;
|
return getString(R.string.spell_checker_not_selected);
|
||||||
}
|
}
|
||||||
if (subtype == null) {
|
if (subtype == null) {
|
||||||
return getString(R.string.use_system_language_to_select_input_method_subtypes);
|
return getString(R.string.use_system_language_to_select_input_method_subtypes);
|
||||||
@@ -173,6 +177,11 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
|
|||||||
mDialog.dismiss();
|
mDialog.dismiss();
|
||||||
}
|
}
|
||||||
final SpellCheckerInfo currentSci = mTsm.getCurrentSpellChecker();
|
final SpellCheckerInfo currentSci = mTsm.getCurrentSpellChecker();
|
||||||
|
if (currentSci == null) {
|
||||||
|
// This can happen in some situations. One example is that the package that the current
|
||||||
|
// spell checker belongs to was uninstalled or being in background.
|
||||||
|
return;
|
||||||
|
}
|
||||||
final SpellCheckerSubtype currentScs = mTsm.getCurrentSpellCheckerSubtype(
|
final SpellCheckerSubtype currentScs = mTsm.getCurrentSpellCheckerSubtype(
|
||||||
false /* allowImplicitlySelectedSubtype */);
|
false /* allowImplicitlySelectedSubtype */);
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
Reference in New Issue
Block a user