Reset patterned animations when solid ripple is reset

Fixes: 194655257
Test: visual using the material demo app + MX player
Change-Id: I47805fe1a36bdadd7de45008c42cf2fcb23d223a
This commit is contained in:
Jay Aliomer
2021-07-28 17:12:05 -04:00
parent 866753754b
commit 304b04a492
2 changed files with 23 additions and 2 deletions

View File

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

View File

@@ -278,6 +278,15 @@ public class RippleDrawable extends LayerDrawable {
}
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() {
@@ -291,7 +300,6 @@ public class RippleDrawable extends LayerDrawable {
Arrays.fill(ripples, 0, count, null);
}
mExitingRipplesCount = 0;
mExitingAnimation = true;
// Always draw an additional "clean" frame after canceling animations.
invalidateSelf(false);
}
@@ -714,7 +722,7 @@ public class RippleDrawable extends LayerDrawable {
}
cancelExitingRipples();
exitPatternedAnimation();
endPatternedAnimations();
}
@Override