List of usage examples for android.graphics Canvas restoreToCount
public void restoreToCount(int saveCount)
From source file:android.support.designox.widget.CollapsingTextHelper.java
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mTextToDraw != null && mDrawTitle) { float x = mCurrentDrawX; float y = mCurrentDrawY; final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null; final float ascent; final float descent; if (drawTexture) { ascent = mTextureAscent * mScale; descent = mTextureDescent * mScale; } else {//from w w w . j a v a 2 s. co m ascent = mTextPaint.ascent() * mScale; descent = mTextPaint.descent() * mScale; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent, DEBUG_DRAW_PAINT); } if (drawTexture) { y += ascent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (drawTexture) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:org.mariotaku.multivalueswitch.library.MultiValueSwitch.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else {//from w w w. ja v a 2s .co m padding.setEmpty(); } final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { if (mSplitTrack && thumbDrawable != null) { final Rect insets = MVS_DrawableUtilsAccessor.getOpticalBounds(thumbDrawable); thumbDrawable.copyBounds(padding); padding.left += insets.left; padding.right -= insets.right; final int saveCount = canvas.save(); canvas.clipRect(padding, Region.Op.DIFFERENCE); trackDrawable.draw(canvas); canvas.restoreToCount(saveCount); } else { trackDrawable.draw(canvas); } final int thumbScrollStart = mSwitchLeft + mThumbWidth - mThumbWidth / 2; final int thumbScrollRange = mSwitchRight - mSwitchLeft - mThumbWidth; final int y = trackDrawable.getBounds().centerY(); for (int i = 0, j = getMax(); i < j; i++) { if (i == 0 || i == j - 1) continue; canvas.drawCircle(thumbScrollStart + i * (thumbScrollRange / (j - 1)), y, mPointRadius, mPointPaint); } } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } canvas.restoreToCount(saveCount); }
From source file:com.android.slidingmenu.HorizontalListView.java
/** * Draws the overscroll edge glow effect on the left and right sides of the * horizontal list//from w w w .j a v a 2 s . c o m */ private void drawEdgeGlow(Canvas canvas) { if (mEdgeGlowLeft != null && !mEdgeGlowLeft.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so // rotate it to draw on the left side. final int restoreCount = canvas.save(); final int height = getHeight(); canvas.rotate(-90, 0, 0); canvas.translate(-height + getPaddingBottom(), 0); mEdgeGlowLeft.setSize(getRenderHeight(), getRenderWidth()); if (mEdgeGlowLeft.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } else if (mEdgeGlowRight != null && !mEdgeGlowRight.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so // rotate it to draw on the right side. final int restoreCount = canvas.save(); final int width = getWidth(); canvas.rotate(90, 0, 0); canvas.translate(getPaddingTop(), -width); mEdgeGlowRight.setSize(getRenderHeight(), getRenderWidth()); if (mEdgeGlowRight.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.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); boolean drawScrim = false; if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately be covered. canvas.getClipBounds(mTmpRect);//www . j a v a 2 s . c o m if (mIsSlidingUp) { mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop()); } else { mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom()); } canvas.clipRect(mTmpRect); if (mSlideOffset < 1) { drawScrim = true; } } result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(save); if (drawScrim) { final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * (1 - mSlideOffset)); final int color = imag << 24 | (mCoveredFadeColor & 0xffffff); mCoveredFadePaint.setColor(color); canvas.drawRect(mTmpRect, mCoveredFadePaint); } return result; }
From source file:com.xiaosu.lib.base.widget.drawerLayout.DrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final boolean drawingContent = child == mContentView; int clipBottom = mDrawerView.getTop(); final int restoreCount = canvas.save(); if (drawingContent) { canvas.clipRect(0, 0, getWidth(), clipBottom); }//from w ww.j a v a2 s . c o m final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); if (mScrimOpacity > 0 && drawingContent) { final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mScrimOpacity); final int color = imag << 24 | (mScrimColor & 0xffffff); mScrimPaint.setColor(color); canvas.drawRect(0, 0, getWidth(), clipBottom, mScrimPaint); } return result; }
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
private void drawEdges(Canvas canvas) { if (mEdgeGlowLeft != null) { final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); if (!mEdgeGlowLeft.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(270);/*from w ww .j ava 2 s. co m*/ canvas.translate(-height + getPaddingTop(), 0); mEdgeGlowLeft.setSize(height, width); if (mEdgeGlowLeft.draw(canvas)) { postInvalidate(); } canvas.restoreToCount(restoreCount); } if (!mEdgeGlowRight.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(90); canvas.translate(-getPaddingTop(), -(mTouchX + width)); mEdgeGlowRight.setSize(height, width); if (mEdgeGlowRight.draw(canvas)) { postInvalidate(); } canvas.restoreToCount(restoreCount); } } }
From source file:android.support.design.widget.CollapsingTextHelper.java
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mTextToDraw != null && mDrawTitle) { float x = mCurrentDrawX; float y = mCurrentDrawY; final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null; final float ascent; final float descent; if (drawTexture) { ascent = mTextureAscent * mScale; descent = mTextureDescent * mScale; } else {/*from ww w .j ava2s .com*/ ascent = mTextPaint.ascent() * mScale; descent = mTextPaint.descent() * mScale; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a magenta rect in the text bounds canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent, DEBUG_DRAW_PAINT); } if (drawTexture) { y += ascent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (drawTexture) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:pl.motyczko.scrollheader.PagerSlidingTabStrip.java
private void drawBackground(Canvas canvas) { if (mViewBackground == null) return;//w w w .j a v a2s .c o m if (mViewBackground instanceof KenBurnsDrawable && !((KenBurnsDrawable) mViewBackground).isAnimating()) { mViewBackground.setBounds(0, 0, getWidth(), getHeight()); ((KenBurnsDrawable) mViewBackground).animate(); mKenBurnsInitialized = true; } if (mDrawMatrix == null && !(mViewBackground instanceof KenBurnsDrawable)) { calculateBackgroundBounds(); } int saveCount = canvas.getSaveCount(); canvas.save(); float translation = mParallaxForBackground ? getTranslationY() / 2 : 0; canvas.translate(getScrollX(), getScrollY() - translation); if (mDrawMatrix != null) canvas.concat(mDrawMatrix); float fraction = Math.abs(getTranslationY() / getAllowedVerticalScrollLength()); int color = (Integer) mColorEvaluator.evaluate(fraction, mOverlayColorExpanded, mOverlayColorCollapsed); mViewBackground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); mViewBackground.draw(canvas); canvas.restoreToCount(saveCount); }
From source file:cn.ieclipse.af.view.StaggeredGridView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (mTopEdge != null) { boolean needsInvalidate = false; if (!mTopEdge.isFinished()) { mTopEdge.draw(canvas);//from w w w . j a va2s .co m needsInvalidate = true; } if (!mBottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); canvas.translate(-width, getHeight()); canvas.rotate(180, width, 0); mBottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); needsInvalidate = true; } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } } }
From source file:com.comcast.freeflow.core.FreeFlowContainer.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); boolean needsInvalidate = false; final int height = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); final int width = getMeasuredWidth(); if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(270);/* w w w . ja v a 2 s .c o m*/ canvas.translate(-height + getPaddingTop(), 0);// width); mLeftEdge.setSize(height, width); needsInvalidate = mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mTopEdge.isFinished()) { final int restoreCount = canvas.save(); mTopEdge.setSize(width, height); needsInvalidate = mTopEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mRightEdge.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(90); canvas.translate(0, -width);// width); mRightEdge.setSize(height, width); needsInvalidate = mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mBottomEdge.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(180); canvas.translate(-width + getPaddingTop(), -height); mBottomEdge.setSize(width, height); needsInvalidate = mBottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (needsInvalidate) postInvalidateOnAnimation(); }