Merge "Reset patterned animations when solid ripple is reset" into sc-dev am: 70c0c93542

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

Change-Id: Ida1cd932e30ad2ddf58c309cac9c2fd1ed849b6a
This commit is contained in:
Jay Aliomer
2021-07-29 22:11:28 +00:00
committed by Automerger Merge Worker
2 changed files with 23 additions and 2 deletions

View File

@@ -53,6 +53,7 @@ public final class RippleAnimationSession {
private long mStartTime; private long mStartTime;
private boolean mForceSoftware; private boolean mForceSoftware;
private Animator mLoopAnimation; private Animator mLoopAnimation;
private Animator mCurrentAnimation;
RippleAnimationSession(@NonNull AnimationProperties<Float, Paint> properties, RippleAnimationSession(@NonNull AnimationProperties<Float, Paint> properties,
boolean forceSoftware) { boolean forceSoftware) {
@@ -74,6 +75,12 @@ public final class RippleAnimationSession {
return this; return this;
} }
void end() {
if (mCurrentAnimation != null) {
mCurrentAnimation.end();
}
}
@NonNull RippleAnimationSession exit(Canvas canvas) { @NonNull RippleAnimationSession exit(Canvas canvas) {
if (isHwAccelerated(canvas)) exitHardware((RecordingCanvas) canvas); if (isHwAccelerated(canvas)) exitHardware((RecordingCanvas) canvas);
else exitSoftware(); else exitSoftware();
@@ -114,10 +121,12 @@ public final class RippleAnimationSession {
if (mLoopAnimation != null) mLoopAnimation.cancel(); if (mLoopAnimation != null) mLoopAnimation.cancel();
Consumer<RippleAnimationSession> onEnd = mOnSessionEnd; Consumer<RippleAnimationSession> onEnd = mOnSessionEnd;
if (onEnd != null) onEnd.accept(RippleAnimationSession.this); if (onEnd != null) onEnd.accept(RippleAnimationSession.this);
if (mCurrentAnimation == expand) mCurrentAnimation = null;
} }
}); });
expand.setInterpolator(LINEAR_INTERPOLATOR); expand.setInterpolator(LINEAR_INTERPOLATOR);
expand.start(); expand.start();
mCurrentAnimation = expand;
} }
private long computeDelay() { private long computeDelay() {
@@ -147,6 +156,7 @@ public final class RippleAnimationSession {
if (mLoopAnimation != null) mLoopAnimation.cancel(); if (mLoopAnimation != null) mLoopAnimation.cancel();
Consumer<RippleAnimationSession> onEnd = mOnSessionEnd; Consumer<RippleAnimationSession> onEnd = mOnSessionEnd;
if (onEnd != null) onEnd.accept(RippleAnimationSession.this); if (onEnd != null) onEnd.accept(RippleAnimationSession.this);
if (mCurrentAnimation == exit) mCurrentAnimation = null;
} }
}); });
exit.setTarget(canvas); exit.setTarget(canvas);
@@ -155,6 +165,7 @@ public final class RippleAnimationSession {
long delay = computeDelay(); long delay = computeDelay();
exit.setStartDelay(delay); exit.setStartDelay(delay);
exit.start(); exit.start();
mCurrentAnimation = exit;
} }
private void enterHardware(RecordingCanvas canvas) { private void enterHardware(RecordingCanvas canvas) {
@@ -167,6 +178,7 @@ public final class RippleAnimationSession {
mStartTime + MAX_NOISE_PHASE); mStartTime + MAX_NOISE_PHASE);
loop.setTarget(canvas); loop.setTarget(canvas);
startAnimation(expand, loop); startAnimation(expand, loop);
mCurrentAnimation = expand;
} }
private void startAnimation(Animator expand, Animator loop) { private void startAnimation(Animator expand, Animator loop) {
@@ -200,6 +212,7 @@ public final class RippleAnimationSession {
mProperties.getShader().setNoisePhase((float) loop.getAnimatedValue()); mProperties.getShader().setNoisePhase((float) loop.getAnimatedValue());
}); });
startAnimation(expand, loop); startAnimation(expand, loop);
mCurrentAnimation = expand;
} }
void setRadius(float radius) { void setRadius(float radius) {

View File

@@ -278,6 +278,15 @@ public class RippleDrawable extends LayerDrawable {
} }
cancelExitingRipples(); cancelExitingRipples();
endPatternedAnimations();
}
private void endPatternedAnimations() {
for (int i = 0; i < mRunningAnimations.size(); i++) {
RippleAnimationSession session = mRunningAnimations.get(i);
session.end();
}
mRunningAnimations.clear();
} }
private void cancelExitingRipples() { private void cancelExitingRipples() {
@@ -291,7 +300,6 @@ public class RippleDrawable extends LayerDrawable {
Arrays.fill(ripples, 0, count, null); Arrays.fill(ripples, 0, count, null);
} }
mExitingRipplesCount = 0; mExitingRipplesCount = 0;
mExitingAnimation = true;
// Always draw an additional "clean" frame after canceling animations. // Always draw an additional "clean" frame after canceling animations.
invalidateSelf(false); invalidateSelf(false);
} }
@@ -714,7 +722,7 @@ public class RippleDrawable extends LayerDrawable {
} }
cancelExitingRipples(); cancelExitingRipples();
exitPatternedAnimation(); endPatternedAnimations();
} }
@Override @Override