diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-08-01 19:00:38 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2012-08-01 19:00:38 -0700 |
commit | 836531b0c4985b0cf6ead247dd2f403f3ec59e37 (patch) | |
tree | afc4379b93dc5012b82bff0834a8aecdea46ee0d /core/java/android/inputmethodservice | |
parent | e6184f839685affd62aa92dec5a6113e60b3b545 (diff) | |
download | frameworks_base-836531b0c4985b0cf6ead247dd2f403f3ec59e37.zip frameworks_base-836531b0c4985b0cf6ead247dd2f403f3ec59e37.tar.gz frameworks_base-836531b0c4985b0cf6ead247dd2f403f3ec59e37.tar.bz2 |
Add API to turn on HW drawing in IMEs.
Change-Id: Ib6a8bda46223ce1153f32834daf02a820d16136e
Diffstat (limited to 'core/java/android/inputmethodservice')
-rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index c2cb1ff..a9de289 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -19,6 +19,7 @@ package android.inputmethodservice; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; +import android.app.ActivityManager; import android.app.Dialog; import android.content.Context; import android.content.res.Configuration; @@ -38,6 +39,7 @@ import android.text.method.MovementMethod; import android.util.Log; import android.util.PrintWriterPrinter; import android.util.Printer; +import android.view.Display; import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -250,6 +252,7 @@ public class InputMethodService extends AbstractInputMethodService { InputMethodManager mImm; int mTheme = 0; + boolean mHardwareAccelerated = false; LayoutInflater mInflater; TypedArray mThemeAttrs; @@ -614,6 +617,26 @@ public class InputMethodService extends AbstractInputMethodService { mTheme = theme; } + /** + * You can call this to try to enable hardware accelerated drawing for + * your IME. This must be set before {@link #onCreate}, so you + * will typically call it in your constructor. It is not always possible + * to use hardware acclerated drawing in an IME (for example on low-end + * devices that do not have the resources to support this), so the call + * returns true if it succeeds otherwise false if you will need to draw + * in software. You must be able to handle either case. + */ + public boolean enableHardwareAcceleration() { + if (mWindow != null) { + throw new IllegalStateException("Must be called before onCreate()"); + } + if (ActivityManager.isHighEndGfx(new Display(Display.DEFAULT_DISPLAY, null))) { + mHardwareAccelerated = true; + return true; + } + return false; + } + @Override public void onCreate() { mTheme = Resources.selectSystemTheme(mTheme, getApplicationInfo().targetSdkVersion, @@ -626,6 +649,9 @@ public class InputMethodService extends AbstractInputMethodService { mInflater = (LayoutInflater)getSystemService( Context.LAYOUT_INFLATER_SERVICE); mWindow = new SoftInputWindow(this, mTheme, mDispatcherState); + if (mHardwareAccelerated) { + mWindow.getWindow().addFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); + } initViews(); mWindow.getWindow().setLayout(MATCH_PARENT, WRAP_CONTENT); } |