Example usage for android.graphics Canvas clipRect

List of usage examples for android.graphics Canvas clipRect

Introduction

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

Prototype

@Deprecated
public boolean clipRect(float left, float top, float right, float bottom, @NonNull Region.Op op) 

Source Link

Document

Modify the current clip with the specified rectangle, which is expressed in local coordinates.

Usage

From source file:com.codegarden.nativenavigation.JuceActivity.java

public final void excludeClipRegion(android.graphics.Canvas canvas, float left, float top, float right,
        float bottom) {
    canvas.clipRect(left, top, right, bottom, android.graphics.Region.Op.DIFFERENCE);
}

From source file:com.juce.JuceAppActivity.java

public final void excludeClipRegion (android.graphics.Canvas canvas, float left, float top, float right, float bottom)
{
    canvas.clipRect (left, top, right, bottom, android.graphics.Region.Op.DIFFERENCE);
}

From source file:com.android.launcher3.BubbleTextView.java

@Override
public void draw(Canvas canvas) {
    if (!mCustomShadowsEnabled) {
        super.draw(canvas);
        return;//from w ww.  j av  a2s. c  o  m
    }

    final Drawable background = mBackground;
    if (background != null) {
        final int scrollX = getScrollX();
        final int scrollY = getScrollY();

        if (mBackgroundSizeChanged) {
            background.setBounds(0, 0, getRight() - getLeft(), getBottom() - getTop());
            mBackgroundSizeChanged = false;
        }

        if ((scrollX | scrollY) == 0) {
            background.draw(canvas);
        } else {
            canvas.translate(scrollX, scrollY);
            background.draw(canvas);
            canvas.translate(-scrollX, -scrollY);
        }
    }

    // If text is transparent, don't draw any shadow
    if (getCurrentTextColor() == ContextCompat.getColor(getContext(), android.R.color.transparent)) {
        getPaint().clearShadowLayer();
        super.draw(canvas);
        return;
    }

    // We enhance the shadow by drawing the shadow twice
    float density = getResources().getDisplayMetrics().density;
    getPaint().setShadowLayer(density * AMBIENT_SHADOW_RADIUS, 0, 0, AMBIENT_SHADOW_COLOR);
    super.draw(canvas);
    canvas.save(Canvas.CLIP_SAVE_FLAG);
    canvas.clipRect(getScrollX(), getScrollY() + getExtendedPaddingTop(), getScrollX() + getWidth(),
            getScrollY() + getHeight(), Region.Op.INTERSECT);
    getPaint().setShadowLayer(density * KEY_SHADOW_RADIUS, 0.0f, density * KEY_SHADOW_OFFSET, KEY_SHADOW_COLOR);
    super.draw(canvas);
    canvas.restore();
}

From source file:android.support.design.widget.CoordinatorLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    if (lp.mBehavior != null) {
        final float scrimAlpha = lp.mBehavior.getScrimOpacity(this, child);
        if (scrimAlpha > 0f) {
            if (mScrimPaint == null) {
                mScrimPaint = new Paint();
            }/*from   w  ww . j a v  a2 s  .c  om*/
            mScrimPaint.setColor(lp.mBehavior.getScrimColor(this, child));
            mScrimPaint.setAlpha(MathUtils.constrain(Math.round(255 * scrimAlpha), 0, 255));

            final int saved = canvas.save();
            if (child.isOpaque()) {
                // If the child is opaque, there is no need to draw behind it so we'll inverse
                // clip the canvas
                canvas.clipRect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom(),
                        Region.Op.DIFFERENCE);
            }
            // Now draw the rectangle for the scrim
            canvas.drawRect(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
                    getHeight() - getPaddingBottom(), mScrimPaint);
            canvas.restoreToCount(saved);
        }
    }
    return super.drawChild(canvas, child, drawingTime);
}