I have extended the Animation class to show circle being drawn as animation here is my Animation class
public class CircleAnimation extends Animation {
private Circle circle;
private float oldAngle;
private float newAngle;
public CircleAnimation(Circle circle, int newAngle) {
this.oldAngle = circle.getAngle();
this.newAngle = newAngle;
this.circle = circle;
setInterpolator(new ReverseInterpolator());
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation transformation) {
float angle = oldAngle + ((newAngle - oldAngle) * interpolatedTime);
circle.setAngle(angle);
circle.requestLayout();
}
}
Everything works as expected and now I wanted to reverse the animation i.e start from a full circle to half circle and finally to empty. The easiest way I found was to use a custom Interpolator as described here in the stackoverflow answer and I implemented the same.
public class ReverseInterpolator implements Interpolator {
@Override
public float getInterpolation(float paramFloat) {
return Math.abs(paramFloat - 1f);
}
}
I have two button to start and stop the animation
public void stop(View v) {
if (circle != null) {
circle.getAnimation().cancel();
}
}
public void start(View v) {
CircleAnimation animation = new CircleAnimation(circle, 360);
animation.setDuration(10000);
circle.startAnimation(animation);
}
The problem is if I use the setInterpolator(new ReverseInterpolator()); in my animation to reverse the circle being drawn the start and stop works only once and if I try starting it again the animation does not work but if I remove the ReverseInterpolator from my animation to draw circle the start and stop works any number of time, Can someone explain why is this happening?