Relayout resize veil before showing

Currently, the resize veil is shown without being updated. This calls
relayout on the resize veil before making it visible.

Bug: 279828760
Test: Open task in freeform and start to resize. App icon should be
centered.

Change-Id: I92d9b65eec554f0d43b79888f7a61bdfc11875a2
This commit is contained in:
Maryam Dehaini
2023-05-04 15:26:47 -07:00
parent 6d824ea830
commit 393c362438
4 changed files with 24 additions and 13 deletions

View File

@@ -296,15 +296,15 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
/**
* Fade in the resize veil
*/
void showResizeVeil() {
mResizeVeil.showVeil(mTaskSurface);
void showResizeVeil(Rect taskBounds) {
mResizeVeil.showVeil(mTaskSurface, taskBounds);
}
/**
* Set new bounds for the resize veil
*/
void updateResizeVeil(Rect newBounds) {
mResizeVeil.relayout(newBounds);
mResizeVeil.updateResizeVeil(newBounds);
}
/**

View File

@@ -104,7 +104,7 @@ public class ResizeVeil {
/**
* Animate veil's alpha to 1, fading it in.
*/
public void showVeil(SurfaceControl parentSurface) {
public void showVeil(SurfaceControl parentSurface, Rect taskBounds) {
// Parent surface can change, ensure it is up to date.
SurfaceControl.Transaction t = mSurfaceControlTransactionSupplier.get();
if (!parentSurface.equals(mParentSurface)) {
@@ -115,8 +115,6 @@ public class ResizeVeil {
int backgroundColorId = getBackgroundColorId();
mViewHost.getView().setBackgroundColor(mContext.getColor(backgroundColorId));
t.show(mVeilSurface)
.apply();
final ValueAnimator animator = new ValueAnimator();
animator.setFloatValues(0f, 1f);
animator.setDuration(RESIZE_ALPHA_DURATION);
@@ -124,19 +122,32 @@ public class ResizeVeil {
t.setAlpha(mVeilSurface, animator.getAnimatedFraction());
t.apply();
});
animator.start();
relayout(taskBounds, t);
t.show(mVeilSurface)
.addTransactionCommittedListener(mContext.getMainExecutor(), () -> animator.start())
.setAlpha(mVeilSurface, 0);
mViewHost.getView().getViewRootImpl().applyTransactionOnDraw(t);
}
/**
* Update veil bounds to match bounds changes.
* @param newBounds bounds to update veil to.
*/
public void relayout(Rect newBounds) {
SurfaceControl.Transaction t = mSurfaceControlTransactionSupplier.get();
private void relayout(Rect newBounds, SurfaceControl.Transaction t) {
mViewHost.relayout(newBounds.width(), newBounds.height());
t.setWindowCrop(mVeilSurface, newBounds.width(), newBounds.height());
t.setPosition(mParentSurface, newBounds.left, newBounds.top);
t.setWindowCrop(mParentSurface, newBounds.width(), newBounds.height());
}
/**
* Calls relayout to update task and veil bounds.
* @param newBounds bounds to update veil to.
*/
public void updateResizeVeil(Rect newBounds) {
SurfaceControl.Transaction t = mSurfaceControlTransactionSupplier.get();
relayout(newBounds, t);
mViewHost.getView().getViewRootImpl().applyTransactionOnDraw(t);
}

View File

@@ -77,7 +77,7 @@ public class VeiledResizeTaskPositioner implements DragPositioningCallback {
mDesktopWindowDecoration.mTaskInfo.configuration.windowConfiguration.getBounds());
mRepositionStartPoint.set(x, y);
if (isResizing()) {
mDesktopWindowDecoration.showResizeVeil();
mDesktopWindowDecoration.showResizeVeil(mTaskBoundsAtDragStart);
if (!mDesktopWindowDecoration.mTaskInfo.isFocused) {
WindowContainerTransaction wct = new WindowContainerTransaction();
wct.reorder(mDesktopWindowDecoration.mTaskInfo.token, true);

View File

@@ -123,7 +123,7 @@ class VeiledResizeTaskPositionerTest : ShellTestCase() {
STARTING_BOUNDS.left.toFloat(),
STARTING_BOUNDS.top.toFloat()
)
verify(mockDesktopWindowDecoration).showResizeVeil()
verify(mockDesktopWindowDecoration).showResizeVeil(STARTING_BOUNDS)
taskPositioner.onDragPositioningEnd(
STARTING_BOUNDS.left.toFloat(),
@@ -180,7 +180,7 @@ class VeiledResizeTaskPositionerTest : ShellTestCase() {
STARTING_BOUNDS.right.toFloat(),
STARTING_BOUNDS.top.toFloat()
)
verify(mockDesktopWindowDecoration).showResizeVeil()
verify(mockDesktopWindowDecoration).showResizeVeil(STARTING_BOUNDS)
taskPositioner.onDragPositioningMove(
STARTING_BOUNDS.right.toFloat() + 10,
@@ -224,7 +224,7 @@ class VeiledResizeTaskPositionerTest : ShellTestCase() {
STARTING_BOUNDS.left.toFloat(),
STARTING_BOUNDS.top.toFloat()
)
verify(mockDesktopWindowDecoration).showResizeVeil()
verify(mockDesktopWindowDecoration).showResizeVeil(STARTING_BOUNDS)
taskPositioner.onDragPositioningMove(
STARTING_BOUNDS.left.toFloat(),