Merge "Factor out roundness updates on scroll" into sc-dev am: 7f626aed7d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14688344

Change-Id: Idde5e954d053db24191335a6eaa4a47dfdec3546
This commit is contained in:
Lyn Han
2021-05-24 20:38:17 +00:00
committed by Automerger Merge Worker

View File

@@ -255,7 +255,6 @@ public class NotificationShelf extends ActivatableNotificationView implements
int backgroundTop = 0; int backgroundTop = 0;
int clipTopAmount = 0; int clipTopAmount = 0;
float firstElementRoundness = 0.0f; float firstElementRoundness = 0.0f;
ActivatableNotificationView previousAnv = null;
for (int i = 0; i < mHostLayoutController.getChildCount(); i++) { for (int i = 0; i < mHostLayoutController.getChildCount(); i++) {
ExpandableView child = mHostLayoutController.getChildAt(i); ExpandableView child = mHostLayoutController.getChildAt(i);
@@ -327,52 +326,10 @@ public class NotificationShelf extends ActivatableNotificationView implements
notGoneIndex++; notGoneIndex++;
} }
final float viewEnd = viewStart + child.getActualHeight();
final float cornerAnimationDistance = mCornerAnimationDistance
* mAmbientState.getExpansionFraction();
final float cornerAnimationTop = shelfStart - cornerAnimationDistance;
if (child instanceof ActivatableNotificationView) { if (child instanceof ActivatableNotificationView) {
ActivatableNotificationView anv = ActivatableNotificationView anv =
(ActivatableNotificationView) child; (ActivatableNotificationView) child;
updateCornerRoundnessOnScroll(anv, viewStart, shelfStart);
final boolean isUnlockedHeadsUp = !mAmbientState.isOnKeyguard()
&& !mAmbientState.isShadeExpanded()
&& child instanceof ExpandableView
&& ((ExpandableNotificationRow) child).isHeadsUp();
if (viewStart < shelfStart
&& !mHostLayoutController.isViewAffectedBySwipe(anv)
&& !isUnlockedHeadsUp
&& !mAmbientState.isPulsing()
&& !mAmbientState.isDozing()) {
if (viewEnd >= cornerAnimationTop) {
// Round bottom corners within animation bounds
final float changeFraction = MathUtils.saturate(
(viewEnd - cornerAnimationTop) / cornerAnimationDistance);
final float roundness = anv.isLastInSection() ? 1f : changeFraction * 1f;
anv.setBottomRoundness(roundness, false);
} else if (viewEnd < cornerAnimationTop) {
// Fast scroll skips frames and leaves corners with unfinished rounding.
// Reset top and bottom corners outside of animation bounds.
anv.setBottomRoundness(anv.isLastInSection() ? 1f : 0f, false);
}
if (viewStart >= cornerAnimationTop) {
// Round top corners within animation bounds
final float changeFraction = MathUtils.saturate(
(viewStart - cornerAnimationTop) / cornerAnimationDistance);
final float roundness = anv.isFirstInSection() ? 1f : changeFraction * 1f;
anv.setTopRoundness(roundness, false);
} else if (viewStart < cornerAnimationTop) {
// Fast scroll skips frames and leaves corners with unfinished rounding.
// Reset top and bottom corners outside of animation bounds.
anv.setTopRoundness(anv.isFirstInSection() ? 1f : 0f, false);
}
}
previousAnv = anv;
} }
} }
@@ -408,6 +365,58 @@ public class NotificationShelf extends ActivatableNotificationView implements
} }
} }
private void updateCornerRoundnessOnScroll(ActivatableNotificationView anv, float viewStart,
float shelfStart) {
final boolean isUnlockedHeadsUp = !mAmbientState.isOnKeyguard()
&& !mAmbientState.isShadeExpanded()
&& anv instanceof ExpandableNotificationRow
&& ((ExpandableNotificationRow) anv).isHeadsUp();
final boolean shouldUpdateCornerRoundness = viewStart < shelfStart
&& !mHostLayoutController.isViewAffectedBySwipe(anv)
&& !isUnlockedHeadsUp
&& !mAmbientState.isPulsing()
&& !mAmbientState.isDozing();
if (!shouldUpdateCornerRoundness) {
return;
}
final float viewEnd = viewStart + anv.getActualHeight();
final float cornerAnimationDistance = mCornerAnimationDistance
* mAmbientState.getExpansionFraction();
final float cornerAnimationTop = shelfStart - cornerAnimationDistance;
if (viewEnd >= cornerAnimationTop) {
// Round bottom corners within animation bounds
final float changeFraction = MathUtils.saturate(
(viewEnd - cornerAnimationTop) / cornerAnimationDistance);
anv.setBottomRoundness(anv.isLastInSection() ? 1f : changeFraction,
false /* animate */);
} else if (viewEnd < cornerAnimationTop) {
// Fast scroll skips frames and leaves corners with unfinished rounding.
// Reset top and bottom corners outside of animation bounds.
anv.setBottomRoundness(anv.isLastInSection() ? 1f : 0f,
false /* animate */);
}
if (viewStart >= cornerAnimationTop) {
// Round top corners within animation bounds
final float changeFraction = MathUtils.saturate(
(viewStart - cornerAnimationTop) / cornerAnimationDistance);
anv.setTopRoundness(anv.isFirstInSection() ? 1f : changeFraction,
false /* animate */);
} else if (viewStart < cornerAnimationTop) {
// Fast scroll skips frames and leaves corners with unfinished rounding.
// Reset top and bottom corners outside of animation bounds.
anv.setTopRoundness(anv.isFirstInSection() ? 1f : 0f,
false /* animate */);
}
}
/** /**
* Clips transient views to the top of the shelf - Transient views are only used for * Clips transient views to the top of the shelf - Transient views are only used for
* disappearing views/animations and need to be clipped correctly by the shelf to ensure they * disappearing views/animations and need to be clipped correctly by the shelf to ensure they