Merge "Scale the leash for expand/collpase PiP transition" into rvc-dev
This commit is contained in:
@@ -110,10 +110,6 @@ public class PipAnimationController {
|
|||||||
return mCurrentAnimator;
|
return mCurrentAnimator;
|
||||||
}
|
}
|
||||||
|
|
||||||
PipTransitionAnimator getCurrentAnimator() {
|
|
||||||
return mCurrentAnimator;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PipTransitionAnimator setupPipTransitionAnimator(PipTransitionAnimator animator) {
|
private PipTransitionAnimator setupPipTransitionAnimator(PipTransitionAnimator animator) {
|
||||||
animator.setSurfaceTransactionHelper(mSurfaceTransactionHelper);
|
animator.setSurfaceTransactionHelper(mSurfaceTransactionHelper);
|
||||||
animator.setInterpolator(mFastOutSlowInInterpolator);
|
animator.setInterpolator(mFastOutSlowInInterpolator);
|
||||||
@@ -178,7 +174,7 @@ public class PipAnimationController {
|
|||||||
@Override
|
@Override
|
||||||
public void onAnimationStart(Animator animation) {
|
public void onAnimationStart(Animator animation) {
|
||||||
mCurrentValue = mStartValue;
|
mCurrentValue = mStartValue;
|
||||||
applySurfaceControlTransaction(mLeash, newSurfaceControlTransaction(), FRACTION_START);
|
onStartTransaction(mLeash, newSurfaceControlTransaction());
|
||||||
if (mPipAnimationCallback != null) {
|
if (mPipAnimationCallback != null) {
|
||||||
mPipAnimationCallback.onPipAnimationStart(this);
|
mPipAnimationCallback.onPipAnimationStart(this);
|
||||||
}
|
}
|
||||||
@@ -194,7 +190,7 @@ public class PipAnimationController {
|
|||||||
public void onAnimationEnd(Animator animation) {
|
public void onAnimationEnd(Animator animation) {
|
||||||
mCurrentValue = mEndValue;
|
mCurrentValue = mEndValue;
|
||||||
final SurfaceControl.Transaction tx = newSurfaceControlTransaction();
|
final SurfaceControl.Transaction tx = newSurfaceControlTransaction();
|
||||||
applySurfaceControlTransaction(mLeash, tx, FRACTION_END);
|
onEndTransaction(mLeash, tx);
|
||||||
if (mPipAnimationCallback != null) {
|
if (mPipAnimationCallback != null) {
|
||||||
mPipAnimationCallback.onPipAnimationEnd(tx, this);
|
mPipAnimationCallback.onPipAnimationEnd(tx, this);
|
||||||
}
|
}
|
||||||
@@ -253,6 +249,13 @@ public class PipAnimationController {
|
|||||||
return mTransitionDirection != TRANSITION_DIRECTION_TO_FULLSCREEN;
|
return mTransitionDirection != TRANSITION_DIRECTION_TO_FULLSCREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean inScaleTransition() {
|
||||||
|
if (mAnimationType != ANIM_TYPE_BOUNDS) return false;
|
||||||
|
final int direction = getTransitionDirection();
|
||||||
|
return direction != TRANSITION_DIRECTION_TO_FULLSCREEN
|
||||||
|
&& direction != TRANSITION_DIRECTION_TO_PIP;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the {@link #mEndValue}.
|
* Updates the {@link #mEndValue}.
|
||||||
*
|
*
|
||||||
@@ -284,6 +287,10 @@ public class PipAnimationController {
|
|||||||
mSurfaceTransactionHelper = helper;
|
mSurfaceTransactionHelper = helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {}
|
||||||
|
|
||||||
|
void onEndTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {}
|
||||||
|
|
||||||
abstract void applySurfaceControlTransaction(SurfaceControl leash,
|
abstract void applySurfaceControlTransaction(SurfaceControl leash,
|
||||||
SurfaceControl.Transaction tx, float fraction);
|
SurfaceControl.Transaction tx, float fraction);
|
||||||
|
|
||||||
@@ -297,11 +304,14 @@ public class PipAnimationController {
|
|||||||
final float alpha = getStartValue() * (1 - fraction) + getEndValue() * fraction;
|
final float alpha = getStartValue() * (1 - fraction) + getEndValue() * fraction;
|
||||||
setCurrentValue(alpha);
|
setCurrentValue(alpha);
|
||||||
getSurfaceTransactionHelper().alpha(tx, leash, alpha);
|
getSurfaceTransactionHelper().alpha(tx, leash, alpha);
|
||||||
if (Float.compare(fraction, FRACTION_START) == 0) {
|
tx.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {
|
||||||
getSurfaceTransactionHelper()
|
getSurfaceTransactionHelper()
|
||||||
.crop(tx, leash, getDestinationBounds())
|
.crop(tx, leash, getDestinationBounds())
|
||||||
.round(tx, leash, shouldApplyCornerRadius());
|
.round(tx, leash, shouldApplyCornerRadius());
|
||||||
}
|
|
||||||
tx.apply();
|
tx.apply();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -329,15 +339,30 @@ public class PipAnimationController {
|
|||||||
getCastedFractionValue(start.right, end.right, fraction),
|
getCastedFractionValue(start.right, end.right, fraction),
|
||||||
getCastedFractionValue(start.bottom, end.bottom, fraction));
|
getCastedFractionValue(start.bottom, end.bottom, fraction));
|
||||||
setCurrentValue(mTmpRect);
|
setCurrentValue(mTmpRect);
|
||||||
|
if (inScaleTransition()) {
|
||||||
|
getSurfaceTransactionHelper().scale(tx, leash, start, mTmpRect);
|
||||||
|
} else {
|
||||||
getSurfaceTransactionHelper().crop(tx, leash, mTmpRect);
|
getSurfaceTransactionHelper().crop(tx, leash, mTmpRect);
|
||||||
if (Float.compare(fraction, FRACTION_START) == 0) {
|
}
|
||||||
// Ensure the start condition
|
tx.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {
|
||||||
getSurfaceTransactionHelper()
|
getSurfaceTransactionHelper()
|
||||||
.alpha(tx, leash, 1f)
|
.alpha(tx, leash, 1f)
|
||||||
.round(tx, leash, shouldApplyCornerRadius());
|
.round(tx, leash, shouldApplyCornerRadius());
|
||||||
}
|
|
||||||
tx.apply();
|
tx.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void onEndTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {
|
||||||
|
if (!inScaleTransition()) return;
|
||||||
|
// NOTE: intentionally does not apply the transaction here.
|
||||||
|
// this end transaction should get executed synchronously with the final
|
||||||
|
// WindowContainerTransaction in task organizer
|
||||||
|
getSurfaceTransactionHelper().resetScale(tx, leash, getDestinationBounds());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ package com.android.systemui.pip;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.RectF;
|
||||||
import android.view.SurfaceControl;
|
import android.view.SurfaceControl;
|
||||||
|
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
@@ -35,6 +37,12 @@ public class PipSurfaceTransactionHelper {
|
|||||||
private final boolean mEnableCornerRadius;
|
private final boolean mEnableCornerRadius;
|
||||||
private final int mCornerRadius;
|
private final int mCornerRadius;
|
||||||
|
|
||||||
|
/** for {@link #scale(SurfaceControl.Transaction, SurfaceControl, Rect, Rect)} operation */
|
||||||
|
private final Matrix mTmpTransform = new Matrix();
|
||||||
|
private final float[] mTmpFloat9 = new float[9];
|
||||||
|
private final RectF mTmpSourceRectF = new RectF();
|
||||||
|
private final RectF mTmpDestinationRectF = new RectF();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PipSurfaceTransactionHelper(Context context) {
|
public PipSurfaceTransactionHelper(Context context) {
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
@@ -63,6 +71,31 @@ public class PipSurfaceTransactionHelper {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operates the scale (setMatrix) on a given transaction and leash
|
||||||
|
* @return same {@link PipSurfaceTransactionHelper} instance for method chaining
|
||||||
|
*/
|
||||||
|
PipSurfaceTransactionHelper scale(SurfaceControl.Transaction tx, SurfaceControl leash,
|
||||||
|
Rect sourceBounds, Rect destinationBounds) {
|
||||||
|
mTmpSourceRectF.set(sourceBounds);
|
||||||
|
mTmpDestinationRectF.set(destinationBounds);
|
||||||
|
mTmpTransform.setRectToRect(mTmpSourceRectF, mTmpDestinationRectF, Matrix.ScaleToFit.FILL);
|
||||||
|
tx.setMatrix(leash, mTmpTransform, mTmpFloat9)
|
||||||
|
.setPosition(leash, destinationBounds.left, destinationBounds.top);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the scale (setMatrix) on a given transaction and leash if there's any
|
||||||
|
* @return same {@link PipSurfaceTransactionHelper} instance for method chaining
|
||||||
|
*/
|
||||||
|
PipSurfaceTransactionHelper resetScale(SurfaceControl.Transaction tx, SurfaceControl leash,
|
||||||
|
Rect destinationBounds) {
|
||||||
|
tx.setMatrix(leash, Matrix.IDENTITY_MATRIX, mTmpFloat9)
|
||||||
|
.setPosition(leash, destinationBounds.left, destinationBounds.top);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operates the round corner radius on a given transaction and leash
|
* Operates the round corner radius on a given transaction and leash
|
||||||
* @return same {@link PipSurfaceTransactionHelper} instance for method chaining
|
* @return same {@link PipSurfaceTransactionHelper} instance for method chaining
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
import android.testing.TestableLooper;
|
import android.testing.TestableLooper;
|
||||||
@@ -178,6 +179,12 @@ public class PipAnimationControllerTest extends SysuiTestCase {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SurfaceControl.Transaction setMatrix(SurfaceControl leash, Matrix matrix,
|
||||||
|
float[] float9) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {}
|
public void apply() {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user