From 990fcb1a6dbb5d1204cc8ec86e4bc3f691f4aeeb Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 23 Jul 2014 10:40:47 -0700 Subject: Use Intent in preference to invoke subtype enabler This CL also allows resetting a title and an icon of subtype enabler. Change-Id: I1de10557aeae9d2185ea0560ba8fdd9889248459 --- .../inputmethodcommon/InputMethodSettingsImpl.java | 69 +++++++++------------- 1 file changed, 28 insertions(+), 41 deletions(-) (limited to 'java/com') 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); } } } -- cgit v1.2.3