show above
package com.skytea.circleview;
import javax.crypto.spec.OAEPParameterSpec;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
/**
* @Title: CircleProgressBarView.java
* @Copyright: Copyright December 14, 2015 4:29:55 pm, all rights reserved
* @Description: TODO
* @author: SkyTea
* @data: 4:29:55 pm on December 14, 2015
* @version: V1.0
*/
public class CircleProgressBarView extends View{
private int progress=20;
private int max=100;
private Paint paint;
private RectF oval;
public CircleProgressBarView(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
// TODO Auto-generated constructor stub
paint=new Paint();
oval=new RectF();
new Thread(new Runnable() {
@Override
public void run() {
while(true){
progress++;
postInvalidate();
if (progress==100) {
break;
}
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
}
public CircleProgressBarView(Context context, AttributeSet attrs) {
this(context,attrs,0);
// TODO Auto-generated constructor stub
}
public CircleProgressBarView(Context context) {
this(context,null);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
paint.setAntiAlias(true);// Set whether to anti -aliasing
paint.setFlags(Paint.ANTI_ALIAS_FLAG);// Help to eliminate jagged
paint.setColor(Color.GRAY);// Set the brush gray
paint.setStrokeWidth(10);// Set the brush width
paint.setStyle(Paint.Style.STROKE);// Set the hollow style
canvas.drawCircle(getWidth()/2, getHeight()/2, 55, paint);
paint.setColor(Color.GREEN);// Set the brush to green
oval.set(getWidth()/2-55, getHeight()/2-55, getWidth()/2+55, getHeight()/2+55);
// canvas.drawRect(oval, paint);
canvas.drawArc(oval, -90, ((float) progress / max) * 360, false, paint);
paint.reset();// Reset the brush
paint.setStrokeWidth(3);// Set the width of the brush again
paint.setTextSize(35);// Set the size of the text
paint.setColor(Color.BLACK);// Set the color of the brush
if (progress == max) {
canvas.drawText("Complete", getWidth()/2-25, getHeight()/2, paint);
} else {
canvas.drawText(progress + "%", getWidth()/2-15, getHeight()/2+10, paint);
}
}
}