Code example for Paint

Methods: ascent, descent, setAlpha, setColor, setTextSize

0
            int layoutYCenter = getHeight() / 2;
            int circleRadius =
                    (int) (Math.min(layoutXCenter, layoutYCenter) * mCircleRadiusMultiplier);
            mAmPmCircleRadius = (int) (circleRadius * mAmPmCircleRadiusMultiplier);
            int textSize = mAmPmCircleRadius * 3 / 4;
            mPaint.setTextSize(textSize);
 
            // Line up the vertical center of the AM/PM circles with the bottom of the main circle. 
            mAmPmYCenter = layoutYCenter - mAmPmCircleRadius / 2 + circleRadius;
            // Line up the horizontal edges of the AM/PM circles with the horizontal edges 
            // of the main circle. 
            mAmXCenter = layoutXCenter - circleRadius + mAmPmCircleRadius;
            mPmXCenter = layoutXCenter + circleRadius - mAmPmCircleRadius;
 
            mDrawValuesReady = true;
        } 
 
        // We'll need to draw either a lighter blue (for selection), a darker blue (for touching) 
        // or white (for not selected). 
        int amColor = mWhite;
        int amAlpha = 255;
        int pmColor = mWhite;
        int pmAlpha = 255;
        if (mAmOrPm == AM) {
            amColor = mBlue;
            amAlpha = SELECTED_ALPHA;
        } else if (mAmOrPm == PM) {
            pmColor = mBlue;
            pmAlpha = SELECTED_ALPHA;
        } 
        if (mAmOrPmPressed == AM) {
            amColor = mBlue;
            amAlpha = PRESSED_ALPHA;
        } else if (mAmOrPmPressed == PM) {
            pmColor = mBlue;
            pmAlpha = PRESSED_ALPHA;
        } 
 
        // Draw the two circles. 
        mPaint.setColor(amColor);
        mPaint.setAlpha(amAlpha);
        canvas.drawCircle(mAmXCenter, mAmPmYCenter, mAmPmCircleRadius, mPaint);
        mPaint.setColor(pmColor);
        mPaint.setAlpha(pmAlpha);
        canvas.drawCircle(mPmXCenter, mAmPmYCenter, mAmPmCircleRadius, mPaint);
 
        // Draw the AM/PM texts on top. 
        mPaint.setColor(mAmPmTextColor);
        int textYCenter = mAmPmYCenter - (int) (mPaint.descent() + mPaint.ascent()) / 2;
        canvas.drawText(mAmText, mAmXCenter, textYCenter, mPaint);
        canvas.drawText(mPmText, mPmXCenter, textYCenter, mPaint);
    } 
}