From b30627adad066229781c422cba562d6ca2eb8d25 Mon Sep 17 00:00:00 2001 From: Ats Jenk Date: Tue, 4 Oct 2022 16:44:53 -0700 Subject: [PATCH] Resize tasks from corners when in touch mode Update task resizing logic for desktop mode. Add a new 44x44dp touch region in each corner of the task that is centered around the corner. This is only used when resizing via touch. This simplifies task resizing with touches and ensures that task resize and back gesture do not conflict. New task resize regions: - with touch: use 44x44dp rect in each corner - with mouse: use 30dp wide task edges TODO: - investigate how to pass taps in touch corners through to app Bug: 251270585 Test: using touches to resize task for corners, check that resizing from edges no longer possible Test: use mouse to resize task from edges Change-Id: Ib1aaf69d2971c29a35200b0f3807871343aa1bf8 --- .../windowdecor/CaptionWindowDecoration.java | 19 +- .../windowdecor/DragResizeInputListener.java | 165 ++++++++++++++++-- .../wm/shell/windowdecor/TaskPositioner.java | 3 +- 3 files changed, 164 insertions(+), 23 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java index 733f6b7d5dbf7..9a9dca05eb335 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java @@ -28,6 +28,7 @@ import android.os.Handler; import android.view.Choreographer; import android.view.SurfaceControl; import android.view.View; +import android.view.ViewConfiguration; import android.window.WindowContainerTransaction; import com.android.wm.shell.R; @@ -55,6 +56,7 @@ public class CaptionWindowDecoration extends WindowDecoration mTouchSlop) { + mDragging = true; + } + } else { + // For all other types allow immediate dragging. + mDragging = true; + } + if (mDragging) { + mCallback.onDragResizeMove(rawX, rawY); + result = true; + } break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { - int dragPointerIndex = e.findPointerIndex(mDragPointerId); - mCallback.onDragResizeEnd( - e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex)); + if (mDragging) { + int dragPointerIndex = e.findPointerIndex(mDragPointerId); + mCallback.onDragResizeEnd( + e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex)); + } + mDragging = false; + mShouldHandleEvents = false; + mActionDownPoint.set(0, 0); mDragPointerId = -1; + result = true; break; } case MotionEvent.ACTION_HOVER_ENTER: case MotionEvent.ACTION_HOVER_MOVE: { updateCursorType(e.getXCursorPosition(), e.getYCursorPosition()); + result = true; break; } case MotionEvent.ACTION_HOVER_EXIT: mInputManager.setPointerIconType(PointerIcon.TYPE_DEFAULT); + result = true; break; } - return true; + return result; + } + + private boolean isInCornerBounds(float xf, float yf) { + return calculateCornersCtrlType(xf, yf) != 0; + } + + private boolean isInResizeHandleBounds(float x, float y) { + return calculateResizeHandlesCtrlType(x, y) != 0; } @TaskPositioner.CtrlType - private int calculateCtrlType(float x, float y) { + private int calculateCtrlType(boolean isTouch, float x, float y) { + if (isTouch) { + return calculateCornersCtrlType(x, y); + } + return calculateResizeHandlesCtrlType(x, y); + } + + @TaskPositioner.CtrlType + private int calculateResizeHandlesCtrlType(float x, float y) { int ctrlType = 0; if (x < mResizeHandleThickness) { ctrlType |= TaskPositioner.CTRL_TYPE_LEFT; @@ -267,8 +383,27 @@ class DragResizeInputListener implements AutoCloseable { return ctrlType; } + @TaskPositioner.CtrlType + private int calculateCornersCtrlType(float x, float y) { + int xi = (int) x; + int yi = (int) y; + if (mLeftTopCornerBounds.contains(xi, yi)) { + return TaskPositioner.CTRL_TYPE_LEFT | TaskPositioner.CTRL_TYPE_TOP; + } + if (mLeftBottomCornerBounds.contains(xi, yi)) { + return TaskPositioner.CTRL_TYPE_LEFT | TaskPositioner.CTRL_TYPE_BOTTOM; + } + if (mRightTopCornerBounds.contains(xi, yi)) { + return TaskPositioner.CTRL_TYPE_RIGHT | TaskPositioner.CTRL_TYPE_TOP; + } + if (mRightBottomCornerBounds.contains(xi, yi)) { + return TaskPositioner.CTRL_TYPE_RIGHT | TaskPositioner.CTRL_TYPE_BOTTOM; + } + return 0; + } + private void updateCursorType(float x, float y) { - @TaskPositioner.CtrlType int ctrlType = calculateCtrlType(x, y); + @TaskPositioner.CtrlType int ctrlType = calculateResizeHandlesCtrlType(x, y); int cursorType = PointerIcon.TYPE_DEFAULT; switch (ctrlType) { @@ -292,4 +427,4 @@ class DragResizeInputListener implements AutoCloseable { mInputManager.setPointerIconType(cursorType); } } -} +} \ No newline at end of file diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/TaskPositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/TaskPositioner.java index 280569b05d870..27c10114ac0ec 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/TaskPositioner.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/TaskPositioner.java @@ -25,9 +25,10 @@ import com.android.wm.shell.ShellTaskOrganizer; class TaskPositioner implements DragResizeCallback { - @IntDef({CTRL_TYPE_LEFT, CTRL_TYPE_RIGHT, CTRL_TYPE_TOP, CTRL_TYPE_BOTTOM}) + @IntDef({CTRL_TYPE_UNDEFINED, CTRL_TYPE_LEFT, CTRL_TYPE_RIGHT, CTRL_TYPE_TOP, CTRL_TYPE_BOTTOM}) @interface CtrlType {} + static final int CTRL_TYPE_UNDEFINED = 0; static final int CTRL_TYPE_LEFT = 1; static final int CTRL_TYPE_RIGHT = 2; static final int CTRL_TYPE_TOP = 4;