@@ -39,7 +39,8 @@ public class LoadingView extends FrameLayout {
39
39
private int mTextAppearance ;
40
40
41
41
private String mLoadText ;
42
-
42
+ private AnimatorSet mUpAnimatorSet ;
43
+ private AnimatorSet mDownAnimatorSet ;
43
44
44
45
public LoadingView (Context context ) {
45
46
super (context );
@@ -118,7 +119,7 @@ public void run() {
118
119
};
119
120
120
121
private void startLoading (long delay ) {
121
- if (mAnimatorSet != null && mAnimatorSet .isRunning ()) {
122
+ if (mDownAnimatorSet != null && mDownAnimatorSet .isRunning ()) {
122
123
return ;
123
124
}
124
125
this .removeCallbacks (mFreeFallRunnable );
@@ -129,13 +130,37 @@ private void startLoading(long delay) {
129
130
}
130
131
}
131
132
133
+ @ Override
134
+ protected void onDetachedFromWindow () {
135
+ super .onDetachedFromWindow ();
136
+ stopLoading ();
137
+ }
138
+
132
139
private void stopLoading () {
133
140
if (mAnimatorSet != null ) {
134
141
if (mAnimatorSet .isRunning ()) {
135
142
mAnimatorSet .cancel ();
136
143
}
137
144
mAnimatorSet = null ;
138
145
}
146
+ if (mUpAnimatorSet != null ) {
147
+ if (mUpAnimatorSet .isRunning ()) {
148
+ mUpAnimatorSet .cancel ();
149
+ }
150
+ mUpAnimatorSet .removeAllListeners ();
151
+ for (Animator animator : mUpAnimatorSet .getChildAnimations ()) {
152
+ animator .removeAllListeners ();
153
+ }
154
+ }
155
+ if (mDownAnimatorSet != null ) {
156
+ if (mDownAnimatorSet .isRunning ()) {
157
+ mDownAnimatorSet .cancel ();
158
+ }
159
+ mDownAnimatorSet .removeAllListeners ();
160
+ for (Animator animator : mDownAnimatorSet .getChildAnimations ()) {
161
+ animator .removeAllListeners ();
162
+ }
163
+ }
139
164
this .removeCallbacks (mFreeFallRunnable );
140
165
}
141
166
@@ -194,12 +219,12 @@ public void upThrow() {
194
219
objectAnimator1 .setDuration (ANIMATION_DURATION );
195
220
objectAnimator .setInterpolator (new DecelerateInterpolator (factor ));
196
221
objectAnimator1 .setInterpolator (new DecelerateInterpolator (factor ));
197
- AnimatorSet animatorSet = new AnimatorSet ();
198
- animatorSet .setDuration (ANIMATION_DURATION );
199
- animatorSet .playTogether (objectAnimator , objectAnimator1 , scaleIndication );
222
+ mUpAnimatorSet = new AnimatorSet ();
223
+ mUpAnimatorSet .setDuration (ANIMATION_DURATION );
224
+ mUpAnimatorSet .playTogether (objectAnimator , objectAnimator1 , scaleIndication );
200
225
201
226
202
- animatorSet .addListener (new Animator .AnimatorListener () {
227
+ mUpAnimatorSet .addListener (new Animator .AnimatorListener () {
203
228
@ Override
204
229
public void onAnimationStart (Animator animation ) {
205
230
@@ -222,7 +247,7 @@ public void onAnimationRepeat(Animator animation) {
222
247
223
248
}
224
249
});
225
- animatorSet .start ();
250
+ mUpAnimatorSet .start ();
226
251
227
252
228
253
}
@@ -240,10 +265,10 @@ public void freeFall() {
240
265
241
266
objectAnimator .setDuration (ANIMATION_DURATION );
242
267
objectAnimator .setInterpolator (new AccelerateInterpolator (factor ));
243
- AnimatorSet animatorSet = new AnimatorSet ();
244
- animatorSet .setDuration (ANIMATION_DURATION );
245
- animatorSet .playTogether (objectAnimator , scaleIndication );
246
- animatorSet .addListener (new Animator .AnimatorListener () {
268
+ mDownAnimatorSet = new AnimatorSet ();
269
+ mDownAnimatorSet .setDuration (ANIMATION_DURATION );
270
+ mDownAnimatorSet .playTogether (objectAnimator , scaleIndication );
271
+ mDownAnimatorSet .addListener (new Animator .AnimatorListener () {
247
272
@ Override
248
273
public void onAnimationStart (Animator animation ) {
249
274
@@ -267,7 +292,7 @@ public void onAnimationRepeat(Animator animation) {
267
292
268
293
}
269
294
});
270
- animatorSet .start ();
295
+ mDownAnimatorSet .start ();
271
296
272
297
273
298
}
0 commit comments