Code example for Canvas

Methods: drawOval, getClipBounds

0
	@Override 
	public void draw(final Canvas c)
	{ 
        if (PreferencesUtil.getShowGraph(context))
        { 
        	final Rect clip = squareIt(c.getClipBounds());
        	drawOnCanvas(c, clip);
        } 
	} 
 
	public void drawOnCanvas(final Canvas c, final Rect clip)
	{ 
		final RectF oval =
		    new RectF(clip.left + DRAWABLE_PADDING,
		              clip.top + DRAWABLE_PADDING,
		              clip.right - DRAWABLE_PADDING,
		              clip.bottom - DRAWABLE_PADDING);
 
		Log.e("drawOnCanvas", oval.toString());
 
		drawBackground(c, oval);
		drawMinutesChart(c, oval);
 
		drawTimeChart(c, oval);
 
		drawStroke(c, oval);
 
		drawText(c, clip);
	} 
 
	public void setAlignment(final int iAlignment)
	{ 
		alignment = iAlignment;
	} 
 
    private void drawText(final Canvas c, final Rect clip)
    { 
        final Paint white = new Paint();
        white.setColor(Color.WHITE);
        white.setTextSize(12);
 
        final Paint black = new Paint();
        black.setColor(Color.BLACK);
        black.setTextSize(12);
 
        String text = ((int) (100 * getMinutesPercent())) + "%";
        text = getAccount().getMinutesTotal() - getAccount().getMinutesUsedInt() + "";
 
        final int textHeight = (int) black.getFontMetrics().top / 2;
 
        c.drawText(text,
        		clip.left + (clip.right - clip.left - black.measureText(text)) / 2,
        		clip.top + (clip.bottom - clip.top - textHeight) / 2,
        		black);
    } 
 
    private void drawBackground(final Canvas c, final RectF clip)
    { 
        final Paint p = new Paint();
        p.setColor(Color.WHITE);
        p.setAlpha(BACKGROUND_ALPHA);
        p.setStyle(Paint.Style.FILL);
        p.setAntiAlias(true);
 
        c.drawOval(clip, p);
    } 
 
    private void drawStroke(final Canvas c, final RectF clip)
    { 
        final Paint p = new Paint();