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

Commit b585b40a authored by Ben Lin's avatar Ben Lin Committed by Automerger Merge Worker
Browse files

Merge "PiP: Enable Pinch Resize by default." into sc-dev am: 4b117e37

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13549568

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I5ffe7845b08875812d23ece984eee17836372938
parents 58b2bf57 4b117e37
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public class PipResizeGestureHandler {
    // For pinch-resize
    private boolean mThresholdCrossed0;
    private boolean mThresholdCrossed1;
    private boolean mUsingPinchToZoom = false;
    private boolean mUsingPinchToZoom = true;
    private float mAngle = 0;
    int mFirstIndex = -1;
    int mSecondIndex = -1;
@@ -139,7 +139,7 @@ public class PipResizeGestureHandler {
        mEnablePinchResize = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_SYSTEMUI,
                PIP_PINCH_RESIZE,
                /* defaultValue = */ false);
                /* defaultValue = */ true);
        DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,
                mMainExecutor,
                new DeviceConfig.OnPropertiesChangedListener() {
@@ -147,7 +147,7 @@ public class PipResizeGestureHandler {
                    public void onPropertiesChanged(DeviceConfig.Properties properties) {
                        if (properties.getKeyset().contains(PIP_PINCH_RESIZE)) {
                            mEnablePinchResize = properties.getBoolean(
                                    PIP_PINCH_RESIZE, /* defaultValue = */ false);
                                    PIP_PINCH_RESIZE, /* defaultValue = */ true);
                        }
                    }
                });
+2 −1
Original line number Diff line number Diff line
@@ -63,8 +63,9 @@ import java.util.function.Consumer;
 * the PIP.
 */
public class PipTouchHandler {
    @VisibleForTesting static final float MINIMUM_SIZE_PERCENT = 0.4f;

    private static final String TAG = "PipTouchHandler";
    private static final float MINIMUM_SIZE_PERCENT = 0.4f;
    private static final float DEFAULT_STASH_VELOCITY_THRESHOLD = 18000.f;

    // Allow PIP to resize to a slightly bigger state upon touch
+28 −34
Original line number Diff line number Diff line
@@ -22,16 +22,14 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.graphics.Point;
import android.graphics.Rect;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.Size;

import androidx.test.filters.SmallTest;

import com.android.wm.shell.R;
import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.FloatingContentCoordinator;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.pip.PipBoundsAlgorithm;
@@ -59,6 +57,9 @@ import org.mockito.MockitoAnnotations;
@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class PipTouchHandlerTest extends ShellTestCase {

    private static final int INSET = 10;
    private static final int PIP_LENGTH = 100;

    private PipTouchHandler mPipTouchHandler;

    @Mock
@@ -85,8 +86,9 @@ public class PipTouchHandlerTest extends ShellTestCase {
    private PipMotionHelper mMotionHelper;
    private PipResizeGestureHandler mPipResizeGestureHandler;

    private DisplayLayout mDisplayLayout;
    private Rect mInsetBounds;
    private Rect mMinBounds;
    private Rect mPipBounds;
    private Rect mCurBounds;
    private boolean mFromImeAdjustment;
    private boolean mFromShelfAdjustment;
@@ -109,12 +111,18 @@ public class PipTouchHandlerTest extends ShellTestCase {
        mPipTouchHandler.setPipMotionHelper(mMotionHelper);
        mPipTouchHandler.setPipResizeGestureHandler(mPipResizeGestureHandler);

        // Assume a display of 1000 x 1000
        // inset of 10
        mInsetBounds = new Rect(10, 10, 990, 990);
        mDisplayLayout = new DisplayLayout(mContext, mContext.getDisplay());
        mPipBoundsState.setDisplayLayout(mDisplayLayout);
        mInsetBounds = new Rect(mPipBoundsState.getDisplayBounds().left + INSET,
                mPipBoundsState.getDisplayBounds().top + INSET,
                mPipBoundsState.getDisplayBounds().right - INSET,
                mPipBoundsState.getDisplayBounds().bottom - INSET);
        // minBounds of 100x100 bottom right corner
        mMinBounds = new Rect(890, 890, 990, 990);
        mCurBounds = new Rect(mMinBounds);
        mPipBounds = new Rect(mPipBoundsState.getDisplayBounds().right - INSET - PIP_LENGTH,
                mPipBoundsState.getDisplayBounds().bottom - INSET - PIP_LENGTH,
                mPipBoundsState.getDisplayBounds().right - INSET,
                mPipBoundsState.getDisplayBounds().bottom - INSET);
        mCurBounds = new Rect(mPipBounds);
        mFromImeAdjustment = false;
        mFromShelfAdjustment = false;
        mDisplayRotation = 0;
@@ -122,37 +130,23 @@ public class PipTouchHandlerTest extends ShellTestCase {
    }

    @Test
    public void updateMovementBounds_minBounds() {
        Rect expectedMinMovementBounds = new Rect();
        mPipBoundsAlgorithm.getMovementBounds(mMinBounds, mInsetBounds, expectedMinMovementBounds,
    public void updateMovementBounds_minMaxBounds() {
        final int shorterLength = Math.min(mPipBoundsState.getDisplayBounds().width(),
                mPipBoundsState.getDisplayBounds().height());
        Rect expectedMovementBounds = new Rect();
        mPipBoundsAlgorithm.getMovementBounds(mPipBounds, mInsetBounds, expectedMovementBounds,
                0);

        mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mMinBounds, mCurBounds,
        mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mPipBounds, mCurBounds,
                mFromImeAdjustment, mFromShelfAdjustment, mDisplayRotation);

        assertEquals(expectedMinMovementBounds, mPipBoundsState.getNormalMovementBounds());
        assertEquals(expectedMovementBounds, mPipBoundsState.getNormalMovementBounds());
        verify(mPipResizeGestureHandler, times(1))
                .updateMinSize(mMinBounds.width(), mMinBounds.height());
    }

    @Test
    public void updateMovementBounds_maxBounds() {
        Point displaySize = new Point();
        mContext.getDisplay().getRealSize(displaySize);
        Size maxSize = mPipBoundsAlgorithm.getSizeForAspectRatio(1,
                mContext.getResources().getDimensionPixelSize(
                        R.dimen.pip_expanded_shortest_edge_size), displaySize.x, displaySize.y);
        Rect maxBounds = new Rect(0, 0, maxSize.getWidth(), maxSize.getHeight());
        Rect expectedMaxMovementBounds = new Rect();
        mPipBoundsAlgorithm.getMovementBounds(maxBounds, mInsetBounds, expectedMaxMovementBounds,
                0);

        mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mMinBounds, mCurBounds,
                mFromImeAdjustment, mFromShelfAdjustment, mDisplayRotation);
                .updateMinSize(mPipBounds.width(), mPipBounds.height());

        assertEquals(expectedMaxMovementBounds, mPipBoundsState.getExpandedMovementBounds());
        verify(mPipResizeGestureHandler, times(1))
                .updateMaxSize(maxBounds.width(), maxBounds.height());
                .updateMaxSize(shorterLength - 2 * mInsetBounds.left,
                        shorterLength - 2 * mInsetBounds.left);
    }

    @Test
@@ -160,7 +154,7 @@ public class PipTouchHandlerTest extends ShellTestCase {
        mFromImeAdjustment = true;
        mPipTouchHandler.onImeVisibilityChanged(true /* imeVisible */, mImeHeight);

        mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mMinBounds, mCurBounds,
        mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mPipBounds, mCurBounds,
                mFromImeAdjustment, mFromShelfAdjustment, mDisplayRotation);

        verify(mMotionHelper, times(1)).animateToOffset(any(), anyInt());