Back to project page markj.
The source code is released under:
GNU Lesser General Public License
If you think the Android project markj listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.markjmind.mobile.api.android.ui.graph; //www .j a v a2 s. com import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.EmbossMaskFilter; import android.graphics.Paint; import android.graphics.Paint.Cap; import android.graphics.RectF; import android.view.View; /** * * ???????? ?? ??? ???? ????? ????.<br> * ?????? ????? Arc ?????? ?? ?? ??????.<br> * ?????? ????? ????????? ???? ???? ?????? ??? ????<br> * ????? ???? canvas?? ????? ???? ??????? ????????.<br> * ?? ????? ?? ??????? ???? ??. * @author ??? */ public class Arc { private PieLayout pl; public float start=0; public float end=360; private int color=Color.BLUE; private int strokSize=1; private Paint paint; private RectF oval = new RectF(); private float x=0; private float y=0; private float height; private float width; private float margin = 0; private boolean isCapRound = false; private EmbossMaskFilter emboss = null; /** * ????? * @param pl PieLayout ??? */ public Arc(PieLayout pl){ this.pl = pl; init(); setArc(start,end,color); } /** * ????? * @param width ???? * @param height ???? * @param pl PieLayout ??? */ public Arc(float width,float height,PieLayout pl){ this.pl = pl; init(); setSize(width,height); setArc(start,end,color); } private void init(){ paint = new Paint(); // pl.setLayerType(View.LAYER_TYPE_SOFTWARE,null); if(isCapRound){ paint.setStrokeCap(Cap.ROUND); } if(emboss!=null){ paint.setMaskFilter(emboss); } paint.setAntiAlias(true); paint.setStyle(Paint.Style.STROKE); } /** * ????? ?? * @param width ???? * @param height ???? */ public void setSize(float width,float height, float margin){ this.margin = margin; this.width = width-margin*2; this.height = height-margin*2; reSetOval(); } /** * ????? ?? * @param width ???? * @param height ???? */ public void setSize(float width,float height){ this.setSize(width, height,0); } /** * ?????? ??? ??? ????. */ private void reSetOval(){ float strok = strokSize/2; float jirm; if(width < height){ this.x = strok+margin; this.y = (height-width)/2+strok+margin; jirm = width; }else{ this.x = (width-height)/2+strok+margin; this.y = strok+margin; jirm = height; } width = jirm+x-strok*2; height = jirm+y-strok*2; oval.set(x,y,width,height); Math.sin(getRadian(20)); } public double getRadian(double degree) { double radian = 0; radian = Math.PI * degree/180; return radian; } /** * ????(?????)?? ?? ?????(?????)????? ??<br> * ??? ??? ????. * @param start ????(?????) * @param end ?????(?????) * @param color ?? */ public void setArc(float start, float end, int color){ this.start = start; this.end = end; this.color = color; setPaint(color); } /** * ????? ???????? ????. * @param start ????(?????) * @param end ?????(?????) */ public void setAngle(float start, float end){ this.start = start; this.end = end; } /** * ?,??????? paint???? ????. * @param paint paint?? ??? */ public void setPaint(Paint paint){ this.paint = paint; } /** * ??? ??? strokSize ??????? ?? ????. * @param color ?? * @param strokSize ???? */ public void setPaint(int color, int strokSize){ setColor(color); setStrokSize(strokSize); } /** * ??? ??? strokSize ??????? ?? ????. * @param color ?? * @param strokSize ???? */ public void setPaint(int color){ setPaint(color, 5); } /** * ???? ??? ????. * @param color ?? */ public void setColor(int color){ this.color = color; paint.setColor(color); } /** * ???? ???? ????. * @param size ???? */ public void setStrokSize(int size){ this.strokSize = size; paint.setStrokeWidth(strokSize); } /** * ?? ???. * @param canvas canvas ??? */ public void draw(Canvas canvas){ oval = new RectF(x,y,width,height); canvas.drawArc(oval, start-90, end, false, paint); } /** * ?????? ????????? ?? ???? ????? ?? ????. * @param end ?????(?????) * @param color ?? */ public Arc addArcAngle(float end,int color){ return pl.addArc(this.start+this.end, end, color); } /** * ?????? ????????? ?? ???? ????? ?? ????. * @param end ?????(?????) * @param color ?? */ public Arc addArcPercent(int addPercent,int color){ float cap = Math.round(pl.getMaxAngle() - pl.getStartAngle()); float curr = Math.round(cap*addPercent/100); return addArcAngle(curr, color); } public Arc setCapRound(boolean isCapRound){ this.isCapRound = isCapRound; init(); return this; } public Arc setMaskFilter(EmbossMaskFilter emboss){ this.emboss = emboss; init(); return this; } public EmbossMaskFilter getMaskFilter(){ return emboss; } }