diff options
author | Tadashi G. Takaoka <takaoka@google.com> | 2014-07-21 12:16:18 -0700 |
---|---|---|
committer | Tadashi G. Takaoka <takaoka@google.com> | 2014-07-22 16:23:50 +0000 |
commit | 5d56f6217f237ec6f1dc20a1c9f7886ca3c6a717 (patch) | |
tree | 1744a86767aa9f04ddf5ab120e1539886f8b0e2d /src/com/android/settings/inputmethod | |
parent | 2c22d6d2040cc846dbaf5152191cc15c5c5995ab (diff) | |
download | packages_apps_Settings-5d56f6217f237ec6f1dc20a1c9f7886ca3c6a717.zip packages_apps_Settings-5d56f6217f237ec6f1dc20a1c9f7886ca3c6a717.tar.gz packages_apps_Settings-5d56f6217f237ec6f1dc20a1c9f7886ca3c6a717.tar.bz2 |
Use OnPreferenceChangeLister for subtype enabler
Change-Id: Id9eaed14803b6c4e194f1cf62900de0a053da012
Diffstat (limited to 'src/com/android/settings/inputmethod')
-rw-r--r-- | src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java index 4019bb4..eff1daa 100644 --- a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java +++ b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java @@ -23,6 +23,7 @@ import android.content.res.Configuration; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceCategory; import android.preference.PreferenceScreen; import android.text.TextUtils; @@ -40,7 +41,8 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; -public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { +public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment + implements OnPreferenceChangeListener { private boolean mHaveHardKeyboard; private final HashMap<String, List<Preference>> mInputMethodAndSubtypePrefsMap = new HashMap<>(); @@ -119,32 +121,34 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { mInputMethodInfoList, mHaveHardKeyboard); } - // TODO: Stop overriding this method. Instead start using {@link OnPreferenceChangedListener}. @Override - public boolean onPreferenceTreeClick(final PreferenceScreen preferenceScreen, - final Preference preference) { - if (!(preference instanceof CheckBoxPreference)) { - return super.onPreferenceTreeClick(preferenceScreen, preference); + public boolean onPreferenceChange(final Preference pref, final Object newValue) { + if (!(newValue instanceof Boolean)) { + return true; // Invoke default behavior. } - final CheckBoxPreference chkPref = (CheckBoxPreference) preference; - + final boolean isChecking = (Boolean) newValue; for (final String imiId : mAutoSelectionPrefsMap.keySet()) { - if (mAutoSelectionPrefsMap.get(imiId) == chkPref) { - // We look for the first preference item in subtype enabler. The first item is used - // for turning on/off subtype auto selection. We are in the subtype enabler and - // trying selecting subtypes automatically. - setAutoSelectionSubtypesEnabled(imiId, chkPref.isChecked()); - return super.onPreferenceTreeClick(preferenceScreen, preference); + // An auto select subtype preference is changing. + if (mAutoSelectionPrefsMap.get(imiId) == pref) { + final CheckBoxPreference autoSelectionPref = (CheckBoxPreference) pref; + autoSelectionPref.setChecked(isChecking); + // Enable or disable subtypes depending on the auto selection preference. + setAutoSelectionSubtypesEnabled(imiId, autoSelectionPref.isChecked()); + return false; } } - - // Turns off a subtype. - if (!chkPref.isChecked()) { - updateAutoSelectionPreferences(); - return super.onPreferenceTreeClick(preferenceScreen, preference); + // A subtype preference is changing. + if (pref instanceof InputMethodSubtypePreference) { + final InputMethodSubtypePreference subtypePref = (InputMethodSubtypePreference) pref; + subtypePref.setChecked(isChecking); + if (!subtypePref.isChecked()) { + // It takes care of the case where no subtypes are explicitly enabled then the auto + // selection preference is going to be checked. + updateAutoSelectionPreferences(); + } + return false; } - - return super.onPreferenceTreeClick(preferenceScreen, preference); + return true; // Invoke default behavior. } private void addInputMethodSubtypePreferences(final InputMethodInfo imi, @@ -166,6 +170,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { final CheckBoxPreference autoSelectionPref = new CheckBoxPreference(context); mAutoSelectionPrefsMap.put(imiId, autoSelectionPref); keyboardSettingsCategory.addPreference(autoSelectionPref); + autoSelectionPref.setOnPreferenceChangeListener(this); final PreferenceCategory activeInputMethodsCategory = new PreferenceCategory(context); activeInputMethodsCategory.setTitle(R.string.active_input_method_subtypes); @@ -199,6 +204,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { for (int index = 0; index < prefCount; ++index) { final Preference pref = subtypePreferences.get(index); activeInputMethodsCategory.addPreference(pref); + pref.setOnPreferenceChangeListener(this); InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref); } mInputMethodAndSubtypePrefsMap.put(imiId, subtypePreferences); |