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

Commit a4a4002f authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Transform touch events in landscape mode now that app is on top

Fixes: 193375232
Test: Swipe up from app in landscape mode, interact with Overview, and make sure it's interactive
Change-Id: Ib1838f02d537918b7a13d51a1fdcacbf3d02b99d
parent 11579eea
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -271,7 +271,9 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        mActivityInterface = gestureState.getActivityInterface();
        mActivityInitListener = mActivityInterface.createActivityInitListener(this::onActivityInit);
        mInputConsumerProxy =
                new InputConsumerProxy(inputConsumer, () -> {
                new InputConsumerProxy(context,
                        () -> mRecentsView.getPagedViewOrientedState().getRecentsActivityRotation(),
                        inputConsumer, () -> {
                    endRunningWindowAnim(mGestureState.getEndTarget() == HOME /* cancel */);
                    endLauncherTransitionController();
                }, new InputProxyHandlerFactory(mActivityInterface, mGestureState));
+104 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.quickstep;

import static com.android.launcher3.states.RotationHelper.deltaRotation;
import static com.android.quickstep.util.RecentsOrientedState.postDisplayRotation;

import android.graphics.Matrix;
import android.graphics.RectF;
import android.util.Log;
import android.view.MotionEvent;

public class OrientationRectF extends RectF {

    private static final String TAG = "OrientationRectF";
    private static final boolean DEBUG = false;

    private final int mRotation;
    private final float mHeight;
    private final float mWidth;

    private final Matrix mTmpMatrix = new Matrix();
    private final float[] mTmpPoint = new float[2];

    public OrientationRectF(float left, float top, float right, float bottom, int rotation) {
        super(left, top, right, bottom);
        mRotation = rotation;
        mHeight = bottom;
        mWidth = right;
    }

    @Override
    public String toString() {
        String s = super.toString();
        s += " rotation: " + mRotation;
        return s;
    }

    @Override
    public boolean contains(float x, float y) {
        // Mark bottom right as included in the Rect (copied from Rect src, added "=" in "<=")
        return left < right && top < bottom  // check for empty first
                && x >= left && x <= right && y >= top && y <= bottom;
    }

    public boolean applyTransformFromRotation(MotionEvent event, int currentRotation,
            boolean forceTransform) {
        return applyTransform(event, deltaRotation(currentRotation, mRotation), forceTransform);
    }

    public boolean applyTransformToRotation(MotionEvent event, int currentRotation,
            boolean forceTransform) {
        return applyTransform(event, deltaRotation(mRotation, currentRotation), forceTransform);
    }

    private boolean applyTransform(MotionEvent event, int deltaRotation, boolean forceTransform) {
        mTmpMatrix.reset();
        postDisplayRotation(deltaRotation, mHeight, mWidth, mTmpMatrix);
        if (forceTransform) {
            if (DEBUG) {
                Log.d(TAG, "Transforming rotation due to forceTransform, "
                        + "deltaRotation: " + deltaRotation
                        + "mRotation: " + mRotation
                        + " this: " + this);
            }
            event.applyTransform(mTmpMatrix);
            return true;
        }
        mTmpPoint[0] = event.getX();
        mTmpPoint[1] = event.getY();
        mTmpMatrix.mapPoints(mTmpPoint);

        if (DEBUG) {
            Log.d(TAG, "original: " + event.getX() + ", " + event.getY()
                    + " new: " + mTmpPoint[0] + ", " + mTmpPoint[1]
                    + " rect: " + this + " forceTransform: " + forceTransform
                    + " contains: " + contains(mTmpPoint[0], mTmpPoint[1])
                    + " this: " + this);
        }

        if (contains(mTmpPoint[0], mTmpPoint[1])) {
            event.applyTransform(mTmpMatrix);
            return true;
        }
        return false;
    }

    int getRotation() {
        return mRotation;
    }
}
+7 −75
Original line number Diff line number Diff line
@@ -22,11 +22,7 @@ import static android.view.MotionEvent.ACTION_MOVE;
import static android.view.MotionEvent.ACTION_POINTER_DOWN;
import static android.view.MotionEvent.ACTION_UP;

import static com.android.launcher3.states.RotationHelper.deltaRotation;
import static com.android.quickstep.util.RecentsOrientedState.postDisplayRotation;

import android.content.res.Resources;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.RectF;
import android.util.Log;
@@ -44,8 +40,8 @@ import java.util.Objects;

/**
 * Maintains state for supporting nav bars and tracking their gestures in multiple orientations.
 * See {@link OrientationRectF#applyTransform(MotionEvent, boolean)} for transformation of
 * MotionEvents from one orientation's coordinate space to another's.
 * See {@link OrientationRectF#applyTransformToRotation(MotionEvent, int, boolean)} for
 * transformation of MotionEvents from one orientation's coordinate space to another's.
 *
 * This class only supports single touch/pointer gesture tracking for touches started in a supported
 * nav bar region.
@@ -95,9 +91,6 @@ class OrientationTouchTransformer {

    private static final int QUICKSTEP_ROTATION_UNINITIALIZED = -1;

    private final Matrix mTmpMatrix = new Matrix();
    private final float[] mTmpPoint = new float[2];

    private final Map<CurrentDisplay, OrientationRectF> mSwipeTouchRegions =
            new HashMap<CurrentDisplay, OrientationRectF>();
    private final RectF mAssistantLeftRegion = new RectF();
@@ -365,7 +358,7 @@ class OrientationTouchTransformer {
                if (mLastRectTouched == null) {
                    return;
                }
                mLastRectTouched.applyTransform(event, true);
                mLastRectTouched.applyTransformFromRotation(event, mCurrentDisplay.rotation, true);
                break;
            }
            case ACTION_CANCEL:
@@ -373,7 +366,7 @@ class OrientationTouchTransformer {
                if (mLastRectTouched == null) {
                    return;
                }
                mLastRectTouched.applyTransform(event, true);
                mLastRectTouched.applyTransformFromRotation(event, mCurrentDisplay.rotation, true);
                mLastRectTouched = null;
                break;
            }
@@ -387,14 +380,14 @@ class OrientationTouchTransformer {
                    if (rect == null) {
                        continue;
                    }
                    if (rect.applyTransform(event, false)) {
                    if (rect.applyTransformFromRotation(event, mCurrentDisplay.rotation, false)) {
                        mLastRectTouched = rect;
                        mActiveTouchRotation = rect.mRotation;
                        mActiveTouchRotation = rect.getRotation();
                        if (mEnableMultipleRegions
                                && mCurrentDisplay.rotation == mActiveTouchRotation) {
                            // TODO(b/154580671) might make this block unnecessary
                            // Start a touch session for the default nav region for the display
                            mQuickStepStartingRotation = mLastRectTouched.mRotation;
                            mQuickStepStartingRotation = mLastRectTouched.getRotation();
                            resetSwipeRegions();
                        }
                        if (DEBUG) {
@@ -423,65 +416,4 @@ class OrientationTouchTransformer {
        pw.println("  mNavBarLargerGesturalHeight=" + mNavBarLargerGesturalHeight);
        pw.println("  mOneHandedModeRegion=" + mOneHandedModeRegion);
    }

    private class OrientationRectF extends RectF {

        private int mRotation;
        private float mHeight;
        private float mWidth;

        OrientationRectF(float left, float top, float right, float bottom, int rotation) {
            super(left, top, right, bottom);
            this.mRotation = rotation;
            mHeight = bottom;
            mWidth = right;
        }

        @Override
        public String toString() {
            String s = super.toString();
            s += " rotation: " + mRotation;
            return s;
        }

        @Override
        public boolean contains(float x, float y) {
            // Mark bottom right as included in the Rect (copied from Rect src, added "=" in "<=")
            return left < right && top < bottom  // check for empty first
                    && x >= left && x <= right && y >= top && y <= bottom;
        }

        boolean applyTransform(MotionEvent event, boolean forceTransform) {
            mTmpMatrix.reset();
            postDisplayRotation(deltaRotation(mCurrentDisplay.rotation, mRotation),
                    mHeight, mWidth, mTmpMatrix);
            if (forceTransform) {
                if (DEBUG) {
                    Log.d(TAG, "Transforming rotation due to forceTransform, "
                            + "mCurrentRotation: " + mCurrentDisplay.rotation
                            + "mRotation: " + mRotation
                            + " this: " + this);
                }
                event.applyTransform(mTmpMatrix);
                return true;
            }
            mTmpPoint[0] = event.getX();
            mTmpPoint[1] = event.getY();
            mTmpMatrix.mapPoints(mTmpPoint);

            if (DEBUG) {
                Log.d(TAG, "original: " + event.getX() + ", " + event.getY()
                        + " new: " + mTmpPoint[0] + ", " + mTmpPoint[1]
                        + " rect: " + this + " forceTransform: " + forceTransform
                        + " contains: " + contains(mTmpPoint[0], mTmpPoint[1])
                        + " this: " + this);
            }

            if (contains(mTmpPoint[0], mTmpPoint[1])) {
                event.applyTransform(mTmpMatrix);
                return true;
            }
            return false;
        }
    }
}
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.quickstep;

import static com.android.launcher3.util.DisplayController.CHANGE_ACTIVE_SCREEN;
import static com.android.launcher3.util.DisplayController.CHANGE_ALL;
import static com.android.launcher3.util.DisplayController.CHANGE_ROTATION;

import android.content.Context;
import android.view.MotionEvent;

import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.MainThreadInitializedObject;

public class SimpleOrientationTouchTransformer implements
        DisplayController.DisplayInfoChangeListener {

    public static final MainThreadInitializedObject<SimpleOrientationTouchTransformer> INSTANCE =
            new MainThreadInitializedObject<>(SimpleOrientationTouchTransformer::new);

    private OrientationRectF mOrientationRectF;

    public SimpleOrientationTouchTransformer(Context context) {
        DisplayController.INSTANCE.get(context).addChangeListener(this);
        onDisplayInfoChanged(context, DisplayController.INSTANCE.get(context).getInfo(),
                CHANGE_ALL);
    }

    @Override
    public void onDisplayInfoChanged(Context context, DisplayController.Info info, int flags) {
        if ((flags & (CHANGE_ROTATION | CHANGE_ACTIVE_SCREEN)) == 0) {
            return;
        }
        mOrientationRectF = new OrientationRectF(0, 0, info.currentSize.y, info.currentSize.x,
                info.rotation);
    }

    public void transform(MotionEvent ev, int rotation) {
        mOrientationRectF.applyTransformToRotation(ev, rotation, true /* forceTransform */);
    }
}
+10 −1
Original line number Diff line number Diff line
@@ -19,12 +19,14 @@ import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_UP;

import android.content.Context;
import android.util.Log;
import android.view.InputEvent;
import android.view.KeyEvent;
import android.view.MotionEvent;

import com.android.quickstep.InputConsumer;
import com.android.quickstep.SimpleOrientationTouchTransformer;
import com.android.systemui.shared.system.InputConsumerController;

import java.util.function.Supplier;
@@ -37,6 +39,8 @@ public class InputConsumerProxy {

    private static final String TAG = "InputConsumerProxy";

    private final Context mContext;
    private final Supplier<Integer> mRotationSupplier;
    private final InputConsumerController mInputConsumerController;
    private Runnable mCallback;
    private Supplier<InputConsumer> mConsumerSupplier;
@@ -48,8 +52,11 @@ public class InputConsumerProxy {
    private boolean mTouchInProgress = false;
    private boolean mDestroyPending = false;

    public InputConsumerProxy(InputConsumerController inputConsumerController,
    public InputConsumerProxy(Context context, Supplier<Integer> rotationSupplier,
            InputConsumerController inputConsumerController,
            Runnable callback, Supplier<InputConsumer> consumerSupplier) {
        mContext = context;
        mRotationSupplier = rotationSupplier;
        mInputConsumerController = inputConsumerController;
        mCallback = callback;
        mConsumerSupplier = consumerSupplier;
@@ -98,6 +105,8 @@ public class InputConsumerProxy {
            }
        }
        if (mInputConsumer != null) {
            SimpleOrientationTouchTransformer.INSTANCE.get(mContext).transform(ev,
                    mRotationSupplier.get());
            mInputConsumer.onMotionEvent(ev);
        }