blob: 8b4bf065fc214cc077758c3c71137631761435e9 (
plain)
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
83
|
package com.android.systemui.cm;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.view.animation.AnticipateOvershootInterpolator;
public class GlowBackground extends Drawable implements ValueAnimator.AnimatorUpdateListener {
private static final int MAX_CIRCLE_SIZE = 150;
private final Paint mPaint;
private Animator mAnimator;
private float mCircleSize;
public GlowBackground(int color) {
mPaint = new Paint();
mPaint.setColor(color);
}
private void startAnimation(boolean hide) {
if (mAnimator != null) {
mAnimator.cancel();
}
if (hide && mCircleSize == 0f) {
return;
} else if (!hide && mCircleSize == MAX_CIRCLE_SIZE) {
return;
}
mAnimator = getAnimator(hide);
mAnimator.start();
}
private Animator getAnimator(boolean hide) {
float start = mCircleSize;
float end = MAX_CIRCLE_SIZE;
if (hide) {
end = 0f;
}
ValueAnimator animator = ObjectAnimator.ofFloat(start, end);
animator.setInterpolator(new AnticipateOvershootInterpolator());
animator.setDuration(300);
animator.addUpdateListener(this);
return animator;
}
@Override
public void draw(Canvas canvas) {
canvas.drawCircle(getBounds().width() / 2, getBounds().height() / 2, mCircleSize, mPaint);
}
@Override
public void setAlpha(int i) {
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
@Override
public int getOpacity() {
return 0;
}
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mCircleSize = (Float) valueAnimator.getAnimatedValue();
invalidateSelf();
}
public void hideGlow() {
startAnimation(true);
}
public void showGlow() {
startAnimation(false);
}
}
|