Allow the users to disable system IME

Bug: 8364845
Change-Id: Icc5173a68fa00b2895c0768ff8f8b9dcf30e6171
This commit is contained in:
Satoshi Kataoka
2013-07-31 16:20:29 +09:00
parent 15885f4998
commit c6fc8e46f2
4 changed files with 119 additions and 54 deletions

View File

@@ -24,6 +24,7 @@ import com.android.settings.Utils;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
@@ -52,8 +53,8 @@ public class InputMethodPreference extends CheckBoxPreference {
private final SettingsPreferenceFragment mFragment;
private final InputMethodInfo mImi;
private final InputMethodManager mImm;
private final boolean mIsValidSystemNonAuxAsciiCapableIme;
private final Intent mSettingsIntent;
private final boolean mAlwaysChecked;
private final boolean mIsSystemIme;
private final Collator mCollator;
@@ -62,6 +63,7 @@ public class InputMethodPreference extends CheckBoxPreference {
private TextView mTitleText;
private TextView mSummaryText;
private View mInputMethodPref;
private OnPreferenceChangeListener mOnImePreferenceChangeListener;
private final OnClickListener mPrefOnclickListener = new OnClickListener() {
@Override
@@ -82,7 +84,7 @@ public class InputMethodPreference extends CheckBoxPreference {
};
public InputMethodPreference(SettingsPreferenceFragment fragment, Intent settingsIntent,
InputMethodManager imm, InputMethodInfo imi, int imiCount) {
InputMethodManager imm, InputMethodInfo imi) {
super(fragment.getActivity(), null, R.style.InputMethodPreferenceStyle);
setLayoutResource(R.layout.preference_inputmethod);
setWidgetLayoutResource(R.layout.preference_inputmethod_widget);
@@ -90,15 +92,12 @@ public class InputMethodPreference extends CheckBoxPreference {
mSettingsIntent = settingsIntent;
mImm = imm;
mImi = imi;
updateSummary();
mAlwaysChecked = InputMethodSettingValuesWrapper.getInstance(
fragment.getActivity()).isAlwaysCheckedIme(
imi, fragment.getActivity());
mIsSystemIme = InputMethodUtils.isSystemIme(imi);
if (mAlwaysChecked) {
setEnabled(false);
}
mCollator = Collator.getInstance(fragment.getResources().getConfiguration().locale);
final Context context = fragment.getActivity();
mIsValidSystemNonAuxAsciiCapableIme = InputMethodSettingValuesWrapper
.getInstance(context).isValidSystemNonAuxAsciiCapableIme(imi, context);
updatePreferenceViews();
}
@Override
@@ -158,9 +157,8 @@ public class InputMethodPreference extends CheckBoxPreference {
}
if (mSettingsIntent == null) {
mInputMethodSettingsButton.setVisibility(View.GONE);
} else {
updatePreferenceViews();
}
updatePreferenceViews();
}
@Override
@@ -169,7 +167,16 @@ public class InputMethodPreference extends CheckBoxPreference {
updatePreferenceViews();
}
private void updatePreferenceViews() {
public void updatePreferenceViews() {
final boolean isAlwaysChecked =
InputMethodSettingValuesWrapper.getInstance(getContext()).isAlwaysCheckedIme(
mImi, getContext());
if (isAlwaysChecked) {
super.setChecked(true);
super.setEnabled(false);
} else {
super.setEnabled(true);
}
final boolean checked = isChecked();
if (mInputMethodSettingsButton != null) {
mInputMethodSettingsButton.setEnabled(checked);
@@ -194,6 +201,7 @@ public class InputMethodPreference extends CheckBoxPreference {
mInputMethodPref.setBackgroundColor(0);
}
}
updateSummary();
}
public static boolean startFragment(
@@ -211,7 +219,7 @@ public class InputMethodPreference extends CheckBoxPreference {
}
}
public String getSummaryString() {
private String getSummaryString() {
final StringBuilder builder = new StringBuilder();
final List<InputMethodSubtype> subtypes = mImm.getEnabledInputMethodSubtypeList(mImi, true);
for (InputMethodSubtype subtype : subtypes) {
@@ -225,7 +233,7 @@ public class InputMethodPreference extends CheckBoxPreference {
return builder.toString();
}
public void updateSummary() {
private void updateSummary() {
final String summary = getSummaryString();
if (TextUtils.isEmpty(summary)) {
return;
@@ -238,17 +246,21 @@ public class InputMethodPreference extends CheckBoxPreference {
* @param checked whether to check the box
* @param save whether to save IME settings
*/
public void setChecked(boolean checked, boolean save) {
private void setChecked(boolean checked, boolean save) {
final boolean wasChecked = isChecked();
super.setChecked(checked);
if (save) {
saveImeSettings();
InputMethodSettingValuesWrapper.getInstance(
getContext()).refreshAllInputMethodAndSubtypes();
if (wasChecked != checked && mOnImePreferenceChangeListener != null) {
mOnImePreferenceChangeListener.onPreferenceChange(this, checked);
}
}
updateSummary();
}
@Override
public void setChecked(boolean checked) {
setChecked(checked, false);
public void setOnImePreferenceChangeListener(OnPreferenceChangeListener listener) {
mOnImePreferenceChangeListener = listener;
}
private void showSecurityWarnDialog(InputMethodInfo imi, final InputMethodPreference chkPref) {
@@ -285,8 +297,8 @@ public class InputMethodPreference extends CheckBoxPreference {
return super.compareTo(p);
}
final InputMethodPreference imp = (InputMethodPreference) p;
final boolean priority0 = mIsSystemIme && mAlwaysChecked;
final boolean priority1 = imp.mIsSystemIme && imp.mAlwaysChecked;
final boolean priority0 = mIsSystemIme && mIsValidSystemNonAuxAsciiCapableIme;
final boolean priority1 = imp.mIsSystemIme && imp.mIsValidSystemNonAuxAsciiCapableIme;
if (priority0 == priority1) {
final CharSequence t0 = getTitle();
final CharSequence t1 = imp.getTitle();