List of usage examples for android.graphics Canvas translate
public void translate(float dx, float dy)
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
private void drawEventText(StaticLayout eventLayout, Rect rect, Canvas canvas, int top, int bottom, boolean center) { // drawEmptyRect(canvas, rect, 0xFFFF00FF); // for debugging int width = rect.right - rect.left; int height = rect.bottom - rect.top; // If the rectangle is too small for text, then return if (eventLayout == null || width < MIN_CELL_WIDTH_FOR_TEXT) { return;/*from w w w . java 2s . c o m*/ } int totalLineHeight = 0; int lineCount = eventLayout.getLineCount(); for (int i = 0; i < lineCount; i++) { int lineBottom = eventLayout.getLineBottom(i); if (lineBottom <= height) { totalLineHeight = lineBottom; } else { break; } } // + 2 is small workaround when the font is slightly bigger then the rect. This will // still allow the text to be shown without overflowing into the other all day rects. if (totalLineHeight == 0 || rect.top > bottom || rect.top + totalLineHeight + 2 < top) { return; } // Use a StaticLayout to format the string. canvas.save(); // canvas.translate(rect.left, rect.top + (rect.bottom - rect.top / 2)); int padding = center ? (rect.bottom - rect.top - totalLineHeight) / 2 : 0; canvas.translate(rect.left, rect.top + padding); rect.left = 0; rect.right = width; rect.top = 0; rect.bottom = totalLineHeight; // There's a bug somewhere. If this rect is outside of a previous // cliprect, this becomes a no-op. What happens is that the text draw // past the event rect. The current fix is to not draw the staticLayout // at all if it is completely out of bound. canvas.clipRect(rect); eventLayout.draw(canvas); canvas.restore(); }
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 v a 2s. 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) { 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:dev.dworks.libs.widget.ViewPager.java
private void drawHorizontally(Canvas 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(); final int width = getWidth(); canvas.rotate(270);/*w w w . jav a2 s .c o m*/ canvas.translate(-height + getPaddingTop(), mFirstOffset * width); mLeftEdge.setSize(height, width); 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(); canvas.rotate(90); canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width); mRightEdge.setSize(height, width); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }
From source file:android.improving.utils.views.cardsview.OrientedViewPager.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 (mOrientation == Orientation.VERTICAL) { if (!mTopLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.translate(getPaddingLeft(), mFirstOffset * height); mTopLeftEdge.setSize(width, height); needsInvalidate |= mTopLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); }/* ww w. j a v a 2 s . c o m*/ if (!mRightBottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.rotate(180); canvas.translate(-width - getPaddingLeft(), -(mLastOffset + 1) * height); mRightBottomEdge.setSize(width, height); needsInvalidate |= mRightBottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { if (!mTopLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int width = getWidth(); canvas.rotate(270); canvas.translate(-height + getPaddingTop(), mFirstOffset * width); mTopLeftEdge.setSize(height, width); needsInvalidate |= mTopLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mRightBottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(90); canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width); mRightBottomEdge.setSize(height, width); needsInvalidate |= mRightBottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } } else { mTopLeftEdge.finish(); mRightBottomEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }
From source file:javalibrary.android.ui.VerticalViewPager.java
@Override public void draw(Canvas canvas) { super.draw(canvas); boolean needsInvalidate = false; if (DEBUG)/*from www . j a v a 2s . c o m*/ Log.v(TAG, "draw"); 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); 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); }*/ if (!mTopEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(270); canvas.translate(-height + getPaddingTop(), 0); mTopEdge.setSize(height, getWidth()); needsInvalidate |= mTopEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mBottomEdge.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); mBottomEdge.setSize(height, width); needsInvalidate |= mBottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); mTopEdge.finish(); mBottomEdge.finish(); } if (needsInvalidate) { // Keep animating invalidate(); } }
From source file:com.raibow.yamahaspk.filtershow.imageshow.ImageShow.java
public void drawImageAndAnimate(Canvas canvas, Bitmap image) { if (image == null) { return;// w w w .jav a2 s .c o m } MasterImage master = MasterImage.getImage(); Matrix m = master.computeImageToScreen(image, 0, false); if (m == null) { return; } canvas.save(); RectF d = new RectF(0, 0, image.getWidth(), image.getHeight()); m.mapRect(d); d.roundOut(mImageBounds); boolean showAnimatedImage = master.onGoingNewLookAnimation(); if (!showAnimatedImage && mDidStartAnimation) { // animation ended, but do we have the correct image to show? if (master.getPreset().equals(master.getCurrentPreset())) { // we do, let's stop showing the animated image mDidStartAnimation = false; MasterImage.getImage().resetAnimBitmap(); } else { showAnimatedImage = true; } } else if (showAnimatedImage) { mDidStartAnimation = true; } if (showAnimatedImage) { canvas.save(); // Animation uses the image before the change Bitmap previousImage = master.getPreviousImage(); Matrix mp = master.computeImageToScreen(previousImage, 0, false); RectF dp = new RectF(0, 0, previousImage.getWidth(), previousImage.getHeight()); mp.mapRect(dp); Rect previousBounds = new Rect(); dp.roundOut(previousBounds); float centerX = dp.centerX(); float centerY = dp.centerY(); boolean needsToDrawImage = true; if (master.getCurrentLookAnimation() == MasterImage.CIRCLE_ANIMATION) { float maskScale = MasterImage.getImage().getMaskScale(); if (maskScale >= 0.0f) { float maskW = sMask.getWidth() / 2.0f; float maskH = sMask.getHeight() / 2.0f; Point point = mActivity.hintTouchPoint(this); float maxMaskScale = 2 * Math.max(getWidth(), getHeight()) / Math.min(maskW, maskH); maskScale = maskScale * maxMaskScale; float x = point.x - maskW * maskScale; float y = point.y - maskH * maskScale; // Prepare the shader mShaderMatrix.reset(); mShaderMatrix.setScale(1.0f / maskScale, 1.0f / maskScale); mShaderMatrix.preTranslate(-x + mImageBounds.left, -y + mImageBounds.top); float scaleImageX = mImageBounds.width() / (float) image.getWidth(); float scaleImageY = mImageBounds.height() / (float) image.getHeight(); mShaderMatrix.preScale(scaleImageX, scaleImageY); mMaskPaint.reset(); mMaskPaint.setShader(createShader(image)); mMaskPaint.getShader().setLocalMatrix(mShaderMatrix); drawShadow(canvas, mImageBounds); // as needed canvas.drawBitmap(previousImage, m, mPaint); canvas.clipRect(mImageBounds); canvas.translate(x, y); canvas.scale(maskScale, maskScale); canvas.drawBitmap(sMask, 0, 0, mMaskPaint); needsToDrawImage = false; } } else if (master.getCurrentLookAnimation() == MasterImage.ROTATE_ANIMATION) { Rect d1 = computeImageBounds(master.getPreviousImage().getHeight(), master.getPreviousImage().getWidth()); Rect d2 = computeImageBounds(master.getPreviousImage().getWidth(), master.getPreviousImage().getHeight()); float finalScale = d1.width() / (float) d2.height(); finalScale = (1.0f * (1.0f - master.getAnimFraction())) + (finalScale * master.getAnimFraction()); canvas.rotate(master.getAnimRotationValue(), centerX, centerY); canvas.scale(finalScale, finalScale, centerX, centerY); } else if (master.getCurrentLookAnimation() == MasterImage.MIRROR_ANIMATION) { if (master.getCurrentFilterRepresentation() instanceof FilterMirrorRepresentation) { FilterMirrorRepresentation rep = (FilterMirrorRepresentation) master .getCurrentFilterRepresentation(); ImagePreset preset = master.getPreset(); ArrayList<FilterRepresentation> geometry = (ArrayList<FilterRepresentation>) preset .getGeometryFilters(); GeometryMathUtils.GeometryHolder holder = null; holder = GeometryMathUtils.unpackGeometry(geometry); if (holder.rotation.value() == 90 || holder.rotation.value() == 270) { if (rep.isHorizontal() && !rep.isVertical()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else if (rep.isVertical() && !rep.isHorizontal()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else if (rep.isHorizontal() && rep.isVertical()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } } else { if (rep.isHorizontal() && !rep.isVertical()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else if (rep.isVertical() && !rep.isHorizontal()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else if (rep.isHorizontal() && rep.isVertical()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } } } } if (needsToDrawImage) { drawShadow(canvas, previousBounds); // as needed canvas.drawBitmap(previousImage, mp, mPaint); } canvas.restore(); } else { drawShadow(canvas, mImageBounds); // as needed canvas.drawBitmap(image, m, mPaint); } canvas.restore(); }
From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.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 width = isOrientationHorizontal() ? getHeight() - getPaddingTop() - getPaddingBottom() : getWidth() - getPaddingLeft() - getPaddingRight(); final int height = isOrientationHorizontal() ? getWidth() - getPaddingLeft() - getPaddingRight() : getHeight() - getPaddingTop() - getPaddingBottom(); if (isOrientationHorizontal()) { canvas.rotate(270);/*from ww w. j a v a 2s . c o m*/ canvas.translate(-width + getPaddingTop(), mFirstOffset * height); } mLeftEdge.setSize(width, height); needsInvalidate |= mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mRightEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = isOrientationHorizontal() ? getHeight() - getPaddingTop() - getPaddingBottom() : getWidth() - getPaddingLeft() - getPaddingRight(); final int height = isOrientationHorizontal() ? getWidth() - getPaddingLeft() - getPaddingRight() : getHeight() - getPaddingTop() - getPaddingBottom(); if (isOrientationHorizontal()) { canvas.rotate(90); canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * height); } else { canvas.rotate(180); canvas.translate(-width, -(mLastOffset + 1) * height); } mRightEdge.setSize(width, height); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
public void drawImageAndAnimate(Canvas canvas, Bitmap image) { if (image == null) { return;/*from w w w . j a va2s . c o m*/ } MasterImage master = MasterImage.getImage(); Matrix m = master.computeImageToScreen(image, 0, false); if (m == null) { return; } canvas.save(); RectF d = new RectF(0, 0, image.getWidth(), image.getHeight()); m.mapRect(d); d.roundOut(mImageBounds); boolean showAnimatedImage = master.onGoingNewLookAnimation(); if (!showAnimatedImage && mDidStartAnimation) { // animation ended, but do we have the correct image to show? if (master.getPreset().equals(master.getCurrentPreset())) { // we do, let's stop showing the animated image mDidStartAnimation = false; MasterImage.getImage().resetAnimBitmap(); } else { showAnimatedImage = true; } } else if (showAnimatedImage) { mDidStartAnimation = true; } if (showAnimatedImage) { canvas.save(); // Animation uses the image before the change Bitmap previousImage = master.getPreviousImage(); Matrix mp = master.computeImageToScreen(previousImage, 0, false); RectF dp = new RectF(0, 0, previousImage.getWidth(), previousImage.getHeight()); mp.mapRect(dp); Rect previousBounds = new Rect(); dp.roundOut(previousBounds); float centerX = dp.centerX(); float centerY = dp.centerY(); boolean needsToDrawImage = true; if (master.getCurrentLookAnimation() == MasterImage.CIRCLE_ANIMATION) { float maskScale = MasterImage.getImage().getMaskScale(); if (maskScale >= 0.0f) { float maskW = sMask.getWidth() / 2.0f; float maskH = sMask.getHeight() / 2.0f; Point point = mActivity.hintTouchPoint(this); float maxMaskScale = 2 * Math.max(getWidth(), getHeight()) / Math.min(maskW, maskH); maskScale = maskScale * maxMaskScale; float x = point.x - maskW * maskScale; float y = point.y - maskH * maskScale; // Prepare the shader mShaderMatrix.reset(); mShaderMatrix.setScale(1.0f / maskScale, 1.0f / maskScale); mShaderMatrix.preTranslate(-x + mImageBounds.left, -y + mImageBounds.top); float scaleImageX = mImageBounds.width() / (float) image.getWidth(); float scaleImageY = mImageBounds.height() / (float) image.getHeight(); mShaderMatrix.preScale(scaleImageX, scaleImageY); mMaskPaint.reset(); Shader maskShader = createShader(image); maskShader.setLocalMatrix(mShaderMatrix); mMaskPaint.setShader(maskShader); drawShadow(canvas, mImageBounds); // as needed canvas.drawBitmap(previousImage, m, mPaint); canvas.clipRect(mImageBounds); canvas.translate(x, y); canvas.scale(maskScale, maskScale); canvas.drawBitmap(sMask, 0, 0, mMaskPaint); needsToDrawImage = false; } } else if (master.getCurrentLookAnimation() == MasterImage.ROTATE_ANIMATION) { Rect d1 = computeImageBounds(master.getPreviousImage().getHeight(), master.getPreviousImage().getWidth()); Rect d2 = computeImageBounds(master.getPreviousImage().getWidth(), master.getPreviousImage().getHeight()); float finalScale = d1.width() / (float) d2.height(); finalScale = (1.0f * (1.0f - master.getAnimFraction())) + (finalScale * master.getAnimFraction()); canvas.rotate(master.getAnimRotationValue(), centerX, centerY); canvas.scale(finalScale, finalScale, centerX, centerY); } else if (master.getCurrentLookAnimation() == MasterImage.MIRROR_ANIMATION) { if (master.getCurrentFilterRepresentation() instanceof FilterMirrorRepresentation) { FilterMirrorRepresentation rep = (FilterMirrorRepresentation) master .getCurrentFilterRepresentation(); ImagePreset preset = master.getPreset(); ArrayList<FilterRepresentation> geometry = (ArrayList<FilterRepresentation>) preset .getGeometryFilters(); GeometryMathUtils.GeometryHolder holder = null; holder = GeometryMathUtils.unpackGeometry(geometry); if (holder.rotation.value() == 90 || holder.rotation.value() == 270) { if (rep.isHorizontal() && !rep.isVertical()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else if (rep.isVertical() && !rep.isHorizontal()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else if (rep.isHorizontal() && rep.isVertical()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } } else { if (rep.isHorizontal() && !rep.isVertical()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else if (rep.isVertical() && !rep.isHorizontal()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else if (rep.isHorizontal() && rep.isVertical()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } } } } if (needsToDrawImage) { drawShadow(canvas, previousBounds); // as needed canvas.drawBitmap(previousImage, mp, mPaint); } canvas.restore(); } else { drawShadow(canvas, mImageBounds); // as needed canvas.drawBitmap(image, m, mPaint); } canvas.restore(); }
From source file:com.marlonjones.voidlauncher.CellLayout.java
@Override protected void onDraw(Canvas canvas) { if (!mIsDragTarget) { return;/* ww w . j a v a2 s . co m*/ } // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mBackgroundAlpha > 0.0f) { mBackground.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mDragOutlines[i], paint); } } if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied.cells[i][j]) { cellToPoint(i, j, pt); canvas.save(); canvas.translate(pt[0], pt[1]); cd.draw(canvas); canvas.restore(); } } } } for (int i = 0; i < mFolderBackgrounds.size(); i++) { FolderIcon.PreviewBackground bg = mFolderBackgrounds.get(i); cellToPoint(bg.delegateCellX, bg.delegateCellY, mTempLocation); canvas.save(); canvas.translate(mTempLocation[0], mTempLocation[1]); bg.drawBackground(canvas, mFolderBgPaint); if (!bg.isClipping) { bg.drawBackgroundStroke(canvas, mFolderBgPaint); } canvas.restore(); } if (mFolderLeaveBehind.delegateCellX >= 0 && mFolderLeaveBehind.delegateCellY >= 0) { cellToPoint(mFolderLeaveBehind.delegateCellX, mFolderLeaveBehind.delegateCellY, mTempLocation); canvas.save(); canvas.translate(mTempLocation[0], mTempLocation[1]); mFolderLeaveBehind.drawLeaveBehind(canvas, mFolderBgPaint); canvas.restore(); } }
From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (mTopEdge != null) { boolean needsInvalidate = false; if (!mTopEdge.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(0, 0); mTopEdge.draw(canvas);/*from w w w .ja v a 2s . c om*/ canvas.restoreToCount(restoreCount); 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); } } }