admin
2022-04-29 67bdeebb4dc381a2f46f31e3027ebcc3243a8aeb
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.yeshi.makemoney.video.app.ui.subview;
 
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
 
import com.demo.lib.common.util.common.DimenUtils;
import com.yeshi.makemoney.video.app.utils.videos.DrawVideoGoldCornManager;
 
public class CircleProgressView extends View {
    private static final String TAG = "CircleProgressView";
 
    private int mCircleLineStrokeWidth = 8;
 
    private final int mTxtStrokeWidth = 2;
 
    // 画圆所在的距形区域
    private final RectF mRectF;
 
    private final Paint mPaint;
 
    private final Context mContext;
 
    private int mMaxProgress = 1000;
 
    private int mProgress = 0;
 
 
    public CircleProgressView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        mRectF = new RectF();
        mPaint = new Paint();
        mCircleLineStrokeWidth = DimenUtils.dip2px(context, 3);
    }
 
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = this.getWidth();
        int height = this.getHeight();
 
        if (width != height) {
            int min = Math.min(width, height);
            width = min;
            height = min;
        }
 
        // 设置画笔相关属性
        mPaint.setAntiAlias(true);
        mPaint.setColor(Color.TRANSPARENT);
        canvas.drawColor(Color.TRANSPARENT);
        mPaint.setStrokeWidth(mCircleLineStrokeWidth);
        mPaint.setStyle(Paint.Style.STROKE);
        // 位置
        mRectF.left = mCircleLineStrokeWidth / 2; // 左上角x
        mRectF.top = mCircleLineStrokeWidth / 2; // 左上角y
        mRectF.right = width - mCircleLineStrokeWidth / 2; // 左下角x
        mRectF.bottom = height - mCircleLineStrokeWidth / 2; // 右下角y
 
        // 绘制圆圈,进度条背景
        canvas.drawArc(mRectF, -90, 360, false, mPaint);
        mPaint.setColor(Color.rgb(0xff, 0xF5, 0xA9));
        //矩形、开始角度、扫过角度、是否实心、画笔
        canvas.drawArc(mRectF, -90, ((float) mProgress / mMaxProgress) * 360, false, mPaint);
    }
 
    public int getMaxProgress() {
        return mMaxProgress;
    }
 
    public void setMaxProgress(int maxProgress) {
        this.mMaxProgress = maxProgress;
    }
 
    public void setProgress(int progress) {
        this.mProgress = progress;
        this.invalidate();
    }
 
    public void setAnimProgress(int p) {
        //设置属性动画
        ValueAnimator valueAnimator = new ValueAnimator().ofInt(mProgress, p);
        valueAnimator.setDuration(DrawVideoGoldCornManager.SPACE);
        //监听值的变化
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int currentV = (Integer) animation.getAnimatedValue();
                Log.e("fwc", "current" + currentV);
                mProgress = currentV;
                invalidate();
            }
        });
        valueAnimator.start();
    }
 
    //非UI线程调用
    public void setProgressNotInUiThread(int progress) {
        this.mProgress = progress;
        this.postInvalidate();
    }
}