Remove unnecessary saved persistent preference

This CL also fixes a bug in
InputMethodAndSubtypeUtil.updateSubtypesPreferenceChecked method that
prevents solving the issue/16115751.

Bug: 16115751
Change-Id: Ib46790172ed539d444fd609a1a97dabb2cb2d2f3
This commit is contained in:
Tadashi G. Takaoka
2014-07-12 16:37:38 +09:00
parent 7ab8929cc6
commit 3460a2683c
3 changed files with 33 additions and 28 deletions

View File

@@ -270,6 +270,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
for (int index = 0; index < prefCount; ++index) { for (int index = 0; index < prefCount; ++index) {
final Preference pref = subtypePreferences.get(index); final Preference pref = subtypePreferences.get(index);
activeInputMethodsCategory.addPreference(pref); activeInputMethodsCategory.addPreference(pref);
InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref);
} }
mInputMethodAndSubtypePrefsMap.put(imiId, subtypePreferences); mInputMethodAndSubtypePrefsMap.put(imiId, subtypePreferences);
if (TextUtils.isEmpty(autoSubtypeLabel)) { if (TextUtils.isEmpty(autoSubtypeLabel)) {

View File

@@ -274,21 +274,21 @@ class InputMethodAndSubtypeUtil {
currentInputMethodId != null ? currentInputMethodId : ""); currentInputMethodId != null ? currentInputMethodId : "");
} }
static void loadInputMethodSubtypeList(SettingsPreferenceFragment context, static void loadInputMethodSubtypeList(final SettingsPreferenceFragment context,
ContentResolver resolver, List<InputMethodInfo> inputMethodInfos, final ContentResolver resolver, final List<InputMethodInfo> inputMethodInfos,
final Map<String, List<Preference>> inputMethodPrefsMap) { final Map<String, List<Preference>> inputMethodPrefsMap) {
HashMap<String, HashSet<String>> enabledSubtypes = final HashMap<String, HashSet<String>> enabledSubtypes =
getEnabledInputMethodsAndSubtypeList(resolver); getEnabledInputMethodsAndSubtypeList(resolver);
for (InputMethodInfo imi : inputMethodInfos) { for (final InputMethodInfo imi : inputMethodInfos) {
final String imiId = imi.getId(); final String imiId = imi.getId();
Preference pref = context.findPreference(imiId); final Preference pref = context.findPreference(imiId);
if (pref != null && pref instanceof CheckBoxPreference) { if (pref instanceof CheckBoxPreference) {
CheckBoxPreference checkBoxPreference = (CheckBoxPreference) pref; final CheckBoxPreference checkBoxPreference = (CheckBoxPreference) pref;
boolean isEnabled = enabledSubtypes.containsKey(imiId); final boolean isEnabled = enabledSubtypes.containsKey(imiId);
checkBoxPreference.setChecked(isEnabled); checkBoxPreference.setChecked(isEnabled);
if (inputMethodPrefsMap != null) { if (inputMethodPrefsMap != null) {
for (Preference childPref: inputMethodPrefsMap.get(imiId)) { for (final Preference childPref: inputMethodPrefsMap.get(imiId)) {
childPref.setEnabled(isEnabled); childPref.setEnabled(isEnabled);
} }
} }
@@ -298,16 +298,17 @@ class InputMethodAndSubtypeUtil {
updateSubtypesPreferenceChecked(context, inputMethodInfos, enabledSubtypes); updateSubtypesPreferenceChecked(context, inputMethodInfos, enabledSubtypes);
} }
static void setSubtypesPreferenceEnabled(SettingsPreferenceFragment context, static void setSubtypesPreferenceEnabled(final SettingsPreferenceFragment context,
List<InputMethodInfo> inputMethodProperties, String id, boolean enabled) { final List<InputMethodInfo> inputMethodProperties, final String id,
PreferenceScreen preferenceScreen = context.getPreferenceScreen(); final boolean enabled) {
for (InputMethodInfo imi : inputMethodProperties) { final PreferenceScreen preferenceScreen = context.getPreferenceScreen();
for (final InputMethodInfo imi : inputMethodProperties) {
if (id.equals(imi.getId())) { if (id.equals(imi.getId())) {
final int subtypeCount = imi.getSubtypeCount(); final int subtypeCount = imi.getSubtypeCount();
for (int i = 0; i < subtypeCount; ++i) { for (int i = 0; i < subtypeCount; ++i) {
InputMethodSubtype subtype = imi.getSubtypeAt(i); final InputMethodSubtype subtype = imi.getSubtypeAt(i);
CheckBoxPreference pref = (CheckBoxPreference) preferenceScreen.findPreference( final CheckBoxPreference pref = (CheckBoxPreference) preferenceScreen
id + subtype.hashCode()); .findPreference(id + subtype.hashCode());
if (pref != null) { if (pref != null) {
pref.setEnabled(enabled); pref.setEnabled(enabled);
} }
@@ -316,24 +317,27 @@ class InputMethodAndSubtypeUtil {
} }
} }
private static void updateSubtypesPreferenceChecked(SettingsPreferenceFragment context, private static void updateSubtypesPreferenceChecked(final SettingsPreferenceFragment context,
List<InputMethodInfo> inputMethodProperties, final List<InputMethodInfo> inputMethodProperties,
HashMap<String, HashSet<String>> enabledSubtypes) { final HashMap<String, HashSet<String>> enabledSubtypes) {
PreferenceScreen preferenceScreen = context.getPreferenceScreen(); final PreferenceScreen preferenceScreen = context.getPreferenceScreen();
for (InputMethodInfo imi : inputMethodProperties) { for (final InputMethodInfo imi : inputMethodProperties) {
String id = imi.getId(); final String id = imi.getId();
if (!enabledSubtypes.containsKey(id)) break; if (!enabledSubtypes.containsKey(id)) {
// There is no need to enable/disable subtypes of disabled IMEs.
continue;
}
final HashSet<String> enabledSubtypesSet = enabledSubtypes.get(id); final HashSet<String> enabledSubtypesSet = enabledSubtypes.get(id);
final int subtypeCount = imi.getSubtypeCount(); final int subtypeCount = imi.getSubtypeCount();
for (int i = 0; i < subtypeCount; ++i) { for (int i = 0; i < subtypeCount; ++i) {
InputMethodSubtype subtype = imi.getSubtypeAt(i); final InputMethodSubtype subtype = imi.getSubtypeAt(i);
String hashCode = String.valueOf(subtype.hashCode()); final String hashCode = String.valueOf(subtype.hashCode());
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "--- Set checked state: " + "id" + ", " + hashCode + ", " Log.d(TAG, "--- Set checked state: " + "id" + ", " + hashCode + ", "
+ enabledSubtypesSet.contains(hashCode)); + enabledSubtypesSet.contains(hashCode));
} }
CheckBoxPreference pref = (CheckBoxPreference) preferenceScreen.findPreference( final CheckBoxPreference pref = (CheckBoxPreference) preferenceScreen
id + hashCode); .findPreference(id + hashCode);
if (pref != null) { if (pref != null) {
pref.setChecked(enabledSubtypesSet.contains(hashCode)); pref.setChecked(enabledSubtypesSet.contains(hashCode));
} }

View File

@@ -33,7 +33,6 @@ import java.util.Locale;
* *
* This preference represents a subtype of an IME. It is used to enable or disable the subtype. * This preference represents a subtype of an IME. It is used to enable or disable the subtype.
*/ */
//TODO: Make this non-persistent.
class InputMethodSubtypePreference extends CheckBoxPreference { class InputMethodSubtypePreference extends CheckBoxPreference {
private final boolean mIsSystemLocale; private final boolean mIsSystemLocale;
private final boolean mIsSystemLanguage; private final boolean mIsSystemLanguage;
@@ -41,6 +40,7 @@ class InputMethodSubtypePreference extends CheckBoxPreference {
InputMethodSubtypePreference(final Context context, final InputMethodSubtype subtype, InputMethodSubtypePreference(final Context context, final InputMethodSubtype subtype,
final InputMethodInfo imi) { final InputMethodInfo imi) {
super(context); super(context);
setPersistent(false);
setKey(imi.getId() + subtype.hashCode()); setKey(imi.getId() + subtype.hashCode());
final CharSequence subtypeLabel = subtype.getDisplayName(context, final CharSequence subtypeLabel = subtype.getDisplayName(context,
imi.getPackageName(), imi.getServiceInfo().applicationInfo); imi.getPackageName(), imi.getServiceInfo().applicationInfo);