Android Open Source - Coloring-book Alpha Modifier

From Project

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.

Java Source Code

package com.plattysoft.leonids.modifiers;
/*  www. j  a v  a  2 s.c  o m*/
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

import com.plattysoft.leonids.Particle;

public class AlphaModifier implements ParticleModifier {

  private int mInitialValue;
  private int mFinalValue;
  private long mStartTime;
  private long mEndTime;
  private float mDuration;
  private float mValueIncrement;
  private Interpolator mInterpolator;

  public AlphaModifier(int initialValue, int finalValue, long startMilis, long endMilis, Interpolator interpolator) {
    mInitialValue = initialValue;
    mFinalValue = finalValue;
    mStartTime = startMilis;    
    mEndTime = endMilis;
    mDuration = mEndTime - mStartTime;
    mValueIncrement = mFinalValue-mInitialValue;
    mInterpolator = interpolator;
  public AlphaModifier (int initialValue, int finalValue, long startMilis, long endMilis) {
    this(initialValue, finalValue, startMilis, endMilis, new LinearInterpolator());

  public void apply(Particle particle, long miliseconds) {
    if (miliseconds < mStartTime) {
      particle.mAlpha = mInitialValue;
    else if (miliseconds > mEndTime) {
      particle.mAlpha = mFinalValue;
    else {  
      float interpolaterdValue = mInterpolator.getInterpolation((miliseconds- mStartTime)*1f/mDuration);
      int newAlphaValue = (int) (mInitialValue + mValueIncrement*interpolaterdValue);
      particle.mAlpha = newAlphaValue;


Java Source Code List