Back to project page Coloring-book.
The source code is released under:
Apache License
If you think the Android project Coloring-book listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.plattysoft.leonids; //from w w w . ja va 2 s . co m import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.BitmapDrawable; public class AnimatedParticle extends Particle { private AnimationDrawable mAnimationDrawable; private int mTotalTime; public AnimatedParticle(AnimationDrawable animationDrawable) { mAnimationDrawable = animationDrawable; mImage = ((BitmapDrawable) mAnimationDrawable.getFrame(0)).getBitmap(); // If it is a repeating animation, calculate the time mTotalTime = 0; for (int i=0; i<mAnimationDrawable.getNumberOfFrames(); i++) { mTotalTime += mAnimationDrawable.getDuration(i); } } @Override public boolean update(long miliseconds) { boolean active = super.update(miliseconds); if (active) { long animationElapsedTime = 0; long realMiliseconds = miliseconds - mStartingMilisecond; if (realMiliseconds > mTotalTime) { if (mAnimationDrawable.isOneShot()) { return false; } else { realMiliseconds = realMiliseconds % mTotalTime; } } for (int i=0; i<mAnimationDrawable.getNumberOfFrames(); i++) { animationElapsedTime += mAnimationDrawable.getDuration(i); if (animationElapsedTime > realMiliseconds) { mImage = ((BitmapDrawable) mAnimationDrawable.getFrame(i)).getBitmap(); break; } } } return active; } }