Set thumbnails for GroupedTaskView based on split layout bounds

Bug: 181704764
Test: Go to stage split in landscape w/
home rotation on/off, swipe up.
Thumbnails aren't perfectly overlaid, polish needed

Change-Id: I54e39cc5a18f527e80a664d60aca72dfd706ebdc
diff --git a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
index cd20f4b..1bc7c75 100644
--- a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
+++ b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
@@ -1,13 +1,10 @@
 package com.android.quickstep.views;
 
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
-
 import android.content.Context;
 import android.util.AttributeSet;
-import android.view.ViewGroup;
 
-import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.R;
+import com.android.launcher3.util.SplitConfigurationOptions;
 import com.android.quickstep.RecentsModel;
 import com.android.quickstep.TaskThumbnailCache;
 import com.android.quickstep.util.CancellableTask;
@@ -48,13 +45,14 @@
         mSnapshotView2 = findViewById(R.id.bottomright_snapshot);
     }
 
-    public void bind(Task primary, Task secondary, RecentsOrientedState orientedState) {
+    public void bind(Task primary, Task secondary, RecentsOrientedState orientedState,
+            SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig) {
         super.bind(primary, orientedState);
         mSecondaryTask = secondary;
         mTaskIdContainer[1] = secondary.key.id;
         mTaskIdAttributeContainer[1] = new TaskIdAttributeContainer(secondary, mSnapshotView2);
         mSnapshotView2.bind(secondary);
-        adjustThumbnailBoundsForSplit();
+        adjustThumbnailBoundsForSplit(splitBoundsConfig, orientedState);
     }
 
     @Override
@@ -108,30 +106,15 @@
         mSnapshotView2.setOverlayEnabled(overlayEnabled);
     }
 
-    private void adjustThumbnailBoundsForSplit() {
-        DeviceProfile deviceProfile = mActivity.getDeviceProfile();
-        ViewGroup.LayoutParams primaryLp = mSnapshotView.getLayoutParams();
-        primaryLp.width = mSecondaryTask == null ?
-                MATCH_PARENT :
-                getWidth();
-        int spaceAboveSnapshot = deviceProfile.overviewTaskThumbnailTopMarginPx;
-        // TODO get divider height
-        int dividerBar = 20;
-        primaryLp.height = mSecondaryTask == null ?
-                MATCH_PARENT :
-                (getHeight() - spaceAboveSnapshot - dividerBar) / 2;
-        mSnapshotView.setLayoutParams(primaryLp);
-
-        if (mSecondaryTask == null) {
-            mSnapshotView2.setVisibility(GONE);
+    private void adjustThumbnailBoundsForSplit(
+            SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig,
+            RecentsOrientedState orientedState) {
+        if (splitBoundsConfig == null) {
             return;
         }
 
-        mSnapshotView2.setVisibility(VISIBLE);
-        ViewGroup.LayoutParams secondaryLp = mSnapshotView2.getLayoutParams();
-        secondaryLp.width = getWidth();
-        secondaryLp.height = primaryLp.height;
-        mSnapshotView2.setLayoutParams(secondaryLp);
-        mSnapshotView2.setTranslationY(primaryLp.height + spaceAboveSnapshot + dividerBar);
+        orientedState.getOrientationHandler().setGroupedTaskViewThumbnailBounds(
+                mSnapshotView, mSnapshotView2, this, splitBoundsConfig,
+                mActivity.getDeviceProfile());
     }
 }
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index abeadfd..763dbfb 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -575,6 +575,7 @@
      */
     private TaskView mSplitHiddenTaskView;
     private TaskView mSecondSplitHiddenTaskView;
+    private SplitConfigurationOptions.StagedSplitBounds mSplitBoundsConfig;
 
     /**
      * Keeps track of the index of the TaskView that split screen was initialized with so we know
@@ -1314,7 +1315,8 @@
                     taskDataIndex--;
                     leftTop = tasks.get(taskDataIndex);
                 }
-                ((GroupedTaskView) taskView).bind(leftTop, rightBottom, mOrientationState);
+                ((GroupedTaskView) taskView).bind(leftTop, rightBottom, mOrientationState,
+                        mSplitBoundsConfig);
             } else {
                 taskView.bind(task, mOrientationState);
             }
@@ -2087,8 +2089,11 @@
                         Task.from(new TaskKey(secondaryTaskInfo), secondaryTaskInfo, false)
                 };
                 addView(taskView, mTaskViewStartIndex);
+                // When we create a placeholder task view mSplitBoundsConfig will be null, but with
+                // the actual app running we won't need to show the thumbnail until all the tasks
+                // load later anyways
                 ((GroupedTaskView)taskView).bind(mTmpRunningTasks[0], mTmpRunningTasks[1],
-                        mOrientationState);
+                        mOrientationState, mSplitBoundsConfig);
             } else {
                 taskView = getTaskViewFromPool(false);
                 addView(taskView, mTaskViewStartIndex);
@@ -4038,12 +4043,13 @@
                     recentsAnimationTargets.getNonAppTargetOfType(TYPE_DOCK_DIVIDER);
             RemoteAnimationTargetCompat primaryTaskTarget = recentsAnimationTargets.apps[0];
             RemoteAnimationTargetCompat secondaryTaskTarget = recentsAnimationTargets.apps[1];
-            SplitConfigurationOptions.StagedSplitBounds
-                    info = new SplitConfigurationOptions.StagedSplitBounds(
+            mSplitBoundsConfig = new SplitConfigurationOptions.StagedSplitBounds(
                     primaryTaskTarget.screenSpaceBounds,
                     secondaryTaskTarget.screenSpaceBounds, dividerTarget.screenSpaceBounds);
-            mRemoteTargetHandles[0].mTaskViewSimulator.setPreview(primaryTaskTarget, info);
-            mRemoteTargetHandles[1].mTaskViewSimulator.setPreview(secondaryTaskTarget, info);
+            mRemoteTargetHandles[0].mTaskViewSimulator.setPreview(primaryTaskTarget,
+                    mSplitBoundsConfig);
+            mRemoteTargetHandles[1].mTaskViewSimulator.setPreview(secondaryTaskTarget,
+                    mSplitBoundsConfig);
             RemoteAnimationTargets rats = new RemoteAnimationTargets(
                     new RemoteAnimationTargetCompat[]{primaryTaskTarget},
                     recentsAnimationTargets.wallpapers, recentsAnimationTargets.nonApps,
diff --git a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
index f386ac1..0304a4e 100644
--- a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
+++ b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
@@ -36,6 +36,7 @@
 import android.view.Surface;
 import android.view.VelocityTracker;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityEvent;
 import android.widget.LinearLayout;
 
@@ -406,6 +407,25 @@
     }
 
     @Override
+    public void setGroupedTaskViewThumbnailBounds(View mSnapshotView, View mSnapshotView2,
+            View taskParent, SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig,
+            DeviceProfile dp) {
+        int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx;
+        int totalThumbnailHeight = taskParent.getHeight() - spaceAboveSnapshot;
+        int totalThumbnailWidth = taskParent.getWidth();
+        int dividerBar = splitBoundsConfig.mDividerBounds.width() / 2;
+        ViewGroup.LayoutParams primaryLp = mSnapshotView.getLayoutParams();
+        ViewGroup.LayoutParams secondaryLp = mSnapshotView2.getLayoutParams();
+
+        primaryLp.width = totalThumbnailWidth;
+        primaryLp.height = (int)(totalThumbnailHeight * splitBoundsConfig.mLeftTaskPercent);
+
+        secondaryLp.width = totalThumbnailWidth;
+        secondaryLp.height = totalThumbnailHeight - primaryLp.height - dividerBar;
+        mSnapshotView2.setTranslationY(primaryLp.height + spaceAboveSnapshot + dividerBar);
+    }
+
+    @Override
     public FloatProperty getSplitSelectTaskOffset(FloatProperty primary, FloatProperty secondary,
             DeviceProfile deviceProfile) {
         return primary;
diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java
index 28ce92b..5ef6950 100644
--- a/src/com/android/launcher3/touch/PagedOrientationHandler.java
+++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java
@@ -160,6 +160,9 @@
             SplitConfigurationOptions.StagedSplitBounds splitInfo,
             @SplitConfigurationOptions.StagePosition int desiredStagePosition);
 
+    void setGroupedTaskViewThumbnailBounds(View mSnapshot1, View mSnapshot2, View taskParent,
+            SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig, DeviceProfile dp);
+
     // Overview TaskMenuView methods
     float getTaskMenuX(float x, View thumbnailView, int overScroll);
     float getTaskMenuY(float y, View thumbnailView, int overScroll);
diff --git a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
index ef6fe53..bc3c0bf 100644
--- a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
+++ b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
@@ -35,6 +35,7 @@
 import android.view.Surface;
 import android.view.VelocityTracker;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityEvent;
 import android.widget.LinearLayout;
 
@@ -508,6 +509,39 @@
     }
 
     @Override
+    public void setGroupedTaskViewThumbnailBounds(View mSnapshotView, View mSnapshotView2,
+            View taskParent, SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig,
+            DeviceProfile dp) {
+        int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx;
+        int totalThumbnailHeight = taskParent.getHeight() - spaceAboveSnapshot;
+        int totalThumbnailWidth = taskParent.getWidth();
+        int dividerBar = (dp.isLandscape ?
+                splitBoundsConfig.mDividerBounds.width() :
+                splitBoundsConfig.mDividerBounds.height())
+                / 2;
+        ViewGroup.LayoutParams primaryLp = mSnapshotView.getLayoutParams();
+        ViewGroup.LayoutParams secondaryLp = mSnapshotView2.getLayoutParams();
+
+        if (dp.isLandscape) {
+            primaryLp.height = totalThumbnailHeight;
+            primaryLp.width = (int)(totalThumbnailWidth * splitBoundsConfig.mLeftTaskPercent);
+
+            secondaryLp.height = totalThumbnailHeight;
+            secondaryLp.width = totalThumbnailWidth - primaryLp.width - dividerBar;
+            mSnapshotView2.setTranslationX(primaryLp.width + dividerBar);
+            mSnapshotView2.setTranslationY(spaceAboveSnapshot);
+        } else {
+            primaryLp.width = totalThumbnailWidth;
+            primaryLp.height = (int)(totalThumbnailHeight * splitBoundsConfig.mTopTaskPercent);
+
+            secondaryLp.width = totalThumbnailWidth;
+            secondaryLp.height = totalThumbnailHeight - primaryLp.height - dividerBar;
+            mSnapshotView2.setTranslationY(primaryLp.height + spaceAboveSnapshot + dividerBar);
+            mSnapshotView2.setTranslationX(0);
+        }
+    }
+
+    @Override
     public FloatProperty getSplitSelectTaskOffset(FloatProperty primary, FloatProperty secondary,
             DeviceProfile dp) {
         if (dp.isLandscape) { // or seascape