From 04d50204705c9da52b218f11972da4e7d7a9cb84 Mon Sep 17 00:00:00 2001 From: satok Date: Mon, 25 Oct 2010 22:20:12 +0900 Subject: [PATCH] Show Subtype Icon properly in the system status bar - Added API for getting the current subtype - Added functions for show/hide status icon Change-Id: Ifcaad00f7f4c658cdb3af367387476bbf316eb19 --- api/current.xml | 11 +++ .../view/inputmethod/InputMethodManager.java | 12 +++ .../android/internal/view/IInputMethodManager.aidl | 2 + .../statusbar/tablet/InputMethodButton.java | 98 ++++++++++++++++++++-- 4 files changed, 118 insertions(+), 5 deletions(-) diff --git a/api/current.xml b/api/current.xml index 86ed7b8a9248..1ca51c2ba41d 100644 --- a/api/current.xml +++ b/api/current.xml @@ -218267,6 +218267,17 @@ + + imis = mImm.getEnabledInputMethodList(); + if (curInputMethodId != null) { + for (InputMethodInfo imi: imis) { + if (imi.getId().equals(curInputMethodId)) { + return imi; + } + } + } + return null; + } + + private Drawable getCurrentSubtypeIcon() { + final PackageManager pm = getContext().getPackageManager(); + InputMethodInfo imi = getCurrentInputMethodInfo(); + InputMethodSubtype subtype = mImm.getCurrentInputMethodSubtype(); + Drawable icon = null; + if (imi != null) { + if (subtype != null) { + return pm.getDrawable(imi.getPackageName(), subtype.getIconResId(), + imi.getServiceInfo().applicationInfo); + } else if (imi.getSubtypes().size() > 0) { + return pm.getDrawable(imi.getPackageName(), + imi.getSubtypes().get(0).getIconResId(), + imi.getServiceInfo().applicationInfo); + } else { + try { + return pm.getApplicationInfo(imi.getPackageName(), 0).loadIcon(pm); + } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, "Current IME cann't be found: " + imi.getPackageName()); + } + } + } + return null; + } + + private void refreshStatusIcon(boolean keyboardShown) { + if (!keyboardShown) { + setVisibility(View.INVISIBLE); + return; + } else { + setVisibility(View.VISIBLE); + } + Drawable icon = getCurrentSubtypeIcon(); + if (icon == null) { + mIcon.setImageResource(R.drawable.ic_sysbar_ime_default); + } else { + mIcon.setImageDrawable(icon); + } + } + + private void postRefreshStatusIcon() { + getHandler().post(new Runnable() { + public void run() { + refreshStatusIcon(mKeyboardShown); + } + }); + } + + public void showSoftInput() { + mKeyboardShown = true; + postRefreshStatusIcon(); + } + + public void hideSoftInput() { + mKeyboardShown = false; + postRefreshStatusIcon(); + } +} -- 2.11.0