Example usage for android.graphics Canvas drawRect

List of usage examples for android.graphics Canvas drawRect

Introduction

In this page you can find the example usage for android.graphics Canvas drawRect.

Prototype

public void drawRect(@NonNull Rect r, @NonNull Paint paint) 

Source Link

Document

Draw the specified Rect using the specified Paint.

Usage

From source file:com.google.android.marvin.utils.HighlightBoundsView.java

@Override
public void onDraw(Canvas c) {
    final int saveCount = c.save();
    c.translate(-SCREEN_LOCATION[0], -SCREEN_LOCATION[1]);
    c.setMatrix(mMatrix);/*from w  w w.  j  a  v a2 s  .co m*/

    mPaint.setColor(mHighlightColor);

    for (AccessibilityNodeInfoCompat node : mNodes) {
        node.getBoundsInScreen(mTemp);
        c.drawRect(mTemp, mPaint);
    }

    c.restoreToCount(saveCount);
}

From source file:com.dean.phonesafe.ui.SlideSwitch.java

@Override
protected void onDraw(Canvas canvas) {
    if (shape == SHAPE_RECT) {
        paint.setColor(Color.GRAY);
        canvas.drawRect(backRect, paint);
        paint.setColor(color_theme);//from w w w  .j ava  2  s. co m
        paint.setAlpha(alpha);
        canvas.drawRect(backRect, paint);
        frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE,
                getMeasuredHeight() - RIM_SIZE);
        paint.setColor(Color.WHITE);
        canvas.drawRect(frontRect, paint);
    } else {
        // draw circle
        int radius;
        radius = backRect.height() / 2 - RIM_SIZE;
        paint.setColor(Color.GRAY);
        backCircleRect.set(backRect);
        canvas.drawRoundRect(backCircleRect, radius, radius, paint);
        paint.setColor(color_theme);
        paint.setAlpha(alpha);
        canvas.drawRoundRect(backCircleRect, radius, radius, paint);
        frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE,
                backRect.height() - RIM_SIZE);
        frontCircleRect.set(frontRect);
        paint.setColor(Color.WHITE);
        canvas.drawRoundRect(frontCircleRect, radius, radius, paint);

    }
    //??
    //?
    paint.setStrokeWidth(2);
    paint.setAlpha(alpha);
    paint.setStyle(Paint.Style.STROKE);

    float gap = backRect.width() - frontRect.width();
    float left = frontRect.left - gap + frontRect.width() / 2;
    canvas.drawLine(left, backRect.height() / 4, left, backRect.height() / 4 * 3, paint);

    //??
    paint.setAlpha(255 - alpha);
    left = frontRect.left + gap + frontRect.width() / 2;
    canvas.drawCircle(left, backRect.height() / 2, frontRect.width() / 5, paint);
    //
    paint.setStyle(Paint.Style.FILL);
}

From source file:com.inetgoes.fangdd.view.SlideSwitch.java

@Override
protected void onDraw(Canvas canvas) {
    if (shape == SHAPE_RECT) {
        //paint.setColor(Color.GRAY);
        paint.setColor(DEFAULT_COLOR_THEME);
        canvas.drawRect(backRect, paint);
        paint.setColor(color_theme);/*from  w w  w .j a v  a 2s.  com*/
        paint.setAlpha(alpha);
        canvas.drawRect(backRect, paint);
        frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE,
                getMeasuredHeight() - RIM_SIZE);
        paint.setColor(Color.WHITE);
        canvas.drawRect(frontRect, paint);
    } else {
        // draw circle
        int radius;
        //radius = backRect.height() / 2 - RIM_SIZE;
        radius = backRect.height() / 2;
        //paint.setColor(Color.GRAY);
        paint.setColor(DEFAULT_COLOR_THEME);
        backCircleRect.set(backRect);
        canvas.drawRoundRect(backCircleRect, radius, radius, paint);
        paint.setColor(color_theme);
        paint.setAlpha(alpha);
        canvas.drawRoundRect(backCircleRect, radius, radius, paint);
        frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE,
                backRect.height() - RIM_SIZE);
        frontCircleRect.set(frontRect);
        paint.setColor(Color.WHITE);
        canvas.drawRoundRect(frontCircleRect, radius, radius, paint);
    }
}

From source file:com.audionote.widget.SlideSwitch.java

@Override
protected void onDraw(Canvas canvas) {
    if (shape == SHAPE_RECT) {
        paint.setColor(color_back_theme);
        canvas.drawRect(backRect, paint);
        paint.setColor(color_theme);/*from   www.jav  a 2s .  c  o m*/
        paint.setAlpha(alpha);
        canvas.drawRect(backRect, paint);
        frontRect.set(frontRect_left, borderWidth, frontRect_left + backRect.height() - 2 * borderWidth,
                backRect.height() - borderWidth);
        paint.setColor(Color.WHITE);
        canvas.drawRect(frontRect, paint);
    } else {
        // draw circle
        int backBorderRadius = backBorderRect.height() / 2;
        int backRadius = backBorderRadius - borderWidth;

        // 
        paint.setColor(border_color);
        backBorderCircleRect.set(backBorderRect);
        canvas.drawRoundRect(backBorderCircleRect, backBorderRadius, backBorderRadius, paint);

        // 
        paint.setColor(color_back_theme);
        backCircleRect.set(backRect);
        canvas.drawRoundRect(backCircleRect, backRadius, backRadius, paint);

        // ??
        paint.setColor(color_theme);
        paint.setAlpha(alpha);
        canvas.drawRoundRect(backBorderCircleRect, backBorderRadius, backBorderRadius, paint);

        // ?
        frontBorderRect.set(frontRect_left, 0, frontRect_left + backBorderRect.height(),
                backBorderRect.height());
        frontBorderCircleRect.set(frontBorderRect);
        paint.setColor(border_color);
        canvas.drawRoundRect(frontBorderCircleRect, backBorderRadius, backBorderRadius, paint);

        // ?
        frontRect.set(frontRect_left + borderWidth, borderWidth,
                frontRect_left + backBorderRect.height() - borderWidth, backBorderRect.height() - borderWidth);
        frontCircleRect.set(frontRect);
        paint.setColor(Color.WHITE);
        canvas.drawRoundRect(frontCircleRect, backRadius, backRadius, paint);
    }
}

From source file:com.jaredrummler.android.colorpicker.ColorPanelView.java

@Override
protected void onDraw(Canvas canvas) {
    borderPaint.setColor(borderColor);//from  w ww . j ava 2s.  c  o m
    colorPaint.setColor(color);
    if (shape == ColorShape.SQUARE) {
        if (borderWidthPx > 0) {
            canvas.drawRect(drawingRect, borderPaint);
        }
        if (alphaPattern != null) {
            alphaPattern.draw(canvas);
        }
        canvas.drawRect(colorRect, colorPaint);
    } else if (shape == ColorShape.CIRCLE) {
        final int outerRadius = getMeasuredWidth() / 2;
        if (borderWidthPx > 0) {
            canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, outerRadius, borderPaint);
        }
        if (Color.alpha(color) < 255) {
            canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, outerRadius - borderWidthPx,
                    alphaPaint);
        }
        if (showOldColor) {
            canvas.drawArc(centerRect, 90, 180, true, originalPaint);
            canvas.drawArc(centerRect, 270, 180, true, colorPaint);
        } else {
            canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, outerRadius - borderWidthPx,
                    colorPaint);
        }
    }
}

From source file:com.google.android.gms.samples.vision.barcodereader.BarcodeGraphic.java

/**
 * Draws the barcode annotations for position, size, and raw value on the supplied canvas.
 *//* w ww.j  a va  2  s.  c om*/
@Override
public void draw(Canvas canvas) {
    Barcode barcode = mBarcode;
    if (barcode == null) {
        return;
    }

    // Draws the bounding box around the barcode.
    RectF rect = new RectF(barcode.getBoundingBox());
    rect.left = translateX(rect.left);
    rect.top = translateY(rect.top);
    rect.right = translateX(rect.right);
    rect.bottom = translateY(rect.bottom);
    if (graphicOverlay.isDrawRect())
        canvas.drawRect(rect, mRectPaint);

    // Draws a label at the bottom of the barcode indicate the barcode value that was detected.
    if (graphicOverlay.isShowText())
        canvas.drawText(barcode.rawValue, rect.left, rect.bottom, mTextPaint);
}

From source file:com.samebits.beacon.locator.ui.view.RadarScanView.java

private void addText(Canvas canvas, String str, int x, int y) {
    mGridPaint.getTextBounds(str, 0, str.length(), mTextBounds);
    mTextBounds.offset(x - (mTextBounds.width() >> 1), y);
    mTextBounds.inset(-2, -2);/*from  ww  w . j a va  2s.c o m*/
    canvas.drawRect(mTextBounds, mErasePaint);
    canvas.drawText(str, x, y, mGridPaint);
}

From source file:com.jwetherell.quick_response_code.DecoderActivity.java

protected void drawResultPoints(Bitmap barcode, Result rawResult) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
        Canvas canvas = new Canvas(barcode);
        Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.result_image_border));
        paint.setStrokeWidth(3.0f);//from w  w  w . j a va  2s.c om
        paint.setStyle(Paint.Style.STROKE);
        Rect border = new Rect(2, 2, barcode.getWidth() - 2, barcode.getHeight() - 2);
        canvas.drawRect(border, paint);

        paint.setColor(getResources().getColor(R.color.result_points));
        if (points.length == 2) {
            paint.setStrokeWidth(4.0f);
            drawLine(canvas, paint, points[0], points[1]);
        } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A
                || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
            // Hacky special case -- draw two lines, for the barcode and
            // metadata
            drawLine(canvas, paint, points[0], points[1]);
            drawLine(canvas, paint, points[2], points[3]);
        } else {
            paint.setStrokeWidth(10.0f);
            for (ResultPoint point : points) {
                canvas.drawPoint(point.getX(), point.getY(), paint);
            }
        }
    }
}

From source file:com.kayac.slidingmenu.ui.views.DraggableLayout.java

public void dispatchDraw(Canvas c) {
    super.dispatchDraw(c);
    if (mShadowDrawable != null) {
        mShadowDrawable.draw(c);//from w w w.ja v  a2  s.c  o m
    }
    if (mPaint != null && mBlackShadowRect != null && mIsDimBackground) {
        c.drawRect(mBlackShadowRect, mPaint);
    }
}

From source file:cn.com.hgh.view.SlideSwitch.java

@Override
protected void onDraw(Canvas canvas) {
    if (shape == SHAPE_RECT) {
        //         paint.setColor(Color.GRAY);
        paint.setColor(0xffededed);//
        canvas.drawRect(backRect, paint);
        paint.setColor(color_theme);/*ww  w  . j ava 2 s  .  c o m*/
        paint.setAlpha(alpha);
        canvas.drawRect(backRect, paint);
        frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE,
                getMeasuredHeight() - RIM_SIZE);
        paint.setColor(Color.WHITE);
        canvas.drawRect(frontRect, paint);
    } else {
        int radius;
        radius = backRect.height() / 2 - RIM_SIZE;
        //         paint.setColor(Color.GRAY);//
        paint.setColor(0xffededed);//

        backCircleRect.set(backRect);
        canvas.drawRoundRect(backCircleRect, radius, radius, paint);
        paint.setColor(Color.BLACK);
        paint.setTextSize(AbViewUtil.sp2px(getContext(), 15));
        //          paint.setAlpha(alpha);
        frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE,
                getMeasuredHeight() - RIM_SIZE);

        frontCircleRect.set(frontRect);
        paint.setColor(Color.WHITE);
        canvas.drawRoundRect(frontCircleRect, radius, radius, paint);
        if (isOpen) {

            //            canvas.drawText("?", radius, radius + 23, paint);//
            paint.setColor(Color.BLACK);
            paint.setTextAlign(Paint.Align.CENTER);
            canvas.drawText("?", width / 4 - RIM_SIZE, radius + 23, paint);//

        } else {
            //            canvas.drawText("?", getMeasuredWidth() - radius - 40 * 3,radius + 23, paint);
            paint.setColor(Color.BLACK);
            paint.setTextAlign(Paint.Align.CENTER);
            canvas.drawText("?", width - frontCircleRect.width() / 2 - RIM_SIZE, radius + 23, paint);
        }

        if (isOpen) {
            paint.setColor(0xff14c4c4);
            paint.setTextAlign(Paint.Align.CENTER);
            paint.getTextBounds("?", 0, "?".length(), frontRect);
            paint.setTextSize(AbViewUtil.sp2px(getContext(), 15));
            //              paint.setAlpha(alpha1);
            //            canvas.drawText("?", getMeasuredWidth() - radius - 40 * 3,radius + 23, paint);
            canvas.drawText("?", frontCircleRect.centerX(), radius + 23, paint);

        } else {

            paint.setColor(0xff14c4c4);
            paint.setTextAlign(Paint.Align.CENTER);
            paint.getTextBounds("?", 0, "?".length(), frontRect);
            paint.setTextSize(AbViewUtil.sp2px(getContext(), 15));
            //            paint.setAlpha(alpha1);
            //            canvas.drawText("?", radius, radius + 23, paint);
            canvas.drawText("?", frontCircleRect.centerX(), radius + 23, paint);

        }

    }
}