summaryrefslogtreecommitdiff
path: root/java/com/android/inputmethodcommon/InputMethodSettingsImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/inputmethodcommon/InputMethodSettingsImpl.java')
-rw-r--r--java/com/android/inputmethodcommon/InputMethodSettingsImpl.java69
1 files changed, 28 insertions, 41 deletions
diff --git a/java/com/android/inputmethodcommon/InputMethodSettingsImpl.java b/java/com/android/inputmethodcommon/InputMethodSettingsImpl.java
index 8c209d7..cfa1a65 100644
--- a/java/com/android/inputmethodcommon/InputMethodSettingsImpl.java
+++ b/java/com/android/inputmethodcommon/InputMethodSettingsImpl.java
@@ -40,7 +40,6 @@ import java.util.List;
private Drawable mSubtypeEnablerIcon;
private InputMethodManager mImm;
private InputMethodInfo mImi;
- private Context mContext;
/**
* Initialize internal states of this object.
@@ -49,31 +48,18 @@ import java.util.List;
* @return true if this application is an IME and has two or more subtypes, false otherwise.
*/
public boolean init(final Context context, final PreferenceScreen prefScreen) {
- mContext = context;
mImm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
mImi = getMyImi(context, mImm);
if (mImi == null || mImi.getSubtypeCount() <= 1) {
return false;
}
+ final Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
+ intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, mImi.getId());
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
+ | Intent.FLAG_ACTIVITY_CLEAR_TOP);
mSubtypeEnablerPreference = new Preference(context);
- mSubtypeEnablerPreference
- .setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- final CharSequence title = getSubtypeEnablerTitle(context);
- final Intent intent =
- new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
- intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, mImi.getId());
- if (!TextUtils.isEmpty(title)) {
- intent.putExtra(Intent.EXTRA_TITLE, title);
- }
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
- | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- context.startActivity(intent);
- return true;
- }
- });
+ mSubtypeEnablerPreference.setIntent(intent);
prefScreen.addPreference(mSubtypeEnablerPreference);
updateSubtypeEnabler();
return true;
@@ -163,30 +149,31 @@ import java.util.List;
updateSubtypeEnabler();
}
- private CharSequence getSubtypeEnablerTitle(Context context) {
+ public void updateSubtypeEnabler() {
+ final Preference pref = mSubtypeEnablerPreference;
+ if (pref == null) {
+ return;
+ }
+ final Context context = pref.getContext();
+ final CharSequence title;
if (mSubtypeEnablerTitleRes != 0) {
- return context.getString(mSubtypeEnablerTitleRes);
+ title = context.getString(mSubtypeEnablerTitleRes);
} else {
- return mSubtypeEnablerTitle;
+ title = mSubtypeEnablerTitle;
}
- }
-
- public void updateSubtypeEnabler() {
- if (mSubtypeEnablerPreference != null) {
- if (mSubtypeEnablerTitleRes != 0) {
- mSubtypeEnablerPreference.setTitle(mSubtypeEnablerTitleRes);
- } else if (!TextUtils.isEmpty(mSubtypeEnablerTitle)) {
- mSubtypeEnablerPreference.setTitle(mSubtypeEnablerTitle);
- }
- final String summary = getEnabledSubtypesLabel(mContext, mImm, mImi);
- if (!TextUtils.isEmpty(summary)) {
- mSubtypeEnablerPreference.setSummary(summary);
- }
- if (mSubtypeEnablerIconRes != 0) {
- mSubtypeEnablerPreference.setIcon(mSubtypeEnablerIconRes);
- } else if (mSubtypeEnablerIcon != null) {
- mSubtypeEnablerPreference.setIcon(mSubtypeEnablerIcon);
- }
+ pref.setTitle(title);
+ final Intent intent = pref.getIntent();
+ if (intent != null) {
+ intent.putExtra(Intent.EXTRA_TITLE, title);
+ }
+ final String summary = getEnabledSubtypesLabel(context, mImm, mImi);
+ if (!TextUtils.isEmpty(summary)) {
+ pref.setSummary(summary);
+ }
+ if (mSubtypeEnablerIconRes != 0) {
+ pref.setIcon(mSubtypeEnablerIconRes);
+ } else {
+ pref.setIcon(mSubtypeEnablerIcon);
}
}
}