123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package com.khmer9.lotto.util;
- import android.graphics.drawable.AnimationDrawable;
- import android.os.Handler;
- public abstract class CustomAnimationDrawable extends AnimationDrawable {
- /** Handles the animation callback. */
- Handler mAnimationHandler;
- public CustomAnimationDrawable(AnimationDrawable aniDrawable) {
- /* Add each frame to our animation drawable */
- for (int i = 0; i < aniDrawable.getNumberOfFrames(); i++) {
- this.addFrame(aniDrawable.getFrame(i), aniDrawable.getDuration(i));
- }
- }
- @Override
- public void start() {
- super.start();
- /*
- * Call super.start() to call the base class start animation method.
- * Then add a handler to call onAnimationFinish() when the total
- * duration for the animation has passed
- */
- mAnimationHandler = new Handler();
- mAnimationHandler.post(new Runnable() {
- @Override
- public void run() {
- onAnimationStart();
- }
- });
- mAnimationHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- onAnimationFinish();
- }
- }, getTotalDuration());
- }
- /**
- * Gets the total duration of all frames.
- *
- * @return The total duration.
- */
- public int getTotalDuration() {
- int iDuration = 0;
- for (int i = 0; i < this.getNumberOfFrames(); i++) {
- iDuration += this.getDuration(i);
- }
- return iDuration;
- }
- /**
- * Called when the animation finishes.
- */
- public abstract void onAnimationFinish();
- /**
- * Called when the animation starts.
- */
- public abstract void onAnimationStart();
- }
|