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

Commit 31595bc9 authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Set gesture exclusion rect for IMEs

Use visible inset values provided by
IMEs to set gesture exclusion rects
for the EdgeBackGestureHandler to ignore
regions where the keyboard is.
If the IME has not overridden
onComputeInsets(), InputMethodService
uses the location of R.id.inputArea
to approximate the location of where
the IME region starts.

Fixes: 141215181
Test: Tested full screen landscape keyboards
(Messenger, Hangouts), non full screen landscape
keyboards (SMS Messages), searching from the top
of the screen in the Toolbar (Google Play Store)

Change-Id: I359d719493fb92d49cd309c2d00371134cd758fe
parent 11c0ef2c
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;

/**
 * InputMethodService provides a standard implementation of an InputMethod,
@@ -434,6 +435,7 @@ public class InputMethodService extends AbstractInputMethodService {
    final int[] mTmpLocation = new int[2];

    final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsComputer = info -> {
        onComputeInsets(mTmpInsets);
        if (isExtractViewShown()) {
            // In true fullscreen mode, we just say the window isn't covering
            // any content so we don't impact whatever is behind.
@@ -442,12 +444,15 @@ public class InputMethodService extends AbstractInputMethodService {
            info.touchableRegion.setEmpty();
            info.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME);
        } else {
            onComputeInsets(mTmpInsets);
            info.contentInsets.top = mTmpInsets.contentTopInsets;
            info.visibleInsets.top = mTmpInsets.visibleTopInsets;
            info.touchableRegion.set(mTmpInsets.touchableRegion);
            info.setTouchableInsets(mTmpInsets.touchableInsets);
        }

        if (mInputFrame != null) {
            setImeExclusionRect(mTmpInsets.visibleTopInsets);
        }
    };

    final View.OnClickListener mActionClickListener = v -> {
@@ -672,6 +677,14 @@ public class InputMethodService extends AbstractInputMethodService {
        mPrivOps.setImeWindowStatus(visibilityFlags, backDisposition);
    }

    /** Set region of the keyboard to be avoided from back gesture */
    private void setImeExclusionRect(int visibleTopInsets) {
        View inputFrameRootView = mInputFrame.getRootView();
        Rect r = new Rect(0, visibleTopInsets, inputFrameRootView.getWidth(),
                inputFrameRootView.getHeight());
        inputFrameRootView.setSystemGestureExclusionRects(Collections.singletonList(r));
    }

    /**
     * Concrete implementation of
     * {@link AbstractInputMethodService.AbstractInputMethodSessionImpl} that provides
+0 −21
Original line number Diff line number Diff line
@@ -56,9 +56,7 @@ import com.android.systemui.R;
import com.android.systemui.bubbles.BubbleController;
import com.android.systemui.model.SysUiState;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.shared.system.PinnedStackListenerForwarder.PinnedStackListener;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.shared.system.WindowManagerWrapper;

import java.io.PrintWriter;
import java.util.concurrent.Executor;
@@ -72,15 +70,6 @@ public class EdgeBackGestureHandler implements DisplayListener {
    private static final int MAX_LONG_PRESS_TIMEOUT = SystemProperties.getInt(
            "gestures.back_timeout", 250);

    private final PinnedStackListener mImeChangedListener = new PinnedStackListener() {
        @Override
        public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) {
            // No need to thread jump, assignments are atomic
            mImeHeight = imeVisible ? imeHeight : 0;
            // TODO: Probably cancel any existing gesture
        }
    };

    private ISystemGestureExclusionListener mGestureExclusionListener =
            new ISystemGestureExclusionListener.Stub() {
                @Override
@@ -128,8 +117,6 @@ public class EdgeBackGestureHandler implements DisplayListener {
    private boolean mInRejectedExclusion = false;
    private boolean mIsOnLeftEdge;

    private int mImeHeight = 0;

    private boolean mIsAttached;
    private boolean mIsGesturalModeEnabled;
    private boolean mIsEnabled;
@@ -231,7 +218,6 @@ public class EdgeBackGestureHandler implements DisplayListener {
        }

        if (!mIsEnabled) {
            WindowManagerWrapper.getInstance().removePinnedStackListener(mImeChangedListener);
            mContext.getSystemService(DisplayManager.class).unregisterDisplayListener(this);

            try {
@@ -248,7 +234,6 @@ public class EdgeBackGestureHandler implements DisplayListener {
                    mContext.getMainThreadHandler());

            try {
                WindowManagerWrapper.getInstance().addPinnedStackListener(mImeChangedListener);
                WindowManagerGlobal.getWindowManagerService()
                        .registerSystemGestureExclusionListener(
                                mGestureExclusionListener, mDisplayId);
@@ -305,11 +290,6 @@ public class EdgeBackGestureHandler implements DisplayListener {
    }

    private boolean isWithinTouchRegion(int x, int y) {
        // Disallow if over the IME
        if (y > (mDisplaySize.y - Math.max(mImeHeight, mNavBarHeight))) {
            return false;
        }

        // Disallow if too far from the edge
        if (x > mEdgeWidth + mLeftInset && x < (mDisplaySize.x - mEdgeWidth - mRightInset)) {
            return false;
@@ -487,7 +467,6 @@ public class EdgeBackGestureHandler implements DisplayListener {
        pw.println("  mInRejectedExclusion" + mInRejectedExclusion);
        pw.println("  mExcludeRegion=" + mExcludeRegion);
        pw.println("  mUnrestrictedExcludeRegion=" + mUnrestrictedExcludeRegion);
        pw.println("  mImeHeight=" + mImeHeight);
        pw.println("  mIsAttached=" + mIsAttached);
        pw.println("  mEdgeWidth=" + mEdgeWidth);
    }