List of usage examples for android.graphics Canvas rotate
public void rotate(float degrees)
From source file:com.github.shareme.gwsmaterialuikit.library.advancerv.draggable.BaseEdgeEffectDecorator.java
private static boolean drawGlow(Canvas c, RecyclerView parent, int dir, EdgeEffectCompat edge) { if (edge.isFinished()) { return false; }// ww w . ja v a 2 s .c o m final int restore = c.save(); final boolean clipToPadding = getClipToPadding(parent); switch (dir) { case EDGE_TOP: if (clipToPadding) { c.translate(parent.getPaddingLeft(), parent.getPaddingTop()); } break; case EDGE_BOTTOM: c.rotate(180); if (clipToPadding) { c.translate(-parent.getWidth() + parent.getPaddingRight(), -parent.getHeight() + parent.getPaddingBottom()); } else { c.translate(-parent.getWidth(), -parent.getHeight()); } break; case EDGE_LEFT: c.rotate(-90); if (clipToPadding) { c.translate(-parent.getHeight() + parent.getPaddingTop(), parent.getPaddingLeft()); } else { c.translate(-parent.getHeight(), 0); } break; case EDGE_RIGHT: c.rotate(90); if (clipToPadding) { c.translate(parent.getPaddingTop(), -parent.getWidth() + parent.getPaddingRight()); } else { c.translate(0, -parent.getWidth()); } break; } boolean needsInvalidate = edge.draw(c); c.restoreToCount(restore); return needsInvalidate; }
From source file:com.github.czy1121.view.CornerLabelView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); float xy = mHeight / SQRT2; canvas.save();/*from ww w . ja v a 2 s. c o m*/ canvas.translate(xy, xy); canvas.rotate((mIsTop ? 1 : -1) * (mIsLeft ? -45 : 45)); canvas.drawPath(calcPath(), mPaint); mText1.draw(canvas, mPaddingBottom, mIsTop); if (mIsTriangle) { mText2.draw(canvas, mPaddingBottom + mPaddingCenter + mText1.height, mIsTop); } canvas.restore(); }
From source file:com.khoai.bus.ui.IconGenerator.java
/** * Creates an icon with the current content and style. * <p/>/*ww w. ja v a2s .co m*/ * This method is useful if a custom view has previously been set, or if text content is not * applicable. */ public Bitmap makeIcon() { int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); mContainer.measure(measureSpec, measureSpec); int measuredWidth = mContainer.getMeasuredWidth(); int measuredHeight = mContainer.getMeasuredHeight(); mContainer.layout(0, 0, measuredWidth, measuredHeight); if (mRotation == 1 || mRotation == 3) { measuredHeight = mContainer.getMeasuredWidth(); measuredWidth = mContainer.getMeasuredHeight(); } Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888); r.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(r); if (mRotation == 0) { // do nothing } else if (mRotation == 1) { canvas.translate(measuredWidth, 0); canvas.rotate(90); } else if (mRotation == 2) { canvas.rotate(180, measuredWidth / 2, measuredHeight / 2); } else { canvas.translate(0, measuredHeight); canvas.rotate(270); } mContainer.draw(canvas); return r; }
From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java
@Override protected synchronized void onDraw(Canvas canvas) { if (!useViewRotation()) { switch (mRotationAngle) { case ROTATION_ANGLE_CW_90: canvas.rotate(90); canvas.translate(0, -super.getWidth()); break; case ROTATION_ANGLE_CW_270: canvas.rotate(-90);/*from w w w . j a v a2 s . c o m*/ canvas.translate(-super.getHeight(), 0); break; } } super.onDraw(canvas); }
From source file:com.h6ah4i.android.widget.advrecyclerview.draggable.EdgeEffectDecorator.java
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { boolean needsInvalidate = false; if (mTopGlow != null && !mTopGlow.isFinished()) { final int restore = c.save(); if (getClipToPadding(parent)) { c.translate(parent.getPaddingLeft(), parent.getPaddingTop()); }/* w w w . java 2s. c om*/ //noinspection ConstantConditions needsInvalidate |= mTopGlow.draw(c); c.restoreToCount(restore); } if (mBottomGlow != null && !mBottomGlow.isFinished()) { final int restore = c.save(); c.rotate(180); if (getClipToPadding(parent)) { c.translate(-parent.getWidth() + parent.getPaddingRight(), -parent.getHeight() + parent.getPaddingBottom()); } else { c.translate(-parent.getWidth(), -parent.getHeight()); } needsInvalidate |= mBottomGlow.draw(c); c.restoreToCount(restore); } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(parent); } }
From source file:com.evilduck.piano.views.instrument.PianoView.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)) { if (!leftEdgeEffect.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int width = getWidth(); canvas.rotate(270); canvas.translate(-height + getPaddingTop(), 0); leftEdgeEffect.setSize(height, width); needsInvalidate |= leftEdgeEffect.draw(canvas); canvas.restoreToCount(restoreCount); }/*w ww .j av a2 s. c om*/ if (!rightEdgeEffect.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(90); canvas.translate(-getPaddingTop(), -width); rightEdgeEffect.setSize(height, width); needsInvalidate |= rightEdgeEffect.draw(canvas); canvas.restoreToCount(restoreCount); } } else { leftEdgeEffect.finish(); rightEdgeEffect.finish(); } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.ttxgps.zoom.GestureImageView.java
@Override protected void onDraw(Canvas canvas) { if (layout) { if (drawable != null && !isRecycled()) { canvas.save();// w ww .ja v a 2 s .co m float adjustedScale = scale * scaleAdjust; canvas.translate(x, y); if (rotation != 0.0f) { canvas.rotate(rotation); } if (adjustedScale != 1.0f) { canvas.scale(adjustedScale, adjustedScale); } drawable.draw(canvas); canvas.restore(); } if (drawLock.availablePermits() <= 0) { drawLock.release(); } } }
From source file:om.sstvencoder.CropView.java
private void drawBitmap(Canvas canvas) { int w = mImageWidth; int h = mImageHeight; for (int i = 0; i < mOrientation / 90; ++i) { int tmp = w; w = h;/* ww w .j a v a 2 s . c om*/ h = tmp; //noinspection SuspiciousNameCombination mImageDrawRect.set(mImageDrawRect.top, h - mImageDrawRect.left, mImageDrawRect.bottom, h - mImageDrawRect.right); //noinspection SuspiciousNameCombination mCanvasDrawRect.set(mCanvasDrawRect.top, -mCanvasDrawRect.right, mCanvasDrawRect.bottom, -mCanvasDrawRect.left); } mImageDrawRect.sort(); canvas.save(); canvas.rotate(mOrientation); if (!mSmallImage) { int sampleSize = getSampleSize(); if (sampleSize < mCacheSampleSize || !mCacheRect.contains(mImageDrawRect)) { if (mCacheBitmap != null) mCacheBitmap.recycle(); int cacheWidth = mImageDrawRect.width(); int cacheHeight = mImageDrawRect.height(); while (cacheWidth * cacheHeight < (sampleSize * 1024 * sampleSize * 1024)) { cacheWidth += mImageDrawRect.width(); cacheHeight += mImageDrawRect.height(); } mCacheRect.set(Math.max(0, ~(sampleSize - 1) & (mImageDrawRect.centerX() - cacheWidth / 2)), Math.max(0, ~(sampleSize - 1) & (mImageDrawRect.centerY() - cacheHeight / 2)), Math.min(mRegionDecoder.getWidth(), ~(sampleSize - 1) & (mImageDrawRect.centerX() + cacheWidth / 2 + sampleSize - 1)), Math.min(mRegionDecoder.getHeight(), ~(sampleSize - 1) & (mImageDrawRect.centerY() + cacheHeight / 2 + sampleSize - 1))); mBitmapOptions.inSampleSize = mCacheSampleSize = sampleSize; mCacheBitmap = mRegionDecoder.decodeRegion(mCacheRect, mBitmapOptions); } mImageDrawRect.offset(-mCacheRect.left, -mCacheRect.top); mImageDrawRect.left /= mCacheSampleSize; mImageDrawRect.top /= mCacheSampleSize; mImageDrawRect.right /= mCacheSampleSize; mImageDrawRect.bottom /= mCacheSampleSize; } canvas.drawBitmap(mCacheBitmap, mImageDrawRect, mCanvasDrawRect, mPaint); canvas.restore(); }
From source file:com.android.photos.views.GalleryThumbnailView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); 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()); if (mLeftEdge.draw(canvas)) { postInvalidateOnAnimation(); }/*from www. j a va 2 s .c o m*/ 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(), width); mRightEdge.setSize(height, width); if (mRightEdge.draw(canvas)) { postInvalidateOnAnimation(); } canvas.restoreToCount(restoreCount); } }
From source file:me.lizheng.deckview.helpers.FakeShadowDrawable.java
private void drawShadow(Canvas canvas) { final float edgeShadowTop = -mCornerRadius - mShadowSize; final float inset = mCornerRadius + mInsetShadow + mRawShadowSize / 2; final boolean drawHorizontalEdges = mCardBounds.width() - 2 * inset > 0; final boolean drawVerticalEdges = mCardBounds.height() - 2 * inset > 0; // LT//from w ww .ja v a2 s . co m int saved = canvas.save(); canvas.translate(mCardBounds.left + inset, mCardBounds.top + inset); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawHorizontalEdges) { canvas.drawRect(0, edgeShadowTop, mCardBounds.width() - 2 * inset, -mCornerRadius, mEdgeShadowPaint); } canvas.restoreToCount(saved); // RB saved = canvas.save(); canvas.translate(mCardBounds.right - inset, mCardBounds.bottom - inset); canvas.rotate(180f); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawHorizontalEdges) { canvas.drawRect(0, edgeShadowTop, mCardBounds.width() - 2 * inset, -mCornerRadius + mShadowSize, mEdgeShadowPaint); } canvas.restoreToCount(saved); // LB saved = canvas.save(); canvas.translate(mCardBounds.left + inset, mCardBounds.bottom - inset); canvas.rotate(270f); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawVerticalEdges) { canvas.drawRect(0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint); } canvas.restoreToCount(saved); // RT saved = canvas.save(); canvas.translate(mCardBounds.right - inset, mCardBounds.top + inset); canvas.rotate(90f); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawVerticalEdges) { canvas.drawRect(0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint); } canvas.restoreToCount(saved); }