/
ChasingDots.java
82 lines (71 loc) · 2.25 KB
/
ChasingDots.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.github.ybq.android.spinkit.style;
import android.animation.ValueAnimator;
import android.graphics.Rect;
import android.os.Build;
import android.view.animation.LinearInterpolator;
import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder;
import com.github.ybq.android.spinkit.sprite.CircleSprite;
import com.github.ybq.android.spinkit.sprite.Sprite;
import com.github.ybq.android.spinkit.sprite.SpriteContainer;
/**
* Created by ybq.
*/
public class ChasingDots extends SpriteContainer {
@Override
public Sprite[] onCreateChild() {
return new Sprite[]{
new Dot(),
new Dot()
};
}
@Override
public void onChildCreated(Sprite... sprites) {
super.onChildCreated(sprites);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
sprites[1].setAnimationDelay(1000);
} else {
sprites[1].setAnimationDelay(-1000);
}
}
@Override
public ValueAnimator onCreateAnimation() {
float fractions[] = new float[]{0f, 1f};
return new SpriteAnimatorBuilder(this).
rotate(fractions, 0, 360).
duration(2000).
interpolator(new LinearInterpolator()).
build();
}
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
bounds = clipSquare(bounds);
int drawW = (int) (bounds.width() * 0.6f);
getChildAt(0).setDrawBounds(
bounds.right - drawW,
bounds.top,
bounds.right
, bounds.top + drawW
);
getChildAt(1).setDrawBounds(
bounds.right - drawW,
bounds.bottom - drawW,
bounds.right,
bounds.bottom
);
}
private class Dot extends CircleSprite {
Dot() {
setScale(0f);
}
@Override
public ValueAnimator onCreateAnimation() {
float fractions[] = new float[]{0f, 0.5f, 1f};
return new SpriteAnimatorBuilder(this).
scale(fractions, 0f, 1f, 0f).
duration(2000).
easeInOut(fractions)
.build();
}
}
}