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

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

Merge "Handle Rotation when one handed is trigger (11/N)"

parents 970022af 5edd62d7
Loading
Loading
Loading
Loading
+21 −31
Original line number Diff line number Diff line
@@ -62,13 +62,11 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer implemen
    private static final String TAG = "OneHandedDisplayAreaOrganizer";

    @VisibleForTesting
    static final int MSG_OFFSET_IMMEDIATE = 1;
    static final int MSG_RESET_IMMEDIATE = 1;
    @VisibleForTesting
    static final int MSG_OFFSET_ANIMATE = 2;
    @VisibleForTesting
    static final int MSG_OFFSET_FINISH = 3;
    @VisibleForTesting
    static final int MSG_RESIZE_IMMEDIATE = 4;

    private final Handler mUpdateHandler;

@@ -118,9 +116,12 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer implemen
        final int yOffset = args.argi2;
        final int direction = args.argi3;

        if (mLeash == null || !mLeash.isValid()) {
            Log.w(TAG, "mLeash is null, abort transition");
            return false;
        }
        switch (msg.what) {
            case MSG_RESIZE_IMMEDIATE:
            case MSG_OFFSET_IMMEDIATE:
            case MSG_RESET_IMMEDIATE:
                final OneHandedAnimationController.OneHandedTransitionAnimator animator =
                        mAnimationController.getAnimator(mLeash, currentBounds,
                                mDefaultDisplayBounds);
@@ -129,9 +130,9 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer implemen
                }
                final SurfaceControl.Transaction tx =
                        mSurfaceControlTransactionFactory.getTransaction();
                mSurfaceTransactionHelper.translate(tx, mLeash, yOffset)
                        .crop(tx, mLeash, currentBounds);
                tx.apply();
                tx.setPosition(mLeash, 0, 0)
                        .setWindowCrop(mLeash, -1/* reset */, -1/* reset */)
                        .apply();
                finishOffset(currentBounds, yOffset, direction);
                break;
            case MSG_OFFSET_ANIMATE:
@@ -177,6 +178,12 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer implemen
    @Override
    public void onDisplayAreaInfoChanged(@NonNull DisplayAreaInfo displayAreaInfo) {
        Objects.requireNonNull(displayAreaInfo, "displayArea must not be null");
        // Stop one handed without animation and reset cropped size immediately
        if (displayAreaInfo.configuration.orientation
                != mDisplayAreaInfo.configuration.orientation) {
            final Rect newBounds = displayAreaInfo.configuration.windowConfiguration.getBounds();
            resetImmediately(newBounds);
        }
        mDisplayAreaInfo = displayAreaInfo;
    }

@@ -192,12 +199,8 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer implemen

        // Stop one handed immediately
        if (isInOneHanded()) {
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = getLastVisualDisplayBounds();
            args.argi1 = 0 /* xOffset */;
            args.argi2 = 0 /* yOffset */;
            args.argi3 = TRANSITION_DIRECTION_EXIT;
            mUpdateHandler.sendMessage(mUpdateHandler.obtainMessage(MSG_OFFSET_IMMEDIATE, args));
            final Rect newBounds = mDisplayAreaInfo.configuration.windowConfiguration.getBounds();
            resetImmediately(newBounds);
        }
    }

@@ -215,23 +218,10 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer implemen
    }

    /**
     * Offset DisplayArea immediately calling from OneHandedManager when screen going to rotate
     */
    public void offsetImmediately(int xOffset, int yOffset) {
        if (mDisplayAreaInfo != null && mLeash != null) {
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = getLastVisualDisplayBounds();
            args.argi1 = xOffset;
            args.argi2 = yOffset;
            args.argi3 = yOffset > 0 ? TRANSITION_DIRECTION_TRIGGER : TRANSITION_DIRECTION_EXIT;
            mUpdateHandler.sendMessage(mUpdateHandler.obtainMessage(MSG_OFFSET_ANIMATE, args));
        }
    }

    /**
     * Resize DisplayArea immediately calling from OneHandedManager when screen going to rotate
     * Immediately resize/reset leash from previous cropped boundary to default.
     * (i.e Screen rotation need to reset crop and position before applying new bounds)
     */
    public void resizeImmediately(Rect newDisplayBounds) {
    public void resetImmediately(Rect newDisplayBounds) {
        updateDisplayBounds(newDisplayBounds);
        if (mDisplayAreaInfo != null && mLeash != null) {
            SomeArgs args = SomeArgs.obtain();
@@ -239,7 +229,7 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer implemen
            args.argi1 = 0 /* xOffset */;
            args.argi2 = 0 /* yOffset */;
            args.argi3 = TRANSITION_DIRECTION_EXIT;
            mUpdateHandler.sendMessage(mUpdateHandler.obtainMessage(MSG_RESIZE_IMMEDIATE, args));
            mUpdateHandler.sendMessage(mUpdateHandler.obtainMessage(MSG_RESET_IMMEDIATE, args));
        }
    }

+16 −19
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Handler;
import android.testing.AndroidTestingRunner;
@@ -62,6 +63,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
    OneHandedDisplayAreaOrganizer mDisplayAreaOrganizer;
    OneHandedAnimationController.OneHandedTransitionAnimator mFakeAnimator;
    WindowContainerToken mToken;
    SurfaceControl mLeash;
    @Mock
    IWindowContainerToken mMockRealToken;
    @Mock
@@ -84,7 +86,9 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
                mMockSurfaceTransactionHelper);
        mUpdateHandler = Mockito.spy(mDisplayAreaOrganizer.getUpdateHandler());
        mToken = new WindowContainerToken(mMockRealToken);
        mLeash = new SurfaceControl();
        mDisplayAreaInfo = new DisplayAreaInfo(mToken, DEFAULT_DISPLAY, FEATURE_ONE_HANDED);
        mDisplayAreaInfo.configuration.orientation = Configuration.ORIENTATION_PORTRAIT;
        mDisplayInfo = new DisplayInfo();
        mDisplayInfo.logicalWidth = DISPLAY_WIDTH;
        mDisplayInfo.logicalHeight = DISPLAY_HEIGHT;
@@ -113,14 +117,14 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {

    @Test
    public void testOnDisplayAreaAppeared() {
        mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mMockLeash);
        mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mLeash);

        verify(mMockAnimationController, never()).getAnimator(any(), any(), any());
    }

    @Test
    public void testOnDisplayAreaVanished() {
        mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mMockLeash);
        mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mLeash);
        mDisplayAreaOrganizer.onDisplayAreaVanished(mDisplayAreaInfo);
    }

@@ -128,7 +132,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
    public void testOnDisplayAreaInfoChanged_updateDisplayAreaInfo() {
        final DisplayAreaInfo newDisplayAreaInfo = new DisplayAreaInfo(mToken, DEFAULT_DISPLAY,
                FEATURE_ONE_HANDED);
        mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mMockLeash);
        mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mLeash);
        mDisplayAreaOrganizer.onDisplayAreaInfoChanged(newDisplayAreaInfo);

        assertThat(mDisplayAreaOrganizer.mDisplayAreaInfo).isEqualTo(newDisplayAreaInfo);
@@ -139,7 +143,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
        final int xOffSet = 0;
        final int yOffSet = 100;

        mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mMockLeash);
        mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mLeash);
        mDisplayAreaOrganizer.scheduleOffset(xOffSet, yOffSet);

        assertThat(mUpdateHandler.hasMessages(
@@ -147,26 +151,19 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
    }

    @Test
    public void testOffsetImmediately() {
        final int xOffSet = 0;
        final int yOffSet = 0;

        mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mMockLeash);
        mDisplayAreaOrganizer.offsetImmediately(xOffSet, yOffSet);

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_OFFSET_IMMEDIATE)).isNotNull();
    }

    @Test
    public void testResizeImmediately() {
    public void testResetImmediately() {
        // To prevent mNativeObject of Surface is null in the test flow
        when(mMockLeash.isValid()).thenReturn(false);
        final Rect newBounds = new Rect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
        final DisplayAreaInfo newDisplayAreaInfo = new DisplayAreaInfo(mToken, DEFAULT_DISPLAY,
                FEATURE_ONE_HANDED);
        newDisplayAreaInfo.configuration.orientation = Configuration.ORIENTATION_LANDSCAPE;

        mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mMockLeash);
        mDisplayAreaOrganizer.resizeImmediately(newBounds);
        mDisplayAreaOrganizer.onDisplayAreaInfoChanged(newDisplayAreaInfo);

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESIZE_IMMEDIATE)).isNotNull();
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isNotNull();
    }

}