Example usage for android.graphics Canvas save

List of usage examples for android.graphics Canvas save

Introduction

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

Prototype

public int save(@Saveflags int saveFlags) 

Source Link

Document

Based on saveFlags, can save the current matrix and clip onto a private stack.

Usage

From source file:com.ylw.split.splitview.view.SplitView.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);
    //            if (isLayoutRtlSupport()) {
    //                mTmpRect.left = Math.max(mTmpRect.left, mSlideableView.getRight());
    //            } else {
    //                mTmpRect.right = Math.min(mTmpRect.right, mSlideableView.getLeft());
    //            }
    //            canvas.clipRect(mTmpRect);
    //        }//www.j  av  a 2  s.  com

    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.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);//from w ww. ja  v a  2 s  .c om

        mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
        canvas.clipRect(mTmpRect);
    }

    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.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());
            }//w  ww. j  a  v  a 2s  .com
            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: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);/*from   w w w .  jav a2s.  c  o m*/
        if (!mOverlayContent) {
            if (mIsSlidingUp) {
                mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
            } else {
                mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom());
            }
        }
        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: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);/*from  w w  w .  jav a2  s.c o  m*/
        mTmpRect.right = Math.min(mTmpRect.right, mSlideableView.getLeft());
        canvas.clipRect(mTmpRect);
    }

    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);//from w  ww  .j  a v a 2  s  . c om
        if (isLayoutRtlSupport()) {
            tmpRect.left = Math.max(tmpRect.left, slideableView.getRight());
        } else {
            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:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void drawMinutes(Canvas canvas, float alphaMod) {
    final int minutesAlpha = (int) (mAlpha[MINUTES].getValue() * alphaMod + 0.5f);
    if (minutesAlpha > 0) {
        // Draw the minute selector under the elements.
        drawSelector(canvas, MINUTES, mSelectorPath, alphaMod);

        // Exclude the selector region, then draw minutes with no
        // activated states.
        canvas.save(Canvas.CLIP_SAVE_FLAG);
        canvas.clipPath(mSelectorPath, Region.Op.DIFFERENCE);
        drawTextElements(canvas, mTextSize[MINUTES], mTypeface, mTextColor[MINUTES], mMinutesText,
                mOuterTextX[MINUTES], mOuterTextY[MINUTES], mPaint[MINUTES], minutesAlpha, false, 0, false);
        canvas.restore();/*w ww  .  j  a va2 s  .com*/

        // Intersect the selector region, then draw minutes with only
        // activated states.
        canvas.save(Canvas.CLIP_SAVE_FLAG);
        canvas.clipPath(mSelectorPath, Region.Op.INTERSECT);
        drawTextElements(canvas, mTextSize[MINUTES], mTypeface, mTextColor[MINUTES], mMinutesText,
                mOuterTextX[MINUTES], mOuterTextY[MINUTES], mPaint[MINUTES], minutesAlpha, true,
                mSelectionDegrees[MINUTES], true);
        canvas.restore();
    }
}

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);
    }//from  w  ww .  ja  va  2s .c  o  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;
}

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);//from   w ww . jav  a2  s .  c  o  m
        mTmpRect.right = Math.min(mTmpRect.right, mSlideableView.getLeft());
        canvas.clipRect(mTmpRect);
    }

    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.HSlidingPaneLayout2.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);
    }//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 && (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(HSlidingPaneLayout2.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;
}