a
554325746@qq.com
2019-12-25 603cb36a5123e46656b06a5deb8d7ac7ff81307f
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
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.animation.LinearInterpolator;
 
import com.basic.security.base.BaseApplication;
import com.basic.security.utils.ResolutionAdaptation;
 
public class ScannerView extends BaseShapeView {
    public float value;
    private Paint mPaint;
    private ValueAnimator anim;
 
    public ScannerView(Context context) {
        super(context);
        init();
    }
 
    public ScannerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
 
    public ScannerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }
 
    public void setMeasuredDimension1(int measuredWidth, int measuredHeight) {
        setMeasuredDimension(measuredWidth, measuredHeight);
    }
 
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
 
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
    }
 
    private void init() {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
        mPaint = new Paint();
        mPaint.setColor(Color.parseColor("#74F8F5"));
        mPaint.setStrokeWidth(BaseApplication.getApplication().activity.getResources().getDimension(ResolutionAdaptation.h3()));
        startAnimation();
    }
 
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = this.getWidth();
        canvas.drawLine(0, value, width, value + 1, mPaint);
    }
 
    public void startAnimation() {
        anim = ValueAnimator.ofFloat(0, (int) BaseApplication.getApplication().activity.getResources().getDimension(com.basic.security.utils.RUtils.R_dimen_h310));
        anim.setRepeatCount(ValueAnimator.INFINITE);
        anim.setDuration(2000);
        anim.setInterpolator(new LinearInterpolator());
        anim.addUpdateListener(animation -> {
            value = (Float) animation.getAnimatedValue();
            postInvalidate();
        });
        anim.start();
    }
}