Skip to content

Commit a8a0f9a

Browse files
committed
fix with addAnimation
1 parent 892bef4 commit a8a0f9a

31 files changed

+175
-0
lines changed

app/src/main/java/com/wang/avi/sample/MainActivity.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.support.v7.app.AppCompatActivity;
44
import android.os.Bundle;
5+
import android.view.View;
56

67

78
public class MainActivity extends AppCompatActivity {
@@ -14,4 +15,15 @@ protected void onCreate(Bundle savedInstanceState) {
1415
}
1516

1617

18+
/* public void visible(View view) {
19+
findViewById(R.id.testView).setVisibility(View.VISIBLE);
20+
}
21+
22+
public void gone(View view) {
23+
findViewById(R.id.testView).setVisibility(View.GONE);
24+
}
25+
26+
public void invisible(View view) {
27+
findViewById(R.id.testView).setVisibility(View.INVISIBLE);
28+
}*/
1729
}

app/src/main/res/layout/test.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="match_parent"
5+
android:background="#FFE75764"
6+
xmlns:app="http://schemas.android.com/apk/res-auto"
7+
android:layout_height="match_parent">
8+
9+
<com.wang.avi.AVLoadingIndicatorView
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
app:indicator="BallPulse"
13+
android:id="@+id/testView"
14+
/>
15+
16+
<Button
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:text="Visible"
20+
android:onClick="visible"
21+
/>
22+
23+
<Button
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:text="GONE"
27+
android:onClick="gone"
28+
/>
29+
30+
<Button
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content"
33+
android:text="Invisible"
34+
android:onClick="invisible"
35+
/>
36+
37+
38+
</LinearLayout>

library/src/main/java/com/wang/avi/AVLoadingIndicatorView.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
315315
}
316316
}
317317

318+
@Override
319+
public void setVisibility(int v) {
320+
if (getVisibility() != v) {
321+
super.setVisibility(v);
322+
if (v == GONE || v == INVISIBLE) {
323+
mIndicatorController.setAnimationStatus(BaseIndicatorController.AnimStatus.END);
324+
} else {
325+
mIndicatorController.setAnimationStatus(BaseIndicatorController.AnimStatus.START);
326+
}
327+
}
328+
}
329+
330+
@Override
331+
protected void onDetachedFromWindow() {
332+
super.onDetachedFromWindow();
333+
mIndicatorController.setAnimationStatus(BaseIndicatorController.AnimStatus.CANCEL);
334+
}
335+
336+
318337
void drawIndicator(Canvas canvas){
319338
mIndicatorController.draw(canvas,mPaint);
320339
}

library/src/main/java/com/wang/avi/indicator/BallBeatIndicator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public void createAnimation() {
5252
@Override
5353
public void onAnimationUpdate(ValueAnimator animation) {
5454
scaleFloats[index] = (float) animation.getAnimatedValue();
55+
System.out.println("scaleFloats="+scaleFloats[index]);
5556
postInvalidate();
5657
}
5758
});
@@ -69,6 +70,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
6970
}
7071
});
7172
alphaAnim.start();
73+
addAnimation(scaleAnim, alphaAnim);
7274
}
7375
}
7476

library/src/main/java/com/wang/avi/indicator/BallClipRotateIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
5353
}
5454
});
5555
rotateAnim.start();
56+
addAnimation(scaleAnim,rotateAnim);
5657
}
5758

5859
}

library/src/main/java/com/wang/avi/indicator/BallClipRotateMultipleIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
7373
}
7474
});
7575
rotateAnim.start();
76+
addAnimation(scaleAnim,rotateAnim);
7677
}
7778

7879
}

library/src/main/java/com/wang/avi/indicator/BallClipRotatePulseIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
8181
}
8282
});
8383
rotateAnim.start();
84+
addAnimation(scaleAnim,scaleAnim2,rotateAnim);
8485
}
8586

8687
}

library/src/main/java/com/wang/avi/indicator/BallGridBeatIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
6161
}
6262
});
6363
alphaAnim.start();
64+
addAnimation(alphaAnim);
6465
}
6566
}
6667

library/src/main/java/com/wang/avi/indicator/BallGridPulseIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
8989
}
9090
});
9191
alphaAnim.start();
92+
addAnimation(scaleAnim,alphaAnim);
9293
}
9394
}
9495

library/src/main/java/com/wang/avi/indicator/BallPulseIndicator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ public void createAnimation() {
5151
@Override
5252
public void onAnimationUpdate(ValueAnimator animation) {
5353
scaleFloats[index] = (float) animation.getAnimatedValue();
54+
System.out.println("scaleFloats="+scaleFloats[index]);
5455
postInvalidate();
5556

5657
}
5758
});
5859
scaleAnim.start();
60+
addAnimation(scaleAnim);
5961
}
6062
}
6163

library/src/main/java/com/wang/avi/indicator/BallPulseRiseIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ public void createAnimation() {
3131
animator.setRepeatCount(-1);
3232
animator.setDuration(1500);
3333
animator.start();
34+
addAnimation(animator);
3435
}
3536
}

library/src/main/java/com/wang/avi/indicator/BallPulseSyncIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
4545
}
4646
});
4747
scaleAnim.start();
48+
addAnimation(scaleAnim);
4849
}
4950
}
5051

library/src/main/java/com/wang/avi/indicator/BallRotateIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
5757
rotateAnim.setRepeatCount(-1);
5858
rotateAnim.start();
5959

60+
addAnimation(scaleAnim,rotateAnim);
6061
}
6162

6263

library/src/main/java/com/wang/avi/indicator/BallScaleIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
5050
}
5151
});
5252
alphaAnim.start();
53+
addAnimation(scaleAnim,alphaAnim);
5354
}
5455

5556

library/src/main/java/com/wang/avi/indicator/BallScaleMultipleIndicator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public void onAnimationUpdate(ValueAnimator animation) {
5656
});
5757
scaleAnim.setStartDelay(delays[i]);
5858
alphaAnim.start();
59+
60+
addAnimation(scaleAnim,alphaAnim);
5961
}
6062
}
6163

library/src/main/java/com/wang/avi/indicator/BallScaleRippleIndicator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public void onAnimationUpdate(ValueAnimator animation) {
4646
}
4747
});
4848
alphaAnim.start();
49+
50+
addAnimation(scaleAnim,alphaAnim);
4951
}
5052

5153
}

library/src/main/java/com/wang/avi/indicator/BallScaleRippleMultipleIndicator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public void onAnimationUpdate(ValueAnimator animation) {
5151
});
5252
scaleAnim.setStartDelay(delays[i]);
5353
alphaAnim.start();
54+
55+
addAnimation(scaleAnim,alphaAnim);
5456
}
5557
}
5658

library/src/main/java/com/wang/avi/indicator/BallSpinFadeLoaderIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
9292
}
9393
});
9494
alphaAnim.start();
95+
addAnimation(scaleAnim,alphaAnim);
9596
}
9697
}
9798

library/src/main/java/com/wang/avi/indicator/BallTrianglePathIndicator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public void onAnimationUpdate(ValueAnimator animation) {
6767
}
6868
});
6969
translateYAnim.start();
70+
71+
addAnimation(translateXAnim,translateYAnim);
7072
}
7173
}
7274

library/src/main/java/com/wang/avi/indicator/BallZigZagDeflectIndicator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public void onAnimationUpdate(ValueAnimator animation) {
5151
}
5252
});
5353
translateYAnim.start();
54+
55+
addAnimation(translateXAnim,translateYAnim);
5456
}
5557
}
5658

library/src/main/java/com/wang/avi/indicator/BallZigZagIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
6262
}
6363
});
6464
translateYAnim.start();
65+
addAnimation(translateXAnim,translateYAnim);
6566
}
6667
}
6768

library/src/main/java/com/wang/avi/indicator/BaseIndicatorController.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22

33
import android.graphics.Canvas;
44
import android.graphics.Paint;
5+
import android.util.Log;
56
import android.view.View;
67

8+
import com.nineoldandroids.animation.Animator;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
713
/**
814
* Created by Jack on 2015/10/15.
915
*/
1016
public abstract class BaseIndicatorController {
1117

18+
1219
private View mTarget;
1320

21+
private List<Animator> mAnimators;
22+
1423

1524
public void setTarget(View target){
1625
this.mTarget=target;
@@ -47,5 +56,63 @@ public void postInvalidate(){
4756
*/
4857
public abstract void createAnimation();
4958

59+
/**
60+
* should be called when you create animation.
61+
* To make animation release better.
62+
* @see #setAnimationStatus(AnimStatus)
63+
* @param animator
64+
*/
65+
public void addAnimation(Animator... animator){
66+
if (mAnimators==null){
67+
mAnimators=new ArrayList<>();
68+
}
69+
int length=animator.length;
70+
for (int i = 0; i < length; i++) {
71+
mAnimators.add(animator[i]);
72+
}
73+
}
74+
75+
76+
/**
77+
* make animation to start or end when target
78+
* view was be Visible or Gone or Invisible.
79+
* make animation to cancel when target view
80+
* be onDetachedFromWindow.
81+
* @param animStatus
82+
*/
83+
public void setAnimationStatus(AnimStatus animStatus){
84+
if (mAnimators==null){
85+
return;
86+
}
87+
Log.d("AnimStatus","setAnimationStatus");
88+
int count=mAnimators.size();
89+
for (int i = 0; i < count; i++) {
90+
Animator animator=mAnimators.get(i);
91+
switch (animStatus){
92+
case START:
93+
if (!animator.isRunning()){
94+
animator.start();
95+
}
96+
break;
97+
case END:
98+
if (animator.isRunning()){
99+
animator.end();
100+
}
101+
break;
102+
case CANCEL:
103+
if (animator.isRunning()){
104+
animator.cancel();
105+
}
106+
break;
107+
}
108+
}
109+
}
110+
111+
112+
public enum AnimStatus{
113+
START,END,CANCEL
114+
}
115+
116+
50117

51118
}

library/src/main/java/com/wang/avi/indicator/CubeTransitionIndicator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public void onAnimationUpdate(ValueAnimator animation) {
6868
}
6969
});
7070
translationYAnim.start();
71+
72+
addAnimation(translationXAnim,translationYAnim);
7173
}
7274

7375
ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.5f,1,0.5f,1);
@@ -95,5 +97,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
9597
}
9698
});
9799
rotateAnim.start();
100+
101+
addAnimation(scaleAnim,rotateAnim);
98102
}
99103
}

library/src/main/java/com/wang/avi/indicator/LineScaleIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
5050
}
5151
});
5252
scaleAnim.start();
53+
addAnimation(scaleAnim);
5354
}
5455
}
5556

library/src/main/java/com/wang/avi/indicator/LineScalePartyIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
5151
}
5252
});
5353
scaleAnim.start();
54+
addAnimation(scaleAnim);
5455
}
5556
}
5657

library/src/main/java/com/wang/avi/indicator/LineScalePulseOutIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
2626
}
2727
});
2828
scaleAnim.start();
29+
addAnimation(scaleAnim);
2930
}
3031
}
3132

library/src/main/java/com/wang/avi/indicator/LineScalePulseOutRapidIndicator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
2525
}
2626
});
2727
scaleAnim.start();
28+
addAnimation(scaleAnim);
2829
}
2930
}
3031

library/src/main/java/com/wang/avi/indicator/PacmanIndicator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
105105
}
106106
});
107107
rotateAnim2.start();
108+
109+
addAnimation(translationAnim,alphaAnim,rotateAnim1,rotateAnim2);
108110
}
109111
}

0 commit comments

Comments
 (0)