Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da8be681 authored by Jay Aliomer's avatar Jay Aliomer Committed by Automerger Merge Worker
Browse files

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

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

Change-Id: Iaaf11e4690faf9b16ec4640850b213c7fecd137b
parents b4db3d25 70c0c935
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -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) {
+10 −2
Original line number Original line Diff line number Diff line
@@ -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