List of usage examples for android.graphics Canvas rotate
public void rotate(float degrees)
From source file:com.hippo.largeimageview.LargeImageView.java
private int transformCanvas(Canvas canvas) { final int saved; switch (mOrientation) { case ORIENTATION_0: saved = 0;/*from w ww.j a va2s. c om*/ break; case ORIENTATION_90: saved = canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.translate(getWidth(), 0); canvas.rotate(90); break; case ORIENTATION_180: saved = canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.translate(getWidth(), getHeight()); canvas.rotate(180); break; case ORIENTATION_270: saved = canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.translate(0, getHeight()); canvas.rotate(-90); break; default: throw new IllegalStateException("Unknown orientation: " + mOrientation); } return saved; }
From source file:co.jlabs.cersei_retailer.zxingfragmentlib.BarCodeScannerFragment.java
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of the barcode. * * @param barcode A bitmap of the captured image. * @param scaleFactor amount by which thumbnail was scaled * @param rawResult The decoded results which contains the points to draw. *///from w w w.j a v a 2s. c o m private void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult) { ResultPoint[] points = rawResult.getResultPoints(); if (points != null && points.length > 0 && barcode != null) { Canvas canvas = new Canvas(barcode); Paint paint = new Paint(); paint.setColor(getResources().getColor(R.color.result_points)); if (points.length == 2) { paint.setStrokeWidth(4.0f); drawLine(canvas, paint, points[0], points[1], scaleFactor); } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) { // Hacky special case -- draw two lines, for the barcode and metadata drawLine(canvas, paint, points[0], points[1], scaleFactor); drawLine(canvas, paint, points[2], points[3], scaleFactor); } else { paint.setStrokeWidth(10.0f); for (ResultPoint point : points) { canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint); } } if (isPortrait()) { Log.d(TAG, "rotating results canvas"); canvas.rotate(90); } } }
From source file:com.bitflake.counter.HorizontalPicker.java
private void drawEdgeEffect(Canvas canvas, EdgeEffect edgeEffect, int degrees) { if (canvas == null || edgeEffect == null || (degrees != 90 && degrees != 270)) { return;/*from ww w.j ava 2s . co m*/ } if (!edgeEffect.isFinished()) { final int restoreCount = canvas.getSaveCount(); final int width = getWidth(); final int height = getHeight(); canvas.rotate(degrees); if (degrees == 270) { canvas.translate(-height, Math.max(0, getScrollX())); } else { // 90 canvas.translate(0, -(Math.max(getScrollRange(), getScaleX()) + width)); } edgeEffect.setSize(height, width); if (edgeEffect.draw(canvas)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { postInvalidateOnAnimation(); } else { postInvalidate(); } } canvas.restoreToCount(restoreCount); } }
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
private void drawEdges(Canvas canvas) { if (mEdgeGlowLeft != null) { final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); if (!mEdgeGlowLeft.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(270); canvas.translate(-height + getPaddingTop(), 0); mEdgeGlowLeft.setSize(height, width); if (mEdgeGlowLeft.draw(canvas)) { postInvalidate();//from ww w . ja va2 s . c o m } canvas.restoreToCount(restoreCount); } if (!mEdgeGlowRight.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(90); canvas.translate(-getPaddingTop(), -(mTouchX + width)); mEdgeGlowRight.setSize(height, width); if (mEdgeGlowRight.draw(canvas)) { postInvalidate(); } canvas.restoreToCount(restoreCount); } } }
From source file:com.acbelter.scheduleview.ScheduleView.java
private void drawEdgeEffects(Canvas canvas) { boolean needsInvalidate = false; final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS) { if (!mTopEdgeEffect.isFinished()) { int saveCount = canvas.save(); int width = mViewWidth - getPaddingLeft() - getPaddingRight(); int height = mViewHeight - getPaddingTop() - getPaddingBottom(); canvas.translate(0, getPaddingTop()); mTopEdgeEffect.setSize(width, height); needsInvalidate |= mTopEdgeEffect.draw(canvas); canvas.restoreToCount(saveCount); }/* w w w. ja v a2 s .c o m*/ if (!mBottomEdgeEffect.isFinished()) { int saveCount = canvas.save(); int width = mViewWidth - getPaddingLeft() - getPaddingRight(); int height = mViewHeight - getPaddingTop() - getPaddingBottom(); canvas.translate(mViewWidth, mViewHeight - getPaddingBottom()); canvas.rotate(180); mBottomEdgeEffect.setSize(width, height); needsInvalidate |= mBottomEdgeEffect.draw(canvas); canvas.restoreToCount(saveCount); } } else { mTopEdgeEffect.finish(); mBottomEdgeEffect.finish(); } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.comcast.freeflow.core.FreeFlowContainer.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(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); canvas.translate(-height + getPaddingTop(), 0);// width); mLeftEdge.setSize(height, width); needsInvalidate = mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); }/*from w ww . java 2 s. c o m*/ 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) postInvalidateOnAnimation(); }
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); canvas.translate(-height + getPaddingTop(), 0);// width); mLeftEdge.setSize(height, width); needsInvalidate = mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); }//ww w . j a v a 2 s . c o m 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.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); canvas.translate(-height + getPaddingTop(), 0); mLeftEdge.setSize(height, getWidth()); needsInvalidate |= mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); }/*from w w w . jav a 2s .c om*/ 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); canvas.translate(-height + getPaddingTop(), 0); mLeftEdge.setSize(getWidth(), height); needsInvalidate = mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); }/*from w w w .j a v a 2 s .co m*/ 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.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); canvas.translate(-height + getPaddingTop(), 0); mLeftEdge.setSize(height, getWidth()); needsInvalidate |= mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); }//from www .jav a 2s .c o m 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(); } }