Code example for Canvas

Methods: drawArc, drawOval, drawText

0
        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();
        p.setColor(Color.BLACK);
        p.setAlpha(255);
        p.setStyle(Paint.Style.STROKE);
        p.setAntiAlias(true);
        p.setStrokeWidth(DRAWABLE_STROKE_WIDTH);
 
        c.drawOval(clip, p);
    } 
 
    private void drawMinutesChart(final Canvas c, final RectF clip)
    { 
        final Paint minPaint = new Paint();
        minPaint.setAlpha(getOpacity());
        minPaint.setStyle(Paint.Style.FILL);
        minPaint.setAntiAlias(true);
        if (dateDeg < (minDeg * 1.05F) && dateDeg > (minDeg * .95F))
        { 
            minPaint.setColor(context.getResources().getColor(R.color.warning));
        } 
        else if (dateDeg < minDeg)
        { 
            minPaint.setColor(context.getResources().getColor(R.color.error));
        } 
        else 
        { 
            minPaint.setColor(context.getResources().getColor(R.color.info));
        } 
 
        c.drawArc(clip, 0, minDeg, true, minPaint);
    } 
 
    private void drawTimeChart(final Canvas c, final RectF clip)
    { 
        final RectF degOval = new RectF(clip.left + 10, clip.top + 10, clip.right - 10, clip.bottom - 10);
        final Paint degPaint = new Paint();
        degPaint.setColor(Color.BLACK);
        degPaint.setStyle(Paint.Style.STROKE);
        degPaint.setStrokeWidth(TIME_STROKE_WIDTH);
        degPaint.setAntiAlias(true);
 
        c.drawArc(degOval, 0, dateDeg, false, degPaint);
 
        // stroke the front of the time / minutes 
        /* 
        degPaint.setStrokeWidth(0); 
        final int x = (int) ((clip.right - clip.left) / 2);