Merge "Set GroupedTaskView child thumbnails in onMeasure" into sc-v2-dev

This commit is contained in:
Vinit Nayak authored and Android (Google) Code Review committed 2021-09-14 17:34:52 +00:00
commit ca549695aa
5 files changed
+82 -51

No files matched your search

@@ -31,6 +31,7 @@ public class GroupedTaskView extends TaskView {
private Task mSecondaryTask; private Task mSecondaryTask;
private TaskThumbnailView mSnapshotView2; private TaskThumbnailView mSnapshotView2;
private CancellableTask mThumbnailLoadRequest2; private CancellableTask mThumbnailLoadRequest2;
private SplitConfigurationOptions.StagedSplitBounds mSplitBoundsConfig;
public GroupedTaskView(Context context) { public GroupedTaskView(Context context) {
super(context); super(context);
@@ -57,7 +58,7 @@ public class GroupedTaskView extends TaskView {
mTaskIdContainer[1] = secondary.key.id; mTaskIdContainer[1] = secondary.key.id;
mTaskIdAttributeContainer[1] = new TaskIdAttributeContainer(secondary, mSnapshotView2); mTaskIdAttributeContainer[1] = new TaskIdAttributeContainer(secondary, mSnapshotView2);
mSnapshotView2.bind(secondary); mSnapshotView2.bind(secondary);
adjustThumbnailBoundsForSplit(splitBoundsConfig, orientedState); mSplitBoundsConfig = splitBoundsConfig;
} }
@Override @Override
@@ -121,6 +122,21 @@ public class GroupedTaskView extends TaskView {
public void onRecycle() { public void onRecycle() {
super.onRecycle(); super.onRecycle();
mSnapshotView2.setThumbnail(mSecondaryTask, null); mSnapshotView2.setThumbnail(mSecondaryTask, null);
mSplitBoundsConfig = null;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
if (mSplitBoundsConfig == null || mSnapshotView == null || mSnapshotView2 == null) {
return;
}
getPagedOrientationHandler().measureGroupedTaskViewThumbnailBounds(mSnapshotView,
mSnapshotView2, widthSize, heightSize, mSplitBoundsConfig,
mActivity.getDeviceProfile());
} }
@Override @Override
@@ -128,16 +144,4 @@ public class GroupedTaskView extends TaskView {
super.setOverlayEnabled(overlayEnabled); super.setOverlayEnabled(overlayEnabled);
mSnapshotView2.setOverlayEnabled(overlayEnabled); mSnapshotView2.setOverlayEnabled(overlayEnabled);
} }
private void adjustThumbnailBoundsForSplit(
SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig,
RecentsOrientedState orientedState) {
if (splitBoundsConfig == null) {
return;
}
orientedState.getOrientationHandler().setGroupedTaskViewThumbnailBounds(
mSnapshotView, mSnapshotView2, this, splitBoundsConfig,
mActivity.getDeviceProfile());
}
} }
@@ -408,22 +408,30 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler {
} }
@Override @Override
public void setGroupedTaskViewThumbnailBounds(View mSnapshotView, View mSnapshotView2, public void measureGroupedTaskViewThumbnailBounds(View primarySnapshot, View secondarySnapshot,
View taskParent, SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig, int parentWidth, int parentHeight,
DeviceProfile dp) { SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig, DeviceProfile dp) {
int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx; int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx;
int totalThumbnailHeight = taskParent.getHeight() - spaceAboveSnapshot; int totalThumbnailHeight = parentHeight - spaceAboveSnapshot;
int totalThumbnailWidth = taskParent.getWidth();
int dividerBar = splitBoundsConfig.visualDividerBounds.width(); int dividerBar = splitBoundsConfig.visualDividerBounds.width();
ViewGroup.LayoutParams primaryLp = mSnapshotView.getLayoutParams(); int primarySnapshotHeight;
ViewGroup.LayoutParams secondaryLp = mSnapshotView2.getLayoutParams(); int primarySnapshotWidth;
int secondarySnapshotHeight;
int secondarySnapshotWidth;
primaryLp.width = totalThumbnailWidth; primarySnapshotWidth = parentWidth;
primaryLp.height = (int) (totalThumbnailHeight * splitBoundsConfig.leftTaskPercent); primarySnapshotHeight = (int) (totalThumbnailHeight * splitBoundsConfig.leftTaskPercent);
secondaryLp.width = totalThumbnailWidth; secondarySnapshotWidth = parentWidth;
secondaryLp.height = totalThumbnailHeight - primaryLp.height - dividerBar; secondarySnapshotHeight = totalThumbnailHeight - primarySnapshotHeight - dividerBar;
mSnapshotView2.setTranslationY(primaryLp.height + spaceAboveSnapshot + dividerBar); secondarySnapshot.setTranslationY(primarySnapshotHeight + spaceAboveSnapshot + dividerBar);
primarySnapshot.measure(
View.MeasureSpec.makeMeasureSpec(primarySnapshotWidth, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(primarySnapshotHeight, View.MeasureSpec.EXACTLY));
secondarySnapshot.measure(
View.MeasureSpec.makeMeasureSpec(secondarySnapshotWidth, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(secondarySnapshotHeight,
View.MeasureSpec.EXACTLY));
} }
@Override @Override
@@ -162,7 +162,8 @@ public interface PagedOrientationHandler {
SplitConfigurationOptions.StagedSplitBounds splitInfo, SplitConfigurationOptions.StagedSplitBounds splitInfo,
@SplitConfigurationOptions.StagePosition int desiredStagePosition); @SplitConfigurationOptions.StagePosition int desiredStagePosition);
void setGroupedTaskViewThumbnailBounds(View mSnapshot1, View mSnapshot2, View taskParent, void measureGroupedTaskViewThumbnailBounds(View primarySnapshot, View secondarySnapshot,
int parentWidth, int parentHeight,
SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig, DeviceProfile dp); SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig, DeviceProfile dp);
// Overview TaskMenuView methods // Overview TaskMenuView methods
@@ -35,7 +35,6 @@ import android.view.MotionEvent;
import android.view.Surface; import android.view.Surface;
import android.view.VelocityTracker; import android.view.VelocityTracker;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@@ -513,35 +512,46 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler {
} }
@Override @Override
public void setGroupedTaskViewThumbnailBounds(View mSnapshotView, View mSnapshotView2, public void measureGroupedTaskViewThumbnailBounds(View primarySnapshot, View secondarySnapshot,
View taskParent, SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig, int parentWidth, int parentHeight,
DeviceProfile dp) { SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig, DeviceProfile dp) {
int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx; int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx;
int totalThumbnailHeight = taskParent.getHeight() - spaceAboveSnapshot; int totalThumbnailHeight = parentHeight - spaceAboveSnapshot;
int totalThumbnailWidth = taskParent.getWidth(); int dividerBar = (splitBoundsConfig.appsStackedVertically ?
int dividerBar = (dp.isLandscape ? splitBoundsConfig.visualDividerBounds.height() :
splitBoundsConfig.visualDividerBounds.width() : splitBoundsConfig.visualDividerBounds.width());
splitBoundsConfig.visualDividerBounds.height()); int primarySnapshotHeight;
ViewGroup.LayoutParams primaryLp = mSnapshotView.getLayoutParams(); int primarySnapshotWidth;
ViewGroup.LayoutParams secondaryLp = mSnapshotView2.getLayoutParams(); int secondarySnapshotHeight;
int secondarySnapshotWidth;
float taskPercent = splitBoundsConfig.appsStackedVertically ?
splitBoundsConfig.topTaskPercent : splitBoundsConfig.leftTaskPercent;
if (dp.isLandscape) { if (dp.isLandscape) {
primaryLp.height = totalThumbnailHeight; primarySnapshotHeight = totalThumbnailHeight;
primaryLp.width = (int) (totalThumbnailWidth * splitBoundsConfig.leftTaskPercent); primarySnapshotWidth = (int) (parentWidth * taskPercent);
secondaryLp.height = totalThumbnailHeight; secondarySnapshotHeight = totalThumbnailHeight;
secondaryLp.width = totalThumbnailWidth - primaryLp.width - dividerBar; secondarySnapshotWidth = parentWidth - primarySnapshotWidth - dividerBar;
mSnapshotView2.setTranslationX(primaryLp.width + dividerBar); int translationX = primarySnapshotWidth + dividerBar;
mSnapshotView2.setTranslationY(spaceAboveSnapshot); secondarySnapshot.setTranslationX(translationX);
secondarySnapshot.setTranslationY(spaceAboveSnapshot);
} else { } else {
primaryLp.width = totalThumbnailWidth; primarySnapshotWidth = parentWidth;
primaryLp.height = (int) (totalThumbnailHeight * splitBoundsConfig.topTaskPercent); primarySnapshotHeight = (int) (totalThumbnailHeight * taskPercent);
secondaryLp.width = totalThumbnailWidth; secondarySnapshotWidth = parentWidth;
secondaryLp.height = totalThumbnailHeight - primaryLp.height - dividerBar; secondarySnapshotHeight = totalThumbnailHeight - primarySnapshotHeight - dividerBar;
mSnapshotView2.setTranslationY(primaryLp.height + spaceAboveSnapshot + dividerBar); int translationY = primarySnapshotHeight + spaceAboveSnapshot + dividerBar;
mSnapshotView2.setTranslationX(0); secondarySnapshot.setTranslationY(translationY);
secondarySnapshot.setTranslationX(0);
} }
primarySnapshot.measure(
View.MeasureSpec.makeMeasureSpec(primarySnapshotWidth, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(primarySnapshotHeight, View.MeasureSpec.EXACTLY));
secondarySnapshot.measure(
View.MeasureSpec.makeMeasureSpec(secondarySnapshotWidth, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(secondarySnapshotHeight,
View.MeasureSpec.EXACTLY));
} }
@Override @Override
@@ -93,7 +93,13 @@ public final class SplitConfigurationOptions {
// This class is orientation-agnostic, so we compute both for later use // This class is orientation-agnostic, so we compute both for later use
public final float topTaskPercent; public final float topTaskPercent;
public final float leftTaskPercent; public final float leftTaskPercent;
/**
* If {@code true}, that means at the time of creation of this object, the
* split-screened apps were vertically stacked. This is useful in scenarios like
* rotation where the bounds won't change, but this variable can indicate what orientation
* the bounds were originally in
*/
public final boolean appsStackedVertically;
public StagedSplitBounds(Rect leftTopBounds, Rect rightBottomBounds) { public StagedSplitBounds(Rect leftTopBounds, Rect rightBottomBounds) {
this.leftTopBounds = leftTopBounds; this.leftTopBounds = leftTopBounds;
@@ -103,10 +109,12 @@ public final class SplitConfigurationOptions {
// vertical apps, horizontal divider // vertical apps, horizontal divider
this.visualDividerBounds = new Rect(leftTopBounds.left, leftTopBounds.bottom, this.visualDividerBounds = new Rect(leftTopBounds.left, leftTopBounds.bottom,
leftTopBounds.right, rightBottomBounds.top); leftTopBounds.right, rightBottomBounds.top);
appsStackedVertically = true;
} else { } else {
// horizontal apps, vertical divider // horizontal apps, vertical divider
this.visualDividerBounds = new Rect(leftTopBounds.right, leftTopBounds.top, this.visualDividerBounds = new Rect(leftTopBounds.right, leftTopBounds.top,
rightBottomBounds.left, leftTopBounds.bottom); rightBottomBounds.left, leftTopBounds.bottom);
appsStackedVertically = false;
} }
leftTaskPercent = this.leftTopBounds.width() / (float) rightBottomBounds.right; leftTaskPercent = this.leftTopBounds.width() / (float) rightBottomBounds.right;