List of usage examples for android.graphics Canvas restoreToCount
public void restoreToCount(int saveCount)
From source file:mega.privacy.android.app.components.SlidingUpPanelLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (mSlideableView != child) { // if main view // Clip against the slider; no sense drawing what will immediately be covered, // Unless the panel is set to overlay content canvas.getClipBounds(mTmpRect);/*from w w w . j a v a 2 s. c om*/ if (!mOverlayContent) { if (mIsSlidingUp) { mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop()); } else { mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom()); } } if (mClipPanel) { canvas.clipRect(mTmpRect); } result = super.drawChild(canvas, child, drawingTime); if (mCoveredFadeColor != 0 && mSlideOffset > 0) { final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mSlideOffset); final int color = imag << 24 | (mCoveredFadeColor & 0xffffff); mCoveredFadePaint.setColor(color); canvas.drawRect(mTmpRect, mCoveredFadePaint); } } else { result = super.drawChild(canvas, child, drawingTime); } canvas.restoreToCount(save); return result; }
From source file:lewa.support.v7.widget.SwitchCompat.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 ww w .j av a 2 s . c o 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) { trackDrawable.draw(canvas); } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.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.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final int width = getWidth(); final boolean drawingContent = isContentView(child); int clipTop = 0, clipBottom = getHeight(); final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getWidth() < width) { continue; }//from www . j a v a 2 s . co m if (checkDrawerViewGravity(v, Gravity.TOP)) { final int vbottom = v.getBottom(); if (vbottom > clipTop) clipTop = vbottom; } else { final int vtop = v.getTop(); if (vtop < clipBottom) clipBottom = vtop; } } canvas.clipRect(0, clipTop, getWidth(), clipBottom); } 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, clipTop, getWidth(), clipBottom, mScrimPaint); } else if (mShadowTop != null && checkDrawerViewGravity(child, Gravity.TOP)) { final int shadowHeight = mShadowTop.getIntrinsicHeight(); final int childBottom = child.getBottom(); final int drawerPeekDistance = mTopDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childBottom / drawerPeekDistance, 1.f)); mShadowTop.setBounds(child.getLeft(), childBottom, child.getRight(), childBottom + shadowHeight); mShadowTop.setAlpha((int) (0xff * alpha)); mShadowTop.draw(canvas); } else if (mShadowBottom != null && checkDrawerViewGravity(child, Gravity.BOTTOM)) { final int shadowHeight = mShadowBottom.getIntrinsicHeight(); final int childTop = child.getTop(); final int showing = getHeight() - childTop; final int drawerPeekDistance = mBottomDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowTop.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop); mShadowBottom.setAlpha((int) (0xff * alpha)); mShadowBottom.draw(canvas); } return result; }
From source file:com.ruesga.timelinechart.TimelineChartView.java
private void drawEdgeEffects(Canvas c) { boolean needsInvalidate = false; if (mEdgeEffectLeft != null && !mEdgeEffectLeft.isFinished()) { final int restoreCount = c.save(); c.rotate(270);//from w ww . ja v a2 s. c om c.translate(-mGraphArea.height() - mGraphArea.top, mGraphArea.left); mEdgeEffectLeft.setSize((int) mGraphArea.height(), (int) mGraphArea.width()); needsInvalidate = mEdgeEffectLeft.draw(c); c.restoreToCount(restoreCount); } if (mEdgeEffectRight != null && !mEdgeEffectRight.isFinished()) { final int restoreCount = c.save(); c.rotate(90); c.translate(mGraphArea.top, -getWidth() + (getWidth() - mGraphArea.right)); mEdgeEffectRight.setSize((int) mGraphArea.height(), (int) mGraphArea.width()); needsInvalidate |= mEdgeEffectRight.draw(c); c.restoreToCount(restoreCount); } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final int height = getHeight(); final boolean drawingContent = isContentView(child); int clipLeft = 0, clipRight = getWidth(); final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getHeight() < height) { continue; }/*from www . j ava 2s . c o m*/ if (checkDrawerViewGravity(v, Gravity.LEFT)) { final int vright = v.getRight(); if (vright > clipLeft) clipLeft = vright; } else { final int vleft = v.getLeft(); if (vleft < clipRight) clipRight = vleft; } } canvas.clipRect(clipLeft, 0, clipRight, getHeight()); } 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(clipLeft, 0, clipRight, getHeight(), mScrimPaint); } else if (mShadowLeft != null && checkDrawerViewGravity(child, Gravity.LEFT)) { final int shadowWidth = mShadowLeft.getIntrinsicWidth(); final int childRight = child.getRight(); final int drawerPeekDistance = mLeftDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f)); mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom()); mShadowLeft.setAlpha((int) (0xff * alpha)); mShadowLeft.draw(canvas); } else if (mShadowRight != null && checkDrawerViewGravity(child, Gravity.RIGHT)) { final int shadowWidth = mShadowRight.getIntrinsicWidth(); final int childLeft = child.getLeft(); final int showing = getWidth() - childLeft; final int drawerPeekDistance = mRightDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom()); mShadowRight.setAlpha((int) (0xff * alpha)); mShadowRight.draw(canvas); } return result; }
From source file:com.lansun.qmyo.view.DrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final int height = getHeight(); final boolean drawingContent = isContentView(child); int clipLeft = 0, clipRight = getWidth(); final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getHeight() < height) { continue; }/*w ww. j a va 2s.co m*/ if (checkDrawerViewGravity(v, Gravity.LEFT)) { final int vright = v.getRight(); if (vright > clipLeft) clipLeft = vright; } else { final int vleft = v.getLeft(); if (vleft < clipRight) clipRight = vleft; } } canvas.clipRect(clipLeft, 0, clipRight, getHeight()); } 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(clipLeft, 0, clipRight, getHeight(), mScrimPaint); } else if (mShadowLeft != null && checkDrawerViewGravity(child, Gravity.LEFT)) { final int shadowWidth = mShadowLeft.getIntrinsicWidth(); final int childRight = child.getRight(); final int drawerPeekDistance = mLeftDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f)); mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom()); mShadowLeft.setAlpha((int) (0xff * alpha)); mShadowLeft.draw(canvas); } else if (mShadowRight != null && checkDrawerViewGravity(child, Gravity.RIGHT)) { final int shadowWidth = mShadowRight.getIntrinsicWidth(); final int childLeft = child.getLeft(); final int showing = getWidth() - childLeft; final int drawerPeekDistance = mRightDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom()); mShadowRight.setAlpha((int) (0xff * alpha)); mShadowRight.draw(canvas); } return result; }
From source file:co.codecrunch.musicplayerlite.slidinguppanelhelper.SlidingUpPanelLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (mSlideableView != child) { // if main view // Clip against the slider; no sense drawing what will immediately // be covered, // Unless the panel is set to overlay content canvas.getClipBounds(mTmpRect);/*from w ww . j a va 2 s . com*/ if (!mOverlayContent) { if (mIsSlidingUp) { mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop()); } else { mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom()); } } if (mClipPanel) { canvas.clipRect(mTmpRect); } result = super.drawChild(canvas, child, drawingTime); if (mCoveredFadeColor != 0 && mSlideOffset > 0) { final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mSlideOffset); final int color = imag << 24 | (mCoveredFadeColor & 0xffffff); mCoveredFadePaint.setColor(color); canvas.drawRect(mTmpRect, mCoveredFadePaint); } } else { result = super.drawChild(canvas, child, drawingTime); } canvas.restoreToCount(save); return result; }
From source file:com.shizhefei.view.largeimage.UpdateImageView.java
@SuppressLint("DrawAllocation") @Override/*from w w w.j a va2 s .c o m*/ protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (getMeasuredWidth() == 0) { return; } if (mDrawable != null) { mDrawable.setBounds((int) mOffsetX, (int) mOffsetY, (int) (getMeasuredWidth() * mScale), (int) (getMeasuredHeight() * mScale)); mDrawable.draw(canvas); } else if (mFactory != null) { Rect visibilityRect = tempRect; getVisibilityRect(visibilityRect); float width = mScale * getWidth(); int imgWidth = imageBlockLoader.getWidth(); float imageScale = imgWidth / width; // ? Rect imageRect = new Rect(); imageRect.left = (int) Math.ceil((visibilityRect.left - mOffsetX) * imageScale); imageRect.top = (int) Math.ceil((visibilityRect.top - mOffsetY) * imageScale); imageRect.right = (int) Math.ceil((visibilityRect.right - mOffsetX) * imageScale); imageRect.bottom = (int) Math.ceil((visibilityRect.bottom - mOffsetY) * imageScale); List<DrawData> drawData = imageBlockLoader.getDrawData(imageScale, imageRect); if (drawData.isEmpty()) { if (defaultDrawable != null) { int height = (int) (1.0f * defaultDrawable.getIntrinsicHeight() / defaultDrawable.getIntrinsicWidth() * getMeasuredWidth()); int offset = (getMeasuredHeight() - height) / 2; defaultDrawable.setBounds((int) mOffsetX, (int) mOffsetY + offset, (int) (getMeasuredWidth() * mScale), (int) (height * mScale)); defaultDrawable.draw(canvas); } } else { int saveCount = canvas.save(); for (DrawData data : drawData) { Rect drawRect = data.imageRect; drawRect.left = (int) (Math.ceil(drawRect.left / imageScale) + mOffsetX); drawRect.top = (int) (Math.ceil(drawRect.top / imageScale) + mOffsetY); drawRect.right = (int) (Math.ceil(drawRect.right / imageScale) + mOffsetX); drawRect.bottom = (int) (Math.ceil(drawRect.bottom / imageScale) + mOffsetY); canvas.drawBitmap(data.bitmap, data.srcRect, drawRect, null); } canvas.restoreToCount(saveCount); } } }
From source file:com.chenglong.muscle.ui.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 ww. j a v a2 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:lagerimage.nicksong.view.largeimage.UpdateImageView.java
@SuppressLint("DrawAllocation") @Override//from w w w .j a v a 2 s . co m protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (getMeasuredWidth() == 0) { return; } if (mDrawable != null) { mDrawable.setBounds((int) mOffsetX, (int) mOffsetY, (int) (getMeasuredWidth() * mScale), (int) (getMeasuredHeight() * mScale)); mDrawable.draw(canvas); } else if (mFactory != null) { Rect visibilityRect = tempRect; getVisibilityRect(visibilityRect); float width = mScale * getWidth(); int imgWidth = imageBlockLoader.getWidth(); float imageScale = imgWidth / width; // ? Rect imageRect = new Rect(); imageRect.left = (int) Math.ceil((visibilityRect.left - mOffsetX) * imageScale); imageRect.top = (int) Math.ceil((visibilityRect.top - mOffsetY) * imageScale); imageRect.right = (int) Math.ceil((visibilityRect.right - mOffsetX) * imageScale); imageRect.bottom = (int) Math.ceil((visibilityRect.bottom - mOffsetY) * imageScale); List<BlockImageLoader.DrawData> drawData = imageBlockLoader.getDrawData(imageScale, imageRect); if (drawData.isEmpty()) { if (defaultDrawable != null) { int height = (int) (1.0f * defaultDrawable.getIntrinsicHeight() / defaultDrawable.getIntrinsicWidth() * getMeasuredWidth()); int offset = (getMeasuredHeight() - height) / 2; defaultDrawable.setBounds((int) mOffsetX, (int) mOffsetY + offset, (int) (getMeasuredWidth() * mScale), (int) (height * mScale)); defaultDrawable.draw(canvas); } } else { int saveCount = canvas.save(); for (BlockImageLoader.DrawData data : drawData) { Rect drawRect = data.imageRect; drawRect.left = (int) (Math.ceil(drawRect.left / imageScale) + mOffsetX); drawRect.top = (int) (Math.ceil(drawRect.top / imageScale) + mOffsetY); drawRect.right = (int) (Math.ceil(drawRect.right / imageScale) + mOffsetX); drawRect.bottom = (int) (Math.ceil(drawRect.bottom / imageScale) + mOffsetY); canvas.drawBitmap(data.bitmap, data.srcRect, drawRect, null); } canvas.restoreToCount(saveCount); } } }