Add a preference for selecting subtypes automatically
bug: 3142286 Change-Id: I9129df7671252d7ccc611a2892a4ba96e1dacdaf
This commit is contained in:
@@ -2264,14 +2264,12 @@ found in the list of installed applications.</string>
|
|||||||
<string name="input_method_settings">Settings</string>
|
<string name="input_method_settings">Settings</string>
|
||||||
<!-- Title for settings of active input methods in each IME -->
|
<!-- Title for settings of active input methods in each IME -->
|
||||||
<string name="active_input_method_subtypes">Active input methods</string>
|
<string name="active_input_method_subtypes">Active input methods</string>
|
||||||
|
<!-- Title for settings whether or not the framework will select input methods in an IME based on the current system locale. -->
|
||||||
<string name="input_methods_settings_summary">Manage text input options</string>
|
<string name="use_system_language_to_select_input_method_subtypes">Use system language</string>
|
||||||
<!-- Input Methods Settings localized format string for generating the appropriate "Foo settings" menu label for the Input Method named "Foo" -->
|
<!-- Input Methods Settings localized format string for generating the appropriate "Foo settings" menu label for the Input Method named "Foo" -->
|
||||||
<string name="input_methods_settings_label_format"><xliff:g id="ime_name">%1$s</xliff:g> settings</string>
|
<string name="input_methods_settings_label_format"><xliff:g id="ime_name">%1$s</xliff:g> settings</string>
|
||||||
<!-- Title for the settings of selecting active input methods of an IME -->
|
<!-- Title for the settings of selecting active input methods of an IME -->
|
||||||
<string name="input_methods_and_subtype_enabler_title">Select active input methods</string>
|
<string name="input_methods_and_subtype_enabler_title">Select active input methods</string>
|
||||||
<!-- Title format for active input methods. "Active input methods in Foo" menu label for the IME named "Foo" -->
|
|
||||||
<string name="input_methods_and_subtype_enabler_title_format">Active input methods in <xliff:g id="ime_application_name">%1$s</xliff:g></string>
|
|
||||||
<!-- Summary for on-screen keyboard settings -->
|
<!-- Summary for on-screen keyboard settings -->
|
||||||
<string name="onscreen_keyboard_settings_summary">Onscreen keyboard settings</string>
|
<string name="onscreen_keyboard_settings_summary">Onscreen keyboard settings</string>
|
||||||
<!-- Title for built-in keyboard settings -->
|
<!-- Title for built-in keyboard settings -->
|
||||||
|
@@ -44,14 +44,18 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
private AlertDialog mDialog = null;
|
private AlertDialog mDialog = null;
|
||||||
private boolean mHaveHardKeyboard;
|
private boolean mHaveHardKeyboard;
|
||||||
final private HashMap<String, List<Preference>> mInputMethodPrefsMap =
|
final private HashMap<String, List<Preference>> mInputMethodAndSubtypePrefsMap =
|
||||||
new HashMap<String, List<Preference>>();
|
new HashMap<String, List<Preference>>();
|
||||||
|
final private HashMap<String, CheckBoxPreference> mSubtypeAutoSelectionCBMap =
|
||||||
|
new HashMap<String, CheckBoxPreference>();
|
||||||
|
private InputMethodManager mImm;
|
||||||
private List<InputMethodInfo> mInputMethodProperties;
|
private List<InputMethodInfo> mInputMethodProperties;
|
||||||
private String mInputMethodId;
|
private String mInputMethodId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
Configuration config = getResources().getConfiguration();
|
Configuration config = getResources().getConfiguration();
|
||||||
mHaveHardKeyboard = (config.keyboard == Configuration.KEYBOARD_QWERTY);
|
mHaveHardKeyboard = (config.keyboard == Configuration.KEYBOARD_QWERTY);
|
||||||
mInputMethodId = getActivity().getIntent().getStringExtra(EXTRA_INPUT_METHOD_ID);
|
mInputMethodId = getActivity().getIntent().getStringExtra(EXTRA_INPUT_METHOD_ID);
|
||||||
@@ -63,12 +67,15 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(
|
InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(
|
||||||
this, getContentResolver(), mInputMethodProperties, mInputMethodPrefsMap);
|
this, getContentResolver(), mInputMethodProperties, mInputMethodAndSubtypePrefsMap);
|
||||||
|
updateAutoSelectionCB();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
// Clear all subtypes of all IMEs to make sure
|
||||||
|
clearImplicitlyEnabledSubtypes(null);
|
||||||
InputMethodAndSubtypeUtil.saveInputMethodSubtypeList(this, getContentResolver(),
|
InputMethodAndSubtypeUtil.saveInputMethodSubtypeList(this, getContentResolver(),
|
||||||
mInputMethodProperties, mHaveHardKeyboard);
|
mInputMethodProperties, mHaveHardKeyboard);
|
||||||
}
|
}
|
||||||
@@ -79,8 +86,18 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
if (preference instanceof CheckBoxPreference) {
|
if (preference instanceof CheckBoxPreference) {
|
||||||
final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
|
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();
|
final String id = chkPref.getKey();
|
||||||
// TODO: Check subtype or not here
|
|
||||||
if (chkPref.isChecked()) {
|
if (chkPref.isChecked()) {
|
||||||
InputMethodInfo selImi = null;
|
InputMethodInfo selImi = null;
|
||||||
final int N = mInputMethodProperties.size();
|
final int N = mInputMethodProperties.size();
|
||||||
@@ -166,21 +183,28 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
for (int i = 0; i < N; ++i) {
|
for (int i = 0; i < N; ++i) {
|
||||||
final InputMethodInfo imi = mInputMethodProperties.get(i);
|
final InputMethodInfo imi = mInputMethodProperties.get(i);
|
||||||
if (imi.getSubtypes().size() <= 1) continue;
|
if (imi.getSubtypes().size() <= 1) continue;
|
||||||
String imiId = imi.getId();
|
final String imiId = imi.getId();
|
||||||
// Add to this subtype the list when no IME is specified or when the IME of this
|
// Add this subtype to the list when no IME is specified or when the IME of this
|
||||||
// subtype is the specified IME.
|
// subtype is the specified IME.
|
||||||
if (!TextUtils.isEmpty(mInputMethodId) && !mInputMethodId.equals(imiId)) {
|
if (!TextUtils.isEmpty(mInputMethodId) && !mInputMethodId.equals(imiId)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
PreferenceCategory keyboardSettingsCategory = new PreferenceCategory(getActivity());
|
PreferenceCategory keyboardSettingsCategory = new PreferenceCategory(getActivity());
|
||||||
root.addPreference(keyboardSettingsCategory);
|
root.addPreference(keyboardSettingsCategory);
|
||||||
|
|
||||||
PackageManager pm = getPackageManager();
|
PackageManager pm = getPackageManager();
|
||||||
CharSequence label = imi.loadLabel(pm);
|
CharSequence label = imi.loadLabel(pm);
|
||||||
|
|
||||||
keyboardSettingsCategory.setTitle(getResources().getString(
|
keyboardSettingsCategory.setTitle(label);
|
||||||
R.string.input_methods_and_subtype_enabler_title_format, label));
|
|
||||||
keyboardSettingsCategory.setKey(imiId);
|
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<InputMethodSubtype> subtypes = imi.getSubtypes();
|
ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes();
|
||||||
ArrayList<Preference> subtypePreferences = new ArrayList<Preference>();
|
ArrayList<Preference> subtypePreferences = new ArrayList<Preference>();
|
||||||
@@ -200,12 +224,92 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
CheckBoxPreference chkbxPref = new CheckBoxPreference(getActivity());
|
CheckBoxPreference chkbxPref = new CheckBoxPreference(getActivity());
|
||||||
chkbxPref.setKey(imiId + subtype.hashCode());
|
chkbxPref.setKey(imiId + subtype.hashCode());
|
||||||
chkbxPref.setTitle(subtypeLabel);
|
chkbxPref.setTitle(subtypeLabel);
|
||||||
keyboardSettingsCategory.addPreference(chkbxPref);
|
activeInputMethodsCategory.addPreference(chkbxPref);
|
||||||
subtypePreferences.add(chkbxPref);
|
subtypePreferences.add(chkbxPref);
|
||||||
}
|
}
|
||||||
mInputMethodPrefsMap.put(imiId, subtypePreferences);
|
mInputMethodAndSubtypePrefsMap.put(imiId, subtypePreferences);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isNoSubtypesExplicitlySelected(String imiId) {
|
||||||
|
boolean allSubtypesOff = true;
|
||||||
|
final List<Preference> 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<Preference> 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<Preference> subtypePrefs = mInputMethodAndSubtypePrefsMap.get(imiId);
|
||||||
|
final List<InputMethodSubtype> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@ import android.provider.Settings;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -49,7 +50,9 @@ public class InputMethodConfig extends SettingsPreferenceFragment {
|
|||||||
private boolean mHaveHardKeyboard;
|
private boolean mHaveHardKeyboard;
|
||||||
// Map of imi and its preferences
|
// Map of imi and its preferences
|
||||||
final private HashMap<String, List<Preference>> mInputMethodPrefsMap =
|
final private HashMap<String, List<Preference>> mInputMethodPrefsMap =
|
||||||
new HashMap<String, List<Preference>>();
|
new HashMap<String, List<Preference>>();
|
||||||
|
final private HashMap<InputMethodInfo, Preference> mActiveInputMethodsPrefMap =
|
||||||
|
new HashMap<InputMethodInfo, Preference>();
|
||||||
private List<InputMethodInfo> mInputMethodProperties;
|
private List<InputMethodInfo> mInputMethodProperties;
|
||||||
|
|
||||||
|
|
||||||
@@ -71,6 +74,7 @@ public class InputMethodConfig extends SettingsPreferenceFragment {
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(
|
InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(
|
||||||
this, getContentResolver(), mInputMethodProperties, mInputMethodPrefsMap);
|
this, getContentResolver(), mInputMethodProperties, mInputMethodPrefsMap);
|
||||||
|
updateActiveInputMethodsSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -205,6 +209,7 @@ public class InputMethodConfig extends SettingsPreferenceFragment {
|
|||||||
intent.putExtra(InputMethodAndSubtypeEnabler.EXTRA_INPUT_METHOD_ID, imiId);
|
intent.putExtra(InputMethodAndSubtypeEnabler.EXTRA_INPUT_METHOD_ID, imiId);
|
||||||
prefScreen.setIntent(intent);
|
prefScreen.setIntent(intent);
|
||||||
keyboardSettingsCategory.addPreference(prefScreen);
|
keyboardSettingsCategory.addPreference(prefScreen);
|
||||||
|
mActiveInputMethodsPrefMap.put(imi, prefScreen);
|
||||||
mInputMethodPrefsMap.get(imiId).add(prefScreen);
|
mInputMethodPrefsMap.get(imiId).add(prefScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,4 +239,25 @@ public class InputMethodConfig extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
return root;
|
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<InputMethodSubtype> 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user