summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-07-23 10:40:47 -0700
committerTadashi G. Takaoka <takaoka@google.com>2014-07-27 14:51:18 +0900
commit990fcb1a6dbb5d1204cc8ec86e4bc3f691f4aeeb (patch)
treeb1761697142c6fa94bcc0714a2ac9d3b455456a2
parentdf9dd39c2047992a43b64e13bb0fc348a1630f3b (diff)
downloadandroid_frameworks_opt_inputmethodcommon-stable/cm-12.0-YNG3C.tar.gz
android_frameworks_opt_inputmethodcommon-stable/cm-12.0-YNG3C.tar.bz2
android_frameworks_opt_inputmethodcommon-stable/cm-12.0-YNG3C.zip
This CL also allows resetting a title and an icon of subtype enabler. Change-Id: I1de10557aeae9d2185ea0560ba8fdd9889248459
-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);
}
}
}