packagecom.soyoungboy.sweepgradientprogress;importandroid.content.Context;importandroid.graphics.BlurMaskFilter;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.EmbossMaskFilter;importandroid.graphics.Paint;importandroid.graphics.RectF;importandroid.util.AttributeSet;importandroid.view.View;/*** 圆形颜色渐变的进度条
*@authorsoyoungboy
**/
public class SweepGradientCircleProgressBar extendsView {privatePaint pathPaint;privatePaint fillArcPaint;//设置光源的方向
private float[] direction = new float[] {1, 1, 1};//设置环境光亮度
private float light = 0.4f;//选择要应用的反射等级
private float specular = 6;privateEmbossMaskFilter emboss;privateRectF oval ;privateBlurMaskFilter mBlur;//view重绘的标记
private boolean reset = false;//向 mask应用一定级别的模糊
private float blur = 3.5f;private int arcradus = 30;publicSweepGradientCircleProgressBar(Context context ,AttributeSet attrs) {super(context,attrs);
initPaint();
oval= newRectF();
emboss= newEmbossMaskFilter(direction, light, specular, blur);
mBlur= new BlurMaskFilter(20, BlurMaskFilter.Blur.NORMAL);
}//初始化画笔操作
private voidinitPaint() {//初始化画笔操作
pathPaint = newPaint();//设置是否抗锯齿
pathPaint.setAntiAlias(true);//帮助消除锯齿
pathPaint.setFlags(Paint.ANTI_ALIAS_FLAG);//设置中空的样式
pathPaint.setStyle(Paint.Style.STROKE);
pathPaint.setDither(true);
pathPaint.setStrokeJoin(Paint.Join.ROUND);
fillArcPaint= newPaint();//设置是否抗锯齿
fillArcPaint.setAntiAlias(true);//帮助消除锯齿
fillArcPaint.setFlags(Paint.ANTI_ALIAS_FLAG);//设置中空的样式
fillArcPaint.setStyle(Paint.Style.STROKE);
fillArcPaint.setDither(true);
fillArcPaint.setStrokeJoin(Paint.Join.ROUND);
}
@Overrideprotected voidonDraw(Canvas canvas) {super.onDraw(canvas);int height =getMeasuredWidth();int width =getMeasuredWidth();//半径 = 宽/2-圆环的宽度
int radius = width/2-arcradus;int cx = width/2;int cy = height/2;//绘制画笔颜色
pathPaint.setColor(Color.RED);//画笔的宽度
pathPaint.setStrokeWidth(10);
pathPaint.setMaskFilter(emboss);
canvas.drawCircle(cx, cy, radius, pathPaint);
}
}