Merge "Animate notification corner radius when it is expanding." into sc-dev

This commit is contained in:
Jordan Demeulenaere
2021-03-11 11:16:18 +00:00
committed by Android (Google) Code Review
5 changed files with 64 additions and 23 deletions

View File

@@ -146,17 +146,19 @@ public class ActivityLaunchAnimator {
private final ExpandableNotificationRow mSourceNotification;
private final ExpandAnimationParameters mParams;
private final Rect mWindowCrop = new Rect();
private final float mNotificationCornerRadius;
private float mCornerRadius;
private boolean mIsFullScreenLaunch = true;
private final SyncRtSurfaceTransactionApplier mSyncRtTransactionApplier;
public AnimationRunner(ExpandableNotificationRow sourceNofitication) {
mSourceNotification = sourceNofitication;
private final float mNotificationStartTopCornerRadius;
private final float mNotificationStartBottomCornerRadius;
AnimationRunner(ExpandableNotificationRow sourceNotification) {
mSourceNotification = sourceNotification;
mParams = new ExpandAnimationParameters();
mSyncRtTransactionApplier = new SyncRtSurfaceTransactionApplier(mSourceNotification);
mNotificationCornerRadius = Math.max(mSourceNotification.getCurrentTopRoundness(),
mSourceNotification.getCurrentBottomRoundness());
mNotificationStartTopCornerRadius = mSourceNotification.getCurrentBackgroundRadiusTop();
mNotificationStartBottomCornerRadius =
mSourceNotification.getCurrentBackgroundRadiusBottom();
}
@Override
@@ -224,7 +226,10 @@ public class ActivityLaunchAnimator {
+ notificationHeight,
primary.position.y + primary.sourceContainerBounds.bottom,
progress);
mCornerRadius = MathUtils.lerp(mNotificationCornerRadius,
mParams.topCornerRadius = MathUtils.lerp(mNotificationStartTopCornerRadius,
mWindowCornerRadius, progress);
mParams.bottomCornerRadius = MathUtils.lerp(
mNotificationStartBottomCornerRadius,
mWindowCornerRadius, progress);
applyParamsToWindow(primary);
applyParamsToNotification(mParams);
@@ -309,12 +314,13 @@ public class ActivityLaunchAnimator {
Matrix m = new Matrix();
m.postTranslate(0, (float) (mParams.top - app.position.y));
mWindowCrop.set(mParams.left, 0, mParams.right, mParams.getHeight());
float cornerRadius = Math.min(mParams.topCornerRadius, mParams.bottomCornerRadius);
SurfaceParams params = new SurfaceParams.Builder(app.leash)
.withAlpha(1f)
.withMatrix(m)
.withWindowCrop(mWindowCrop)
.withLayer(app.prefixOrderIndex)
.withCornerRadius(mCornerRadius)
.withCornerRadius(cornerRadius)
.withVisibility(true)
.build();
mSyncRtTransactionApplier.scheduleApply(params);
@@ -339,6 +345,8 @@ public class ActivityLaunchAnimator {
int bottom;
int startClipTopAmount;
int parentStartClipTopAmount;
float topCornerRadius;
float bottomCornerRadius;
public ExpandAnimationParameters() {
}
@@ -389,6 +397,14 @@ public class ActivityLaunchAnimator {
public float getStartTranslationZ() {
return startTranslationZ;
}
public float getTopCornerRadius() {
return topCornerRadius;
}
public float getBottomCornerRadius() {
return bottomCornerRadius;
}
}
public interface Callback {

View File

@@ -883,8 +883,8 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
}
private void applyBackgroundRoundness(float topRadius, float bottomRadius) {
mBackgroundDimmed.setRoundness(topRadius, bottomRadius);
mBackgroundNormal.setRoundness(topRadius, bottomRadius);
mBackgroundDimmed.setRadius(topRadius, bottomRadius);
mBackgroundNormal.setRadius(topRadius, bottomRadius);
}
@Override

View File

@@ -346,6 +346,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
private SystemNotificationAsyncTask mSystemNotificationAsyncTask =
new SystemNotificationAsyncTask();
private float mTopRoundnessDuringExpandAnimation;
private float mBottomRoundnessDuringExpandAnimation;
/**
* Returns whether the given {@code statusBarNotification} is a system notification.
* <b>Note</b>, this should be run in the background thread if possible as it makes multiple IPC
@@ -2009,6 +2012,24 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
return false;
}
@Override
public float getCurrentTopRoundness() {
if (mExpandAnimationRunning) {
return mTopRoundnessDuringExpandAnimation;
}
return super.getCurrentTopRoundness();
}
@Override
public float getCurrentBottomRoundness() {
if (mExpandAnimationRunning) {
return mBottomRoundnessDuringExpandAnimation;
}
return super.getCurrentBottomRoundness();
}
public void applyExpandAnimationParams(ExpandAnimationParameters params) {
if (params == null) {
return;
@@ -2053,6 +2074,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
setTranslationY(top);
setActualHeight(params.getHeight());
mTopRoundnessDuringExpandAnimation = params.getTopCornerRadius() / mOutlineRadius;
mBottomRoundnessDuringExpandAnimation = params.getBottomCornerRadius() / mOutlineRadius;
invalidateOutline();
mBackgroundNormal.setExpandAnimationParams(params);
}

View File

@@ -27,7 +27,6 @@ import android.util.AttributeSet;
import android.view.View;
import android.view.ViewOutlineProvider;
import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.AnimatableProperty;
import com.android.systemui.statusbar.notification.PropertyAnimator;
@@ -83,8 +82,8 @@ public abstract class ExpandableOutlineView extends ExpandableView {
private final ViewOutlineProvider mProvider = new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
if (!mCustomOutline && mCurrentTopRoundness == 0.0f
&& mCurrentBottomRoundness == 0.0f && !mAlwaysRoundBothCorners
if (!mCustomOutline && getCurrentTopRoundness() == 0.0f
&& getCurrentBottomRoundness() == 0.0f && !mAlwaysRoundBothCorners
&& !mTopAmountRounded) {
int translation = mShouldTranslateContents ? (int) getTranslation() : 0;
int left = Math.max(translation, 0);
@@ -135,10 +134,12 @@ public abstract class ExpandableOutlineView extends ExpandableView {
? mOutlineRadius : getCurrentBackgroundRadiusBottom();
if (topRoundness + bottomRoundness > height) {
float overShoot = topRoundness + bottomRoundness - height;
topRoundness -= overShoot * mCurrentTopRoundness
/ (mCurrentTopRoundness + mCurrentBottomRoundness);
bottomRoundness -= overShoot * mCurrentBottomRoundness
/ (mCurrentTopRoundness + mCurrentBottomRoundness);
float currentTopRoundness = getCurrentTopRoundness();
float currentBottomRoundness = getCurrentBottomRoundness();
topRoundness -= overShoot * currentTopRoundness
/ (currentTopRoundness + currentBottomRoundness);
bottomRoundness -= overShoot * currentBottomRoundness
/ (currentTopRoundness + currentBottomRoundness);
}
getRoundedRectPath(left, top, right, bottom, topRoundness, bottomRoundness, mTmpPath);
return mTmpPath;
@@ -267,7 +268,7 @@ public abstract class ExpandableOutlineView extends ExpandableView {
if (mTopAmountRounded) {
return mOutlineRadius;
}
return mCurrentTopRoundness * mOutlineRadius;
return getCurrentTopRoundness() * mOutlineRadius;
}
public float getCurrentTopRoundness() {
@@ -278,8 +279,8 @@ public abstract class ExpandableOutlineView extends ExpandableView {
return mCurrentBottomRoundness;
}
protected float getCurrentBackgroundRadiusBottom() {
return mCurrentBottomRoundness * mOutlineRadius;
public float getCurrentBackgroundRadiusBottom() {
return getCurrentBottomRoundness() * mOutlineRadius;
}
@Override

View File

@@ -224,10 +224,9 @@ public class NotificationBackgroundView extends View {
}
/**
* Sets the current top and bottom roundness amounts for this background, between 0.0 (not
* rounded) and 1.0 (maximally rounded).
* Sets the current top and bottom radius for this background.
*/
public void setRoundness(float topRoundness, float bottomRoundness) {
public void setRadius(float topRoundness, float bottomRoundness) {
if (topRoundness == mCornerRadii[0] && bottomRoundness == mCornerRadii[4]) {
return;
}