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

Commit 84b3ee4f authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Iterate over all swipeable regions when calculating quickswitch gesture bounds

Previously when creating a new CurrentDisplay, we would
never get the correct OrientationRectF from the hashmap
because the size field of CurrentDisplay would be incorrect
for a given rotation.
Ex. Rotation 0 and Rotation 1 would have inverted display sizes
Thus hashcode would return different values and we would only
ever see if a point is contained in the current rotation's
OrientationRectF.

Bug: 183897242
Test: Tested swiping from portrait to landscape app, was
able to swipe continuously

Change-Id: I6de625389956f55cfc2142dcb7aeef2e90c157ac
parent 781b8414
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -247,10 +247,7 @@ public class OrientationTouchTransformerTest {
    }

    @Test
    @Ignore("There's too much that goes into needing to mock a real motion event so the "
            + "transforms in native code get applied correctly. Once that happens then maybe we can"
            + " write slightly more complex unit tests")
    public void applyTransform_taskNotFrozen_90Rotate_inTwoRegions() {
    public void applyTransform_taskNotFrozen_90Rotate_withTwoRegions() {
        mTouchTransformer.createOrAddTouchRegion(mInfo);
        mTouchTransformer.enableMultipleRegions(true, mInfo);
        mTouchTransformer
@@ -262,6 +259,7 @@ public class OrientationTouchTransformerTest {
        // Portrait point in landscape orientation axis
        MotionEvent inRegion2 = generateMotionEvent(MotionEvent.ACTION_DOWN, 10, 10);
        mTouchTransformer.transform(inRegion1_down);
        // no-op
        mTouchTransformer.transform(inRegion2);
        assertTrue(mTouchTransformer.touchInValidSwipeRegions(
                inRegion1_down.getX(), inRegion1_down.getY()));
@@ -269,9 +267,19 @@ public class OrientationTouchTransformerTest {
        assertFalse(mTouchTransformer.touchInValidSwipeRegions(inRegion2.getX(), inRegion2.getY()));

        mTouchTransformer.transform(inRegion1_up);
    }

        // Set the new region with this MotionEvent.ACTION_DOWN
        inRegion2 = generateAndTransformMotionEvent(MotionEvent.ACTION_DOWN, 10, 370);
    @Test
    public void applyTransform_90Rotate_inRotatedRegion() {
        // Create regions for both 0 Rotation and 90 Rotation
        mTouchTransformer.createOrAddTouchRegion(mInfo);
        mTouchTransformer.enableMultipleRegions(true, mInfo);
        mTouchTransformer
                .createOrAddTouchRegion(createDisplayInfo(NORMAL_SCREEN_SIZE, Surface.ROTATION_90));
        // Portrait point in landscape orientation axis
        float x1 = generateTouchRegionHeight(NORMAL_SCREEN_SIZE, Surface.ROTATION_0);
        // bottom of screen, from landscape perspective right side of screen
        MotionEvent inRegion2 = generateAndTransformMotionEvent(MotionEvent.ACTION_DOWN, x1, 370);
        assertTrue(mTouchTransformer.touchInValidSwipeRegions(inRegion2.getX(), inRegion2.getY()));
    }

+11 −8
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ import java.util.Objects;
 */
class OrientationTouchTransformer {

    class CurrentDisplay {
    private static class CurrentDisplay {
        public Point size;
        public int rotation;

@@ -67,6 +67,13 @@ class OrientationTouchTransformer {
            this.rotation = rotation;
        }

        @Override
        public String toString() {
            return "CurrentDisplay:"
                    + " rotation: " + rotation
                    + " size: " + size;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
@@ -86,21 +93,20 @@ class OrientationTouchTransformer {

    private static final String TAG = "OrientationTouchTransformer";
    private static final boolean DEBUG = false;
    private static final int MAX_ORIENTATIONS = 4;

    private static final int QUICKSTEP_ROTATION_UNINITIALIZED = -1;

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

    private Map<CurrentDisplay, OrientationRectF> mSwipeTouchRegions =
    private final Map<CurrentDisplay, OrientationRectF> mSwipeTouchRegions =
            new HashMap<CurrentDisplay, OrientationRectF>();
    private final RectF mAssistantLeftRegion = new RectF();
    private final RectF mAssistantRightRegion = new RectF();
    private final RectF mOneHandedModeRegion = new RectF();
    private CurrentDisplay mCurrentDisplay = new CurrentDisplay();
    private int mNavBarGesturalHeight;
    private int mNavBarLargerGesturalHeight;
    private final int mNavBarLargerGesturalHeight;
    private boolean mEnableMultipleRegions;
    private Resources mResources;
    private OrientationRectF mLastRectTouched;
@@ -374,10 +380,7 @@ class OrientationTouchTransformer {
                    return;
                }

                for (int i = 0; i < MAX_ORIENTATIONS; i++) {
                    CurrentDisplay display = new CurrentDisplay(mCurrentDisplay.size, i);
                    OrientationRectF rect = mSwipeTouchRegions.get(display);

                for (OrientationRectF rect : mSwipeTouchRegions.values()) {
                    if (TestProtocol.sDebugTracing) {
                        Log.d(TestProtocol.NO_SWIPE_TO_HOME, "transform:DOWN, rect=" + rect);
                    }