DeteMin
2020-03-31 77c62e023d2dc31200fc696158df84b3aee90ee7
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.basic.security.widget;
 
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.LinearInterpolator;
 
import com.basic.security.R;
import com.basic.security.base.BaseApplication;
 
public class PlusView extends View {
 
    public float value;
    private Paint mPaint;
    private ValueAnimator anim;
 
    public PlusView(Context context) {
        super(context);
        init();
    }
 
    public PlusView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
 
    public PlusView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }
 
    private void init() {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
        mPaint = new Paint();
        mPaint.setColor(Color.parseColor("#74F8F5"));
        mPaint.setStrokeWidth(BaseApplication.getApplication().activity.getResources().getDimension(R.dimen.h3));
 
        startAnimation();
//        mPaint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.SOLID));
    }
 
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = this.getWidth();
//        int height = this.getHeight();
 
//        int lineLong = (int) BaseApplication.getApplication().activity.getResources().getDimension(R.dimen.h70);
 
//        // 横
//        canvas.drawLine(width / 2 - lineLong / 2, height / 2, width / 2 + lineLong / 2, height / 2, mPaint);
//
//        // 竖
//        canvas.drawLine(width / 2, height / 2 - lineLong / 2, width / 2, height / 2 + lineLong / 2, mPaint);
 
 
        canvas.drawLine(0, value, width, value + 1, mPaint);
 
    }
 
 
    public void startAnimation() {
        anim = ValueAnimator.ofFloat(0, (int) BaseApplication.getApplication().activity.getResources().getDimension(R.dimen.h310));
        anim.setRepeatCount(ValueAnimator.INFINITE);
//        anim.setRepeatMode(ValueAnimator.REVERSE);
        anim.setDuration(2000);
        anim.setInterpolator(new LinearInterpolator());
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                value = (Float) animation.getAnimatedValue();
                postInvalidate();
            }
        });
        anim.start();
    }
 
}