diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java b/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java index b5753ba39a43c..745f5a5a773e6 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java +++ b/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java @@ -275,10 +275,16 @@ public class TaskStack { new RectF(0, 0.5f, 1, 1)); @Override - public boolean acceptsDrop(int x, int y, int width, int height, boolean isCurrentTarget) { - return isCurrentTarget - ? areaContainsPoint(expandedTouchDockArea, width, height, x, y) - : areaContainsPoint(touchArea, width, height, x, y); + public boolean acceptsDrop(int x, int y, int width, int height, Rect insets, + boolean isCurrentTarget) { + if (isCurrentTarget) { + getMappedRect(expandedTouchDockArea, width, height, mTmpRect); + return mTmpRect.contains(x, y); + } else { + getMappedRect(touchArea, width, height, mTmpRect); + updateBoundsWithSystemInsets(mTmpRect, insets); + return mTmpRect.contains(x, y); + } } // Represents the view state of this dock state @@ -423,6 +429,7 @@ public class TaskStack { private final RectF touchArea; private final RectF dockArea; private final RectF expandedTouchDockArea; + private static final Rect mTmpRect = new Rect(); /** * @param createMode used to pass to ActivityManager to dock the task @@ -451,24 +458,12 @@ public class TaskStack { viewState.update(context); } - /** - * Returns whether {@param x} and {@param y} are contained in the area scaled to the - * given {@param width} and {@param height}. - */ - public boolean areaContainsPoint(RectF area, int width, int height, float x, float y) { - int left = (int) (area.left * width); - int top = (int) (area.top * height); - int right = (int) (area.right * width); - int bottom = (int) (area.bottom * height); - return x >= left && y >= top && x <= right && y <= bottom; - } - /** * Returns the docked task bounds with the given {@param width} and {@param height}. */ - public Rect getPreDockedBounds(int width, int height) { - return new Rect((int) (dockArea.left * width), (int) (dockArea.top * height), - (int) (dockArea.right * width), (int) (dockArea.bottom * height)); + public Rect getPreDockedBounds(int width, int height, Rect insets) { + getMappedRect(dockArea, width, height, mTmpRect); + return updateBoundsWithSystemInsets(mTmpRect, insets); } /** @@ -511,10 +506,34 @@ public class TaskStack { int top = dockArea.bottom < 1f ? 0 : insets.top; - layoutAlgorithm.getTaskStackBounds(displayRect, windowRectOut, top, insets.left, - insets.right, taskStackBounds); + // For now, ignore the left insets since we always dock on the left and show Recents + // on the right + layoutAlgorithm.getTaskStackBounds(displayRect, windowRectOut, top, 0, insets.right, + taskStackBounds); return taskStackBounds; } + + /** + * Returns the expanded bounds in certain dock sides such that the bounds account for the + * system insets (namely the vertical nav bar). This call modifies and returns the given + * {@param bounds}. + */ + private Rect updateBoundsWithSystemInsets(Rect bounds, Rect insets) { + if (dockSide == DOCKED_LEFT) { + bounds.right += insets.left; + } else if (dockSide == DOCKED_RIGHT) { + bounds.left -= insets.right; + } + return bounds; + } + + /** + * Returns the mapped rect to the given dimensions. + */ + private void getMappedRect(RectF bounds, int width, int height, Rect out) { + out.set((int) (bounds.left * width), (int) (bounds.top * height), + (int) (bounds.right * width), (int) (bounds.bottom * height)); + } } // A comparator that sorts tasks by their freeform state diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/DropTarget.java b/packages/SystemUI/src/com/android/systemui/recents/views/DropTarget.java index 3ad368cbf60af..f2a631078d3cb 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/DropTarget.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/DropTarget.java @@ -16,6 +16,8 @@ package com.android.systemui.recents.views; +import android.graphics.Rect; + /** * Represents a drop target for a drag gesture. */ @@ -25,5 +27,5 @@ public interface DropTarget { * Returns whether this target can accept this drop. The x,y are relative to the top level * RecentsView, and the width/height are of the RecentsView. */ - boolean acceptsDrop(int x, int y, int width, int height, boolean isCurrentTarget); + boolean acceptsDrop(int x, int y, int width, int height, Rect insets, boolean isCurrentTarget); } diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java index 41622083c7927..24ef433bd4d82 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java @@ -104,7 +104,7 @@ public class RecentsView extends FrameLayout { private boolean mLastTaskLaunchedWasFreeform; @ViewDebug.ExportedProperty(category="recents") - private Rect mSystemInsets = new Rect(); + Rect mSystemInsets = new Rect(); private int mDividerSize; private Drawable mBackgroundScrim = new ColorDrawable( @@ -222,13 +222,6 @@ public class RecentsView extends FrameLayout { return mBackgroundScrim; } - /** - * Returns whether the nav bar is on the right. - */ - public boolean isNavBarOnRight() { - return mSystemInsets.right > 0; - } - /** * Returns whether the last task launched was in the freeform stack or not. */ @@ -746,9 +739,10 @@ public class RecentsView extends FrameLayout { ? overrideHintAlpha : viewState.hintTextAlpha; Rect bounds = isDefaultDockState - ? dockState.getPreDockedBounds(getMeasuredWidth(), getMeasuredHeight()) + ? dockState.getPreDockedBounds(getMeasuredWidth(), getMeasuredHeight(), + mSystemInsets) : dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight(), - mDividerSize, mSystemInsets, getResources()); + mDividerSize, mSystemInsets, getResources()); if (viewState.dockAreaOverlay.getCallback() != this) { viewState.dockAreaOverlay.setCallback(this); viewState.dockAreaOverlay.setBounds(bounds); diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsViewTouchHandler.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsViewTouchHandler.java index 9ff7a68208c9b..265f3197d8daa 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsViewTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsViewTouchHandler.java @@ -47,14 +47,10 @@ import java.util.ArrayList; * Represents the dock regions for each orientation. */ class DockRegion { - // The phone landscape dock states correspond to the opposite end of the screen that the nav bar - // appears - public static TaskStack.DockState[] PHONE_LANDSCAPE_LEFT = { + public static TaskStack.DockState[] PHONE_LANDSCAPE = { + // We only allow docking to the left in landscape for now on small devices TaskStack.DockState.LEFT }; - public static TaskStack.DockState[] PHONE_LANDSCAPE_RIGHT = { - TaskStack.DockState.RIGHT - }; public static TaskStack.DockState[] PHONE_PORTRAIT = { // We only allow docking to the top for now on small devices TaskStack.DockState.TOP @@ -123,13 +119,7 @@ public class RecentsViewTouchHandler { if (config.isLargeScreen) { return isLandscape ? DockRegion.TABLET_LANDSCAPE : DockRegion.TABLET_PORTRAIT; } else { - if (isLandscape) { - return mRv.isNavBarOnRight() - ? DockRegion.PHONE_LANDSCAPE_LEFT - : DockRegion.PHONE_LANDSCAPE_RIGHT; - } else { - return DockRegion.PHONE_PORTRAIT; - } + return isLandscape ? DockRegion.PHONE_LANDSCAPE : DockRegion.PHONE_PORTRAIT; } } @@ -244,7 +234,7 @@ public class RecentsViewTouchHandler { // Give priority to the current drop target to retain the touch handling if (mLastDropTarget != null) { if (mLastDropTarget.acceptsDrop((int) evX, (int) evY, width, height, - true /* isCurrentTarget */)) { + mRv.mSystemInsets, true /* isCurrentTarget */)) { currentDropTarget = mLastDropTarget; } } @@ -253,7 +243,7 @@ public class RecentsViewTouchHandler { if (currentDropTarget == null) { for (DropTarget target : mDropTargets) { if (target.acceptsDrop((int) evX, (int) evY, width, height, - false /* isCurrentTarget */)) { + mRv.mSystemInsets, false /* isCurrentTarget */)) { currentDropTarget = target; break; } diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java index fef05562b98ba..d29fbfd3daa16 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java @@ -218,7 +218,8 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal // The drop targets for a task drag private DropTarget mFreeformWorkspaceDropTarget = new DropTarget() { @Override - public boolean acceptsDrop(int x, int y, int width, int height, boolean isCurrentTarget) { + public boolean acceptsDrop(int x, int y, int width, int height, Rect insets, + boolean isCurrentTarget) { // This drop target has a fixed bounds and should be checked last, so just fall through // if it is the current target if (!isCurrentTarget) { @@ -230,7 +231,8 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal private DropTarget mStackDropTarget = new DropTarget() { @Override - public boolean acceptsDrop(int x, int y, int width, int height, boolean isCurrentTarget) { + public boolean acceptsDrop(int x, int y, int width, int height, Rect insets, + boolean isCurrentTarget) { // This drop target has a fixed bounds and should be checked last, so just fall through // if it is the current target if (!isCurrentTarget) {