diff --git a/res/values/strings.xml b/res/values/strings.xml index 345d8fe3c59..912f0420a66 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2264,14 +2264,12 @@ found in the list of installed applications. Settings Active input methods - - Manage text input options + + Use system language %1$s settings Select active input methods - - Active input methods in %1$s Onscreen keyboard settings diff --git a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java index c2c0a070431..1575e132801 100644 --- a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java +++ b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java @@ -44,14 +44,18 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { private AlertDialog mDialog = null; private boolean mHaveHardKeyboard; - final private HashMap> mInputMethodPrefsMap = - new HashMap>(); + final private HashMap> mInputMethodAndSubtypePrefsMap = + new HashMap>(); + final private HashMap mSubtypeAutoSelectionCBMap = + new HashMap(); + private InputMethodManager mImm; private List mInputMethodProperties; private String mInputMethodId; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); + mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); Configuration config = getResources().getConfiguration(); mHaveHardKeyboard = (config.keyboard == Configuration.KEYBOARD_QWERTY); mInputMethodId = getActivity().getIntent().getStringExtra(EXTRA_INPUT_METHOD_ID); @@ -63,12 +67,15 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { public void onResume() { super.onResume(); InputMethodAndSubtypeUtil.loadInputMethodSubtypeList( - this, getContentResolver(), mInputMethodProperties, mInputMethodPrefsMap); + this, getContentResolver(), mInputMethodProperties, mInputMethodAndSubtypePrefsMap); + updateAutoSelectionCB(); } @Override public void onPause() { super.onPause(); + // Clear all subtypes of all IMEs to make sure + clearImplicitlyEnabledSubtypes(null); InputMethodAndSubtypeUtil.saveInputMethodSubtypeList(this, getContentResolver(), mInputMethodProperties, mHaveHardKeyboard); } @@ -79,8 +86,18 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { if (preference instanceof CheckBoxPreference) { final CheckBoxPreference chkPref = (CheckBoxPreference) preference; + + for (String imiId: mSubtypeAutoSelectionCBMap.keySet()) { + if (mSubtypeAutoSelectionCBMap.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. + setSubtypeAutoSelectionEnabled(imiId, chkPref.isChecked()); + return super.onPreferenceTreeClick(preferenceScreen, preference); + } + } + final String id = chkPref.getKey(); - // TODO: Check subtype or not here if (chkPref.isChecked()) { InputMethodInfo selImi = null; final int N = mInputMethodProperties.size(); @@ -166,21 +183,28 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { for (int i = 0; i < N; ++i) { final InputMethodInfo imi = mInputMethodProperties.get(i); if (imi.getSubtypes().size() <= 1) continue; - String imiId = imi.getId(); - // Add to this subtype the list when no IME is specified or when the IME of this + final String imiId = imi.getId(); + // Add this subtype to the list when no IME is specified or when the IME of this // subtype is the specified IME. if (!TextUtils.isEmpty(mInputMethodId) && !mInputMethodId.equals(imiId)) { continue; } PreferenceCategory keyboardSettingsCategory = new PreferenceCategory(getActivity()); root.addPreference(keyboardSettingsCategory); - PackageManager pm = getPackageManager(); CharSequence label = imi.loadLabel(pm); - keyboardSettingsCategory.setTitle(getResources().getString( - R.string.input_methods_and_subtype_enabler_title_format, label)); + keyboardSettingsCategory.setTitle(label); keyboardSettingsCategory.setKey(imiId); + // TODO: Use toggle Preference if images are ready. + CheckBoxPreference autoCB = new CheckBoxPreference(getActivity()); + autoCB.setTitle(R.string.use_system_language_to_select_input_method_subtypes); + mSubtypeAutoSelectionCBMap.put(imiId, autoCB); + keyboardSettingsCategory.addPreference(autoCB); + + PreferenceCategory activeInputMethodsCategory = new PreferenceCategory(getActivity()); + activeInputMethodsCategory.setTitle(R.string.active_input_method_subtypes); + root.addPreference(activeInputMethodsCategory); ArrayList subtypes = imi.getSubtypes(); ArrayList subtypePreferences = new ArrayList(); @@ -200,12 +224,92 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { CheckBoxPreference chkbxPref = new CheckBoxPreference(getActivity()); chkbxPref.setKey(imiId + subtype.hashCode()); chkbxPref.setTitle(subtypeLabel); - keyboardSettingsCategory.addPreference(chkbxPref); + activeInputMethodsCategory.addPreference(chkbxPref); subtypePreferences.add(chkbxPref); } - mInputMethodPrefsMap.put(imiId, subtypePreferences); + mInputMethodAndSubtypePrefsMap.put(imiId, subtypePreferences); } } return root; } + + private boolean isNoSubtypesExplicitlySelected(String imiId) { + boolean allSubtypesOff = true; + final List subtypePrefs = mInputMethodAndSubtypePrefsMap.get(imiId); + for (Preference subtypePref: subtypePrefs) { + if (subtypePref instanceof CheckBoxPreference + && ((CheckBoxPreference)subtypePref).isChecked()) { + allSubtypesOff = false; + break; + } + } + return allSubtypesOff; + } + + private void setSubtypeAutoSelectionEnabled(String imiId, boolean autoSelectionEnabled) { + mSubtypeAutoSelectionCBMap.get(imiId).setChecked(autoSelectionEnabled); + final List subtypePrefs = mInputMethodAndSubtypePrefsMap.get(imiId); + for (Preference subtypePref: subtypePrefs) { + if (subtypePref instanceof CheckBoxPreference) { + // 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. + subtypePref.setEnabled(!autoSelectionEnabled); + if (autoSelectionEnabled) { + ((CheckBoxPreference)subtypePref).setChecked(false); + } + } + } + if (autoSelectionEnabled) { + InputMethodAndSubtypeUtil.saveInputMethodSubtypeList(this, getContentResolver(), + mInputMethodProperties, mHaveHardKeyboard); + setCheckedImplicitlyEnabledSubtypes(imiId); + } + } + + private void setCheckedImplicitlyEnabledSubtypes(String targetImiId) { + updateImplicitlyEnabledSubtypes(targetImiId, true); + } + + private void clearImplicitlyEnabledSubtypes(String targetImiId) { + updateImplicitlyEnabledSubtypes(targetImiId, false); + } + + private void updateImplicitlyEnabledSubtypes(String targetImiId, boolean check) { + // When targetImiId is null, apply to all subtypes of all IMEs + for (InputMethodInfo imi: mInputMethodProperties) { + String imiId = imi.getId(); + if (targetImiId != null && !targetImiId.equals(imiId)) continue; + final CheckBoxPreference autoCB = mSubtypeAutoSelectionCBMap.get(imiId); + // No need to update implicitly enabled subtypes when the user has unchecked the + // "subtype auto selection". + if (autoCB == null || !autoCB.isChecked()) continue; + final List subtypePrefs = mInputMethodAndSubtypePrefsMap.get(imiId); + final List implicitlyEnabledSubtypes = + mImm.getEnabledInputMethodSubtypeList(imi, true); + if (subtypePrefs == null || implicitlyEnabledSubtypes == null) continue; + for (Preference subtypePref: subtypePrefs) { + if (subtypePref instanceof CheckBoxPreference) { + CheckBoxPreference cb = (CheckBoxPreference)subtypePref; + cb.setChecked(false); + if (check) { + for (InputMethodSubtype subtype: implicitlyEnabledSubtypes) { + String implicitlyEnabledSubtypePrefKey = imiId + subtype.hashCode(); + if (cb.getKey().equals(implicitlyEnabledSubtypePrefKey)) { + cb.setChecked(true); + break; + } + } + } + } + } + } + } + + private void updateAutoSelectionCB() { + for (String imiId: mInputMethodAndSubtypePrefsMap.keySet()) { + setSubtypeAutoSelectionEnabled(imiId, isNoSubtypesExplicitlySelected(imiId)); + } + setCheckedImplicitlyEnabledSubtypes(null); + } } diff --git a/src/com/android/settings/inputmethod/InputMethodConfig.java b/src/com/android/settings/inputmethod/InputMethodConfig.java index 640a77333f7..4702b087033 100644 --- a/src/com/android/settings/inputmethod/InputMethodConfig.java +++ b/src/com/android/settings/inputmethod/InputMethodConfig.java @@ -34,6 +34,7 @@ import android.provider.Settings; import android.text.TextUtils; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; +import android.view.inputmethod.InputMethodSubtype; import java.util.ArrayList; import java.util.HashMap; @@ -49,7 +50,9 @@ public class InputMethodConfig extends SettingsPreferenceFragment { private boolean mHaveHardKeyboard; // Map of imi and its preferences final private HashMap> mInputMethodPrefsMap = - new HashMap>(); + new HashMap>(); + final private HashMap mActiveInputMethodsPrefMap = + new HashMap(); private List mInputMethodProperties; @@ -71,6 +74,7 @@ public class InputMethodConfig extends SettingsPreferenceFragment { super.onResume(); InputMethodAndSubtypeUtil.loadInputMethodSubtypeList( this, getContentResolver(), mInputMethodProperties, mInputMethodPrefsMap); + updateActiveInputMethodsSummary(); } @Override @@ -205,6 +209,7 @@ public class InputMethodConfig extends SettingsPreferenceFragment { intent.putExtra(InputMethodAndSubtypeEnabler.EXTRA_INPUT_METHOD_ID, imiId); prefScreen.setIntent(intent); keyboardSettingsCategory.addPreference(prefScreen); + mActiveInputMethodsPrefMap.put(imi, prefScreen); mInputMethodPrefsMap.get(imiId).add(prefScreen); } @@ -234,4 +239,25 @@ public class InputMethodConfig extends SettingsPreferenceFragment { } return root; } + + private void updateActiveInputMethodsSummary() { + final InputMethodManager imm = + (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + final PackageManager pm = getPackageManager(); + for (InputMethodInfo imi: mActiveInputMethodsPrefMap.keySet()) { + Preference pref = mActiveInputMethodsPrefMap.get(imi); + List subtypes = imm.getEnabledInputMethodSubtypeList(imi, true); + StringBuilder summary = new StringBuilder(); + boolean subtypeAdded = false; + for (InputMethodSubtype subtype: subtypes) { + if (subtypeAdded) { + summary.append(", "); + } + summary.append(pm.getText(imi.getPackageName(), subtype.getNameResId(), + imi.getServiceInfo().applicationInfo)); + subtypeAdded = true; + } + pref.setSummary(summary.toString()); + } + } }