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

public boolean clipRect(int left, int top, int right, int bottom) 

Source Link

Document

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

Usage

From source file:io.plaidapp.core.ui.widget.CollapsingTitleLayout.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (lineCount == 1) {
        collapsingText.draw(canvas);/*  w w w.  jav  a 2 s  . c o m*/
    } else {
        int savePoint = canvas.save();
        float x = titleInsetStart;
        float y = Math.max(textTop - scrollOffset, titleInsetTop);
        canvas.translate(x, y);
        canvas.clipRect(0, 0, getWidth() - titleInsetStart - titleInsetEnd,
                Math.max(getHeight() - scrollOffset, collapsedHeight) - y);
        layout.draw(canvas);
        canvas.restoreToCount(savePoint);
    }
}

From source file:app.newbee.lib.swipeback.SwipeBackLayout.java

private void drawScrim(Canvas canvas, View child) {
    final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
    final int alpha = (int) (baseAlpha * mScrimOpacity);
    final int color = alpha << 24 | (mScrimColor & 0xffffff);

    if ((mTrackingEdge & EDGE_LEFT) != 0) {
        canvas.clipRect(0, 0, child.getLeft(), getHeight());
    } else if ((mTrackingEdge & EDGE_RIGHT) != 0) {
        canvas.clipRect(child.getRight(), 0, getRight(), getHeight());
    } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) {
        canvas.clipRect(child.getLeft(), child.getBottom(), getRight(), getHeight());
    }/*from  ww w  .ja  v a  2 s . c o  m*/
    canvas.drawColor(color);
}

From source file:com.example.carlitos.swipeitemrecycler.view.animation.swipe_item.swipeable.RemovingItemDecorator.java

private void fillSwipingItemBackground(Canvas c, Drawable drawable, float scale) {
    final Rect bounds = mSwipingItemBounds;
    final int translationX = mTranslationX;
    final int translationY = mTranslationY;
    final float hScale = (mHorizontal) ? 1.0f : scale;
    final float vScale = (mHorizontal) ? scale : 1.0f;

    int width = (int) (hScale * bounds.width() + 0.5f);
    int height = (int) (vScale * bounds.height() + 0.5f);

    if ((height == 0) || (width == 0) || (drawable == null)) {
        return;//from   w ww . j a v  a  2 s .co m
    }

    final int savedCount = c.save();

    c.clipRect(bounds.left + translationX, bounds.top + translationY, bounds.left + translationX + width,
            bounds.top + translationY + height);

    // c.drawColor(0xffff0000); // <-- debug

    c.translate(bounds.left + translationX - (bounds.width() - width) / 2,
            bounds.top + translationY - (bounds.height() - height) / 2);
    drawable.setBounds(0, 0, bounds.width(), bounds.height());

    drawable.draw(c);

    c.restoreToCount(savedCount);
}

From source file:com.example.administrator.common.widget.swipeback.SwipeBackLayout.java

private void drawScrim(Canvas canvas, View child) {
    final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
    final int alpha = (int) (baseAlpha * mScrimOpacity);
    final int color = alpha << 24 | (mScrimColor & 0xffffff);

    if ((mTrackingEdge & EDGE_LEFT) != 0) {
        canvas.clipRect(0, 0, child.getLeft(), getHeight());
    } else if ((mTrackingEdge & EDGE_RIGHT) != 0) {
        canvas.clipRect(child.getRight(), 0, getRight(), getHeight());
    } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) {
        canvas.clipRect(child.getLeft(), child.getBottom(), getRight(), getHeight());
    } else if ((mTrackingEdge & EDGE_TOP) != 0) {
        canvas.clipRect(0, child.getTop(), 0, getHeight());
    }//from   www . j  a  va2 s .  c  om
    canvas.drawColor(color);
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    if (stickyWrapper != null) {

        int pLeft = getListPaddingLeft();
        int pTop = getListPaddingTop();
        View view = stickyWrapper.view;
        int headerTop = view.getTop();
        pLeft += stickyWrapper.additionalIndent;
        // draw child
        canvas.save();/*from  w ww.  jav  a 2 s .  c  om*/

        int clipHeight = view.getHeight() + (shadowDrawable == null ? 0 : shadowHeight);
        canvas.clipRect(pLeft, pTop, pLeft + view.getWidth() - 2 * stickyWrapper.additionalIndent,
                pTop + clipHeight);

        canvas.translate(pLeft - stickyWrapper.additionalIndent, pTop - headerTop);
        drawChild(canvas, stickyWrapper.view, getDrawingTime());

        if (shadowDrawable != null) {
            shadowDrawable.setBounds(stickyWrapper.view.getLeft(), stickyWrapper.view.getBottom(),
                    stickyWrapper.view.getRight(), stickyWrapper.view.getBottom() + shadowHeight);
            shadowDrawable.draw(canvas);
        }

        canvas.restore();
    }
}

From source file:eu.davidea.flexibleadapter.common.FlexibleItemDecoration.java

@SuppressLint("NewApi")
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();/*from   www  . ja  va 2s.c o  m*/
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int itemCount = parent.getChildCount();
    for (int i = 0; i < itemCount - 1; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}

From source file:eu.davidea.flexibleadapter.common.FlexibleItemDecoration.java

@SuppressLint("NewApi")
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();//from   w  w  w  .j  av  a 2s.  c o m
    final int top;
    final int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int itemCount = parent.getChildCount();
    for (int i = 0; i < itemCount - 1; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}

From source file:org.chromium.chrome.browser.omnibox.LocationBarPhone.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    boolean needsCanvasRestore = false;
    if (child == mUrlBar && mUrlActionsContainer.getVisibility() == VISIBLE) {
        canvas.save();//from w  ww .  j a  v  a2s .c o  m

        // Clip the URL bar contents to ensure they do not draw under the URL actions during
        // focus animations.  Based on the RTL state of the location bar, the url actions
        // container can be on the left or right side, so clip accordingly.
        if (mUrlBar.getLeft() < mUrlActionsContainer.getLeft()) {
            canvas.clipRect(0, 0, (int) mUrlActionsContainer.getX(), getBottom());
        } else {
            canvas.clipRect(mUrlActionsContainer.getX() + mUrlActionsContainer.getWidth(), 0, getWidth(),
                    getBottom());
        }
        needsCanvasRestore = true;
    }
    boolean retVal = super.drawChild(canvas, child, drawingTime);
    if (needsCanvasRestore) {
        canvas.restore();
    }
    return retVal;
}

From source file:com.taobao.weex.ui.view.WXScrollView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (mCurrentStickyView != null) {
        canvas.save();/*from  w ww .j  a  v a2 s .  c  o  m*/
        mCurrentStickyView.getLocationOnScreen(mStickyP);
        int realOffset = (mStickyOffset <= 0 ? mStickyOffset : 0);
        canvas.translate(mStickyP[0], getScrollY() + realOffset);
        canvas.clipRect(0, realOffset, mCurrentStickyView.getWidth(), mCurrentStickyView.getHeight());
        mCurrentStickyView.draw(canvas);
        canvas.restore();
    }
}

From source file:com.dm.xz.views.PinnedSectionListView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    if (mPinnedSection != null) {

        // prepare variables
        int pLeft = getListPaddingLeft();
        int pTop = getListPaddingTop();
        View view = mPinnedSection.view;

        // draw child
        canvas.save();/*from w  w w  . ja  va2  s  . c  om*/

        int clipHeight = view.getHeight()
                + (mShadowDrawable == null ? 0 : Math.min(mShadowHeight, mSectionsDistanceY));
        canvas.clipRect(pLeft, pTop, pLeft + view.getWidth(), pTop + clipHeight);

        canvas.translate(pLeft, pTop + mTranslateY);
        drawChild(canvas, mPinnedSection.view, getDrawingTime());

        if (mShadowDrawable != null && mSectionsDistanceY > 0) {
            mShadowDrawable.setBounds(mPinnedSection.view.getLeft(), mPinnedSection.view.getBottom(),
                    mPinnedSection.view.getRight(), mPinnedSection.view.getBottom() + mShadowHeight);
            mShadowDrawable.draw(canvas);
        }

        canvas.restore();
    }
}