android 下载文件图片圆形进度条

public class CircleProgressImageView extends View {

    private RectF mRect;

    private Paint mPaint;

    private int mCircleStoreWidth = 50;
    /**
     * 最大进度值
     */
    private int mMaxProcessValue = 100;
    /**
     * 进度值
     */
    private int mProcessValue  = -1;

    private int width;

    private int height;

    private int bitmap;

    private Bitmap drawBitmap;

    private Context context;

    public CircleProgressImageView(Context context) {
        this(context, null);
    }

    public CircleProgressImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CircleProgressImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);
    }

    private void init(Context context, AttributeSet attrs, int defStyleAttr) {
        this.context = context;
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CIRCLEPROGRESSIMAGEVIEWATTRS);
        bitmap = a.getResourceId(R.styleable.CIRCLEPROGRESSIMAGEVIEWATTRS_imagers, R.mipmap.fujian_icon);
        drawBitmap = BitmapFactory.decodeResource(context.getResources(), bitmap);
        mRect = new RectF();
        mPaint = new Paint();
        mPaint.setAntiAlias(true);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        width = 120;
        height = 100;
        mRect.left = mCircleStoreWidth / 2 - 10;
        mRect.top = mCircleStoreWidth / 2 - 10;
        mRect.right = width - mCircleStoreWidth / 2 + 10;
        mRect.bottom = width - mCircleStoreWidth / 2 + 10;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(Color.TRANSPARENT);

        //画圆
        float imageLeft = width  - drawBitmap.getWidth() ;
        float imageTop = height - drawBitmap.getHeight();
        canvas.drawBitmap(drawBitmap, imageLeft, imageTop, mPaint);

        if (mProcessValue > 0 && mProcessValue != 100){
            mPaint.setColor(getResources().getColor(R.color.color_800000));
            mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
            mPaint.setStrokeWidth(mCircleStoreWidth);
            canvas.drawRect(mRect,mPaint);
            mPaint.setStyle(Paint.Style.STROKE);
            mPaint.setStrokeWidth(3);
            mPaint.setColor(getResources().getColor((R.color.color_80FFFFFF)));
            canvas.drawArc(mRect,-90,360,false ,mPaint);
            mPaint.setStyle(Paint.Style.FILL);
            mPaint.setStrokeWidth(mCircleStoreWidth);
            canvas.drawArc(mRect,-90,((float) mProcessValue/mMaxProcessValue)*360,true,mPaint);
        }


    }


    public int getmCircleStoreWidth() {
        return mCircleStoreWidth;
    }

    public void setmCircleStoreWidth(int mCircleStoreWidth) {
        this.mCircleStoreWidth = mCircleStoreWidth;
    }

    public int getmProcessValue() {
        return mProcessValue;
    }

    public void setmProcessValue(int mProcessValue) {
        this.mProcessValue = mProcessValue;
        invalidate();
    }

你可能感兴趣的:(android)