List of usage examples for android.graphics Canvas restoreToCount
public void restoreToCount(int saveCount)
From source file:com.hippo.nimingban.widget.BottomShadowScrollView.java
@Override protected void dispatchDraw(@NonNull Canvas canvas) { super.dispatchDraw(canvas); mShadowDrawable.setBounds(0, 0, getWidth(), mShadowHeight); int saved = canvas.save(); int height = getChildCount() != 0 ? Math.max(getChildAt(0).getHeight(), getHeight()) : getHeight(); canvas.translate(0, height - mShadowHeight); mShadowDrawable.draw(canvas);//ww w. j av a2s . co m canvas.restoreToCount(saved); }
From source file:com.tr4android.support.extension.widget.CollapsingDrawableHelper.java
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mDrawable != null && mDrawIcon) { // Let the drawable draw to the canvas (bounds are already set) mDrawable.draw(canvas);/*from w ww . ja va2 s.c o m*/ } canvas.restoreToCount(saveCount); }
From source file:com.rks.musicx.misc.widgets.DiagonalLayout.java
@Override protected void dispatchDraw(Canvas canvas) { int saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG); super.dispatchDraw(canvas); paint.setXfermode(pdMode);//from www . ja v a 2 s.co m canvas.drawPath(clipPath, paint); canvas.restoreToCount(saveCount); paint.setXfermode(null); }
From source file:com.google.android.marvin.utils.HighlightBoundsView.java
@Override public void onDraw(Canvas c) { final int saveCount = c.save(); c.translate(-SCREEN_LOCATION[0], -SCREEN_LOCATION[1]); c.setMatrix(mMatrix);/* w w w.j a va 2 s .c o m*/ mPaint.setColor(mHighlightColor); for (AccessibilityNodeInfoCompat node : mNodes) { node.getBoundsInScreen(mTemp); c.drawRect(mTemp, mPaint); } c.restoreToCount(saveCount); }
From source file:com.tr4android.support.extension.drawable.IndeterminateProgressDrawable.java
@Override public void draw(Canvas canvas) { int saveCount = canvas.save(); canvas.rotate(mRotation, mArcRect.centerX(), mArcRect.centerY()); float startAngle = -90 + 360 * (mOffset + mStart); float sweepAngle = 360 * (mEnd - mStart); canvas.drawArc(mArcRect, startAngle, sweepAngle, false, mArcPaint); canvas.restoreToCount(saveCount); }
From source file:com.h6ah4i.android.widget.advrecyclerview.draggable.EdgeEffectDecorator.java
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { boolean needsInvalidate = false; if (mTopGlow != null && !mTopGlow.isFinished()) { final int restore = c.save(); if (getClipToPadding(parent)) { c.translate(parent.getPaddingLeft(), parent.getPaddingTop()); }/*from w w w. ja va2 s .c om*/ //noinspection ConstantConditions needsInvalidate |= mTopGlow.draw(c); c.restoreToCount(restore); } if (mBottomGlow != null && !mBottomGlow.isFinished()) { final int restore = c.save(); c.rotate(180); if (getClipToPadding(parent)) { c.translate(-parent.getWidth() + parent.getPaddingRight(), -parent.getHeight() + parent.getPaddingBottom()); } else { c.translate(-parent.getWidth(), -parent.getHeight()); } needsInvalidate |= mBottomGlow.draw(c); c.restoreToCount(restore); } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(parent); } }
From source file:cl.monsoon.s1next.widget.BezelImageView.java
@Override protected void onDraw(@NonNull Canvas canvas) { if (mBounds == null) { return;//from ww w . j a v a2 s . c o m } int width = mBounds.width(); int height = mBounds.height(); if (width == 0 || height == 0) { return; } if (!mCacheValid || mCachedWidth != width || mCachedHeight != height) { // need to redraw the cache if (mCachedWidth == width && mCachedHeight == height) { // have a correct-sized bitmap cache already allocated // just erase it mCacheBitmap.eraseColor(Color.TRANSPARENT); } 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 saveCount = cacheCanvas.save(); mMaskDrawable.draw(cacheCanvas); cacheCanvas.saveLayer(mBoundsF, mMaskedPaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG); super.onDraw(cacheCanvas); cacheCanvas.restoreToCount(saveCount); } 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.hippo.widget.ProgressView.java
@Override protected void onDraw(Canvas canvas) { int saved = canvas.save(); canvas.rotate(mTrimRotation, mRectF.centerX(), mRectF.centerY()); float startAngle = (mTrimStart + mTrimOffset) * 360.0f - 90; float sweepAngle = (mTrimEnd - mTrimStart) * 360.0f; canvas.drawArc(mRectF, startAngle, sweepAngle, false, mPaint); canvas.restoreToCount(saved); if (mShouldStartAnimationDrawable) { mShouldStartAnimationDrawable = false; startAnimationActually();//from ww w .ja v a 2 s .c o m } }
From source file:com.example.zhangyangjing.roundcornerimageview.BezelImageView.java
@Override protected void onDraw(Canvas canvas) { if (mBounds == null) { return;/* ww 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; generateMaskPath(mCachedWidth, mCachedHeight); } Canvas cacheCanvas = new Canvas(mCacheBitmap); int sc = cacheCanvas.save(); mDesaturatePaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null); cacheCanvas.saveLayer(mBoundsF, mDesaturatePaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG); super.onDraw(cacheCanvas); cacheCanvas.drawPath(this.mMaskedPath, this.mMaskedPaint); cacheCanvas.restoreToCount(sc); } // Draw from cache canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null); }
From source file:com.github.shareme.gwsmaterialuikit.library.advancerv.draggable.BaseEdgeEffectDecorator.java
private static boolean drawGlow(Canvas c, RecyclerView parent, int dir, EdgeEffectCompat edge) { if (edge.isFinished()) { return false; }/*from w w w.j a v a 2s . com*/ final int restore = c.save(); final boolean clipToPadding = getClipToPadding(parent); switch (dir) { case EDGE_TOP: if (clipToPadding) { c.translate(parent.getPaddingLeft(), parent.getPaddingTop()); } break; case EDGE_BOTTOM: c.rotate(180); if (clipToPadding) { c.translate(-parent.getWidth() + parent.getPaddingRight(), -parent.getHeight() + parent.getPaddingBottom()); } else { c.translate(-parent.getWidth(), -parent.getHeight()); } break; case EDGE_LEFT: c.rotate(-90); if (clipToPadding) { c.translate(-parent.getHeight() + parent.getPaddingTop(), parent.getPaddingLeft()); } else { c.translate(-parent.getHeight(), 0); } break; case EDGE_RIGHT: c.rotate(90); if (clipToPadding) { c.translate(parent.getPaddingTop(), -parent.getWidth() + parent.getPaddingRight()); } else { c.translate(0, -parent.getWidth()); } break; } boolean needsInvalidate = edge.draw(c); c.restoreToCount(restore); return needsInvalidate; }