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:
Yohei Yukawa
2016-02-26 09:34:54 -08:00
parent c2bcc727d9
commit 1ea368b5d5
3 changed files with 33 additions and 17 deletions

View File

@@ -261,12 +261,16 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
if (spellChecker != null) {
final TextServicesManager tsm = (TextServicesManager) getSystemService(
Context.TEXT_SERVICES_MANAGER_SERVICE);
final SpellCheckerInfo sci = tsm.getCurrentSpellChecker();
spellChecker.setEnabled(sci != null);
if (tsm.isSpellCheckerEnabled() && sci != null) {
spellChecker.setSummary(sci.loadLabel(getPackageManager()));
} else {
if (!tsm.isSpellCheckerEnabled()) {
spellChecker.setEnabled(false);
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);
}
}
}