Skip to content

Commit e74a231

Browse files
committed
Add CustomIndicator
1 parent 52d4a7a commit e74a231

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ It's very simple use just like Progressbar.
6060

6161
```
6262

63+
## Custom Indicator
64+
65+
See [MyCustomIndicator]()
66+
6367
## Indicators
6468

6569
As seen above in the **Demo**, the indicators are as follows:
@@ -105,6 +109,9 @@ As seen above in the **Demo**, the indicators are as follows:
105109
* `Pacman`
106110
* `BallGridBeat`
107111
* `SemiCircleSpin`
112+
113+
**Row 8**
114+
* `com.wang.avi.sample.MyCustomIndicator`
108115

109116
## Thanks
110117
- [nineoldandroids](https://github.com/JakeWharton/NineOldAndroids)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.wang.avi.sample;
2+
3+
import android.graphics.Canvas;
4+
import android.graphics.Paint;
5+
6+
import com.nineoldandroids.animation.ValueAnimator;
7+
import com.wang.avi.Indicator;
8+
9+
import java.util.ArrayList;
10+
11+
/**
12+
* Created by Jack Wang on 2016/8/5.
13+
*/
14+
15+
public class MyCustomIndicator extends Indicator{
16+
17+
18+
public static final float SCALE=1.0f;
19+
20+
//scale x ,y
21+
private float[] scaleFloats=new float[]{SCALE,
22+
SCALE,
23+
SCALE,
24+
SCALE,
25+
SCALE};
26+
27+
28+
29+
@Override
30+
public void draw(Canvas canvas, Paint paint) {
31+
float circleSpacing=4;
32+
float radius=(Math.min(getWidth(),getHeight())-circleSpacing*2)/12;
33+
float x = getWidth()/ 2-(radius*2+circleSpacing);
34+
float y=getHeight() / 2;
35+
for (int i = 0; i < 4; i++) {
36+
canvas.save();
37+
float translateX=x+(radius*2)*i+circleSpacing*i;
38+
canvas.translate(translateX, y);
39+
canvas.scale(scaleFloats[i], scaleFloats[i]);
40+
canvas.drawCircle(0, 0, radius, paint);
41+
canvas.restore();
42+
}
43+
}
44+
45+
@Override
46+
public ArrayList<ValueAnimator> onCreateAnimators() {
47+
ArrayList<ValueAnimator> animators=new ArrayList<>();
48+
int[] delays=new int[]{120,240,360,480};
49+
for (int i = 0; i < 4; i++) {
50+
final int index=i;
51+
52+
ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.3f,1);
53+
54+
scaleAnim.setDuration(750);
55+
scaleAnim.setRepeatCount(-1);
56+
scaleAnim.setStartDelay(delays[i]);
57+
58+
scaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
59+
@Override
60+
public void onAnimationUpdate(ValueAnimator animation) {
61+
scaleFloats[index] = (float) animation.getAnimatedValue();
62+
postInvalidate();
63+
64+
}
65+
});
66+
animators.add(scaleAnim);
67+
}
68+
return animators;
69+
}
70+
71+
72+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public IndicatorHolder(View itemView) {
8686
"TriangleSkewSpinIndicator",
8787
"PacmanIndicator",
8888
"BallGridBeatIndicator",
89-
"SemiCircleSpinIndicator"
89+
"SemiCircleSpinIndicator",
90+
"com.wang.avi.sample.MyCustomIndicator"
9091
};
9192

9293
}

0 commit comments

Comments
 (0)