Merge "Scale screenWidth for split proportionally for thumbnail matrix" into tm-qpr-dev

This commit is contained in:
Vinit Nayak
2022-10-20 22:49:54 +00:00
committed by Android (Google) Code Review
2 changed files with 51 additions and 8 deletions

View File

@@ -33,6 +33,8 @@ public class SplitBounds implements Parcelable {
// 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;
public final float dividerWidthPercent;
public final float dividerHeightPercent;
/** /**
* If {@code true}, that means at the time of creation of this object, the * 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 * split-screened apps were vertically stacked. This is useful in scenarios like
@@ -62,8 +64,12 @@ public class SplitBounds implements Parcelable {
appsStackedVertically = false; appsStackedVertically = false;
} }
leftTaskPercent = this.leftTopBounds.width() / (float) rightBottomBounds.right; float totalWidth = rightBottomBounds.right - leftTopBounds.left;
topTaskPercent = this.leftTopBounds.height() / (float) rightBottomBounds.bottom; float totalHeight = rightBottomBounds.bottom - leftTopBounds.top;
leftTaskPercent = leftTopBounds.width() / totalWidth;
topTaskPercent = leftTopBounds.height() / totalHeight;
dividerWidthPercent = visualDividerBounds.width() / totalWidth;
dividerHeightPercent = visualDividerBounds.height() / totalHeight;
} }
public SplitBounds(Parcel parcel) { public SplitBounds(Parcel parcel) {
@@ -75,6 +81,8 @@ public class SplitBounds implements Parcelable {
appsStackedVertically = parcel.readBoolean(); appsStackedVertically = parcel.readBoolean();
leftTopTaskId = parcel.readInt(); leftTopTaskId = parcel.readInt();
rightBottomTaskId = parcel.readInt(); rightBottomTaskId = parcel.readInt();
dividerWidthPercent = parcel.readInt();
dividerHeightPercent = parcel.readInt();
} }
@Override @Override
@@ -87,6 +95,8 @@ public class SplitBounds implements Parcelable {
parcel.writeBoolean(appsStackedVertically); parcel.writeBoolean(appsStackedVertically);
parcel.writeInt(leftTopTaskId); parcel.writeInt(leftTopTaskId);
parcel.writeInt(rightBottomTaskId); parcel.writeInt(rightBottomTaskId);
parcel.writeFloat(dividerWidthPercent);
parcel.writeFloat(dividerHeightPercent);
} }
@Override @Override

View File

@@ -1,13 +1,16 @@
package com.android.systemui.shared.recents.utilities; package com.android.systemui.shared.recents.utilities;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.view.Surface.ROTATION_180;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.RectF; import android.graphics.RectF;
import android.view.Surface;
import com.android.systemui.shared.recents.model.ThumbnailData; import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.wm.shell.util.SplitBounds;
/** /**
* Utility class to position the thumbnail in the TaskView * Utility class to position the thumbnail in the TaskView
@@ -16,10 +19,26 @@ public class PreviewPositionHelper {
public static final float MAX_PCT_BEFORE_ASPECT_RATIOS_CONSIDERED_DIFFERENT = 0.1f; public static final float MAX_PCT_BEFORE_ASPECT_RATIOS_CONSIDERED_DIFFERENT = 0.1f;
/**
* Specifies that a stage is positioned at the top half of the screen if
* in portrait mode or at the left half of the screen if in landscape mode.
* TODO(b/254378592): Remove after consolidation
*/
public static final int STAGE_POSITION_TOP_OR_LEFT = 0;
/**
* Specifies that a stage is positioned at the bottom half of the screen if
* in portrait mode or at the right half of the screen if in landscape mode.
* TODO(b/254378592): Remove after consolidation
*/
public static final int STAGE_POSITION_BOTTOM_OR_RIGHT = 1;
// Contains the portion of the thumbnail that is unclipped when fullscreen progress = 1. // Contains the portion of the thumbnail that is unclipped when fullscreen progress = 1.
private final RectF mClippedInsets = new RectF(); private final RectF mClippedInsets = new RectF();
private final Matrix mMatrix = new Matrix(); private final Matrix mMatrix = new Matrix();
private boolean mIsOrientationChanged; private boolean mIsOrientationChanged;
private SplitBounds mSplitBounds;
private int mDesiredStagePosition;
public Matrix getMatrix() { public Matrix getMatrix() {
return mMatrix; return mMatrix;
@@ -33,6 +52,11 @@ public class PreviewPositionHelper {
return mIsOrientationChanged; return mIsOrientationChanged;
} }
public void setSplitBounds(SplitBounds splitBounds, int desiredStagePosition) {
mSplitBounds = splitBounds;
mDesiredStagePosition = desiredStagePosition;
}
/** /**
* Updates the matrix based on the provided parameters * Updates the matrix based on the provided parameters
*/ */
@@ -42,10 +66,19 @@ public class PreviewPositionHelper {
boolean isRotated = false; boolean isRotated = false;
boolean isOrientationDifferent; boolean isOrientationDifferent;
float fullscreenTaskWidth = screenWidthPx;
if (mSplitBounds != null && !mSplitBounds.appsStackedVertically) {
// For landscape, scale the width
float taskPercent = mDesiredStagePosition == STAGE_POSITION_TOP_OR_LEFT
? mSplitBounds.leftTaskPercent
: (1 - (mSplitBounds.leftTaskPercent + mSplitBounds.dividerWidthPercent));
// Scale landscape width to that of actual screen
fullscreenTaskWidth = screenWidthPx * taskPercent;
}
int thumbnailRotation = thumbnailData.rotation; int thumbnailRotation = thumbnailData.rotation;
int deltaRotate = getRotationDelta(currentRotation, thumbnailRotation); int deltaRotate = getRotationDelta(currentRotation, thumbnailRotation);
RectF thumbnailClipHint = new RectF(); RectF thumbnailClipHint = new RectF();
float canvasScreenRatio = canvasWidth / (float) screenWidthPx; float canvasScreenRatio = canvasWidth / fullscreenTaskWidth;
float scaledTaskbarSize = taskbarSize * canvasScreenRatio; float scaledTaskbarSize = taskbarSize * canvasScreenRatio;
thumbnailClipHint.bottom = isTablet ? scaledTaskbarSize : 0; thumbnailClipHint.bottom = isTablet ? scaledTaskbarSize : 0;
@@ -180,7 +213,7 @@ public class PreviewPositionHelper {
* portrait or vice versa, {@code false} otherwise * portrait or vice versa, {@code false} otherwise
*/ */
private boolean isOrientationChange(int deltaRotation) { private boolean isOrientationChange(int deltaRotation) {
return deltaRotation == Surface.ROTATION_90 || deltaRotation == Surface.ROTATION_270; return deltaRotation == ROTATION_90 || deltaRotation == ROTATION_270;
} }
private void setThumbnailRotation(int deltaRotate, Rect thumbnailPosition) { private void setThumbnailRotation(int deltaRotate, Rect thumbnailPosition) {
@@ -189,13 +222,13 @@ public class PreviewPositionHelper {
mMatrix.setRotate(90 * deltaRotate); mMatrix.setRotate(90 * deltaRotate);
switch (deltaRotate) { /* Counter-clockwise */ switch (deltaRotate) { /* Counter-clockwise */
case Surface.ROTATION_90: case ROTATION_90:
translateX = thumbnailPosition.height(); translateX = thumbnailPosition.height();
break; break;
case Surface.ROTATION_270: case ROTATION_270:
translateY = thumbnailPosition.width(); translateY = thumbnailPosition.width();
break; break;
case Surface.ROTATION_180: case ROTATION_180:
translateX = thumbnailPosition.width(); translateX = thumbnailPosition.width();
translateY = thumbnailPosition.height(); translateY = thumbnailPosition.height();
break; break;