@@ -63,9 +63,9 @@ public class ParticleSystem {
63
63
private int mEmiterYMin ;
64
64
private int mEmiterYMax ;
65
65
66
- private ParticleSystem (Activity a , int maxParticles , long timeToLive ) {
66
+ private ParticleSystem (Activity a , int maxParticles , long timeToLive , int parentResId ) {
67
67
mRandom = new Random ();
68
- mParentView = (ViewGroup ) a .findViewById (android . R . id . content );
68
+ mParentView = (ViewGroup ) a .findViewById (parentResId );
69
69
70
70
mModifiers = new ArrayList <ParticleModifier >();
71
71
mInitializers = new ArrayList <ParticleInitializer >();
@@ -92,19 +92,44 @@ private ParticleSystem(Activity a, int maxParticles, long timeToLive) {
92
92
* @param timeToLive The time to live for the particles
93
93
*/
94
94
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
+ }
98
122
/**
99
123
* Utility constructor that receives a Drawable
100
124
*
101
125
* @param a The parent activity
102
126
* @param maxParticles The maximum number of particles
103
127
* @param drawable The drawable to use as particle (supports Bitmaps and Animations)
104
128
* @param timeToLive The time to live for the particles
129
+ * @param parentViewId The view Id for the parent of the particle system
105
130
*/
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 );
108
133
if (drawable instanceof BitmapDrawable ) {
109
134
Bitmap bitmap = ((BitmapDrawable ) drawable ).getBitmap ();
110
135
for (int i =0 ; i <mMaxParticles ; i ++) {
@@ -126,36 +151,62 @@ public float dpToPx(float dp) {
126
151
return dp * mDpToPxScale ;
127
152
}
128
153
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
+ }
129
165
/**
130
166
* Utility constructor that receives a Bitmap
131
167
*
132
168
* @param a The parent activity
133
169
* @param maxParticles The maximum number of particles
134
170
* @param bitmap The bitmap to use as particle
135
171
* @param timeToLive The time to live for the particles
172
+ * @param parentViewId The view Id for the parent of the particle system
136
173
*/
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 );
139
176
for (int i =0 ; i <mMaxParticles ; i ++) {
140
177
mParticles .add (new Particle (bitmap ));
141
178
}
142
179
}
143
180
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
+
144
193
/**
145
194
* Utility constructor that receives an AnimationDrawble
146
195
*
147
196
* @param a The parent activity
148
197
* @param maxParticles The maximum number of particles
149
198
* @param animation The animation to use as particle
150
199
* @param timeToLive The time to live for the particles
200
+ * @param parentViewId The view Id for the parent of the particle system
151
201
*/
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 );
154
204
// Create the particles
155
205
for (int i =0 ; i <mMaxParticles ; i ++) {
156
206
mParticles .add (new AnimatedParticle (animation ));
157
207
}
158
208
}
209
+
159
210
/**
160
211
* Adds a modifier to the Particle system, it will be executed on each update.
161
212
*
@@ -385,7 +436,7 @@ public void oneShot(View emiter, int numParticles, Interpolator interpolator) {
385
436
}
386
437
387
438
private void startAnimator (Interpolator interpolator , long animnationTime ) {
388
- mAnimator = ValueAnimator .ofInt (new int [] { 0 , (int ) animnationTime } );
439
+ mAnimator = ValueAnimator .ofInt (0 , (int ) animnationTime );
389
440
mAnimator .setDuration (animnationTime );
390
441
mAnimator .addUpdateListener (new AnimatorUpdateListener () {
391
442
@ Override
0 commit comments