List of usage examples for android.graphics Canvas restoreToCount
public void restoreToCount(int saveCount)
From source file:net.simonvt.staggeredgridview.StaggeredGridView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (topEdge != null) { boolean needsInvalidate = false; if (!topEdge.isFinished()) { topEdge.draw(canvas);/* ww w . j av a2s .co m*/ needsInvalidate = true; } if (!bottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); canvas.translate(-width, getHeight()); canvas.rotate(180, width, 0); bottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); needsInvalidate = true; } if (needsInvalidate) { postInvalidateOnAnimation(); } } if (!selectorRect.isEmpty()) { selector.setBounds(selectorRect); selector.draw(canvas); } }
From source file:rikka.akashitoolkit.ui.widget.IconSwitchCompat.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 va 2s. co m*/ padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final int switchInnerTop = switchTop + padding.top; final int switchInnerBottom = switchBottom - padding.bottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { if (mSplitTrack && thumbDrawable != null) { final Rect insets = DrawableUtils.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 saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } final Drawable iconDrawable = mIconDrawable; if (iconDrawable != null) { if (mSplitTrack) { final Rect insets = DrawableUtils.getOpticalBounds(iconDrawable); iconDrawable.copyBounds(padding); padding.left += insets.left; padding.right -= insets.right; //final int saveCount = canvas.save(); canvas.clipRect(padding, Region.Op.DIFFERENCE); iconDrawable.draw(canvas); canvas.restoreToCount(saveCount); } else { iconDrawable.draw(canvas); } } final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; if (switchText != null) { final int drawableState[] = getDrawableState(); if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0)); } mTextPaint.drawableState = drawableState; final int cX; if (thumbDrawable != null) { final Rect bounds = thumbDrawable.getBounds(); cX = bounds.left + bounds.right; } else { cX = getWidth(); } final int left = cX / 2 - switchText.getWidth() / 2; final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2; canvas.translate(left, top); switchText.draw(canvas); } canvas.restoreToCount(saveCount); }
From source file:com.marshalchen.common.uimodule.freeflow.core.FreeFlowContainer.java
@Override public void draw(Canvas canvas) { super.draw(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);/*from w w w . jav a2 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) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (mEdgeGlowTop != null) { final int scrollY = getScrollY(); if (!mEdgeGlowTop.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.translate(getPaddingLeft(), Math.min(0, scrollY)); mEdgeGlowTop.setSize(width, getHeight()); if (mEdgeGlowTop.draw(canvas)) { ViewCompat.postInvalidateOnAnimation(this); }/* ww w .j av a 2 s.com*/ canvas.restoreToCount(restoreCount); } if (!mEdgeGlowBottom.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); canvas.translate(-width + getPaddingLeft(), Math.max(getScrollRange(), scrollY) + height); canvas.rotate(180, width, 0); mEdgeGlowBottom.setSize(width, height); if (mEdgeGlowBottom.draw(canvas)) { ViewCompat.postInvalidateOnAnimation(this); } canvas.restoreToCount(restoreCount); } } }
From source file:com.jzh.stuapp.view.MyViewPager.java
@Override public void draw(Canvas canvas) { super.draw(canvas); boolean needsInvalidate = false; final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null && mAdapter.getCount() > 1)) { if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(270);//from w w w .j ava 2s .c o m canvas.translate(-height + getPaddingTop(), 0); mLeftEdge.setSize(height, getWidth()); needsInvalidate |= mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mRightEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int itemCount = mAdapter != null ? mAdapter.getCount() : 1; canvas.rotate(90); canvas.translate(-getPaddingTop(), -itemCount * (width + mPageMargin) + mPageMargin); mRightEdge.setSize(height, width); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { invalidate(); } }
From source file:com.yimeng.babymom.view.LazyViewPager.java
@Override public void draw(Canvas canvas) { super.draw(canvas); boolean needsInvalidate = false; final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null && mAdapter.getCount() > 1)) { if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(270);/*from w w w. j a va2 s . co m*/ canvas.translate(-height + getPaddingTop(), 0); mLeftEdge.setSize(getWidth(), height); needsInvalidate = mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mRightEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int itemCount = mAdapter != null ? mAdapter.getCount() : 1; canvas.rotate(90); canvas.translate(-getPaddingTop(), -itemCount * (width + mPageMargin) + mPageMargin); mRightEdge.setSize(width, height); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating invalidate(); } }
From source file:com.example.nwilde.myfirstapp.SimpleListDividerDecorator.java
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { final int childCount = parent.getChildCount(); final float yPositionThreshold = (mOverlap) ? 1.0f : (mDividerHeight + 1.0f); // [px] final float zPositionThreshold = 1.0f; // [px] if (childCount == 0) { return;//from w w w . java2s . c o m } int savedCount = c.save(Canvas.CLIP_SAVE_FLAG); c.clipRect(parent.getLeft() + parent.getPaddingLeft(), parent.getTop() + parent.getPaddingTop(), parent.getRight() - parent.getPaddingRight(), parent.getBottom() + parent.getPaddingBottom()); for (int i = 0; i < childCount - 1; i++) { final View child = parent.getChildAt(i); final View nextChild = parent.getChildAt(i + 1); if ((child.getVisibility() != View.VISIBLE) || (nextChild.getVisibility() != View.VISIBLE)) { continue; } // check if the next item is placed at the bottom final float childBottom = child.getBottom() + ViewCompat.getTranslationY(child); final float nextChildTop = nextChild.getTop() + ViewCompat.getTranslationY(nextChild); if (!(Math.abs(nextChildTop - childBottom) < yPositionThreshold)) { continue; } // check if the next item is placed on the same plane final float childZ = ViewCompat.getTranslationZ(child) + ViewCompat.getElevation(child); final float nextChildZ = ViewCompat.getTranslationZ(nextChild) + ViewCompat.getElevation(nextChild); if (!(Math.abs(nextChildZ - childZ) < zPositionThreshold)) { continue; } final float childAlpha = ViewCompat.getAlpha(child); final float nextChildAlpha = ViewCompat.getAlpha(nextChild); final int tx = (int) (ViewCompat.getTranslationX(child) + 0.5f); final int ty = (int) (ViewCompat.getTranslationY(child) + 0.5f); final int left = child.getLeft(); final int right = child.getRight(); final int top = child.getBottom(); final int bottom = top + mDividerHeight; mDividerDrawable.setAlpha((int) ((0.5f * 255) * (childAlpha + nextChildAlpha) + 0.5f)); mDividerDrawable.setBounds(left + tx, top + ty, right + tx, bottom + ty); mDividerDrawable.draw(c); } c.restoreToCount(savedCount); }
From source file:com.cnpeng.cnpeng_mydemosfrom2016_12.a_12_GetLocalFiles_VP_FM.CustomNoPreLoadViewPager.java
@Override public void draw(Canvas canvas) { super.draw(canvas); boolean needsInvalidate = false; final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null && mAdapter.getCount() > 1)) { if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(270);//w ww . j a va 2 s .c om canvas.translate(-height + getPaddingTop(), 0); mLeftEdge.setSize(height, getWidth()); needsInvalidate |= mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mRightEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int itemCount = mAdapter != null ? mAdapter.getCount() : 1; canvas.rotate(90); canvas.translate(-getPaddingTop(), -itemCount * (width + mPageMargin) + mPageMargin); mRightEdge.setSize(height, width); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating invalidate(); } }
From source file:com.guodong.sun.guodong.widget.ZoomImageView.java
@Override protected void onDraw(Canvas canvas) { if (getDrawable() == null) { return; // couldn't resolve the URI }//from ww w . ja va2 s .com 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); } }
From source file:com.hippo.widget.recyclerview.EasyRecyclerView.java
@Override protected void dispatchDraw(@NonNull Canvas canvas) { boolean clipToPadding = mClipToPadding; int saveCount = 0; if (clipToPadding) { saveCount = canvas.save();//from www .java 2 s. c o m final int scrollX = getScrollX(); final int scrollY = getScrollY(); canvas.clipRect(scrollX + getPaddingLeft(), scrollY + getPaddingTop(), scrollX + getRight() - getLeft() - getPaddingRight(), scrollY + getBottom() - getTop() - getPaddingBottom()); } // TODO disable selector drawable state change when need not to draw selector boolean drawSelector = mOnDrawSelectorListener == null || mSelectorPosition < 0 || mSelectorPosition >= mAdapter.getItemCount() || mOnDrawSelectorListener.beforeDrawSelector(mSelectorPosition); final boolean drawSelectorOnTop = mDrawSelectorOnTop; if (drawSelector && !drawSelectorOnTop) { drawSelector(canvas); } super.dispatchDraw(canvas); if (drawSelector && drawSelectorOnTop) { drawSelector(canvas); } if (clipToPadding) { canvas.restoreToCount(saveCount); } }