Skip to content

Commit 3b18132

Browse files
committed
fix for #17 new constructors for using any view as parent
1 parent c947054 commit 3b18132

File tree

1 file changed

+63
-12
lines changed

1 file changed

+63
-12
lines changed

Diff for: LeonidasLib/src/com/plattysoft/leonids/ParticleSystem.java

+63-12
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public class ParticleSystem {
6363
private int mEmiterYMin;
6464
private int mEmiterYMax;
6565

66-
private ParticleSystem(Activity a, int maxParticles, long timeToLive) {
66+
private ParticleSystem(Activity a, int maxParticles, long timeToLive, int parentResId) {
6767
mRandom = new Random();
68-
mParentView = (ViewGroup) a.findViewById(android.R.id.content);
68+
mParentView = (ViewGroup) a.findViewById(parentResId);
6969

7070
mModifiers = new ArrayList<ParticleModifier>();
7171
mInitializers = new ArrayList<ParticleInitializer>();
@@ -92,19 +92,44 @@ private ParticleSystem(Activity a, int maxParticles, long timeToLive) {
9292
* @param timeToLive The time to live for the particles
9393
*/
9494
public ParticleSystem(Activity a, int maxParticles, int drawableRedId, long timeToLive) {
95-
this(a, maxParticles, a.getResources().getDrawable(drawableRedId), timeToLive);
96-
}
97-
95+
this(a, maxParticles, a.getResources().getDrawable(drawableRedId), timeToLive, android.R.id.content);
96+
}
97+
98+
/**
99+
* Creates a particle system with the given parameters
100+
*
101+
* @param a The parent activity
102+
* @param maxParticles The maximum number of particles
103+
* @param drawableRedId The drawable resource to use as particle (supports Bitmaps and Animations)
104+
* @param timeToLive The time to live for the particles
105+
* @param parentViewId The view Id for the parent of the particle system
106+
*/
107+
public ParticleSystem(Activity a, int maxParticles, int drawableRedId, long timeToLive, int parentViewId) {
108+
this(a, maxParticles, a.getResources().getDrawable(drawableRedId), timeToLive, parentViewId);
109+
}
110+
111+
/**
112+
* Utility constructor that receives a Drawable
113+
*
114+
* @param a The parent activity
115+
* @param maxParticles The maximum number of particles
116+
* @param drawable The drawable to use as particle (supports Bitmaps and Animations)
117+
* @param timeToLive The time to live for the particles
118+
*/
119+
public ParticleSystem(Activity a, int maxParticles, Drawable drawable, long timeToLive) {
120+
this(a, maxParticles, drawable, timeToLive, android.R.id.content);
121+
}
98122
/**
99123
* Utility constructor that receives a Drawable
100124
*
101125
* @param a The parent activity
102126
* @param maxParticles The maximum number of particles
103127
* @param drawable The drawable to use as particle (supports Bitmaps and Animations)
104128
* @param timeToLive The time to live for the particles
129+
* @param parentViewId The view Id for the parent of the particle system
105130
*/
106-
public ParticleSystem(Activity a, int maxParticles, Drawable drawable, long timeToLive) {
107-
this(a, maxParticles, timeToLive);
131+
public ParticleSystem(Activity a, int maxParticles, Drawable drawable, long timeToLive, int parentViewId) {
132+
this(a, maxParticles, timeToLive, parentViewId);
108133
if (drawable instanceof BitmapDrawable) {
109134
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
110135
for (int i=0; i<mMaxParticles; i++) {
@@ -126,36 +151,62 @@ public float dpToPx(float dp) {
126151
return dp * mDpToPxScale;
127152
}
128153

154+
/**
155+
* Utility constructor that receives a Bitmap
156+
*
157+
* @param a The parent activity
158+
* @param maxParticles The maximum number of particles
159+
* @param bitmap The bitmap to use as particle
160+
* @param timeToLive The time to live for the particles
161+
*/
162+
public ParticleSystem(Activity a, int maxParticles, Bitmap bitmap, long timeToLive) {
163+
this(a, maxParticles, bitmap, timeToLive, android.R.id.content);
164+
}
129165
/**
130166
* Utility constructor that receives a Bitmap
131167
*
132168
* @param a The parent activity
133169
* @param maxParticles The maximum number of particles
134170
* @param bitmap The bitmap to use as particle
135171
* @param timeToLive The time to live for the particles
172+
* @param parentViewId The view Id for the parent of the particle system
136173
*/
137-
public ParticleSystem(Activity a, int maxParticles, Bitmap bitmap, long timeToLive) {
138-
this(a, maxParticles, timeToLive);
174+
public ParticleSystem(Activity a, int maxParticles, Bitmap bitmap, long timeToLive, int parentViewId) {
175+
this(a, maxParticles, timeToLive, parentViewId);
139176
for (int i=0; i<mMaxParticles; i++) {
140177
mParticles.add (new Particle (bitmap));
141178
}
142179
}
143180

181+
/**
182+
* Utility constructor that receives an AnimationDrawble
183+
*
184+
* @param a The parent activity
185+
* @param maxParticles The maximum number of particles
186+
* @param animation The animation to use as particle
187+
* @param timeToLive The time to live for the particles
188+
*/
189+
public ParticleSystem(Activity a, int maxParticles, AnimationDrawable animation, long timeToLive) {
190+
this(a, maxParticles, animation, timeToLive, android.R.id.content);
191+
}
192+
144193
/**
145194
* Utility constructor that receives an AnimationDrawble
146195
*
147196
* @param a The parent activity
148197
* @param maxParticles The maximum number of particles
149198
* @param animation The animation to use as particle
150199
* @param timeToLive The time to live for the particles
200+
* @param parentViewId The view Id for the parent of the particle system
151201
*/
152-
public ParticleSystem(Activity a, int maxParticles, AnimationDrawable animation, long timeToLive) {
153-
this(a, maxParticles, timeToLive);
202+
public ParticleSystem(Activity a, int maxParticles, AnimationDrawable animation, long timeToLive, int parentViewId) {
203+
this(a, maxParticles, timeToLive, parentViewId);
154204
// Create the particles
155205
for (int i=0; i<mMaxParticles; i++) {
156206
mParticles.add (new AnimatedParticle (animation));
157207
}
158208
}
209+
159210
/**
160211
* Adds a modifier to the Particle system, it will be executed on each update.
161212
*
@@ -385,7 +436,7 @@ public void oneShot(View emiter, int numParticles, Interpolator interpolator) {
385436
}
386437

387438
private void startAnimator(Interpolator interpolator, long animnationTime) {
388-
mAnimator = ValueAnimator.ofInt(new int[] {0, (int) animnationTime});
439+
mAnimator = ValueAnimator.ofInt(0, (int) animnationTime);
389440
mAnimator.setDuration(animnationTime);
390441
mAnimator.addUpdateListener(new AnimatorUpdateListener() {
391442
@Override

0 commit comments

Comments
 (0)