diff options
-rw-r--r-- | core/java/android/provider/Settings.java | 15 | ||||
-rw-r--r-- | core/res/res/drawable-hdpi/ic_notification_ime_default.png | bin | 0 -> 749 bytes | |||
-rw-r--r-- | core/res/res/drawable-mdpi/ic_notification_ime_default.png | bin | 0 -> 749 bytes | |||
-rw-r--r-- | core/res/res/values-sw600dp/bools.xml | 1 | ||||
-rw-r--r-- | core/res/res/values/bools.xml | 1 | ||||
-rw-r--r-- | services/java/com/android/server/InputMethodManagerService.java | 75 |
6 files changed, 92 insertions, 0 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 01e028e7..bdfbdac 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -300,6 +300,21 @@ public final class Settings { "android.settings.INPUT_METHOD_SUBTYPE_SETTINGS"; /** + * Activity Action: Show a dialog to select input method. + * <p> + * In some cases, a matching Activity may not exist, so ensure you + * safeguard against this. + * <p> + * Input: Nothing. + * <p> + * Output: Nothing. + * @hide + */ + @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) + public static final String ACTION_SHOW_INPUT_METHOD_PICKER = + "android.settings.SHOW_INPUT_METHOD_PICKER"; + + /** * Activity Action: Show settings to manage the user input dictionary. * <p> * In some cases, a matching Activity may not exist, so ensure you diff --git a/core/res/res/drawable-hdpi/ic_notification_ime_default.png b/core/res/res/drawable-hdpi/ic_notification_ime_default.png Binary files differnew file mode 100644 index 0000000..1a9d88c --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_notification_ime_default.png diff --git a/core/res/res/drawable-mdpi/ic_notification_ime_default.png b/core/res/res/drawable-mdpi/ic_notification_ime_default.png Binary files differnew file mode 100644 index 0000000..1a9d88c --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_notification_ime_default.png diff --git a/core/res/res/values-sw600dp/bools.xml b/core/res/res/values-sw600dp/bools.xml index 734031f..d73ff99 100644 --- a/core/res/res/values-sw600dp/bools.xml +++ b/core/res/res/values-sw600dp/bools.xml @@ -16,4 +16,5 @@ <resources> <bool name="preferences_prefer_dual_pane">true</bool> + <bool name="show_ongoing_ime_switcher">false</bool> </resources> diff --git a/core/res/res/values/bools.xml b/core/res/res/values/bools.xml index 9d6309d..9647bb7 100644 --- a/core/res/res/values/bools.xml +++ b/core/res/res/values/bools.xml @@ -19,4 +19,5 @@ <bool name="action_bar_embed_tabs">false</bool> <bool name="split_action_bar_is_narrow">true</bool> <bool name="preferences_prefer_dual_pane">false</bool> + <bool name="show_ongoing_ime_switcher">true</bool> </resources> diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java index fbde9d1..8037d7a 100644 --- a/services/java/com/android/server/InputMethodManagerService.java +++ b/services/java/com/android/server/InputMethodManagerService.java @@ -35,6 +35,8 @@ import org.xmlpull.v1.XmlSerializer; import android.app.ActivityManagerNative; import android.app.AlertDialog; +import android.app.Notification; +import android.app.NotificationManager; import android.app.PendingIntent; import android.content.ComponentName; import android.content.ContentResolver; @@ -52,6 +54,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.database.ContentObserver; +import android.graphics.BitmapFactory; import android.inputmethodservice.InputMethodService; import android.os.Binder; import android.os.Environment; @@ -154,6 +157,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans = new LruCache<SuggestionSpan, InputMethodInfo>(SECURE_SUGGESTION_SPANS_MAX_SIZE); + // Ongoing notification + private final NotificationManager mNotificationManager; + private final Notification mImeSwitcherNotification; + private final PendingIntent mImeSwitchPendingIntent; + private final boolean mShowOngoingImeSwitcherForPhones; + private boolean mNotificationShown; + class SessionState { final ClientState client; final IInputMethod method; @@ -508,6 +518,25 @@ public class InputMethodManagerService extends IInputMethodManager.Stub handleMessage(msg); } }); + + mNotificationManager = (NotificationManager) + mContext.getSystemService(Context.NOTIFICATION_SERVICE); + mImeSwitcherNotification = new Notification(); + mImeSwitcherNotification.icon = com.android.internal.R.drawable.ic_notification_ime_default; + mImeSwitcherNotification.when = 0; + mImeSwitcherNotification.flags = Notification.FLAG_ONGOING_EVENT; + mImeSwitcherNotification.tickerText = null; + mImeSwitcherNotification.defaults = 0; // please be quiet + mImeSwitcherNotification.sound = null; + mImeSwitcherNotification.vibrate = null; + Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED + | Intent.FLAG_ACTIVITY_CLEAR_TOP); + mImeSwitchPendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0); + mShowOngoingImeSwitcherForPhones = mRes.getBoolean( + com.android.internal.R.bool.show_ongoing_ime_switcher); + synchronized (mMethodMap) { mFileManager = new InputMethodFileManager(mMethodMap); } @@ -522,6 +551,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mStatusBar = statusBar; statusBar.setIconVisibility("ime", false); + mNotificationShown = false; // mSettings should be created before buildInputMethodListLocked mSettings = new InputMethodSettings( @@ -1022,6 +1052,32 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } + private boolean needsToShowImeSwitchOngoingNotification() { + if (!mShowOngoingImeSwitcherForPhones) return false; + synchronized (mMethodMap) { + List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); + final int N = imis.size(); + int count = 0; + for(int i = 0; i < N; ++i) { + final InputMethodInfo imi = imis.get(i); + final List<InputMethodSubtype> subtypes = getEnabledInputMethodSubtypeListLocked( + imi, true); + final int subtypeCount = subtypes.size(); + if (subtypeCount == 0) { + ++count; + } else { + for (int j = 0; j < subtypeCount; ++j) { + if (!subtypes.get(j).isAuxiliary()) { + ++count; + } + } + } + if (count > 1) return true; + } + } + return false; + } + @Override public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { int uid = Binder.getCallingUid(); @@ -1036,6 +1092,25 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mImeWindowVis = vis; mBackDisposition = backDisposition; mStatusBar.setImeWindowStatus(token, vis, backDisposition); + final boolean iconVisibility = (vis & InputMethodService.IME_ACTIVE) != 0; + if (iconVisibility && needsToShowImeSwitchOngoingNotification()) { + final PackageManager pm = mContext.getPackageManager(); + final CharSequence label = mMethodMap.get(mCurMethodId).loadLabel(pm); + final CharSequence title = mRes.getText( + com.android.internal.R.string.select_input_method); + mImeSwitcherNotification.setLatestEventInfo( + mContext, title, label, mImeSwitchPendingIntent); + mNotificationManager.notify( + com.android.internal.R.string.select_input_method, + mImeSwitcherNotification); + mNotificationShown = true; + } else { + if (mNotificationShown) { + mNotificationManager.cancel( + com.android.internal.R.string.select_input_method); + mNotificationShown = false; + } + } } } finally { Binder.restoreCallingIdentity(ident); |