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

Commit 6999d217 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Simplify SoftInputWindow"

parents f32842bd ea7801bd
Loading
Loading
Loading
Loading
+1 −3
Original line number Original line Diff line number Diff line
@@ -94,7 +94,6 @@ import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.util.Printer;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;
import android.view.Gravity;
import android.view.KeyCharacterMap;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
@@ -1340,8 +1339,7 @@ public class InputMethodService extends AbstractInputMethodService {
        mInflater = (LayoutInflater)getSystemService(
        mInflater = (LayoutInflater)getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
                Context.LAYOUT_INFLATER_SERVICE);
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.initSoftInputWindow");
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.initSoftInputWindow");
        mWindow = new SoftInputWindow(this, "InputMethod", mTheme, null, null, mDispatcherState,
        mWindow = new SoftInputWindow(this, mTheme, mDispatcherState);
                WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.BOTTOM, false);
        mWindow.getWindow().getAttributes().setFitInsetsTypes(statusBars() | navigationBars());
        mWindow.getWindow().getAttributes().setFitInsetsTypes(statusBars() | navigationBars());
        mWindow.getWindow().getAttributes().setFitInsetsSides(Side.all() & ~Side.BOTTOM);
        mWindow.getWindow().getAttributes().setFitInsetsSides(Side.all() & ~Side.BOTTOM);
        mWindow.getWindow().getAttributes().receiveInsetsIgnoringZOrder = true;
        mWindow.getWindow().getAttributes().receiveInsetsIgnoringZOrder = true;
+19 −100
Original line number Original line Diff line number Diff line
@@ -42,23 +42,15 @@ import android.view.WindowManager;
import java.lang.annotation.Retention;
import java.lang.annotation.Retention;


/**
/**
 * A SoftInputWindow is a Dialog that is intended to be used for a top-level input
 * A {@link SoftInputWindow} is a {@link Dialog} that is intended to be used for a top-level input
 * method window.  It will be displayed along the edge of the screen, moving
 * method window.  It will be displayed along the edge of the screen, moving the application user
 * the application user interface away from it so that the focused item is
 * interface away from it so that the focused item is always visible.
 * always visible.
 * @hide
 */
 */
public final class SoftInputWindow extends Dialog {
final class SoftInputWindow extends Dialog {
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;
    private static final String TAG = "SoftInputWindow";
    private static final String TAG = "SoftInputWindow";


    private final String mName;
    private final Callback mCallback;
    private final KeyEvent.Callback mKeyEventCallback;
    private final KeyEvent.DispatcherState mDispatcherState;
    private final KeyEvent.DispatcherState mDispatcherState;
    private final int mWindowType;
    private final int mGravity;
    private final boolean mTakesFocus;
    private final Rect mBounds = new Rect();
    private final Rect mBounds = new Rect();


    @Retention(SOURCE)
    @Retention(SOURCE)
@@ -92,23 +84,13 @@ public final class SoftInputWindow extends Dialog {
    @WindowState
    @WindowState
    private int mWindowState = WindowState.TOKEN_PENDING;
    private int mWindowState = WindowState.TOKEN_PENDING;


    /**
     * Used to provide callbacks.
     */
    public interface Callback {
        /**
         * Used to be notified when {@link Dialog#onBackPressed()} gets called.
         */
        void onBackPressed();
    }

    /**
    /**
     * Set {@link IBinder} window token to the window.
     * Set {@link IBinder} window token to the window.
     *
     *
     * <p>This method can be called only once.</p>
     * <p>This method can be called only once.</p>
     * @param token {@link IBinder} token to be associated with the window.
     * @param token {@link IBinder} token to be associated with the window.
     */
     */
    public void setToken(IBinder token) {
    void setToken(IBinder token) {
        switch (mWindowState) {
        switch (mWindowState) {
            case WindowState.TOKEN_PENDING:
            case WindowState.TOKEN_PENDING:
                // Normal scenario.  Nothing to worry about.
                // Normal scenario.  Nothing to worry about.
@@ -152,17 +134,9 @@ public final class SoftInputWindow extends Dialog {
     *        using styles. This theme is applied on top of the current theme in
     *        using styles. This theme is applied on top of the current theme in
     *        <var>context</var>. If 0, the default dialog theme will be used.
     *        <var>context</var>. If 0, the default dialog theme will be used.
     */
     */
    public SoftInputWindow(Context context, String name, int theme, Callback callback,
    SoftInputWindow(Context context, int theme, KeyEvent.DispatcherState dispatcherState) {
            KeyEvent.Callback keyEventCallback, KeyEvent.DispatcherState dispatcherState,
            int windowType, int gravity, boolean takesFocus) {
        super(context, theme);
        super(context, theme);
        mName = name;
        mCallback = callback;
        mKeyEventCallback = keyEventCallback;
        mDispatcherState = dispatcherState;
        mDispatcherState = dispatcherState;
        mWindowType = windowType;
        mGravity = gravity;
        mTakesFocus = takesFocus;
        initDockWindow();
        initDockWindow();
    }
    }


@@ -188,79 +162,23 @@ public final class SoftInputWindow extends Dialog {
        }
        }
    }
    }


    private void updateWidthHeight(WindowManager.LayoutParams lp) {
        if (lp.gravity == Gravity.TOP || lp.gravity == Gravity.BOTTOM) {
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        } else {
            lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (mKeyEventCallback != null && mKeyEventCallback.onKeyDown(keyCode, event)) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyLongPress(int keyCode, KeyEvent event) {
        if (mKeyEventCallback != null && mKeyEventCallback.onKeyLongPress(keyCode, event)) {
            return true;
        }
        return super.onKeyLongPress(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (mKeyEventCallback != null && mKeyEventCallback.onKeyUp(keyCode, event)) {
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

    @Override
    public boolean onKeyMultiple(int keyCode, int count, KeyEvent event) {
        if (mKeyEventCallback != null && mKeyEventCallback.onKeyMultiple(keyCode, count, event)) {
            return true;
        }
        return super.onKeyMultiple(keyCode, count, event);
    }

    @Override
    public void onBackPressed() {
        if (mCallback != null) {
            mCallback.onBackPressed();
        } else {
            super.onBackPressed();
        }
    }

    private void initDockWindow() {
    private void initDockWindow() {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        WindowManager.LayoutParams lp = getWindow().getAttributes();


        lp.type = mWindowType;
        lp.setTitle("InputMethod");
        lp.setTitle(mName);
        lp.type = WindowManager.LayoutParams.TYPE_INPUT_METHOD;

        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.gravity = mGravity;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        updateWidthHeight(lp);
        lp.gravity = Gravity.BOTTOM;


        getWindow().setAttributes(lp);
        getWindow().setAttributes(lp);


        int windowSetFlags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
        final int windowModFlags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
        int windowModFlags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_DIM_BEHIND;
                | WindowManager.LayoutParams.FLAG_DIM_BEHIND;


        if (!mTakesFocus) {
        final int windowSetFlags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
            windowSetFlags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        } else {
            windowSetFlags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
            windowModFlags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
        }


        getWindow().setFlags(windowSetFlags, windowModFlags);
        getWindow().setFlags(windowSetFlags, windowModFlags);
    }
    }
@@ -372,10 +290,11 @@ public final class SoftInputWindow extends Dialog {


    void dumpDebug(ProtoOutputStream proto, long fieldId) {
    void dumpDebug(ProtoOutputStream proto, long fieldId) {
        final long token = proto.start(fieldId);
        final long token = proto.start(fieldId);
        proto.write(NAME, mName);
        // TODO(b/192412909): Deprecate the following 4 entries, as they are all constant.
        proto.write(WINDOW_TYPE, mWindowType);
        proto.write(NAME, "InputMethod");
        proto.write(GRAVITY, mGravity);
        proto.write(WINDOW_TYPE, WindowManager.LayoutParams.TYPE_INPUT_METHOD);
        proto.write(TAKES_FOCUS, mTakesFocus);
        proto.write(GRAVITY, Gravity.BOTTOM);
        proto.write(TAKES_FOCUS, false);
        mBounds.dumpDebug(proto, BOUNDS);
        mBounds.dumpDebug(proto, BOUNDS);
        proto.write(WINDOW_STATE, mWindowState);
        proto.write(WINDOW_STATE, mWindowState);
        proto.end(token);
        proto.end(token);