Skip to content

Commit a7ce155

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Add API to turn on HW drawing in IMEs." into jb-mr1-dev
2 parents 450ec41 + 836531b commit a7ce155

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10157,6 +10157,7 @@ package android.inputmethodservice {
1015710157

1015810158
public class InputMethodService extends android.inputmethodservice.AbstractInputMethodService {
1015910159
ctor public InputMethodService();
10160+
method public boolean enableHardwareAcceleration();
1016010161
method public int getBackDisposition();
1016110162
method public int getCandidatesHiddenVisibility();
1016210163
method public android.view.inputmethod.InputBinding getCurrentInputBinding();

core/java/android/inputmethodservice/InputMethodService.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
2020
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
2121

22+
import android.app.ActivityManager;
2223
import android.app.Dialog;
2324
import android.content.Context;
2425
import android.content.res.Configuration;
@@ -38,6 +39,7 @@
3839
import android.util.Log;
3940
import android.util.PrintWriterPrinter;
4041
import android.util.Printer;
42+
import android.view.Display;
4143
import android.view.KeyCharacterMap;
4244
import android.view.KeyEvent;
4345
import android.view.LayoutInflater;
@@ -250,6 +252,7 @@ public class InputMethodService extends AbstractInputMethodService {
250252
InputMethodManager mImm;
251253

252254
int mTheme = 0;
255+
boolean mHardwareAccelerated = false;
253256

254257
LayoutInflater mInflater;
255258
TypedArray mThemeAttrs;
@@ -614,6 +617,26 @@ public void setTheme(int theme) {
614617
mTheme = theme;
615618
}
616619

620+
/**
621+
* You can call this to try to enable hardware accelerated drawing for
622+
* your IME. This must be set before {@link #onCreate}, so you
623+
* will typically call it in your constructor. It is not always possible
624+
* to use hardware acclerated drawing in an IME (for example on low-end
625+
* devices that do not have the resources to support this), so the call
626+
* returns true if it succeeds otherwise false if you will need to draw
627+
* in software. You must be able to handle either case.
628+
*/
629+
public boolean enableHardwareAcceleration() {
630+
if (mWindow != null) {
631+
throw new IllegalStateException("Must be called before onCreate()");
632+
}
633+
if (ActivityManager.isHighEndGfx(new Display(Display.DEFAULT_DISPLAY, null))) {
634+
mHardwareAccelerated = true;
635+
return true;
636+
}
637+
return false;
638+
}
639+
617640
@Override public void onCreate() {
618641
mTheme = Resources.selectSystemTheme(mTheme,
619642
getApplicationInfo().targetSdkVersion,
@@ -626,6 +649,9 @@ public void setTheme(int theme) {
626649
mInflater = (LayoutInflater)getSystemService(
627650
Context.LAYOUT_INFLATER_SERVICE);
628651
mWindow = new SoftInputWindow(this, mTheme, mDispatcherState);
652+
if (mHardwareAccelerated) {
653+
mWindow.getWindow().addFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
654+
}
629655
initViews();
630656
mWindow.getWindow().setLayout(MATCH_PARENT, WRAP_CONTENT);
631657
}

0 commit comments

Comments
 (0)