List of usage examples for android.graphics Canvas restoreToCount
public void restoreToCount(int saveCount)
From source file:danonino.danonino_the_game.Core.GamePanel.java
@Override public void draw(Canvas canvas) { final float scaleFactorX = getWidth() / (WIDTH * 1.f); final float scaleFactorY = getHeight() / (HEIGHT * 1.f); if (canvas != null) { final int savedState = canvas.save(); canvas.scale(scaleFactorX, scaleFactorY); this.bg.draw(canvas); this.progress.draw(canvas); //draw butterflies for (Butterfly b : this.butterflies) { b.draw(canvas);/*from w w w .ja v a 2s. co m*/ } //draw enemies for (Fruit e : this.enemies) { e.draw(canvas); } this.player.draw(canvas); if (this.event != null) { this.event.draw(canvas); } if (!this.gameOver) { if (this.joystickEnabled) { this.joystick.draw(canvas); } if (this.powerUpLabel != null) { this.powerUpLabel.draw(canvas); } } else { GameOver.draw(canvas); } this.bgFront.draw(canvas); canvas.restoreToCount(savedState); } }
From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mFitPaddingTop != 0) { int saved = canvas.save(); canvas.clipRect(0, 0, getWidth(), mFitPaddingTop); canvas.drawColor(mStatusBarColor); canvas.restoreToCount(saved); }/*w w w.ja va 2 s . c o m*/ if (mFitPaddingBottom != 0) { int saved = canvas.save(); int height = getHeight(); canvas.clipRect(0, height - mFitPaddingBottom, getWidth(), height); canvas.drawColor(mNavigationBarColor); canvas.restoreToCount(saved); } }
From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Draws axes and text labels drawAxes(canvas);// www . ja v a2 s. c om // Clips the next few drawing operations to the content area int clipRestoreCount = canvas.save(); canvas.clipRect(mContentRect); drawDataSeriesUnclipped(canvas); drawEdgeEffectsUnclipped(canvas); // Removes clipping rectangle canvas.restoreToCount(clipRestoreCount); // Draws chart container canvas.drawRect(mContentRect, mAxisPaint); }
From source file:vc908.stickerfactory.ui.advancedrecyclerview.decoration.ItemShadowDecorator.java
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { final int childCount = parent.getChildCount(); if (childCount == 0) { return;/*w w w.ja v a 2 s .c om*/ } int savedCount = c.save(Canvas.CLIP_SAVE_FLAG); c.clipRect(parent.getLeft() + Math.max(0, parent.getPaddingLeft() - mShadowPadding.left), parent.getTop()/* + Math.max(0, parent.getPaddingTop() - mShadowPadding.top)*/, parent.getRight() - Math.max(0, parent.getPaddingRight() - mShadowPadding.right), parent.getBottom()/* - Math.max(0, parent.getPaddingBottom() - mShadowPadding.bottom)*/); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); if (!shouldDrawDropShadow(child)) { continue; } final int tx = (int) (ViewCompat.getTranslationX(child) + 0.5f); final int ty = (int) (ViewCompat.getTranslationY(child) + 0.5f); final int left = child.getLeft() - mShadowPadding.left; final int right = child.getRight() + mShadowPadding.right; final int top = child.getTop() - mShadowPadding.top; final int bottom = child.getBottom() + mShadowPadding.bottom; mShadowDrawable.setBounds(left + tx, top + ty, right + tx, bottom + ty); mShadowDrawable.draw(c); } c.restoreToCount(savedCount); ViewCompat.postInvalidateOnAnimation(parent); }
From source file:com.acbelter.scheduleview.ScheduleView.java
private void drawEdgeEffects(Canvas canvas) { boolean needsInvalidate = false; final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS) { if (!mTopEdgeEffect.isFinished()) { int saveCount = canvas.save(); int width = mViewWidth - getPaddingLeft() - getPaddingRight(); int height = mViewHeight - getPaddingTop() - getPaddingBottom(); canvas.translate(0, getPaddingTop()); mTopEdgeEffect.setSize(width, height); needsInvalidate |= mTopEdgeEffect.draw(canvas); canvas.restoreToCount(saveCount); }/*ww w.j a v a 2s . c om*/ if (!mBottomEdgeEffect.isFinished()) { int saveCount = canvas.save(); int width = mViewWidth - getPaddingLeft() - getPaddingRight(); int height = mViewHeight - getPaddingTop() - getPaddingBottom(); canvas.translate(mViewWidth, mViewHeight - getPaddingBottom()); canvas.rotate(180); mBottomEdgeEffect.setSize(width, height); needsInvalidate |= mBottomEdgeEffect.draw(canvas); canvas.restoreToCount(saveCount); } } else { mTopEdgeEffect.finish(); mBottomEdgeEffect.finish(); } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.mikepenz.materialize.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()); if (!mSystemUIVisible) { mInsets.top = 0;//from w w w.j a v a 2s .c om mInsets.right = 0; mInsets.bottom = 0; mInsets.left = 0; } // Top if (mTintStatusBar) { mTempRect.set(0, 0, width, mInsets.top); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); } // Bottom if (mTintNavigationBar) { 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:org.telegram.ui.Components.Switch.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 .j a v a2 s . c o m padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { if (mSplitTrack && thumbDrawable != null) { final Insets insets = Insets.NONE; 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 saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } canvas.restoreToCount(saveCount); }
From source file:android.widget.PinnedHeaderListView.java
private void drawHeader(final Canvas canvas, final PinnedHeader header, final long currentTime) { if (header.animating) { final int timeLeft = (int) (header.targetTime - currentTime); if (timeLeft <= 0) { header.y = header.targetY;// w ww . j a v a2 s .c o m header.visible = header.targetVisible; header.animating = false; } else header.y = header.targetY + (header.sourceY - header.targetY) * timeLeft / mAnimationDuration; } if (header.visible) { final View view = header.view; final int saveCount = canvas.save(); final int translateX = ViewUtil.isViewLayoutRtl(this) ? getWidth() - mHeaderPaddingStart - view.getWidth() : mHeaderPaddingStart; canvas.translate(translateX, header.y); if (header.state == FADING) { mBounds.set(0, 0, view.getWidth(), view.getHeight()); canvas.saveLayerAlpha(mBounds, header.alpha, Canvas.ALL_SAVE_FLAG); } view.draw(canvas); canvas.restoreToCount(saveCount); } }
From source file:com.lamcreations.scaffold.common.utils.CollapsingTextHelper.java
public void draw(Canvas canvas) { int saveCount = canvas.save(); if (this.mTextToDraw != null) { boolean isRtl = this.mIsRtl; float x = isRtl ? this.mCurrentRight : this.mCurrentLeft; float y = this.mCurrentTop; boolean drawTexture = this.mUseTexture && this.mExpandedTitleTexture != null; this.mTextPaint.setTextSize(this.mCurrentTextSize); float ascent; if (drawTexture) { ascent = this.mTextureAscent * this.mScale; } else {/*from ww w .java 2 s . c om*/ ascent = this.mTextPaint.ascent() * this.mScale; } if (drawTexture) { y += ascent; } if (this.mScale != 1.0F) { canvas.scale(this.mScale, this.mScale, x, y); } if (isRtl) { x -= this.mTextWidth; } if (drawTexture) { canvas.drawBitmap(this.mExpandedTitleTexture, x, y, this.mTexturePaint); } else { canvas.drawText(this.mTextToDraw, 0, this.mTextToDraw.length(), x, y, this.mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:com.appunite.scroll.ScaleImageView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Clips the next few drawing operations to the content area int clipRestoreCount = canvas.save(); canvas.clipRect(mContentRect);/*from w w w.j a va 2s. co m*/ if (mSrc != null) { getRealTranslation(mTranslation, mRealTranslation); canvas.translate(mRealTranslation.x, mRealTranslation.y); canvas.scale(mScale, mScale); Log.v(TAG, "scale=" + mScale + " translation=" + mTranslation.toString() + " realTranslation=" + mRealTranslation.toString()); mSrc.draw(canvas); } // Removes clipping rectangle canvas.restoreToCount(clipRestoreCount); drawEdgeEffectsUnclipped(canvas); }