List of usage examples for android.graphics Canvas save
public int save()
From source file:com.ziv.recyclerview.gridview.vertical.DividerGridItemDecoration.java
/** * Draw vertical divider/* ww w . j a v a 2 s. c om*/ * * @param canvas Canvas to draw into * @param parent RecyclerView this ItemDecoration is drawing into */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save(); final int left; final int right; if (parent.getClipToPadding()) { left = parent.getPaddingLeft(); right = parent.getWidth() - parent.getPaddingRight(); canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom()); } else { left = 0; right = parent.getWidth(); } final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); parent.getDecoratedBoundsWithMargins(child, mBounds); final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child)); final int top = bottom - mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } canvas.restore(); }
From source file:com.ziv.recyclerview.gridview.vertical.DividerGridItemDecoration.java
/** * Draw horizontal divider/* w ww. ja v a 2 s . c o m*/ * * @param canvas Canvas to draw into * @param parent RecyclerView this ItemDecoration is drawing into */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void drawHorizontal(Canvas canvas, RecyclerView parent) { canvas.save(); final int top; final int bottom; if (parent.getClipToPadding()) { top = parent.getPaddingTop(); bottom = parent.getHeight() - parent.getPaddingBottom(); canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom); } else { top = 0; bottom = parent.getHeight(); } final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds); final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child)); final int left = right - mDivider.getIntrinsicWidth(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } canvas.restore(); }
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// www . j a v a 2 s . c o m 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:io.github.sin3hz.wifispinnerview.WifiSpinnerDrawable.java
@Override public void draw(Canvas canvas) { canvas.save(); canvas.rotate(mGlobalAngle, mBounds.centerX(), mBounds.centerY()); for (int i = 0; i < mSpinnerCount; i++) { canvas.drawPath(mSpinners[i].path, mSpinners[i].paint); }//ww w . j av a 2 s .co m canvas.restore(); }
From source file:android.support.design.internal.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/*from www. jav a 2 s . com*/ 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:ar.worq.microturistas.view.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//from w w w .jav a 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.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);/*from w ww. j a v a 2s . co m*/ if (mShouldStartAnimationDrawable) { mShouldStartAnimationDrawable = false; startAnimationActually(); } }
From source file:org.akvo.caddisfly.sensor.colorimetry.strip.widget.PercentageMeterView.java
@Override public void onDraw(@NonNull Canvas canvas) { if (Float.isNaN(percentage)) { return;/*from ww w.ja v a 2s .c om*/ } double number = (100 - percentage) * NUMBER_OF_BARS * PERCENT; canvas.save(); // Set each dot's diameter to half the canvas height canvas.translate( canvas.getWidth() / 2f - ((canvas.getHeight() / 2f + GUTTER_SPACE) * ((NUMBER_OF_BARS - 1) / 2f)), 0); for (double i = 0; i < NUMBER_OF_BARS; i++) { // Reset color paint.setColor(Color.LTGRAY); if (number >= 0) { if (i < 2) { // Red if number is lower than i + 1 // 2 red dots if number < 1 or 1 red dot if number > 1 if (number <= i + 1) { paint.setColor(red); } } else if (i < 4) { // Orange if number between 1 and 4 // if number == 1.5 then 1 red followed by orange dot // if number == 2.5 then 2 orange dots // if number == 3.5 then 1 orange dot if (number >= i - 1 && number <= i + 2) { paint.setColor(orange); } } else { if (number > i) { // Green if number larger than 3 but yellow if number exceeds optimum if (number > NUMBER_OF_BARS) { paint.setColor(Color.YELLOW); } else { paint.setColor(green); } } } } canvas.drawCircle(0, canvas.getHeight() / 2f, canvas.getHeight() / 4f, paint); // Position next circle canvas.translate(canvas.getHeight() / 2f + GUTTER_SPACE, 0); } canvas.restore(); super.onDraw(canvas); }
From source file:cl.monsoon.s1next.widget.BezelImageView.java
@Override protected void onDraw(@NonNull Canvas canvas) { if (mBounds == null) { return;//from w w w .j a va 2 s . c om } 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.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 ww .j av a 2s .c o m*/ //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); } }