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

Commit 4c218880 authored by Vania Desmonda's avatar Vania Desmonda Committed by Android (Google) Code Review
Browse files

Merge "Update edge resize handle to 10dp and add a 2dp inset into the task...

Merge "Update edge resize handle to 10dp and add a 2dp inset into the task bounds for edge resizing." into main
parents 9e541c22 1f99b44c
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -539,20 +539,23 @@
    <!-- The size of the icon shown in the resize veil. -->
    <dimen name="desktop_mode_resize_veil_icon_size">96dp</dimen>

    <!-- The with of the border around the app task for edge resizing, when
    <!-- The width of the border outside the app task eligible for edge resizing, when
         enable_windowing_edge_drag_resize is enabled. -->
    <dimen name="desktop_mode_edge_handle">12dp</dimen>
    <dimen name="freeform_edge_handle_outset">10dp</dimen>

    <!-- The size of the border inside the app task eligible for edge resizing, when
         enable_windowing_edge_drag_resize is enabled. -->
    <dimen name="freeform_edge_handle_inset">2dp</dimen>

    <!-- The original width of the border around the app task for edge resizing, when
         enable_windowing_edge_drag_resize is disabled. -->
    <dimen name="freeform_resize_handle">15dp</dimen>

    <!-- The size of the corner region for drag resizing with touch, when a larger touch region is
         appropriate. Applied when enable_windowing_edge_drag_resize is enabled. -->
         appropriate. -->
    <dimen name="desktop_mode_corner_resize_large">48dp</dimen>

    <!-- The original size of the corner region for darg resizing, when
         enable_windowing_edge_drag_resize is disabled. -->
    <!-- The size of the corner region for drag resizing with a cursor or a stylus. -->
    <dimen name="freeform_resize_corner">44dp</dimen>

    <!-- The thickness in dp for all desktop drag transition regions. -->
+3 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.wm.shell.windowdecor;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getFineResizeCornerSize;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getLargeResizeCornerSize;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getResizeEdgeHandleSize;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getResizeHandleEdgeInset;

import android.annotation.NonNull;
import android.annotation.SuppressLint;
@@ -286,7 +287,8 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
        final Resources res = mResult.mRootView.getResources();
        mDragResizeListener.setGeometry(new DragResizeWindowGeometry(0 /* taskCornerRadius */,
                new Size(mResult.mWidth, mResult.mHeight), getResizeEdgeHandleSize(mContext, res),
                getFineResizeCornerSize(res), getLargeResizeCornerSize(res)), touchSlop);
                getResizeHandleEdgeInset(res), getFineResizeCornerSize(res),
                getLargeResizeCornerSize(res)), touchSlop);
    }

    /**
+3 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSIT
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getFineResizeCornerSize;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getLargeResizeCornerSize;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getResizeEdgeHandleSize;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getResizeHandleEdgeInset;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -515,8 +516,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        if (mDragResizeListener.setGeometry(
                new DragResizeWindowGeometry(mRelayoutParams.mCornerRadius,
                        new Size(mResult.mWidth, mResult.mHeight),
                        getResizeEdgeHandleSize(mContext, res), getFineResizeCornerSize(res),
                        getLargeResizeCornerSize(res)), touchSlop)
                        getResizeEdgeHandleSize(mContext, res), getResizeHandleEdgeInset(res),
                        getFineResizeCornerSize(res), getLargeResizeCornerSize(res)), touchSlop)
                || !mTaskInfo.positionInParent.equals(mPositionInParent)) {
            updateExclusionRegion();
        }
+38 −20
Original line number Diff line number Diff line
@@ -44,27 +44,32 @@ import java.util.Objects;
final class DragResizeWindowGeometry {
    private final int mTaskCornerRadius;
    private final Size mTaskSize;
    // The size of the handle applied to the edges of the window, for the user to drag resize.
    private final int mResizeHandleThickness;
    // The size of the handle outside the task window applied to the edges of the window, for the
    // user to drag resize.
    private final int mResizeHandleEdgeOutset;
    // The size of the handle inside the task window applied to the edges of the window, for the
    // user to drag resize.
    private final int mResizeHandleEdgeInset;
    // The task corners to permit drag resizing with a course input, such as touch.

    private final @NonNull TaskCorners mLargeTaskCorners;
    // The task corners to permit drag resizing with a fine input, such as stylus or cursor.
    private final @NonNull TaskCorners mFineTaskCorners;
    // The bounds for each edge drag region, which can resize the task in one direction.
    private final @NonNull TaskEdges mTaskEdges;
    final @NonNull TaskEdges mTaskEdges;

    DragResizeWindowGeometry(int taskCornerRadius, @NonNull Size taskSize,
            int resizeHandleThickness, int fineCornerSize, int largeCornerSize) {
            int resizeHandleEdgeOutset, int resizeHandleEdgeInset, int fineCornerSize,
            int largeCornerSize) {
        mTaskCornerRadius = taskCornerRadius;
        mTaskSize = taskSize;
        mResizeHandleThickness = resizeHandleThickness;
        mResizeHandleEdgeOutset = resizeHandleEdgeOutset;
        mResizeHandleEdgeInset = resizeHandleEdgeInset;

        mLargeTaskCorners = new TaskCorners(mTaskSize, largeCornerSize);
        mFineTaskCorners = new TaskCorners(mTaskSize, fineCornerSize);

        // Save touch areas for each edge.
        mTaskEdges = new TaskEdges(mTaskSize, mResizeHandleThickness);
        mTaskEdges = new TaskEdges(mTaskSize, mResizeHandleEdgeOutset, mResizeHandleEdgeInset);
    }

    /**
@@ -72,10 +77,17 @@ final class DragResizeWindowGeometry {
     */
    static int getResizeEdgeHandleSize(@NonNull Context context, @NonNull Resources res) {
        return EDGE_DRAG_RESIZE.isEnabled(context)
                ? res.getDimensionPixelSize(R.dimen.desktop_mode_edge_handle)
                ? res.getDimensionPixelSize(R.dimen.freeform_edge_handle_outset)
                : res.getDimensionPixelSize(R.dimen.freeform_resize_handle);
    }

    /**
     * Returns the resource value to use for the edge resize handle inside the task bounds.
     */
    static int getResizeHandleEdgeInset(@NonNull Resources res) {
        return res.getDimensionPixelSize(R.dimen.freeform_edge_handle_inset);
    }

    /**
     * Returns the resource value to use for course input, such as touch, that benefits from a large
     * square on each of the window's corners.
@@ -95,7 +107,8 @@ final class DragResizeWindowGeometry {
    /**
     * Returns the size of the task this geometry is calculated for.
     */
    @NonNull Size getTaskSize() {
    @NonNull
    Size getTaskSize() {
        // Safe to return directly since size is immutable.
        return mTaskSize;
    }
@@ -217,13 +230,15 @@ final class DragResizeWindowGeometry {
            ctrlType |= CTRL_TYPE_BOTTOM;
        }
        // If the touch is within one of the four corners, check if it is within the bounds of the
        // // handle.
        // handle.
        if ((ctrlType & (CTRL_TYPE_LEFT | CTRL_TYPE_RIGHT)) != 0
                && (ctrlType & (CTRL_TYPE_TOP | CTRL_TYPE_BOTTOM)) != 0) {
            return checkDistanceFromCenter(ctrlType, x, y);
        }
        // Otherwise, we should make sure we don't resize tasks inside task bounds.
        return (x < 0 || y < 0 || x >= mTaskSize.getWidth() || y >= mTaskSize.getHeight())
        // Allow a small resize handle inside the task bounds defined by the edge inset.
        return (x <= mResizeHandleEdgeInset || y <= mResizeHandleEdgeInset
                || x >= mTaskSize.getWidth() - mResizeHandleEdgeInset
                || y >= mTaskSize.getHeight() - mResizeHandleEdgeInset)
                ? ctrlType : CTRL_TYPE_UNDEFINED;
    }

@@ -237,7 +252,7 @@ final class DragResizeWindowGeometry {
        final Point cornerRadiusCenter = calculateCenterForCornerRadius(ctrlType);
        double distanceFromCenter = Math.hypot(x - cornerRadiusCenter.x, y - cornerRadiusCenter.y);

        if (distanceFromCenter < mTaskCornerRadius + mResizeHandleThickness
        if (distanceFromCenter < mTaskCornerRadius + mResizeHandleEdgeOutset
                && distanceFromCenter >= mTaskCornerRadius) {
            return ctrlType;
        }
@@ -288,7 +303,8 @@ final class DragResizeWindowGeometry {

        return this.mTaskCornerRadius == other.mTaskCornerRadius
                && this.mTaskSize.equals(other.mTaskSize)
                && this.mResizeHandleThickness == other.mResizeHandleThickness
                && this.mResizeHandleEdgeOutset == other.mResizeHandleEdgeOutset
                && this.mResizeHandleEdgeInset == other.mResizeHandleEdgeInset
                && this.mFineTaskCorners.equals(other.mFineTaskCorners)
                && this.mLargeTaskCorners.equals(other.mLargeTaskCorners)
                && this.mTaskEdges.equals(other.mTaskEdges);
@@ -299,7 +315,8 @@ final class DragResizeWindowGeometry {
        return Objects.hash(
                mTaskCornerRadius,
                mTaskSize,
                mResizeHandleThickness,
                mResizeHandleEdgeOutset,
                mResizeHandleEdgeInset,
                mFineTaskCorners,
                mLargeTaskCorners,
                mTaskEdges);
@@ -421,26 +438,27 @@ final class DragResizeWindowGeometry {
        private final @NonNull Rect mBottomEdgeBounds;
        private final @NonNull Region mRegion;

        private TaskEdges(@NonNull Size taskSize, int resizeHandleThickness) {
        private TaskEdges(@NonNull Size taskSize, int resizeHandleThickness,
                int resizeHandleEdgeInset) {
            // Save touch areas for each edge.
            mTopEdgeBounds = new Rect(
                    -resizeHandleThickness,
                    -resizeHandleThickness,
                    taskSize.getWidth() + resizeHandleThickness,
                    0);
                    resizeHandleThickness);
            mLeftEdgeBounds = new Rect(
                    -resizeHandleThickness,
                    0,
                    0,
                    resizeHandleEdgeInset,
                    taskSize.getHeight());
            mRightEdgeBounds = new Rect(
                    taskSize.getWidth(),
                    taskSize.getWidth() - resizeHandleEdgeInset,
                    0,
                    taskSize.getWidth() + resizeHandleThickness,
                    taskSize.getHeight());
            mBottomEdgeBounds = new Rect(
                    -resizeHandleThickness,
                    taskSize.getHeight(),
                    taskSize.getHeight() - resizeHandleEdgeInset,
                    taskSize.getWidth() + resizeHandleThickness,
                    taskSize.getHeight() + resizeHandleThickness);

+39 −20
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Arrays;
import java.util.List;

/**
 * Tests for {@link DragResizeWindowGeometry}.
 *
@@ -57,11 +60,12 @@ public class DragResizeWindowGeometryTests extends ShellTestCase {
    private static final Size TASK_SIZE = new Size(500, 1000);
    private static final int TASK_CORNER_RADIUS = 10;
    private static final int EDGE_RESIZE_THICKNESS = 12;
    private static final int EDGE_RESIZE_HANDLE_INSET = 4;
    private static final int FINE_CORNER_SIZE = EDGE_RESIZE_THICKNESS * 2 + 10;
    private static final int LARGE_CORNER_SIZE = FINE_CORNER_SIZE + 10;
    private static final DragResizeWindowGeometry GEOMETRY = new DragResizeWindowGeometry(
            TASK_CORNER_RADIUS, TASK_SIZE, EDGE_RESIZE_THICKNESS, FINE_CORNER_SIZE,
            LARGE_CORNER_SIZE);
            TASK_CORNER_RADIUS, TASK_SIZE, EDGE_RESIZE_THICKNESS, EDGE_RESIZE_HANDLE_INSET,
            FINE_CORNER_SIZE, LARGE_CORNER_SIZE);
    // Points in the edge resize handle. Note that coordinates start from the top left.
    private static final Point TOP_EDGE_POINT = new Point(TASK_SIZE.getWidth() / 2,
            -EDGE_RESIZE_THICKNESS / 2);
@@ -71,6 +75,16 @@ public class DragResizeWindowGeometryTests extends ShellTestCase {
            TASK_SIZE.getWidth() + EDGE_RESIZE_THICKNESS / 2, TASK_SIZE.getHeight() / 2);
    private static final Point BOTTOM_EDGE_POINT = new Point(TASK_SIZE.getWidth() / 2,
            TASK_SIZE.getHeight() + EDGE_RESIZE_THICKNESS / 2);
    // Points in the inset of the task bounds still within the edge resize handle.
    // Note that coordinates start from the top left.
    private static final Point TOP_INSET_POINT = new Point(TASK_SIZE.getWidth() / 2,
            EDGE_RESIZE_HANDLE_INSET / 2);
    private static final Point LEFT_INSET_POINT = new Point(EDGE_RESIZE_HANDLE_INSET / 2,
            TASK_SIZE.getHeight() / 2);
    private static final Point RIGHT_INSET_POINT = new Point(
            TASK_SIZE.getWidth() - EDGE_RESIZE_HANDLE_INSET / 2, TASK_SIZE.getHeight() / 2);
    private static final Point BOTTOM_INSET_POINT = new Point(TASK_SIZE.getWidth() / 2,
            TASK_SIZE.getHeight() - EDGE_RESIZE_HANDLE_INSET / 2);

    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@@ -85,18 +99,23 @@ public class DragResizeWindowGeometryTests extends ShellTestCase {
                .addEqualityGroup(
                        GEOMETRY,
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                                EDGE_RESIZE_THICKNESS, FINE_CORNER_SIZE, LARGE_CORNER_SIZE))
                                EDGE_RESIZE_THICKNESS, EDGE_RESIZE_HANDLE_INSET, FINE_CORNER_SIZE,
                                LARGE_CORNER_SIZE))
                .addEqualityGroup(
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                                EDGE_RESIZE_THICKNESS + 10, FINE_CORNER_SIZE, LARGE_CORNER_SIZE),
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                FINE_CORNER_SIZE, LARGE_CORNER_SIZE),
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                                EDGE_RESIZE_THICKNESS + 10, FINE_CORNER_SIZE, LARGE_CORNER_SIZE))
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                FINE_CORNER_SIZE, LARGE_CORNER_SIZE))
                .addEqualityGroup(
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                                EDGE_RESIZE_THICKNESS + 10, FINE_CORNER_SIZE,
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                FINE_CORNER_SIZE,
                                LARGE_CORNER_SIZE + 5),
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                                EDGE_RESIZE_THICKNESS + 10, FINE_CORNER_SIZE,
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                FINE_CORNER_SIZE,
                                LARGE_CORNER_SIZE + 5))
                .testEquals();
    }
@@ -127,7 +146,7 @@ public class DragResizeWindowGeometryTests extends ShellTestCase {
        assertThat(region.contains(point.x - EDGE_RESIZE_THICKNESS, point.y)).isTrue();
        // Vertically along the edge is not contained.
        assertThat(region.contains(point.x, point.y - EDGE_RESIZE_THICKNESS)).isFalse();
        assertThat(region.contains(point.x, point.y + EDGE_RESIZE_THICKNESS)).isFalse();
        assertThat(region.contains(point.x, point.y + EDGE_RESIZE_THICKNESS + 10)).isFalse();
    }

    private static void verifyVerticalEdge(@NonNull Region region, @NonNull Point point) {
@@ -188,18 +207,18 @@ public class DragResizeWindowGeometryTests extends ShellTestCase {
    }

    private void validateCtrlTypeForEdges(boolean isTouchscreen, boolean isEdgeResizePermitted) {
        List<Point> points = Arrays.asList(LEFT_EDGE_POINT, TOP_EDGE_POINT, RIGHT_EDGE_POINT,
                BOTTOM_EDGE_POINT, LEFT_INSET_POINT, TOP_INSET_POINT, RIGHT_INSET_POINT,
                BOTTOM_INSET_POINT);
        List<Integer> expectedCtrlType = Arrays.asList(CTRL_TYPE_LEFT, CTRL_TYPE_TOP,
                CTRL_TYPE_RIGHT, CTRL_TYPE_BOTTOM, CTRL_TYPE_LEFT, CTRL_TYPE_TOP, CTRL_TYPE_RIGHT,
                CTRL_TYPE_BOTTOM);

        for (int i = 0; i < points.size(); i++) {
            assertThat(GEOMETRY.calculateCtrlType(mContext, isTouchscreen, isEdgeResizePermitted,
                LEFT_EDGE_POINT.x, LEFT_EDGE_POINT.y)).isEqualTo(
                        isEdgeResizePermitted ? CTRL_TYPE_LEFT : CTRL_TYPE_UNDEFINED);
        assertThat(GEOMETRY.calculateCtrlType(mContext, isTouchscreen, isEdgeResizePermitted,
                TOP_EDGE_POINT.x, TOP_EDGE_POINT.y)).isEqualTo(
                        isEdgeResizePermitted ? CTRL_TYPE_TOP : CTRL_TYPE_UNDEFINED);
        assertThat(GEOMETRY.calculateCtrlType(mContext, isTouchscreen, isEdgeResizePermitted,
                RIGHT_EDGE_POINT.x, RIGHT_EDGE_POINT.y)).isEqualTo(
                        isEdgeResizePermitted ? CTRL_TYPE_RIGHT : CTRL_TYPE_UNDEFINED);
        assertThat(GEOMETRY.calculateCtrlType(mContext, isTouchscreen, isEdgeResizePermitted,
                BOTTOM_EDGE_POINT.x, BOTTOM_EDGE_POINT.y)).isEqualTo(
                        isEdgeResizePermitted ? CTRL_TYPE_BOTTOM : CTRL_TYPE_UNDEFINED);
                    points.get(i).x, points.get(i).y)).isEqualTo(
                    isEdgeResizePermitted ? expectedCtrlType.get(i) : CTRL_TYPE_UNDEFINED);
        }
    }

    @Test