Code example for RectF

Methods: centerX, centerY, width

0
        mAlphaPaint.setShader(mAlphaShader);
 
        canvas.drawRect(rect, mAlphaPaint);
 
        if (mAlphaSliderText != null && mAlphaSliderText != "") {
            canvas.drawText(mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity,
                    mAlphaTextPaint);
        } 
 
        float rectWidth = 4 * mDensity / 2;
        Point p = alphaToPoint(mAlpha);
 
        RectF r = new RectF();
        r.left = p.x - rectWidth;
        r.right = p.x + rectWidth;
        r.top = rect.top - RECTANGLE_TRACKER_OFFSET;
        r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET;
 
        canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
    } 
 
    private Point hueToPoint(float hue) {
        final RectF rect = mHueRect;
        final float height = rect.height();
 
        Point p = new Point();
        p.y = (int) (height - (hue * height / 360f) + rect.top);
        p.x = (int) rect.left;
        return p;
    } 
 
    private Point satValToPoint(float sat, float val) {
 
        final RectF rect = mSatValRect;
        final float height = rect.height();
        final float width = rect.width();
 
        Point p = new Point();
 
        p.x = (int) (sat * width + rect.left);
        p.y = (int) ((1f - val) * height + rect.top);
 
        return p;
    } 
 
    private Point alphaToPoint(int alpha) {
        final RectF rect = mAlphaRect;
        final float width = rect.width();
 
        Point p = new Point();
        p.x = (int) (width - (alpha * width / 0xff) + rect.left);
        p.y = (int) rect.top;
        return p;