Android Open Source - Coloring-book Animated Particle






From Project

Back to project page Coloring-book.

License

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.

Java Source Code

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;
  }
}




Java Source Code List

com.kidsgames.gamebase.DrawerActivity.java
com.kidsgames.gamebase.DrawingView.java
com.kidsgames.menu.DrawerSliderActivity.java
com.kidsgames.menu.FixedSpeedScroller.java
com.kidsgames.menu.FixedSpeedViewPager.java
com.kidsgames.menu.MainMenu.java
com.kidsgames.menu.SlideAdapter.java
com.kidsgames.utils.ResourceId.java
com.plattysoft.leonids.AnimatedParticle.java
com.plattysoft.leonids.ParticleField.java
com.plattysoft.leonids.ParticleSystem.java
com.plattysoft.leonids.Particle.java
com.plattysoft.leonids.initializers.AccelerationInitializer.java
com.plattysoft.leonids.initializers.ParticleInitializer.java
com.plattysoft.leonids.initializers.RotationInitiazer.java
com.plattysoft.leonids.initializers.RotationSpeedInitializer.java
com.plattysoft.leonids.initializers.ScaleInitializer.java
com.plattysoft.leonids.initializers.SpeeddByComponentsInitializer.java
com.plattysoft.leonids.initializers.SpeeddModuleAndRangeInitializer.java
com.plattysoft.leonids.modifiers.AccelerationModifier.java
com.plattysoft.leonids.modifiers.AlphaModifier.java
com.plattysoft.leonids.modifiers.ParticleModifier.java
com.plattysoft.leonids.modifiers.ScaleModifier.java