Use SwitchPreference for input method subtype enabler
Bug: 15781377 Change-Id: I80fe987e499722af7768147a184934650bbf8385
This commit is contained in:
@@ -21,11 +21,11 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
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.preference.TwoStatePreference;
|
||||
import android.text.TextUtils;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
@@ -46,7 +46,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment
|
||||
private boolean mHaveHardKeyboard;
|
||||
private final HashMap<String, List<Preference>> mInputMethodAndSubtypePrefsMap =
|
||||
new HashMap<>();
|
||||
private final HashMap<String, CheckBoxPreference> mAutoSelectionPrefsMap = new HashMap<>();
|
||||
private final HashMap<String, TwoStatePreference> mAutoSelectionPrefsMap = new HashMap<>();
|
||||
private InputMethodManager mImm;
|
||||
// TODO: Change mInputMethodInfoList to Map
|
||||
private List<InputMethodInfo> mInputMethodInfoList;
|
||||
@@ -130,7 +130,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment
|
||||
for (final String imiId : mAutoSelectionPrefsMap.keySet()) {
|
||||
// An auto select subtype preference is changing.
|
||||
if (mAutoSelectionPrefsMap.get(imiId) == pref) {
|
||||
final CheckBoxPreference autoSelectionPref = (CheckBoxPreference) pref;
|
||||
final TwoStatePreference autoSelectionPref = (TwoStatePreference) pref;
|
||||
autoSelectionPref.setChecked(isChecking);
|
||||
// Enable or disable subtypes depending on the auto selection preference.
|
||||
setAutoSelectionSubtypesEnabled(imiId, autoSelectionPref.isChecked());
|
||||
@@ -167,7 +167,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment
|
||||
keyboardSettingsCategory.setTitle(label);
|
||||
keyboardSettingsCategory.setKey(imiId);
|
||||
// TODO: Use toggle Preference if images are ready.
|
||||
final CheckBoxPreference autoSelectionPref = new CheckBoxPreference(context);
|
||||
final TwoStatePreference autoSelectionPref = new SwitchWithNoTextPreference(context);
|
||||
mAutoSelectionPrefsMap.put(imiId, autoSelectionPref);
|
||||
keyboardSettingsCategory.addPreference(autoSelectionPref);
|
||||
autoSelectionPref.setOnPreferenceChangeListener(this);
|
||||
@@ -219,7 +219,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment
|
||||
private boolean isNoSubtypesExplicitlySelected(final String imiId) {
|
||||
final List<Preference> subtypePrefs = mInputMethodAndSubtypePrefsMap.get(imiId);
|
||||
for (final Preference pref : subtypePrefs) {
|
||||
if (pref instanceof CheckBoxPreference && ((CheckBoxPreference)pref).isChecked()) {
|
||||
if (pref instanceof TwoStatePreference && ((TwoStatePreference)pref).isChecked()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -228,20 +228,20 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment
|
||||
|
||||
private void setAutoSelectionSubtypesEnabled(final String imiId,
|
||||
final boolean autoSelectionEnabled) {
|
||||
final CheckBoxPreference autoSelectionPref = mAutoSelectionPrefsMap.get(imiId);
|
||||
final TwoStatePreference autoSelectionPref = mAutoSelectionPrefsMap.get(imiId);
|
||||
if (autoSelectionPref == null) {
|
||||
return;
|
||||
}
|
||||
autoSelectionPref.setChecked(autoSelectionEnabled);
|
||||
final List<Preference> subtypePrefs = mInputMethodAndSubtypePrefsMap.get(imiId);
|
||||
for (final Preference pref : subtypePrefs) {
|
||||
if (pref instanceof CheckBoxPreference) {
|
||||
if (pref instanceof TwoStatePreference) {
|
||||
// When autoSelectionEnabled is true, all subtype prefs need to be disabled with
|
||||
// implicitly checked subtypes. In case of false, all subtype prefs need to be
|
||||
// enabled.
|
||||
pref.setEnabled(!autoSelectionEnabled);
|
||||
if (autoSelectionEnabled) {
|
||||
((CheckBoxPreference)pref).setChecked(false);
|
||||
((TwoStatePreference)pref).setChecked(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,7 +256,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment
|
||||
// When targetImiId is null, apply to all subtypes of all IMEs
|
||||
for (final InputMethodInfo imi : mInputMethodInfoList) {
|
||||
final String imiId = imi.getId();
|
||||
final CheckBoxPreference autoSelectionPref = mAutoSelectionPrefsMap.get(imiId);
|
||||
final TwoStatePreference autoSelectionPref = mAutoSelectionPrefsMap.get(imiId);
|
||||
// No need to update implicitly enabled subtypes when the user has unchecked the
|
||||
// "subtype auto selection".
|
||||
if (autoSelectionPref == null || !autoSelectionPref.isChecked()) {
|
||||
@@ -277,10 +277,10 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment
|
||||
return;
|
||||
}
|
||||
for (final Preference pref : subtypePrefs) {
|
||||
if (!(pref instanceof CheckBoxPreference)) {
|
||||
if (!(pref instanceof TwoStatePreference)) {
|
||||
continue;
|
||||
}
|
||||
final CheckBoxPreference subtypePref = (CheckBoxPreference)pref;
|
||||
final TwoStatePreference subtypePref = (TwoStatePreference)pref;
|
||||
subtypePref.setChecked(false);
|
||||
if (check) {
|
||||
for (final InputMethodSubtype subtype : implicitlyEnabledSubtypes) {
|
||||
|
@@ -18,7 +18,6 @@ package com.android.settings.inputmethod;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.preference.TwoStatePreference;
|
||||
@@ -186,12 +185,12 @@ class InputMethodAndSubtypeUtil {
|
||||
for (int i = 0; i < subtypeCount; ++i) {
|
||||
InputMethodSubtype subtype = imi.getSubtypeAt(i);
|
||||
final String subtypeHashCodeStr = String.valueOf(subtype.hashCode());
|
||||
CheckBoxPreference subtypePref = (CheckBoxPreference) context.findPreference(
|
||||
imiId + subtypeHashCodeStr);
|
||||
final TwoStatePreference subtypePref = (TwoStatePreference) context
|
||||
.findPreference(imiId + subtypeHashCodeStr);
|
||||
// In the Configure input method screen which does not have subtype preferences.
|
||||
if (subtypePref == null) continue;
|
||||
if (!subtypePrefFound) {
|
||||
// Once subtype checkbox is found, subtypeSet needs to be cleared.
|
||||
// Once subtype preference is found, subtypeSet needs to be cleared.
|
||||
// Because of system change, hashCode value could have been changed.
|
||||
subtypesSet.clear();
|
||||
// If selected subtype preference is disabled, needs to reset.
|
||||
@@ -283,10 +282,10 @@ class InputMethodAndSubtypeUtil {
|
||||
for (final InputMethodInfo imi : inputMethodInfos) {
|
||||
final String imiId = imi.getId();
|
||||
final Preference pref = context.findPreference(imiId);
|
||||
if (pref instanceof CheckBoxPreference) {
|
||||
final CheckBoxPreference checkBoxPreference = (CheckBoxPreference) pref;
|
||||
if (pref instanceof TwoStatePreference) {
|
||||
final TwoStatePreference subtypePref = (TwoStatePreference) pref;
|
||||
final boolean isEnabled = enabledSubtypes.containsKey(imiId);
|
||||
checkBoxPreference.setChecked(isEnabled);
|
||||
subtypePref.setChecked(isEnabled);
|
||||
if (inputMethodPrefsMap != null) {
|
||||
for (final Preference childPref: inputMethodPrefsMap.get(imiId)) {
|
||||
childPref.setEnabled(isEnabled);
|
||||
@@ -307,7 +306,7 @@ class InputMethodAndSubtypeUtil {
|
||||
final int subtypeCount = imi.getSubtypeCount();
|
||||
for (int i = 0; i < subtypeCount; ++i) {
|
||||
final InputMethodSubtype subtype = imi.getSubtypeAt(i);
|
||||
final CheckBoxPreference pref = (CheckBoxPreference) preferenceScreen
|
||||
final TwoStatePreference pref = (TwoStatePreference) preferenceScreen
|
||||
.findPreference(id + subtype.hashCode());
|
||||
if (pref != null) {
|
||||
pref.setEnabled(enabled);
|
||||
@@ -336,7 +335,7 @@ class InputMethodAndSubtypeUtil {
|
||||
Log.d(TAG, "--- Set checked state: " + "id" + ", " + hashCode + ", "
|
||||
+ enabledSubtypesSet.contains(hashCode));
|
||||
}
|
||||
final CheckBoxPreference pref = (CheckBoxPreference) preferenceScreen
|
||||
final TwoStatePreference pref = (TwoStatePreference) preferenceScreen
|
||||
.findPreference(id + hashCode);
|
||||
if (pref != null) {
|
||||
pref.setChecked(enabledSubtypesSet.contains(hashCode));
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.inputmethod;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
@@ -33,7 +32,7 @@ import java.util.Locale;
|
||||
*
|
||||
* This preference represents a subtype of an IME. It is used to enable or disable the subtype.
|
||||
*/
|
||||
class InputMethodSubtypePreference extends CheckBoxPreference {
|
||||
class InputMethodSubtypePreference extends SwitchWithNoTextPreference {
|
||||
private final boolean mIsSystemLocale;
|
||||
private final boolean mIsSystemLanguage;
|
||||
|
||||
|
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.inputmethod;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.SwitchPreference;
|
||||
|
||||
class SwitchWithNoTextPreference extends SwitchPreference {
|
||||
private static final String EMPTY_TEXT = "";
|
||||
|
||||
SwitchWithNoTextPreference(final Context context) {
|
||||
super(context);
|
||||
setSwitchTextOn(EMPTY_TEXT);
|
||||
setSwitchTextOff(EMPTY_TEXT);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user