diff --git a/LeonidsLib/src/main/java/com/plattysoft/leonids/ParticleField.java b/LeonidsLib/src/main/java/com/plattysoft/leonids/ParticleField.java index d7837cc..027b9ee 100644 --- a/LeonidsLib/src/main/java/com/plattysoft/leonids/ParticleField.java +++ b/LeonidsLib/src/main/java/com/plattysoft/leonids/ParticleField.java @@ -31,8 +31,10 @@ public void setParticles(ArrayList particles) { protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Draw all the particles - for (int i=0; i mParticles; - private ArrayList mActiveParticles; + private final ArrayList mActiveParticles = new ArrayList(); private long mTimeToLive; private long mCurrentTime = 0; @@ -72,7 +72,7 @@ private ParticleSystem(Activity a, int maxParticles, long timeToLive, int parent mMaxParticles = maxParticles; // Create the particles - mActiveParticles = new ArrayList(); + mParticles = new ArrayList (); mTimeToLive = timeToLive; @@ -142,9 +142,9 @@ else if (drawable instanceof AnimationDrawable) { mParticles.add (new AnimatedParticle (animation)); } } - else { +// else { // Not supported, no particles are being created - } +// } } public float dpToPx(float dp) { @@ -210,7 +210,7 @@ public ParticleSystem(Activity a, int maxParticles, AnimationDrawable animation, /** * Adds a modifier to the Particle system, it will be executed on each update. * - * @param modifier + * @param modifier modifier to be added to the ParticleSystem */ public ParticleSystem addModifier(ParticleModifier modifier) { mModifiers.add(modifier); @@ -357,7 +357,7 @@ private void startEmiting(int particlesPerSecond) { mDrawingView.setParticles (mActiveParticles); updateParticlesBeforeStartTime(particlesPerSecond); mTimer = new Timer(); - mTimer.schedule(new TimerTask() { + mTimer.schedule(new TimerTask() { @Override public void run() { onUpdate(mCurrentTime); @@ -389,7 +389,7 @@ private void startEmiting(int particlesPerSecond, int emitingTime) { mDrawingView.setParticles (mActiveParticles); updateParticlesBeforeStartTime(particlesPerSecond); mEmitingTime = emitingTime; - startAnimator(new LinearInterpolator(), emitingTime+mTimeToLive); + startAnimator(new LinearInterpolator(), emitingTime + mTimeToLive); } public void emit (int emitterX, int emitterY, int particlesPerSecond) { @@ -429,7 +429,7 @@ public void oneShot(View emiter, int numParticles, Interpolator interpolator) { // Add a full size view to the parent view mDrawingView = new ParticleField(mParentView.getContext()); mParentView.addView(mDrawingView); - mDrawingView.setParticles (mActiveParticles); + mDrawingView.setParticles(mActiveParticles); // We start a property animator that will call us to do the update // Animate from 0 to timeToLiveMax startAnimator(interpolator, mTimeToLive); @@ -438,7 +438,7 @@ public void oneShot(View emiter, int numParticles, Interpolator interpolator) { private void startAnimator(Interpolator interpolator, long animnationTime) { mAnimator = ValueAnimator.ofInt(0, (int) animnationTime); mAnimator.setDuration(animnationTime); - mAnimator.addUpdateListener(new AnimatorUpdateListener() { + mAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int miliseconds = (Integer) animation.getAnimatedValue(); @@ -543,12 +543,14 @@ private void onUpdate(long miliseconds) { // Activate a new particle activateParticle(miliseconds); } - for (int i=0; i