Reverting ag/1288123

- Reverts the change to draw the drop targets opposite of the nav bar
- Fixes the issue with the drop divider being occluded by the nav bar
  when the phone is in landscape orientation.  Instead, expand the 
  drag overlay to include the nav bar space.

Bug: 30548794
Change-Id: I70ed3513547e101e49c8eba114a153c5a1f36bee
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 b5753ba..745f5a5 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 @@
                 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 @@
         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
@@ -452,23 +459,11 @@
         }
 
         /**
-         * 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 @@
             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 3ad368c..f2a6310 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 @@
      * 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 4162208..24ef433 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 @@
     private boolean mLastTaskLaunchedWasFreeform;
 
     @ViewDebug.ExportedProperty(category="recents")
-    private Rect mSystemInsets = new Rect();
+    Rect mSystemInsets = new Rect();
     private int mDividerSize;
 
     private Drawable mBackgroundScrim = new ColorDrawable(
@@ -223,13 +223,6 @@
     }
 
     /**
-     * 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.
      */
     public boolean isLastTaskLaunchedFreeform() {
@@ -746,9 +739,10 @@
                         ? 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 55d9964..636d4d6 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsViewTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsViewTouchHandler.java
@@ -45,14 +45,10 @@
  * 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
@@ -120,13 +116,7 @@
         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;
         }
     }
 
@@ -237,7 +227,7 @@
                         // 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;
                             }
                         }
@@ -246,7 +236,7 @@
                         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 21780a6..24e75ac 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 @@
     // 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 @@
 
     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) {