Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 836531b0 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Add API to turn on HW drawing in IMEs.

Change-Id: Ib6a8bda46223ce1153f32834daf02a820d16136e
parent e6184f83
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10157,6 +10157,7 @@ package android.inputmethodservice {
  public class InputMethodService extends android.inputmethodservice.AbstractInputMethodService {
    ctor public InputMethodService();
    method public boolean enableHardwareAcceleration();
    method public int getBackDisposition();
    method public int getCandidatesHiddenVisibility();
    method public android.view.inputmethod.InputBinding getCurrentInputBinding();
+26 −0
Original line number Diff line number Diff line
@@ -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);
    }