Code example for Canvas

Methods: drawArc, drawText

0
        } else if (getBatteryStatus() == BatteryManager.BATTERY_STATUS_FULL) {
            level = 100;
        } 
 
        // draw thin gray ring first 
        canvas.drawArc(drawRect, 270, 360, false, mPaintGray);
        // draw colored arc representing charge level 
        canvas.drawArc(drawRect, 270 + animOffset, 3.6f * level, false, usePaint);
        // if chosen by options, draw percentage text in the middle 
        // always skip percentage when 100, so layout doesnt break 
        if (unknownStatus) {
            mPaintFont.setColor(usePaint.getColor());
            canvas.drawText("?", textX, mTextY, mPaintFont);
        } else if (level < 100 && mPercentage) {
            mPaintFont.setColor(usePaint.getColor());
            canvas.drawText(Integer.toString(level), textX, mTextY, mPaintFont);
        } 
 
    } 
 
    @Override