Example usage for android.graphics Canvas restoreToCount

List of usage examples for android.graphics Canvas restoreToCount

Introduction

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

Prototype

public void restoreToCount(int saveCount) 

Source Link

Document

Efficient way to pop any calls to save() that happened after the save count reached saveCount.

Usage

From source file:com.dream.yzbb.wolfkiller.widget.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;/*w w  w  . j  a v  a 2 s  .c  o  m*/
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache.
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed())
                    ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache.
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:org.mozilla.focus.widget.AnimatedProgressBar.java

@Override
public void onDraw(Canvas canvas) {
    if (mClipRegion == 0) {
        super.onDraw(canvas);
    } else {//from w  w  w. j  a  va 2s.  c  om
        canvas.getClipBounds(tempRect);
        final float clipWidth = tempRect.width() * mClipRegion;
        final int saveCount = canvas.save();

        if (mIsRtl) {
            canvas.clipRect(tempRect.left, tempRect.top, tempRect.right - clipWidth, tempRect.bottom);
        } else {
            canvas.clipRect(tempRect.left + clipWidth, tempRect.top, tempRect.right, tempRect.bottom);
        }
        super.onDraw(canvas);
        canvas.restoreToCount(saveCount);
    }
}

From source file:com.abewy.android.apps.klyph.messenger.widget.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;//  www.j av a2  s .c  o m
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            // noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null && mMaskEnabled == true) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:com.yanzhenjie.album.widget.loading.LevelLoadingRenderer.java

@Override
protected void draw(Canvas canvas) {
    int saveCount = canvas.save();

    mTempBounds.set(mBounds);//from  w w w .j a v a  2 s.c  om
    mTempBounds.inset(mStrokeInset, mStrokeInset);
    canvas.rotate(mGroupRotation, mTempBounds.centerX(), mTempBounds.centerY());

    for (int i = 0; i < 3; i++) {
        if (mLevelSwipeDegrees[i] != 0) {
            mPaint.setColor(mLevelColors[i]);
            canvas.drawArc(mTempBounds, mEndDegrees, mLevelSwipeDegrees[i], false, mPaint);
        }
    }

    canvas.restoreToCount(saveCount);
}

From source file:me.lizheng.deckview.views.DeckChildViewHeader.java

@SuppressLint("DrawAllocation")
@Override//from   ww  w.  ja  va 2s.c o m
protected void onDraw(Canvas canvas) {
    // Draw the highlight at the top edge (but put the bottom edge just out of view)
    float offset = (float) Math.ceil(mConfig.taskViewHighlightPx / 2f);
    float radius = mConfig.taskViewRoundedCornerRadiusPx;
    int count = canvas.save(Canvas.CLIP_SAVE_FLAG);
    canvas.clipRect(0, 0, getMeasuredWidth(), getMeasuredHeight());
    canvas.drawRoundRect(
            new RectF(-offset, 0f, (float) getMeasuredWidth() + offset, getMeasuredHeight() + radius), radius,
            radius, sHighlightPaint);
    canvas.restoreToCount(count);
}

From source file:com.visenze.visearch.camerademo.views.RoundImageView.java

@Override
protected void onDraw(Canvas canvas) {

    if (mBounds == null) {
        return;/*from   w w w  .j ava2 s  .  c om*/
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {

        // Need to redraw the cache
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        cacheCanvas
                .setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:com.mobility.android.ui.widget.MaterialProgressDrawable.java

@Override
public void draw(@NonNull Canvas c) {
    Rect bounds = getBounds();/* w ww. java 2 s . c o m*/
    int saveCount = c.save();
    c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
    mRing.draw(c, bounds);
    c.restoreToCount(saveCount);
}

From source file:com.xfzbd.cqi.widget.srl.ShyaringanProgressDrawable.java

@Override
public void draw(Canvas c) {
    final Rect bounds = getBounds();
    final int saveCount = c.save();
    c.rotate(0f, bounds.exactCenterX(), bounds.exactCenterY());
    mRing.draw(c, bounds);//from   ww w .  j  a  v  a2s  . c o  m
    c.restoreToCount(saveCount);
}

From source file:me.lizheng.deckview.helpers.FakeShadowDrawable.java

private void drawShadow(Canvas canvas) {
    final float edgeShadowTop = -mCornerRadius - mShadowSize;
    final float inset = mCornerRadius + mInsetShadow + mRawShadowSize / 2;
    final boolean drawHorizontalEdges = mCardBounds.width() - 2 * inset > 0;
    final boolean drawVerticalEdges = mCardBounds.height() - 2 * inset > 0;
    // LT/*from w ww  . j a  v  a2s.  c om*/
    int saved = canvas.save();
    canvas.translate(mCardBounds.left + inset, mCardBounds.top + inset);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawHorizontalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.width() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // RB
    saved = canvas.save();
    canvas.translate(mCardBounds.right - inset, mCardBounds.bottom - inset);
    canvas.rotate(180f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawHorizontalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.width() - 2 * inset, -mCornerRadius + mShadowSize,
                mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // LB
    saved = canvas.save();
    canvas.translate(mCardBounds.left + inset, mCardBounds.bottom - inset);
    canvas.rotate(270f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawVerticalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // RT
    saved = canvas.save();
    canvas.translate(mCardBounds.right - inset, mCardBounds.top + inset);
    canvas.rotate(90f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawVerticalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
}

From source file:com.emmaguy.todayilearned.PanView.java

/**
 * Draws the overscroll "glow" at the four edges, if necessary
 *
 * @see EdgeEffect/* ww w  .j a  va 2s .c  o m*/
 */
private void drawEdgeEffects(Canvas canvas) {
    // The methods below rotate and translate the canvas as needed before drawing the glow,
    // since EdgeEffect always draws a top-glow at 0,0.

    boolean needsInvalidate = false;

    if (!mEdgeEffectTop.isFinished()) {
        final int restoreCount = canvas.save();
        mEdgeEffectTop.setSize(mWidth, mHeight);
        if (mEdgeEffectTop.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (!mEdgeEffectBottom.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(-mWidth, mHeight);
        canvas.rotate(180, mWidth, 0);
        mEdgeEffectBottom.setSize(mWidth, mHeight);
        if (mEdgeEffectBottom.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (!mEdgeEffectLeft.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(0, mHeight);
        canvas.rotate(-90, 0, 0);
        //noinspection SuspiciousNameCombination
        mEdgeEffectLeft.setSize(mHeight, mWidth);
        if (mEdgeEffectLeft.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (!mEdgeEffectRight.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(mWidth, 0);
        canvas.rotate(90, 0, 0);
        //noinspection SuspiciousNameCombination
        mEdgeEffectRight.setSize(mHeight, mWidth);
        if (mEdgeEffectRight.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (needsInvalidate) {
        invalidate();
    }
}