I'm trying to play animations one after another on pre-honeycomb devices.
I've tried to play animations one after another using the AnimationSet and the startOffset value of each animation without luck.
I've also tried to create a new class that manages the animations to start one after another, but it also doesn't work.
Here's the code:
public class AnimationChain {
private final List<Animation> mAnimations = new ArrayList<Animation>();
private AnimationListener mAnimationListener;
private final View mViewToAnimate;
public AnimationChain(final View viewToAnimate) {
this.mViewToAnimate = viewToAnimate;
}
public void addAnimation(final Animation animation) {
mAnimations.add(animation);
}
public void setAnimationListener(final AnimationListener animationListener) {
this.mAnimationListener = animationListener;
}
public List<Animation> getAnimations() {
return this.mAnimations;
}
public Animation getLastAnimation() {
final int size = mAnimations.size();
if (size == 0)
return null;
return mAnimations.get(size - 1);
}
public void startAnimations() {
if (mAnimations.size() == 0)
return;
for (int i = 0; i < mAnimations.size(); ++i) {
final Animation currentAnimation = mAnimations.get(i);
final Animation nextAnimation;
if (i != mAnimations.size() - 1)
nextAnimation = mAnimations.get(i + 1);
else
nextAnimation = null;
currentAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(final Animation animation) {
if (mAnimationListener != null)
mAnimationListener.onAnimationStart(animation);
}
@Override
public void onAnimationRepeat(final Animation animation) {
if (mAnimationListener != null)
mAnimationListener.onAnimationRepeat(animation);
}
@Override
public void onAnimationEnd(final Animation animation) {
if (mAnimationListener != null)
mAnimationListener.onAnimationEnd(animation);
if (nextAnimation != null)
mViewToAnimate.startAnimation(nextAnimation);
}
});
}
final Animation firstAnimation = mAnimations.get(0);
mViewToAnimate.startAnimation(firstAnimation);
}
}
It seems that it does call the next animation to start, but it doesn't do anything that I can see. Using a single animation works fine for any animation though.
Can anyone please help me? What have I done wrong?
Also, if I try to work on honeycomb version and above, will this problem still exist ? How will I handle it there? Maybe using the 9-old-android library can help?