Last active
July 12, 2017 13:57
-
-
Save patrick-elmquist/20768891513bfe509028003852eec18d to your computer and use it in GitHub Desktop.
Frame by frame #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SpinnerLoaderView extends View { | |
private static final long ANIMATION_DURATION = 1250L; | |
private ValueAnimator mAnimator; | |
private float mArcStart; | |
private float mArcSize; | |
// ... | |
@Override | |
protected void onAttachedToWindow() { | |
super.onAttachedToWindow(); | |
mAnimator = ValueAnimator.ofFloat(0f, 1f); | |
mAnimator.setRepeatMode(ValueAnimator.RESTART); | |
mAnimator.setRepeatCount(ValueAnimator.INFINITE); | |
mAnimator.setInterpolator(new LinearInterpolator()); | |
mAnimator.setDuration(ANIMATION_DURATION); | |
mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | |
@Override | |
public void onAnimationUpdate(ValueAnimator valueAnimator) { | |
final float progress = (float) valueAnimator.getAnimatedValue(); | |
mArcStart = calculateArcStart(progress); | |
mArcSize = calculateArcSize(progress); | |
invalidate(); | |
} | |
}); | |
mAnimator.start(); | |
} | |
@Override | |
protected void onDetachedFromWindow() { | |
super.onDetachedFromWindow(); | |
mAnimator.cancel(); | |
mAnimator.removeAllUpdateListeners(); | |
mAnimator = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment