Refactor ime settings
Bug: 8364845 Change-Id: Ie8db248314f2014278e1006b4b37aa64ce76f893
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import com.android.internal.inputmethod.InputMethodUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
@@ -145,7 +146,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
InputMethodInfo imi = mInputMethodProperties.get(i);
|
InputMethodInfo imi = mInputMethodProperties.get(i);
|
||||||
if (id.equals(imi.getId())) {
|
if (id.equals(imi.getId())) {
|
||||||
selImi = imi;
|
selImi = imi;
|
||||||
if (InputMethodAndSubtypeUtil.isSystemIme(imi)) {
|
if (InputMethodUtils.isSystemIme(imi)) {
|
||||||
InputMethodAndSubtypeUtil.setSubtypesPreferenceEnabled(
|
InputMethodAndSubtypeUtil.setSubtypesPreferenceEnabled(
|
||||||
this, mInputMethodProperties, id, true);
|
this, mInputMethodProperties, id, true);
|
||||||
// This is a built-in IME, so no need to warn.
|
// This is a built-in IME, so no need to warn.
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import com.android.internal.inputmethod.InputMethodUtils;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
@@ -176,8 +177,9 @@ public class InputMethodAndSubtypeUtil {
|
|||||||
((CheckBoxPreference) pref).isChecked()
|
((CheckBoxPreference) pref).isChecked()
|
||||||
: enabledIMEAndSubtypesMap.containsKey(imiId);
|
: enabledIMEAndSubtypesMap.containsKey(imiId);
|
||||||
final boolean isCurrentInputMethod = imiId.equals(currentInputMethodId);
|
final boolean isCurrentInputMethod = imiId.equals(currentInputMethodId);
|
||||||
final boolean systemIme = isSystemIme(imi);
|
final boolean systemIme = InputMethodUtils.isSystemIme(imi);
|
||||||
if ((!hasHardKeyboard && isAlwaysCheckedIme(imi, context.getActivity(), imiCount))
|
if ((!hasHardKeyboard && InputMethodSettingValuesWrapper.getInstance(
|
||||||
|
context.getActivity()).isAlwaysCheckedIme(imi, context.getActivity()))
|
||||||
|| isImeChecked) {
|
|| isImeChecked) {
|
||||||
if (!enabledIMEAndSubtypesMap.containsKey(imiId)) {
|
if (!enabledIMEAndSubtypesMap.containsKey(imiId)) {
|
||||||
// imiId has just been enabled
|
// imiId has just been enabled
|
||||||
@@ -345,56 +347,4 @@ public class InputMethodAndSubtypeUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSystemIme(InputMethodInfo property) {
|
|
||||||
return (property.getServiceInfo().applicationInfo.flags
|
|
||||||
& ApplicationInfo.FLAG_SYSTEM) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isAuxiliaryIme(InputMethodInfo imi) {
|
|
||||||
return imi.isAuxiliaryIme();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isAlwaysCheckedIme(InputMethodInfo imi, Context context, int imiCount) {
|
|
||||||
if (imiCount <= 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!isSystemIme(imi)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isAuxiliaryIme(imi)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isValidDefaultIme(imi, context)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return containsSubtypeOf(imi, ENGLISH_LOCALE.getLanguage());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isValidDefaultIme(InputMethodInfo imi, Context context) {
|
|
||||||
if (imi.getIsDefaultResourceId() != 0) {
|
|
||||||
try {
|
|
||||||
Resources res = context.createPackageContext(
|
|
||||||
imi.getPackageName(), 0).getResources();
|
|
||||||
if (res.getBoolean(imi.getIsDefaultResourceId())
|
|
||||||
&& containsSubtypeOf(imi, context.getResources().getConfiguration().
|
|
||||||
locale.getLanguage())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (PackageManager.NameNotFoundException ex) {
|
|
||||||
} catch (Resources.NotFoundException ex) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean containsSubtypeOf(InputMethodInfo imi, String language) {
|
|
||||||
final int N = imi.getSubtypeCount();
|
|
||||||
for (int i = 0; i < N; ++i) {
|
|
||||||
if (imi.getSubtypeAt(i).getLocale().startsWith(language)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import com.android.internal.inputmethod.InputMethodUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
@@ -44,7 +45,6 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class InputMethodPreference extends CheckBoxPreference {
|
public class InputMethodPreference extends CheckBoxPreference {
|
||||||
@@ -91,9 +91,10 @@ public class InputMethodPreference extends CheckBoxPreference {
|
|||||||
mImm = imm;
|
mImm = imm;
|
||||||
mImi = imi;
|
mImi = imi;
|
||||||
updateSummary();
|
updateSummary();
|
||||||
mAlwaysChecked = InputMethodAndSubtypeUtil.isAlwaysCheckedIme(
|
mAlwaysChecked = InputMethodSettingValuesWrapper.getInstance(
|
||||||
imi, fragment.getActivity(), imiCount);
|
fragment.getActivity()).isAlwaysCheckedIme(
|
||||||
mIsSystemIme = InputMethodAndSubtypeUtil.isSystemIme(imi);
|
imi, fragment.getActivity());
|
||||||
|
mIsSystemIme = InputMethodUtils.isSystemIme(imi);
|
||||||
if (mAlwaysChecked) {
|
if (mAlwaysChecked) {
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,7 @@ import android.view.inputmethod.InputMethodSubtype;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is a wrapper for InputMethodSettings. You need to refresh internal states
|
* This class is a wrapper for InputMethodSettings. You need to refresh internal states
|
||||||
@@ -39,6 +40,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class InputMethodSettingValuesWrapper {
|
public class InputMethodSettingValuesWrapper {
|
||||||
private static final String TAG = InputMethodSettingValuesWrapper.class.getSimpleName();
|
private static final String TAG = InputMethodSettingValuesWrapper.class.getSimpleName();
|
||||||
|
private static final Locale ENGLISH_LOCALE = new Locale("en");
|
||||||
|
|
||||||
private static volatile InputMethodSettingValuesWrapper sInstance;
|
private static volatile InputMethodSettingValuesWrapper sInstance;
|
||||||
private final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>();
|
private final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>();
|
||||||
private final HashMap<String, InputMethodInfo> mMethodMap =
|
private final HashMap<String, InputMethodInfo> mMethodMap =
|
||||||
@@ -104,4 +107,26 @@ public class InputMethodSettingValuesWrapper {
|
|||||||
return InputMethodUtils.getImeAndSubtypeDisplayName(context, imi, subtype);
|
return InputMethodUtils.getImeAndSubtypeDisplayName(context, imi, subtype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAlwaysCheckedIme(InputMethodInfo imi, Context context) {
|
||||||
|
if (getInputMethodList().size() <= 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!InputMethodUtils.isSystemIme(imi)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return isValidSystemNonAuxAsciiCapableIme(imi, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isValidSystemNonAuxAsciiCapableIme(
|
||||||
|
InputMethodInfo imi, Context context) {
|
||||||
|
if (imi.isAuxiliaryIme()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (InputMethodUtils.isValidSystemDefaultIme(true /* isSystemReady */, imi, context)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return InputMethodUtils.containsSubtypeOf(
|
||||||
|
imi, ENGLISH_LOCALE.getLanguage(), null /* mode */);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user