summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorsatok <satok@google.com>2010-10-25 22:20:12 +0900
committersatok <satok@google.com>2010-10-28 16:18:50 +0900
commit04d50204705c9da52b218f11972da4e7d7a9cb84 (patch)
tree2849675f95a40a938c61a351f32f890dbffc7516 /packages
parent267e91688b2351dceddb0a1c37e3e2c6bb91d696 (diff)
downloadframeworks_base-04d50204705c9da52b218f11972da4e7d7a9cb84.zip
frameworks_base-04d50204705c9da52b218f11972da4e7d7a9cb84.tar.gz
frameworks_base-04d50204705c9da52b218f11972da4e7d7a9cb84.tar.bz2
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
Diffstat (limited to 'packages')
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java98
1 files changed, 93 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
index ba682b7..56b4f24 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
@@ -17,25 +17,38 @@
package com.android.systemui.statusbar.tablet;
import android.content.Context;
+import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
+import android.provider.Settings;
+import android.util.Log;
import android.util.Slog;
-import android.view.View;
import android.util.AttributeSet;
-import android.widget.ImageView;
+import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
+import android.view.inputmethod.InputMethodSubtype;
+import android.view.View;
+import android.widget.ImageView;
import com.android.server.InputMethodManagerService;
+import com.android.systemui.R;
+
+import java.util.List;
public class InputMethodButton extends ImageView {
+ private static final String TAG = "StatusBar/InputMethodButton";
+
+ private boolean mKeyboardShown;
+ private ImageView mIcon;
// other services we wish to talk to
- InputMethodManager mImm;
+ private InputMethodManager mImm;
public InputMethodButton(Context context, AttributeSet attrs) {
super(context, attrs);
+ mKeyboardShown = false;
// IME hookup
mImm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
-
// TODO: read the current icon & visibility state directly from the service
// TODO: register for notifications about changes to visibility & subtype from service
@@ -47,5 +60,80 @@ public class InputMethodButton extends ImageView {
}
});
}
-}
+ protected void onAttachedToWindow() {
+ mIcon = (ImageView) findViewById(R.id.imeButton);
+ refreshStatusIcon(mKeyboardShown);
+ }
+
+ private InputMethodInfo getCurrentInputMethodInfo() {
+ String curInputMethodId = Settings.Secure.getString(getContext()
+ .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
+ List<InputMethodInfo> 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();
+ }
+}