List of usage examples for android.graphics Canvas restoreToCount
public void restoreToCount(int saveCount)
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
@Override protected void dispatchDraw(Canvas canvas) { boolean restore = false; int restoreCount = 0; if (mItemCount < 1) return;// www . ja v a 2 s. co m if (mCurrentScreen < 0) return; boolean fastDraw = mTouchState != TOUCH_STATE_SCROLLING && mNextScreen == INVALID_SCREEN; // If we are not scrolling or flinging, draw only the current screen if (fastDraw) { try { drawChild(canvas, getChildAt(mCurrentScreen - mFirstPosition), getDrawingTime()); } catch (RuntimeException e) { e.printStackTrace(); } } else { final long drawingTime = getDrawingTime(); final float scrollPos = (float) getScrollX() / getTotalWidth(); final int leftScreen = (int) scrollPos; final int rightScreen = leftScreen + 1; if (leftScreen >= 0) { try { drawChild(canvas, getChildAt(leftScreen - mFirstPosition), drawingTime); } catch (RuntimeException e) { e.printStackTrace(); } } if (scrollPos != leftScreen && rightScreen < mItemCount) { try { drawChild(canvas, getChildAt(rightScreen - mFirstPosition), drawingTime); } catch (RuntimeException e) { e.printStackTrace(); } } } // let's draw the edges only if we have more than 1 page if (mEdgeGlowLeft != null && mItemCount > 1) { drawEdges(canvas); } if (restore) { canvas.restoreToCount(restoreCount); } }
From source file:com.shouhuan.view.ResideLayout.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.ALL_SAVE_FLAG); if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately // be covered. canvas.scale(1.2f - 0.2f * mSlideOffset, 1.2f - 0.2f * mSlideOffset, child.getRight(), getHeight() / 2); } else {/*from w ww . ja v a 2 s. co m*/ assert mSlideableView != null; canvas.scale(1 - mSlideOffset / 3, 1 - mSlideOffset / 3, mSlideableView.getLeft(), getHeight() / 2); // ViewCompat.setRotationY(child, -10 * mSlideOffset); } if (!lp.slideable && mSlideOffset == 0) { result = true; } else { if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && mSlideOffset > 0) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } final Bitmap cache = child.getDrawingCache(); if (cache != null) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache"); result = super.drawChild(canvas, child, drawingTime); } } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } } } canvas.restoreToCount(save); return result; }
From source file:administrator.example.com.myscrollview.VerticalViewPager.java
@Override public void draw(Canvas canvas) { // XXX ?// w w w . j a v a 2 s .c om 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 (!mTopEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.rotate(270); canvas.translate(-width + getPaddingLeft(), 0); mTopEdge.setSize(width, getHeight()); needsInvalidate |= mTopEdge.draw(canvas); canvas.restoreToCount(restoreCount); } /* end of if */ if (!mBottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); final int itemCount = mAdapter != null ? mAdapter.getCount() : 1; canvas.rotate(180); canvas.translate(-width + getPaddingLeft(), -itemCount * (height + mPageMargin) + mPageMargin); mBottomEdge.setSize(width, height); needsInvalidate |= mBottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); } /* end of if */ } else { mTopEdge.finish(); mBottomEdge.finish(); } /* end of if */ if (needsInvalidate) { // Keep animating invalidate(); } /* end of if */ }
From source file:com.lanou.mirror.tool.VerticalViewPager.java
@Override public void draw(Canvas canvas) { // XXX //from w w w .j a v a 2 s . c o m 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 (!mTopEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.rotate(270); canvas.translate(-width + getPaddingLeft(), 0); mTopEdge.setSize(width, getHeight()); needsInvalidate |= mTopEdge.draw(canvas); canvas.restoreToCount(restoreCount); } /* end of if */ if (!mBottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); final int itemCount = mAdapter != null ? mAdapter.getCount() : 1; canvas.rotate(180); canvas.translate(-width + getPaddingLeft(), -itemCount * (height + mPageMargin) + mPageMargin); mBottomEdge.setSize(width, height); needsInvalidate |= mBottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); } /* end of if */ } else { mTopEdge.finish(); mBottomEdge.finish(); } /* end of if */ if (needsInvalidate) { // Keep animating invalidate(); } /* end of if */ }
From source file:com.bluetoothlamp.tiny.view.verticalview.VerticalViewPager.java
@Override public void draw(Canvas canvas) { // XXX ??//from w ww . j a v a 2 s. c om 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 (!mTopEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.rotate(270); canvas.translate(-width + getPaddingLeft(), 0); mTopEdge.setSize(width, getHeight()); needsInvalidate |= mTopEdge.draw(canvas); canvas.restoreToCount(restoreCount); } /* end of if */ if (!mBottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); final int itemCount = mAdapter != null ? mAdapter.getCount() : 1; canvas.rotate(180); canvas.translate(-width + getPaddingLeft(), -itemCount * (height + mPageMargin) + mPageMargin); mBottomEdge.setSize(width, height); needsInvalidate |= mBottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); } /* end of if */ } else { mTopEdge.finish(); mBottomEdge.finish(); } /* end of if */ if (needsInvalidate) { // Keep animating invalidate(); } /* end of if */ }
From source file:com.bright.cloudutils.view.ResideLayout.java
@Override protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.ALL_SAVE_FLAG); if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately // be covered. canvas.scale(1.2f - 0.2f * mSlideOffset, 1.2f - 0.2f * mSlideOffset, child.getRight(), getHeight() / 2); } else {/*from ww w .j a va 2s. c om*/ assert mSlideableView != null; canvas.scale(1 - mSlideOffset / 3, 1 - mSlideOffset / 3, mSlideableView.getLeft(), getHeight() / 2); ViewCompat.setRotationY(child, -10 * mSlideOffset); } if (!lp.slideable && mSlideOffset == 0) { result = true; } else { if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && mSlideOffset > 0) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } final Bitmap cache = child.getDrawingCache(); if (cache != null) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache"); result = super.drawChild(canvas, child, drawingTime); } } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } } } canvas.restoreToCount(save); return result; }
From source file:com.ad.view.staggeredgridview.StaggeredGridView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (mTopEdge != null) { boolean needsInvalidate = false; if (!mTopEdge.isFinished()) { mTopEdge.draw(canvas);// ww w .ja v a 2 s . com 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) { invalidate(); } } // drawSelector(canvas); }
From source file:com.waz.zclient.pages.main.conversationpager.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 (canSlide && !lp.slideable && slideableView != null) { // Clip against the slider; no sense drawing what will immediately be covered. canvas.getClipBounds(tmpRect);/*from www .j a va2s . c o m*/ if (isLayoutRtlSupport()) { tmpRect.left = Math.max(tmpRect.left, slideableView.getRight()); } else { tmpRect.right = Math.min(tmpRect.right, slideableView.getLeft()); } canvas.clipRect(tmpRect); } if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && slideOffset > 0) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } final Bitmap cache = child.getDrawingCache(); if (cache != null) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Timber.e("drawChild: child view %s returned null drawing cache", child); result = super.drawChild(canvas, child, drawingTime); } } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } } canvas.restoreToCount(save); return result; }
From source file:com.example.zhaozhu.practisecustomview.customviewgroup.HSlidingPaneLayout.java
@Override protected boolean drawChild(final Canvas canvas, final View child, final long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (this.mCanSlide && !lp.slideable && (this.mSlideableView != null)) { // Clip against the slider; no sense drawing what will immediately // be covered. canvas.getClipBounds(this.mTmpRect); this.mTmpRect.right = Math.min(this.mTmpRect.right, this.mSlideableView.getLeft()); canvas.clipRect(this.mTmpRect); }//from w w w . j a v a 2 s . com if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && (this.mSlideOffset > 0)) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } Bitmap cache = child.getDrawingCache(); if (cache != null && !cache.isRecycled()) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(HSlidingPaneLayout.TAG, "drawChild: child view " + child + " returned null drawing cache"); result = super.drawChild(canvas, child, drawingTime); } } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } } canvas.restoreToCount(save); return result; }
From source file:com.example.zhaozhu.practisecustomview.customviewgroup.HSlidingPaneLayout2.java
@Override protected boolean drawChild(final Canvas canvas, final View child, final long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (this.mCanSlide && !lp.slideable && (this.mSlideableView != null)) { // Clip against the slider; no sense drawing what will immediately // be covered. canvas.getClipBounds(this.mTmpRect); this.mTmpRect.right = Math.min(this.mTmpRect.right, this.mSlideableView.getLeft()); canvas.clipRect(this.mTmpRect); }// w ww.j a va 2 s . c o m if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && (this.mSlideOffset > 0)) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } Bitmap cache = child.getDrawingCache(); if (cache != null && !cache.isRecycled()) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(HSlidingPaneLayout2.TAG, "drawChild: child view " + child + " returned null drawing cache"); result = super.drawChild(canvas, child, drawingTime); } } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } } canvas.restoreToCount(save); return result; }