Java Code Examples for android.graphics.Canvas#getSaveCount()
The following examples show how to use
android.graphics.Canvas#getSaveCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PorterShapeImageView.java From UltimateAndroid with Apache License 2.0 | 6 votes |
@Override protected void paintMaskCanvas(Canvas maskCanvas, Paint maskPaint, int width, int height) { if(shape != null) { if (shape instanceof BitmapDrawable) { configureBitmapBounds(width, height); if(drawMatrix != null) { int drawableSaveCount = maskCanvas.getSaveCount(); maskCanvas.save(); maskCanvas.concat(matrix); shape.draw(maskCanvas); maskCanvas.restoreToCount(drawableSaveCount); return; } } shape.setBounds(0, 0, width, height); shape.draw(maskCanvas); } }
Example 2
Source File: RxPorterShapeImageView.java From RxTools-master with Apache License 2.0 | 6 votes |
@Override protected void paintMaskCanvas(Canvas maskCanvas, Paint maskPaint, int width, int height) { if(shape != null) { if (shape instanceof BitmapDrawable) { configureBitmapBounds(getWidth(), getHeight()); if(drawMatrix != null) { int drawableSaveCount = maskCanvas.getSaveCount(); maskCanvas.save(); maskCanvas.concat(matrix); shape.draw(maskCanvas); maskCanvas.restoreToCount(drawableSaveCount); return; } } shape.setBounds(0, 0, getWidth(), getHeight()); shape.draw(maskCanvas); } }
Example 3
Source File: MultiImageView.java From commonadapter with MIT License | 6 votes |
@Override protected void onDraw(Canvas canvas) { for (int i = 0; i < mImages.size(); i++) { final ImageItem item = mImages.get(i); // 绘制图片 int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(pLeft, pTop); if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); } // 绘制三张图片 canvas.drawBitmap(item.bitmap, item.rect.left + i * mHorizontalSpacing, item.rect.top, mPaint); canvas.restoreToCount(saveCount); } }
Example 4
Source File: GifView.java From GifAssistant with Apache License 2.0 | 6 votes |
protected void onDraw(Canvas canvas) { super.onDraw(canvas); if(gifDecoder == null) return; if(currentImage == null){ currentImage = gifDecoder.getImage(); } if(currentImage == null){ return; } int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(getPaddingLeft(), getPaddingTop()); calculateDrawRect(); canvas.drawBitmap(currentImage, null, rect, null); canvas.restoreToCount(saveCount); }
Example 5
Source File: PorterShapeImageView.java From UltimateAndroid with Apache License 2.0 | 6 votes |
@Override protected void paintMaskCanvas(Canvas maskCanvas, Paint maskPaint, int width, int height) { if(shape != null) { if (shape instanceof BitmapDrawable) { configureBitmapBounds(width, height); if(drawMatrix != null) { int drawableSaveCount = maskCanvas.getSaveCount(); maskCanvas.save(); maskCanvas.concat(matrix); shape.draw(maskCanvas); maskCanvas.restoreToCount(drawableSaveCount); return; } } shape.setBounds(0, 0, width, height); shape.draw(maskCanvas); } }
Example 6
Source File: MaterialMenuView.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override public void draw(Canvas canvas) { super.draw(canvas); if (getPaddingLeft() != 0 || getPaddingTop() != 0) { int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(getPaddingLeft(), getPaddingTop()); drawable.draw(canvas); canvas.restoreToCount(saveCount); } else { drawable.draw(canvas); } }
Example 7
Source File: MaterialMenuView.java From NHentai-android with GNU General Public License v3.0 | 5 votes |
@Override public void draw(Canvas canvas) { super.draw(canvas); if (getPaddingLeft() != 0 || getPaddingTop() != 0) { int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(getPaddingLeft(), getPaddingTop()); drawable.draw(canvas); canvas.restoreToCount(saveCount); } else { drawable.draw(canvas); } }
Example 8
Source File: MaterialMenuView.java From WeGit with Apache License 2.0 | 5 votes |
@Override public void draw(Canvas canvas) { super.draw(canvas); if (getPaddingLeft() != 0 || getPaddingTop() != 0) { int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(getPaddingLeft(), getPaddingTop()); drawable.draw(canvas); canvas.restoreToCount(saveCount); } else { drawable.draw(canvas); } }
Example 9
Source File: ShapeImageView.java From aurora-imui with MIT License | 5 votes |
@Override protected void onDraw(Canvas canvas) { int saveCount = canvas.getSaveCount(); canvas.save(); super.onDraw(canvas); if (mShape != null) { mShape.draw(canvas, mPaint); } canvas.restoreToCount(saveCount); }
Example 10
Source File: AnimatedImageView.java From UILibrary with MIT License | 5 votes |
@Override public void onDraw(Canvas canvas){ if(mAnimationMark){ startProgressiveMatrixTransform(); mAnimationMark = false; } Drawable drawable = getDrawable(); if(drawable != null){ int saveCount = canvas.getSaveCount(); canvas.save(); boolean cropToPadding = Build.VERSION.SDK_INT > 16 && getCropToPadding(); if(cropToPadding){ final int scrollX = getScrollX(); final int scrollY = getScrollY(); canvas.clipRect(scrollX + getPaddingLeft(), scrollY + getPaddingTop(), scrollX + getRight() - getLeft() - getPaddingRight(), scrollY + getBottom() - getTop() - getPaddingBottom()); } canvas.translate(getPaddingLeft(), getPaddingTop()); if(mProgressiveMatrix != null){ canvas.concat(mProgressiveMatrix); } drawable.draw(canvas); canvas.restoreToCount(saveCount); } }
Example 11
Source File: ImageView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mDrawable == null) { return; // couldn't resolve the URI } if (mDrawableWidth == 0 || mDrawableHeight == 0) { return; // nothing to draw (empty bounds) } if (mDrawMatrix == null && mPaddingTop == 0 && mPaddingLeft == 0) { mDrawable.draw(canvas); } else { final int saveCount = canvas.getSaveCount(); canvas.save(); if (mCropToPadding) { final int scrollX = mScrollX; final int scrollY = mScrollY; canvas.clipRect(scrollX + mPaddingLeft, scrollY + mPaddingTop, scrollX + mRight - mLeft - mPaddingRight, scrollY + mBottom - mTop - mPaddingBottom); } canvas.translate(mPaddingLeft, mPaddingTop); if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); } mDrawable.draw(canvas); canvas.restoreToCount(saveCount); } }
Example 12
Source File: MaterialMenuView.java From material-menu with Apache License 2.0 | 5 votes |
@Override public void draw(Canvas canvas) { super.draw(canvas); if (getPaddingLeft() != 0 || getPaddingTop() != 0) { int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(getPaddingLeft(), getPaddingTop()); drawable.draw(canvas); canvas.restoreToCount(saveCount); } else { drawable.draw(canvas); } }
Example 13
Source File: Graphics.java From J2ME-Loader with Apache License 2.0 | 5 votes |
public void setCanvas(Canvas canvas, Bitmap canvasBitmap) { if (canvas.getSaveCount() > 1) { canvas.restoreToCount(1); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { canvas.save(); } canvas.save(); this.canvas = canvas; this.canvasBitmap = canvasBitmap; }
Example 14
Source File: BubbleImageView.java From chatui with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { int saveCount = canvas.getSaveCount(); canvas.translate(getPaddingLeft(), getPaddingTop()); if (bubbleDrawable != null) bubbleDrawable.draw(canvas); canvas.restoreToCount(saveCount); }
Example 15
Source File: BubbleImageView.java From SocketIO_Chat_APP with MIT License | 5 votes |
@Override protected void onDraw(Canvas canvas) { int saveCount = canvas.getSaveCount(); canvas.translate(getPaddingLeft(), getPaddingTop()); if (bubbleDrawable != null) bubbleDrawable.draw(canvas); canvas.restoreToCount(saveCount); }
Example 16
Source File: BubbleImageView.java From imsdk-android with MIT License | 5 votes |
@Override protected void onDraw(Canvas canvas) { int saveCount = canvas.getSaveCount(); canvas.translate(getPaddingLeft(), getPaddingTop()); if (bubbleDrawable != null) bubbleDrawable.draw(canvas); canvas.restoreToCount(saveCount); }
Example 17
Source File: QuickContactBadge.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (!isEnabled()) { // not clickable? don't show triangle return; } if (mOverlay == null || mOverlay.getIntrinsicWidth() == 0 || mOverlay.getIntrinsicHeight() == 0) { // nothing to draw return; } mOverlay.setBounds(0, 0, getWidth(), getHeight()); if (mPaddingTop == 0 && mPaddingLeft == 0) { mOverlay.draw(canvas); } else { int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(mPaddingLeft, mPaddingTop); mOverlay.draw(canvas); canvas.restoreToCount(saveCount); } }
Example 18
Source File: SmoothImageView.java From Lay-s with MIT License | 4 votes |
@Override protected void onDraw(Canvas canvas) { if (getDrawable() == null) { return; // couldn't resolve the URI } if (mState == STATE_TRANSFORM_IN || mState == STATE_TRANSFORM_OUT) { if (mTransformStart) { initTransform(); } if (mTransfrom == null) { super.onDraw(canvas); return; } if (mTransformStart) { if (mState == STATE_TRANSFORM_IN) { mTransfrom.initStartIn(); } else { mTransfrom.initStartOut(); } } if (mTransformStart) { Log.d("Dean", "mTransfrom.startScale:" + mTransfrom.startScale); Log.d("Dean", "mTransfrom.startScale:" + mTransfrom.endScale); Log.d("Dean", "mTransfrom.scale:" + mTransfrom.scale); Log.d("Dean", "mTransfrom.startRect:" + mTransfrom.startRect.toString()); Log.d("Dean", "mTransfrom.endRect:" + mTransfrom.endRect.toString()); Log.d("Dean", "mTransfrom.rect:" + mTransfrom.rect.toString()); } mPaint.setAlpha(mBgAlpha); canvas.drawPaint(mPaint); int saveCount = canvas.getSaveCount(); canvas.save(); // 先得到图片在此刻的图像Matrix矩阵 getBmpMatrix(); canvas.translate(mTransfrom.rect.left, mTransfrom.rect.top); canvas.clipRect(0, 0, mTransfrom.rect.width, mTransfrom.rect.height); canvas.concat(mSmoothMatrix); getDrawable().draw(canvas); canvas.restoreToCount(saveCount); if (mTransformStart) { mTransformStart = false; startTransform(mState); } } else { //当Transform In变化完成后,把背景改为黑色,使得Activity不透明 mPaint.setAlpha(255); canvas.drawPaint(mPaint); super.onDraw(canvas); } }
Example 19
Source File: SmoothImageView.java From SimplifyReader with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { if (getDrawable() == null) { return; // couldn't resolve the URI } if (mState == STATE_TRANSFORM_IN || mState == STATE_TRANSFORM_OUT) { if (mTransformStart) { initTransform(); } if (mTransfrom == null) { super.onDraw(canvas); return; } if (mTransformStart) { if (mState == STATE_TRANSFORM_IN) { mTransfrom.initStartIn(); } else { mTransfrom.initStartOut(); } } if (mTransformStart) { Log.d("Dean", "mTransfrom.startScale:" + mTransfrom.startScale); Log.d("Dean", "mTransfrom.startScale:" + mTransfrom.endScale); Log.d("Dean", "mTransfrom.scale:" + mTransfrom.scale); Log.d("Dean", "mTransfrom.startRect:" + mTransfrom.startRect.toString()); Log.d("Dean", "mTransfrom.endRect:" + mTransfrom.endRect.toString()); Log.d("Dean", "mTransfrom.rect:" + mTransfrom.rect.toString()); } mPaint.setAlpha(mBgAlpha); canvas.drawPaint(mPaint); int saveCount = canvas.getSaveCount(); canvas.save(); // 先得到图片在此刻的图像Matrix矩阵 getBmpMatrix(); canvas.translate(mTransfrom.rect.left, mTransfrom.rect.top); canvas.clipRect(0, 0, mTransfrom.rect.width, mTransfrom.rect.height); canvas.concat(mSmoothMatrix); getDrawable().draw(canvas); canvas.restoreToCount(saveCount); if (mTransformStart) { mTransformStart = false; startTransform(mState); } } else { //当Transform In变化完成后,把背景改为黑色,使得Activity不透明 mPaint.setAlpha(255); canvas.drawPaint(mPaint); super.onDraw(canvas); } }
Example 20
Source File: BubbleImageView.java From BubbleView with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { if (bubbleDrawable == null) { return; // couldn't resolve the URI } if (bubbleDrawable.getIntrinsicHeight() == 0 || bubbleDrawable.getIntrinsicWidth() == 0) { return; // nothing to draw (empty bounds) } final Matrix mDrawMatrix = getImageMatrix(); final int mPaddingLeft = getPaddingLeft(); final int mPaddingTop = getPaddingTop(); if (mDrawMatrix == null && getPaddingTop() == 0 && getPaddingLeft() == 0) { bubbleDrawable.draw(canvas); } else { final int saveCount = canvas.getSaveCount(); canvas.save(); //crop to padding api above 16 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (getCropToPadding()) { final int scrollX = getScrollX(); final int scrollY = getScrollY(); canvas.clipRect(scrollX + mPaddingLeft, scrollY + mPaddingTop, scrollX + getRight() - getLeft() - getRight(), scrollY + getBottom() - getTop() - getBottom()); } } canvas.translate(mPaddingLeft, mPaddingTop); if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); mDrawMatrix.getValues(matrixValues); final float scaleX = matrixValues[Matrix.MSCALE_X]; final float scaleY = matrixValues[Matrix.MSCALE_Y]; final float translateX = matrixValues[Matrix.MTRANS_X]; final float translateY = matrixValues[Matrix.MTRANS_Y]; final ScaleType scaleType = getScaleType(); if (scaleType == ScaleType.CENTER) { bubbleDrawable.setOffsetLeft(-translateX); bubbleDrawable.setOffsetTop(-translateY); bubbleDrawable.setOffsetBottom(-translateY); bubbleDrawable.setOffsetRight(-translateX); } else if (scaleType == ScaleType.CENTER_CROP) { float scale = scaleX > scaleY ? 1 / scaleY : 1 / scaleX; bubbleDrawable.setOffsetLeft(-translateX * scale); bubbleDrawable.setOffsetTop(-translateY * scale); bubbleDrawable.setOffsetBottom(-translateY * scale); bubbleDrawable.setOffsetRight(-translateX * scale); bubbleDrawable.setScale(scale); } else { bubbleDrawable.setScale(scaleX > scaleY ? 1 / scaleY : 1 / scaleX); } } bubbleDrawable.draw(canvas); canvas.restoreToCount(saveCount); } }