Code example for Rect

Methods: centerXcenterYheightwidth

0
    } 
 
    @Override 
    protected void onDraw(Canvas canvas) {
        BitmapDrawable bmDrawable = (BitmapDrawable) getDrawable();
        Rect rect = new Rect();
        getDrawingRect(rect);
        Bitmap product = Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888);
 
        if (bmDrawable != null && bmDrawable.getBitmap() != null) {
            product.setDensity(bmDrawable.getBitmap().getDensity());
            Canvas c = new Canvas(product);
            c.setDensity(canvas.getDensity());
            c.drawColor(mFillColor);
            super.onDraw(c);
            if (maskDrawable != null) {
                Paint p = new Paint();
                p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
                c.drawBitmap(maskDrawable.getBitmap(), null, rect, p);
            } else if (maskDrawableNine != null) {
                maskDrawableNine.setBounds(rect);
                maskDrawableNine.getPaint().setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
                maskDrawableNine.draw(c);
            } 
            if(shadowColor!=0){
                //draw glare 
                Paint glarePaint = new Paint();
                glarePaint.setColor(shadowColor);
                glarePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
                Path glarePath = new Path();
                glarePath.moveTo(rect.centerX()-rect.width()/2, rect.centerY()-rect.height()/2);
                glarePath.lineTo(rect.centerX()-rect.width()/2, rect.centerY()+rect.height()/2-rect.height()/5);
                glarePath.lineTo(rect.centerX()+rect.width()/2, rect.centerY()-rect.height()/2+rect.height()/5);
                glarePath.lineTo(rect.centerX()+rect.width()/2, rect.centerY()-rect.height()/2);
                c.drawPath(glarePath, glarePaint);
            } 
            if (overlayDrawable != null) {
                Paint p = new Paint();
                c.drawBitmap(overlayDrawable.getBitmap(), null, rect, p);