Removing some dependency on Launcher UI

Change-Id: Ic1c84880cfe4daa9398b8eb27c3afc0837c5a8ca
diff --git a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
index 989803a..2e5e75e 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
@@ -18,6 +18,7 @@
 import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
 import static com.android.launcher3.anim.Interpolators.ACCEL_2;
 
+import android.content.Context;
 import android.graphics.Rect;
 import android.view.View;
 
@@ -74,15 +75,7 @@
 
     @Override
     public float getVerticalProgress(Launcher launcher) {
-        DeviceProfile grid = launcher.getDeviceProfile();
-        if (!grid.isVerticalBarLayout()) {
-            return 1f;
-        }
-
-        float total = grid.heightPx;
-        float searchHeight = total - grid.availableHeightPx +
-                launcher.getResources().getDimension(R.dimen.all_apps_search_box_full_height);
-        return 1 - (searchHeight / total);
+        return getVerticalProgress(launcher.getDeviceProfile(), launcher);
     }
 
     @Override
@@ -125,4 +118,15 @@
 
         return new float[] {scale, translationX, translationY};
     }
+
+    public static float getVerticalProgress(DeviceProfile grid, Context context) {
+        if (!grid.isVerticalBarLayout()) {
+            return 1f;
+        }
+
+        float total = grid.heightPx;
+        float searchHeight = total - grid.availableHeightPx +
+                context.getResources().getDimension(R.dimen.all_apps_search_box_full_height);
+        return 1 - (searchHeight / total);
+    }
 }
diff --git a/quickstep/src/com/android/quickstep/NavBarSwipeInteractionHandler.java b/quickstep/src/com/android/quickstep/NavBarSwipeInteractionHandler.java
index 3ca1865..2e251d1 100644
--- a/quickstep/src/com/android/quickstep/NavBarSwipeInteractionHandler.java
+++ b/quickstep/src/com/android/quickstep/NavBarSwipeInteractionHandler.java
@@ -33,14 +33,15 @@
 import android.view.ViewTreeObserver.OnPreDrawListener;
 
 import com.android.launcher3.AbstractFloatingView;
+import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.Hotseat;
 import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.LauncherState;
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.anim.AnimationSuccessListener;
 import com.android.launcher3.anim.Interpolators;
-import com.android.launcher3.dragndrop.DragLayer;
 import com.android.launcher3.states.InternalStateHandler;
 import com.android.launcher3.uioverrides.RecentsViewStateController;
 import com.android.launcher3.util.TraceHelper;
@@ -112,6 +113,15 @@
         mContext = context;
         WindowManagerWrapper.getInstance().getStableInsets(mStableInsets);
 
+        DeviceProfile dp = LauncherAppState.getIDP(mContext).getDeviceProfile(mContext);
+        // TODO: If in multi window mode, dp = dp.getMultiWindowProfile()
+        dp = dp.copy(mContext);
+        // TODO: Use different insets for multi-window mode
+        dp.updateInsets(mStableInsets);
+        RecentsView.getPageRect(dp, mContext, mTargetRect);
+        mSourceRect.set(0, 0, dp.widthPx - mStableInsets.left - mStableInsets.right,
+                dp.heightPx - mStableInsets.top - mStableInsets.bottom);
+
         // Build the state callback
         mStateCallback = new MultiStateCallback();
         mStateCallback.addCallback(STATE_LAUNCHER_READY, this::onLauncherReady);
@@ -218,13 +228,6 @@
             return;
         }
 
-        if (mTargetRect.isEmpty()) {
-            RecentsView.getPageRect(mLauncher, mTargetRect);
-            DragLayer dl = mLauncher.getDragLayer();
-            mSourceRect.set(0, 0, dl.getWidth() - mStableInsets.left - mStableInsets.right,
-                    dl.getHeight() - mStableInsets.top - mStableInsets.bottom);
-        }
-
         float shift = mCurrentShift.value * mActivityMultiplier.value;
         int hotseatSize = getHotseatSize();
 
diff --git a/quickstep/src/com/android/quickstep/RecentsView.java b/quickstep/src/com/android/quickstep/RecentsView.java
index e7e794f..0ea5b7c 100644
--- a/quickstep/src/com/android/quickstep/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/RecentsView.java
@@ -29,6 +29,7 @@
 import com.android.launcher3.PagedView;
 import com.android.launcher3.R;
 import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.uioverrides.OverviewState;
 import com.android.launcher3.uioverrides.RecentsViewStateController;
 import com.android.systemui.shared.recents.model.RecentsTaskLoadPlan;
 import com.android.systemui.shared.recents.model.RecentsTaskLoader;
@@ -106,7 +107,8 @@
     protected void onFinishInflate() {
         super.onFinishInflate();
 
-        Rect padding = getPadding(Launcher.getLauncher(getContext()));
+        Rect padding =
+                getPadding(Launcher.getLauncher(getContext()).getDeviceProfile(), getContext());
         setPadding(padding.left, padding.top, padding.right, padding.bottom);
 
         mFirstTaskIndex = getPageCount();
@@ -213,8 +215,7 @@
         }
     }
 
-    private static Rect getPadding(Launcher launcher) {
-        DeviceProfile profile = launcher.getDeviceProfile();
+    private static Rect getPadding(DeviceProfile profile, Context context) {
         Rect stableInsets = new Rect();
         WindowManagerWrapper.getInstance().getStableInsets(stableInsets);
         Rect padding = new Rect(profile.workspacePadding);
@@ -228,7 +229,7 @@
             float availableWidth = taskWidth - 2 * Math.max(padding.left, padding.right);
             float availableHeight = profile.availableHeightPx - padding.top - padding.bottom
                     - stableInsets.top
-                    - profile.heightPx * (1 - OVERVIEW.getVerticalProgress(launcher));
+                    - profile.heightPx * (1 - OverviewState.getVerticalProgress(profile, context));
 
             float scaledRatio = Math.min(availableWidth / taskWidth, availableHeight / taskHeight);
             overviewHeight = taskHeight * scaledRatio;
@@ -247,15 +248,18 @@
     }
 
     public static void getPageRect(Launcher launcher, Rect outRect) {
-        DragLayer dl = launcher.getDragLayer();
-        Rect targetPadding = getPadding(launcher);
-        Rect insets = dl.getInsets();
+        getPageRect(launcher.getDeviceProfile(), launcher, outRect);
+    }
+
+    public static void getPageRect(DeviceProfile grid, Context context, Rect outRect) {
+        Rect targetPadding = getPadding(grid, context);
+        Rect insets = grid.getInsets();
         outRect.set(
                 targetPadding.left + insets.left,
                 targetPadding.top + insets.top,
-                dl.getWidth() - targetPadding.right - insets.right,
-                dl.getHeight() - targetPadding.bottom - insets.bottom);
-        outRect.top += launcher.getResources()
+                grid.widthPx - targetPadding.right - insets.right,
+                grid.heightPx - targetPadding.bottom - insets.bottom);
+        outRect.top += context.getResources()
                 .getDimensionPixelSize(R.dimen.task_thumbnail_top_margin);
     }
 
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 75e2f70..7a6a244 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -214,6 +214,11 @@
         mBadgeRenderer = new BadgeRenderer(iconSizePx);
     }
 
+    public DeviceProfile copy(Context context) {
+        Point size = new Point(availableWidthPx, availableHeightPx);
+        return new DeviceProfile(context, inv, size, size, widthPx, heightPx, isLandscape);
+    }
+
     DeviceProfile getMultiWindowProfile(Context context, Point mwSize) {
         // We take the minimum sizes of this profile and it's multi-window variant to ensure that
         // the system decor is always excluded.
@@ -376,6 +381,10 @@
         updateWorkspacePadding();
     }
 
+    public Rect getInsets() {
+        return mInsets;
+    }
+
     public void updateAppsViewNumCols() {
         allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns;
     }
@@ -509,6 +518,5 @@
         Configuration context = new Configuration(c.getResources().getConfiguration());
         context.orientation = orientation;
         return c.createConfigurationContext(context);
-
     }
 }