List of usage examples for android.graphics Canvas restoreToCount
public void restoreToCount(int saveCount)
From source file:android.wuliqing.com.mylibrary.header.MaterialProgressDrawable.java
@Override public void draw(Canvas c) { if (mShadow != null) { mShadow.getPaint().setColor(mBackgroundColor); mShadow.draw(c);// ww w . j a v a 2 s . c o m } final Rect bounds = getBounds(); final int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds); c.restoreToCount(saveCount); }
From source file:im.ene.lab.io_timer.ui.widget.MiniDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final int restoreCount = canvas.save(); final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); return result; }
From source file:de.mrapp.android.util.view.ScrimInsetsLayout.java
@Override public final void draw(final Canvas canvas) { super.draw(canvas); int width = getWidth(); int height = getHeight(); if (insets != null && insetDrawable != null) { int saveCount = canvas.save(); canvas.translate(getScrollX(), getScrollY()); insetDrawable.setBounds(0, 0, width, insets.top); insetDrawable.draw(canvas);/*w w w .jav a 2 s .c o m*/ insetDrawable.setBounds(0, height - insets.bottom, width, height); insetDrawable.draw(canvas); insetDrawable.setBounds(0, insets.top, insets.left, height - insets.bottom); insetDrawable.draw(canvas); insetDrawable.setBounds(width - insets.right, insets.top, width, height - insets.bottom); insetDrawable.draw(canvas); canvas.restoreToCount(saveCount); } }
From source file:ezy.ui.view.ViewPagerIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int flags = Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG; int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, flags); int wg = mItemWidth + mItemGap; int x = (getWidth() - mWidth) / 2; int y = (getHeight() - mItemHeight) / 2; mItemDrawable.setBounds(0, 0, mItemWidth, mItemHeight); mItemDrawableSelected.setBounds(0, 0, mItemWidth, mItemHeight); for (int i = 0; i < mItemCount; i++) { canvas.save();/*from ww w .j a v a 2 s. c om*/ canvas.translate(x + i * wg, y); mItemDrawable.draw(canvas); canvas.restore(); } canvas.save(); canvas.translate(x + (mPosition + mPositionOffset) * wg, y); mItemDrawableSelected.draw(canvas); canvas.restore(); canvas.restoreToCount(sc); }
From source file:com.holmes.ponderosa.ui.debug.NonConsumingScrimInsetsFrameLayout.java
@Override public void draw(@NonNull Canvas canvas) { super.draw(canvas); int width = getWidth(); int height = getHeight(); if (insets != null && insetForeground != null) { int sc = canvas.save(); canvas.translate(getScrollX(), getScrollY()); // Top/*from www .j av a2 s. c om*/ tempRect.set(0, 0, width, insets.top); insetForeground.setBounds(tempRect); insetForeground.draw(canvas); // Bottom tempRect.set(0, height - insets.bottom, width, height); insetForeground.setBounds(tempRect); insetForeground.draw(canvas); // Left tempRect.set(0, insets.top, insets.left, height - insets.bottom); insetForeground.setBounds(tempRect); insetForeground.draw(canvas); // Right tempRect.set(width - insets.right, insets.top, width, height - insets.bottom); insetForeground.setBounds(tempRect); insetForeground.draw(canvas); canvas.restoreToCount(sc); } }
From source file:at.linuxtage.companion.widgets.ScrimInsetsFrameLayout.java
@Override public void draw(@NonNull Canvas canvas) { super.draw(canvas); int width = getWidth(); int height = getHeight(); if (mInsets != null && mInsetForeground != null) { int sc = canvas.save(); canvas.translate(getScrollX(), getScrollY()); // Top/*www .j a va 2 s . c o m*/ mTempRect.set(0, 0, width, mInsets.top); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); // Bottom mTempRect.set(0, height - mInsets.bottom, width, height); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); // Left mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); // Right mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); canvas.restoreToCount(sc); } }
From source file:com.gj.administrator.gjerp.view.CircleIndicator.java
@Override protected void onDraw(Canvas canvas) { Log.e("CircleIndicator", "onDraw()"); super.onDraw(canvas); int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); for (ShapeHolder item : tabItems) { canvas.save();/*from www . ja va 2 s . c om*/ canvas.translate(item.getX(), item.getY()); item.getShape().draw(canvas); canvas.restore(); } if (movingItem != null) { canvas.save(); canvas.translate(movingItem.getX(), movingItem.getY()); movingItem.getShape().draw(canvas); canvas.restore(); } canvas.restoreToCount(sc); }
From source file:com.mobidev.myliveonavigationmaterial.ui.widget.ScrimInsetsFrameLayout.java
@Override public void draw(Canvas canvas) { super.draw(canvas); int width = getWidth(); int height = getHeight(); if (mInsets != null && mInsetForeground != null) { int sc = canvas.save(); canvas.translate(getScrollX(), getScrollY()); // Top// ww w . j a v a 2 s .c om mTempRect.set(0, 0, width, mInsets.top); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); // Bottom mTempRect.set(0, height - mInsets.bottom, width, height); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); // Left mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); // Right mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); canvas.restoreToCount(sc); } }
From source file:com.cnh.library.materialdrawer.view.BezelImageView.java
@Override protected void onDraw(Canvas canvas) { if (mBounds == null) { return;// ww w . j ava2s. c o m } int width = mBounds.width(); int height = mBounds.height(); if (width == 0 || height == 0) { return; } if (!mCacheValid || width != mCachedWidth || height != mCachedHeight || isSelected != isPressed) { // 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); if (isSelected) { if (mSelectorFilter != null) { mMaskedPaint.setColorFilter(mSelectorFilter); } else { mMaskedPaint.setColorFilter(mDesaturateColorFilter); } } else { mMaskedPaint.setColorFilter(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 (isSelected) { int sc = cacheCanvas.save(); cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint); if (mSelectorFilter != null) { mMaskedPaint.setColorFilter(mSelectorFilter); } else { 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); } } // Draw from cache canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null); //remember the previous press state isPressed = isPressed(); }
From source file:com.raghu.test.widgets.BezelImageView.java
@SuppressLint("WrongConstant") @Override//from w ww . j a va 2 s .co m protected void onDraw(Canvas canvas) { if (mBounds == null) { return; } int width = mBounds.width(); int height = mBounds.height(); if (width == 0 || height == 0) { return; } if (!mCacheValid || width != mCachedWidth || height != mCachedHeight || isSelected != isPressed) { // 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); if (isSelected) { if (mSelectorFilter != null) { mMaskedPaint.setColorFilter(mSelectorFilter); } else { mMaskedPaint.setColorFilter(mDesaturateColorFilter); } } else { mMaskedPaint.setColorFilter(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 (isSelected) { int sc = cacheCanvas.save(); cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint); if (mSelectorFilter != null) { mMaskedPaint.setColorFilter(mSelectorFilter); } else { 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); } } // Draw from cache canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null); //remember the previous press state isPressed = isPressed(); }