List of usage examples for android.graphics Canvas restoreToCount
public void restoreToCount(int saveCount)
From source file:com.hippo.largeimageview.LargeImageView.java
@Override protected void onDraw(Canvas canvas) { // Set max bitmap size if (mMaxBitmapSize == 0) { mMaxBitmapSize = getMaxBitmapSize(canvas); if (mImage != null) { mImage.setMaxBitmapSize(mMaxBitmapSize); }//from w w w.j ava 2 s.co m } if (mImage == null || mDst.isEmpty()) { return; } if (mRectDirty) { applyRectInWindow(); } if (!mSrcActual.isEmpty()) { final int saved = transformCanvas(canvas); mImage.draw(canvas, mSrcActual, mDstActual); if (saved != 0) { canvas.restoreToCount(saved); } } }
From source file:com.shizhefei.view.coolrefreshview.header.JellyHeader.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int totalDistance = totalDistance(); int headerHeight; int pullHeight; int offsetToKeepHeaderWhileLoading = offsetToKeepHeaderWhileLoading(); if (status == CoolRefreshView.PULL_STATUS_REFRESHING) { headerHeight = offsetToKeepHeaderWhileLoading; pullHeight = currentDistance;/* w w w .ja v a 2 s . co m*/ } else { headerHeight = Math.min(currentDistance / 2, offsetToKeepHeaderWhileLoading); pullHeight = currentDistance; } if (headerHeight == 0) { return; } int saveCount = canvas.save(); canvas.translate(0, totalDistance - currentDistance); final int width = canvas.getWidth(); //??touchx ????touchx?? mPointX = width / 2; final float mDisplayX = (mPointX - width / 2f) * 0.5f + width / 2f; mPaint.setColor(mColor); mPath.rewind(); // ? mPath.moveTo(0, 0); mPath.lineTo(0, headerHeight); // ??? mPath.quadTo(mDisplayX, pullHeight, width, headerHeight); mPath.lineTo(width, 0); mPath.close(); canvas.drawPath(mPath, mPaint); canvas.restoreToCount(saveCount); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setOutlineProvider(mViewOutlineProvider); } }
From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java
/** * Draws the overscroll "glow" at the four edges of the chart region, if necessary. The edges * of the chart region are stored in {@link #mContentRect}. * * @see EdgeEffectCompat/*from w w w.j a va 2 s .co m*/ */ private void drawEdgeEffectsUnclipped(Canvas canvas) { // The methods below rotate and translate the canvas as needed before drawing the glow, // since EdgeEffectCompat always draws a top-glow at 0,0. boolean needsInvalidate = false; if (!mEdgeEffectTop.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(mContentRect.left, mContentRect.top); mEdgeEffectTop.setSize(mContentRect.width(), mContentRect.height()); if (mEdgeEffectTop.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (!mEdgeEffectBottom.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(2 * mContentRect.left - mContentRect.right, mContentRect.bottom); canvas.rotate(180, mContentRect.width(), 0); mEdgeEffectBottom.setSize(mContentRect.width(), mContentRect.height()); if (mEdgeEffectBottom.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (!mEdgeEffectLeft.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(mContentRect.left, mContentRect.bottom); canvas.rotate(-90, 0, 0); mEdgeEffectLeft.setSize(mContentRect.height(), mContentRect.width()); if (mEdgeEffectLeft.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (!mEdgeEffectRight.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(mContentRect.right, mContentRect.top); canvas.rotate(90, 0, 0); mEdgeEffectRight.setSize(mContentRect.height(), mContentRect.width()); if (mEdgeEffectRight.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:de.telekom.pde.codelibrary.ui.layout.PDESwipeRefreshLayout.java
@Override public void draw(@NonNull Canvas canvas) { super.draw(canvas); int width = mBounds.width(); int height = mBounds.height(); int cx = width / 2; int cy = height / 2; int restoreCount = canvas.save(); canvas.clipRect(mBounds);// ww w.j av a 2 s .c om if (mRunning) { long now = AnimationUtils.currentAnimationTimeMillis(); long elapsed = (now - mStartTime) % mAnimationDuration; float currentAngle = (elapsed / (mAnimationDuration / 100f)) * 3.6f; canvas.drawCircle(cx, cy, PDEBuildingUnits.BU(), mPaint); canvas.save(); canvas.rotate(currentAngle, cx, cy); canvas.drawPath(mCirclePath, mWhitePaint); canvas.restore(); ViewCompat.postInvalidateOnAnimation(this); } else { // Otherwise if we're in the middle of a trigger, draw that. if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) { drawTrigger(canvas, cx, cy); } } canvas.restoreToCount(restoreCount); }
From source file:com.cocosw.accessory.views.layout.CollapsingTitleLayout.java
@Override public void draw(Canvas canvas) { final int saveCount = canvas.save(); final int toolbarHeight = mToolbar.getHeight(); canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset)); // Now call super and let it draw the background, etc super.draw(canvas); if (mTitleToDraw != null) { float x = mTextLeft; float y = mTextTop; if (!mUseTexture) { // If we're not drawing a texture, we need to properly offset the text x -= mDrawnTextBounds.left;/* w ww . j a va 2 s. com*/ y -= mDrawnTextBounds.top; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mTextLeft, mTextTop, mTextRight, mTextTop + mDrawnTextBounds.height(), DEBUG_DRAW_PAINT); } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (mUseTexture && mExpandedTitleTexture != null) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTitleToDraw, x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:com.android.widget.SlidingPaneLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately be covered. canvas.getClipBounds(mTmpRect);/*from ww w . j a v a 2 s . c o m*/ mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop()); canvas.clipRect(mTmpRect); } result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(save); return result; }
From source file:com.h6ah4i.android.materialshadowninepatch.MaterialShadowContainerView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if ((getChildCount() > 0) && (getChildAt(0).getVisibility() == View.VISIBLE)) { if (mUseAmbientShadow) { if (mCurrentAmbientShadowDrawable1 != null) { mCurrentAmbientShadowDrawable1.draw(canvas); }//from www .j ava2 s .co m if (mCurrentAmbientShadowDrawable2 != null) { mCurrentAmbientShadowDrawable2.draw(canvas); } } if (mUseSpotShadow && (mCurrentSpotShadowDrawable1 != null || mCurrentSpotShadowDrawable2 != null)) { final int savedCount = canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.translate(mSpotShadowTranslationX, mSpotShadowTranslationY); if (mCurrentSpotShadowDrawable1 != null) { mCurrentSpotShadowDrawable1.draw(canvas); } if (mCurrentSpotShadowDrawable2 != null) { mCurrentSpotShadowDrawable2.draw(canvas); } canvas.restoreToCount(savedCount); } } }
From source file:com.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java
@Override public void draw(Canvas canvas) { final int saveCount = canvas.save(); final int toolbarHeight = mToolbar.getHeight(); canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset)); // Now call super and let it draw the background, etc super.draw(canvas); if (mTitleToDraw != null) { float x = mTextLeft; float y = mTextTop; final float ascent = mTextPaint.ascent() * mScale; final float descent = mTextPaint.descent() * mScale; final float h = descent - ascent; if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mTextLeft, y - h + descent, mTextRight, y + descent, DEBUG_DRAW_PAINT); }//from w w w.j a v a 2 s. com if (mUseTexture) { y = y - h + descent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (mUseTexture && mExpandedTitleTexture != null) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTitleToDraw, x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:cl.monsoon.s1next.widget.PhotoView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // draw the photo if (mDrawable != null) { int saveCount = canvas.getSaveCount(); canvas.save();/*from ww w . j a va 2s . com*/ if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); } mDrawable.draw(canvas); canvas.restoreToCount(saveCount); if (mVideoBlob != null) { final Bitmap videoImage = (mVideoReady ? sVideoImage : sVideoNotReadyImage); final int drawLeft = (getWidth() - videoImage.getWidth()) / 2; final int drawTop = (getHeight() - videoImage.getHeight()) / 2; canvas.drawBitmap(videoImage, drawLeft, drawTop, null); } // Extract the drawable's bounds (in our own copy, to not alter the image) mTranslateRect.set(mDrawable.getBounds()); if (mDrawMatrix != null) { mDrawMatrix.mapRect(mTranslateRect); } if (mAllowCrop) { int previousSaveCount = canvas.getSaveCount(); canvas.drawRect(0, 0, getWidth(), getHeight(), sCropDimPaint); canvas.save(); canvas.clipRect(mCropRect); if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); } mDrawable.draw(canvas); canvas.restoreToCount(previousSaveCount); canvas.drawRect(mCropRect, sCropPaint); } } }
From source file:martin.app.bitunion.widget.PhotoView.java
@Override protected void onDraw(@NonNull Canvas canvas) { super.onDraw(canvas); // draw the photo if (mDrawable != null) { int saveCount = canvas.getSaveCount(); canvas.save();/*from ww w . j a v a2 s . c o m*/ if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); } mDrawable.draw(canvas); canvas.restoreToCount(saveCount); if (mVideoBlob != null) { final Bitmap videoImage = (mVideoReady ? sVideoImage : sVideoNotReadyImage); final int drawLeft = (getWidth() - videoImage.getWidth()) / 2; final int drawTop = (getHeight() - videoImage.getHeight()) / 2; canvas.drawBitmap(videoImage, drawLeft, drawTop, null); } // Extract the drawable's bounds (in our own copy, to not alter the image) mTranslateRect.set(mDrawable.getBounds()); if (mDrawMatrix != null) { mDrawMatrix.mapRect(mTranslateRect); } if (mAllowCrop) { int previousSaveCount = canvas.getSaveCount(); canvas.drawRect(0, 0, getWidth(), getHeight(), sCropDimPaint); canvas.save(); canvas.clipRect(mCropRect); if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); } mDrawable.draw(canvas); canvas.restoreToCount(previousSaveCount); canvas.drawRect(mCropRect, sCropPaint); } } }