Example usage for android.graphics Canvas getClipBounds

List of usage examples for android.graphics Canvas getClipBounds

Introduction

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

Prototype

public boolean getClipBounds(@Nullable Rect bounds) 

Source Link

Document

Return the bounds of the current clip (in local coordinates) in the bounds parameter, and return true if it is non-empty.

Usage

From source file:mega.privacy.android.app.components.SlidingUpPanelLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (mSlideableView != child) { // if main view
        // Clip against the slider; no sense drawing what will immediately be covered,
        // Unless the panel is set to overlay content
        canvas.getClipBounds(mTmpRect);
        if (!mOverlayContent) {
            if (mIsSlidingUp) {
                mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
            } else {
                mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom());
            }/*from w  ww .  ja va 2s  .c om*/
        }
        if (mClipPanel) {
            canvas.clipRect(mTmpRect);
        }

        result = super.drawChild(canvas, child, drawingTime);

        if (mCoveredFadeColor != 0 && mSlideOffset > 0) {
            final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24;
            final int imag = (int) (baseAlpha * mSlideOffset);
            final int color = imag << 24 | (mCoveredFadeColor & 0xffffff);
            mCoveredFadePaint.setColor(color);
            canvas.drawRect(mTmpRect, mCoveredFadePaint);
        }
    } else {
        result = super.drawChild(canvas, child, drawingTime);
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:com.android.dialer.widget.OverlappingPaneLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately be covered.
        canvas.getClipBounds(mTmpRect);

        mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
        canvas.clipRect(mTmpRect);//from  ww w.j av a  2 s.c o m
    }

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (child.isDrawingCacheEnabled()) {
            child.setDrawingCacheEnabled(false);
        }
        result = super.drawChild(canvas, child, drawingTime);
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:com.akshay.protocol10.asplayer.widget.SlidingUpPanelLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (isSlidingEnabled() && mSlideableView != child) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered,
        // Unless the panel is set to overlay content
        if (!mOverlayContent) {
            canvas.getClipBounds(mTmpRect);
            if (mIsSlidingUp) {
                mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
            } else {
                mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom());
            }//  w  ww  . ja v  a  2 s .  com
            canvas.clipRect(mTmpRect);
        }
    }

    result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(save);

    if (mCoveredFadeColor != 0 && mSlideOffset > 0) {
        final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * mSlideOffset);
        final int color = imag << 24 | (mCoveredFadeColor & 0xffffff);
        mCoveredFadePaint.setColor(color);
        canvas.drawRect(mTmpRect, mCoveredFadePaint);
    }

    return result;
}

From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java

@Override
protected void dispatchDraw(Canvas canvas) {
    mInvalidated = false; //last invalidate which marked redrawInProgress, caused this
    // dispatchDraw. Clear flag to prevent creating loop

    mReverseOrderIndex = -1;/*from  w w  w.  ja va 2  s.c o m*/

    canvas.getClipBounds(mTempRect);
    mTempRect.top = 0;
    mTempRect.bottom = getHeight();
    canvas.clipRect(mTempRect);

    super.dispatchDraw(canvas);

    if (mScrollToPositionOnNextInvalidate != -1 && mAdapter != null && mAdapter.getCount() > 0) {
        final int lastCenterItemPosition = (mFirstItemPosition + mLastCenterItemIndex) % mAdapter.getCount();
        final int di = lastCenterItemPosition - mScrollToPositionOnNextInvalidate;
        mScrollToPositionOnNextInvalidate = -1;
        if (di != 0) {
            final int dst = (int) (di * mCoverWidth * mSpacing) - mCenterItemOffset;
            scrollBy(-dst, 0);
            shouldRepeat = true;
            postInvalidate();
            return;
        }
    }

    if (mTouchState == TOUCH_STATE_RESTING) {
        if (mAdapter != null) {
            final int lastCenterItemPosition = (mFirstItemPosition + mLastCenterItemIndex)
                    % mAdapter.getCount();
            if (mLastTouchState != TOUCH_STATE_RESTING || mlastCenterItemPosition != lastCenterItemPosition) {
                mLastTouchState = TOUCH_STATE_RESTING;
                mlastCenterItemPosition = lastCenterItemPosition;
                if (mOnScrollPositionListener != null)
                    mOnScrollPositionListener.onScrolledToPosition(lastCenterItemPosition);
            }
        }
    }

    if (mTouchState == TOUCH_STATE_SCROLLING && mLastTouchState != TOUCH_STATE_SCROLLING) {
        mLastTouchState = TOUCH_STATE_SCROLLING;
        if (mOnScrollPositionListener != null)
            mOnScrollPositionListener.onScrolling();
    }
    if (mTouchState == TOUCH_STATE_FLING && mLastTouchState != TOUCH_STATE_FLING) {
        mLastTouchState = TOUCH_STATE_FLING;
        if (mOnScrollPositionListener != null)
            mOnScrollPositionListener.onScrolling();
    }

    //make sure we never stay unaligned after last draw in resting state
    if (mTouchState == TOUCH_STATE_RESTING && mCenterItemOffset != 0) {
        scrollBy(mCenterItemOffset, 0);
        postInvalidate();
    }

    try {
        View v = getChildAt(mLastCenterItemIndex);
        if (v != null)
            v.requestFocus(FOCUS_FORWARD);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:co.codecrunch.musicplayerlite.slidinguppanelhelper.SlidingUpPanelLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (mSlideableView != child) { // if main view
        // Clip against the slider; no sense drawing what will immediately
        // be covered,
        // Unless the panel is set to overlay content
        canvas.getClipBounds(mTmpRect);
        if (!mOverlayContent) {
            if (mIsSlidingUp) {
                mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
            } else {
                mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom());
            }/*from w w  w  . j  a  v  a  2s  .c o  m*/
        }
        if (mClipPanel) {
            canvas.clipRect(mTmpRect);
        }

        result = super.drawChild(canvas, child, drawingTime);

        if (mCoveredFadeColor != 0 && mSlideOffset > 0) {
            final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24;
            final int imag = (int) (baseAlpha * mSlideOffset);
            final int color = imag << 24 | (mCoveredFadeColor & 0xffffff);
            mCoveredFadePaint.setColor(color);
            canvas.drawRect(mTmpRect, mCoveredFadePaint);
        }
    } else {
        result = super.drawChild(canvas, child, drawingTime);
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:com.quran.labs.androidquran.widgets.SlidingUpPanelLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    boolean drawScrim = false;

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately be covered,
        // Unless the panel is set to overlay content
        if (!mOverlayContent) {
            canvas.getClipBounds(mTmpRect);
            if (mIsSlidingUp) {
                mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
            } else {
                mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom());
            }/*from   ww w .j a  va 2s  .c  o m*/
            canvas.clipRect(mTmpRect);
        }
        if (mSlideOffset < 1) {
            drawScrim = true;
        }
    }

    result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(save);

    if (drawScrim) {
        final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * (1 - mSlideOffset));
        final int color = imag << 24 | (mCoveredFadeColor & 0xffffff);
        mCoveredFadePaint.setColor(color);
        canvas.drawRect(mTmpRect, mCoveredFadePaint);
    }

    return result;
}

From source file:cn.emagsoftware.ui.BugFixedSlidingPaneLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately be covered.
        canvas.getClipBounds(mTmpRect);
        mTmpRect.right = Math.min(mTmpRect.right, mSlideableView.getLeft());
        canvas.clipRect(mTmpRect);//from   ww  w  .  ja v  a2 s. co  m
    }

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (lp.dimWhenOffset && mSlideOffset > 0) {
            if (!child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(true);
            }
            final Bitmap cache = child.getDrawingCache();
            if (cache != null) {
                canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                result = false;
            } else {
                Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache");
                result = super.drawChild(canvas, child, drawingTime);
            }
        } else {
            if (child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(false);
            }
            result = super.drawChild(canvas, child, drawingTime);
        }
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:com.waz.zclient.pages.main.conversationpager.SlidingPaneLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (canSlide && !lp.slideable && slideableView != null) {
        // Clip against the slider; no sense drawing what will immediately be covered.
        canvas.getClipBounds(tmpRect);
        if (isLayoutRtlSupport()) {
            tmpRect.left = Math.max(tmpRect.left, slideableView.getRight());
        } else {// w  w  w. j ava  2s.  c o  m
            tmpRect.right = Math.min(tmpRect.right, slideableView.getLeft());
        }
        canvas.clipRect(tmpRect);
    }

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (lp.dimWhenOffset && slideOffset > 0) {
            if (!child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(true);
            }
            final Bitmap cache = child.getDrawingCache();
            if (cache != null) {
                canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                result = false;
            } else {
                Timber.e("drawChild: child view %s returned null drawing cache", child);
                result = super.drawChild(canvas, child, drawingTime);
            }
        } else {
            if (child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(false);
            }
            result = super.drawChild(canvas, child, drawingTime);
        }
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:rp3.widget.SlidingPaneLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered.
        canvas.getClipBounds(mTmpRect);
        mTmpRect.right = Math.min(mTmpRect.right, mSlideableView.getLeft());
        canvas.clipRect(mTmpRect);/*from  w  w  w  .j  a  v  a2s .c o m*/
    }

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (lp.dimWhenOffset && mSlideOffset > 0) {
            if (!child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(true);
            }
            final Bitmap cache = child.getDrawingCache();
            if (cache != null) {
                canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                result = false;
            } else {
                Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache");
                result = super.drawChild(canvas, child, drawingTime);
            }
        } else {
            if (child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(false);
            }
            result = super.drawChild(canvas, child, drawingTime);
        }
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:com.example.zhaozhu.practisecustomview.customviewgroup.HSlidingPaneLayout.java

@Override
protected boolean drawChild(final Canvas canvas, final View child, final long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (this.mCanSlide && !lp.slideable && (this.mSlideableView != null)) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered.
        canvas.getClipBounds(this.mTmpRect);
        this.mTmpRect.right = Math.min(this.mTmpRect.right, this.mSlideableView.getLeft());
        canvas.clipRect(this.mTmpRect);
    }/*  ww w.  j  a  v a  2s .co m*/

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (lp.dimWhenOffset && (this.mSlideOffset > 0)) {
            if (!child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(true);
            }
            Bitmap cache = child.getDrawingCache();
            if (cache != null && !cache.isRecycled()) {
                canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                result = false;
            } else {
                Log.e(HSlidingPaneLayout.TAG,
                        "drawChild: child view " + child + " returned null drawing cache");
                result = super.drawChild(canvas, child, drawingTime);
            }
        } else {
            if (child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(false);
            }
            result = super.drawChild(canvas, child, drawingTime);
        }
    }

    canvas.restoreToCount(save);

    return result;
}