List of usage examples for android.graphics Canvas rotate
public final void rotate(float degrees, float px, float py)
From source file:com.android.slidingmenu.HorizontalListView.java
/** * Draws the overscroll edge glow effect on the left and right sides of the * horizontal list/* w w w .jav a 2 s. c o m*/ */ private void drawEdgeGlow(Canvas canvas) { if (mEdgeGlowLeft != null && !mEdgeGlowLeft.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so // rotate it to draw on the left side. final int restoreCount = canvas.save(); final int height = getHeight(); canvas.rotate(-90, 0, 0); canvas.translate(-height + getPaddingBottom(), 0); mEdgeGlowLeft.setSize(getRenderHeight(), getRenderWidth()); if (mEdgeGlowLeft.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } else if (mEdgeGlowRight != null && !mEdgeGlowRight.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so // rotate it to draw on the right side. final int restoreCount = canvas.save(); final int width = getWidth(); canvas.rotate(90, 0, 0); canvas.translate(getPaddingTop(), -width); mEdgeGlowRight.setSize(getRenderHeight(), getRenderWidth()); if (mEdgeGlowRight.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw regular cards with suits representing values on card * @param r application resources reference *//*w ww.ja v a2s . c o m*/ private void drawCards(final Resources r) { Paint cardFrontPaint = new Paint(); Paint cardBorderPaint = new Paint(); Bitmap[] suit = new Bitmap[4]; Bitmap[] revSuit = new Bitmap[4]; Bitmap[] smallSuit = new Bitmap[4]; Bitmap redJack; Bitmap redQueen; Bitmap redKing; Bitmap blackJack; Bitmap blackQueen; Bitmap blackKing; Canvas canvas; final int width = Card.WIDTH; final int height = Card.HEIGHT; final String[] card_values = mResources.getStringArray(R.array.card_values); final Paint textPaintLeft = getTextPaint(mSuitsSize, Paint.Align.LEFT); Drawable drawable = ResourcesCompat.getDrawable(r, R.drawable.cardback, null); mCardHidden = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT, Bitmap.Config.ARGB_8888); canvas = new Canvas(mCardHidden); drawable.setBounds(0, 0, Card.WIDTH, Card.HEIGHT); drawable.draw(canvas); for (int i = 0; i < 4; i++) { suit[i] = Bitmap.createBitmap((int) mSuitsSize, (int) mSuitsSize, Bitmap.Config.ARGB_8888); revSuit[i] = Bitmap.createBitmap((int) mSuitsSize, (int) mSuitsSize, Bitmap.Config.ARGB_8888); canvas = new Canvas(suit[i]); drawSuit(i, canvas, mSuitsSize); canvas = new Canvas(revSuit[i]); canvas.rotate(180, mSuitsSize / 2, mSuitsSize / 2); drawSuit(i, canvas, mSuitsSize); } for (int i = 0; i < 4; i++) { smallSuit[i] = Bitmap.createBitmap((int) mSuitsSizeHalf, (int) mSuitsSizeHalf, Bitmap.Config.ARGB_8888); canvas = new Canvas(smallSuit[i]); drawSuit(i, canvas, mSuitsSizeHalf); } final int faceWidth = width - 20; final int faceHeight = height / 2 - (int) mSuitsSize; blackJack = createFaceBitmap(r, R.drawable.blackjack, faceWidth, faceHeight); blackQueen = createFaceBitmap(r, R.drawable.blackqueen, faceWidth, faceHeight); blackKing = createFaceBitmap(r, R.drawable.blackking, faceWidth, faceHeight); redJack = createFaceBitmap(r, R.drawable.redjack, faceWidth, faceHeight); redQueen = createFaceBitmap(r, R.drawable.redqueen, faceWidth, faceHeight); redKing = createFaceBitmap(r, R.drawable.redking, faceWidth, faceHeight); cardBorderPaint.setARGB(255, 0, 0, 0); cardFrontPaint.setARGB(255, 255, 255, 255); RectF rectf = new RectF(); for (int suitIdx = 0; suitIdx < 4; suitIdx++) { for (int valueIdx = 0; valueIdx < 13; valueIdx++) { mCardBitmap[suitIdx * 13 + valueIdx] = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); canvas = new Canvas(mCardBitmap[suitIdx * 13 + valueIdx]); drawCardBackground(rectf, canvas, cardBorderPaint, cardFrontPaint); drawCardValue(textPaintLeft, canvas, card_values[valueIdx], smallSuit[suitIdx], suitIdx); if (valueIdx >= 10) { canvas.drawBitmap(suit[suitIdx], mSuitsSize, mSuitsSize, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], width - mSuitsSize * 2, height - mSuitsSize * 2, mSuitPaint); } final float height_7th = height / 7; final float height_9th = height / 9; // Columns final float width_5th = width / 5; final float[] suitX = { width_5th, width / 2 - mSuitsSizeHalf, width - width_5th - mSuitsSize }; // Rows final float[] suitY = { height_7th, // row 1 height_9th * 3, // row 2 height - (height_9th * 4) - mSuitsSizeHalf / 2, // row 4 height - (height_7th * 2) }; // row 5 // Center final float suitMidY = height / 2 - mSuitsSizeHalf; switch (valueIdx + 1) { case 1: canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint); break; case 2: canvas.drawBitmap(suit[suitIdx], suitX[1], suitY[0], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[1], suitY[3], mSuitPaint); break; case 3: canvas.drawBitmap(suit[suitIdx], suitX[1], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[1], suitY[3], mSuitPaint); break; case 4: canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint); break; case 5: canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint); break; case 6: canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[0], suitMidY, mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitMidY, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint); break; case 7: canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[0], suitMidY, mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitMidY, mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[1], (suitMidY + suitY[0]) / 2, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint); break; case 8: canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[0], suitMidY, mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitMidY, mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[1], (suitMidY + suitY[0]) / 2, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[1], (suitY[3] + suitMidY) / 2, mSuitPaint); break; case 9: for (int i = 0; i < 4; i++) { canvas.drawBitmap(suit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2 + 2], mSuitPaint); } canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint); break; case 10: for (int i = 0; i < 4; i++) { canvas.drawBitmap(suit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2 + 2], mSuitPaint); } canvas.drawBitmap(suit[suitIdx], suitX[1], (suitMidY + suitY[0]) / 2 - mSuitsSizeHalf, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[1], (suitY[3] + suitMidY) / 2 + mSuitsSizeHalf / 2, mSuitPaint); break; case Card.JACK: if ((suitIdx & 1) == 1) { drawFaceBitmap(canvas, redJack, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } else { drawFaceBitmap(canvas, blackJack, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } break; case Card.QUEEN: if ((suitIdx & 1) == 1) { drawFaceBitmap(canvas, redQueen, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } else { drawFaceBitmap(canvas, blackQueen, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } break; case Card.KING: if ((suitIdx & 1) == 1) { drawFaceBitmap(canvas, redKing, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } else { drawFaceBitmap(canvas, blackKing, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } break; } } } }
From source file:com.irccloud.android.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { Rect bounds = getBounds();//from w w w .ja va 2 s . com final boolean isRtl = isLayoutRtl(); // Interpolated widths of arrow bars final float arrowSize = lerp(mBarSize, mTopBottomArrowSize, mProgress); final float middleBarSize = lerp(mBarSize, mMiddleArrowSize, mProgress); // Interpolated size of middle bar final float middleBarCut = lerp(0, mBarThickness / 2, mProgress); // The rotation of the top and bottom bars (that make the arrow head) final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress); // The whole canvas rotates as the transition happens final float canvasRotate = lerp(isRtl ? 0 : -180, isRtl ? 180 : 0, mProgress); final float topBottomBarOffset = lerp(mBarGap + mBarThickness, 0, mProgress); mPath.rewind(); final float arrowEdge = -middleBarSize / 2; // draw middle bar mPath.moveTo(arrowEdge + middleBarCut, 0); mPath.rLineTo(middleBarSize - middleBarCut, 0); final float arrowWidth = Math.round(arrowSize * Math.cos(rotation)); final float arrowHeight = Math.round(arrowSize * Math.sin(rotation)); // top bar mPath.moveTo(arrowEdge, topBottomBarOffset); mPath.rLineTo(arrowWidth, arrowHeight); // bottom bar mPath.moveTo(arrowEdge, -topBottomBarOffset); mPath.rLineTo(arrowWidth, -arrowHeight); mPath.moveTo(0, 0); mPath.close(); canvas.save(); // Rotate the whole canvas if spinning, if not, rotate it 180 to get // the arrow pointing the other way for RTL. if (mSpin) { canvas.rotate(canvasRotate * ((mVerticalMirror ^ isRtl) ? -1 : 1), bounds.centerX(), bounds.centerY()); } else if (isRtl) { canvas.rotate(180, bounds.centerX(), bounds.centerY()); } canvas.translate(bounds.centerX(), bounds.centerY()); canvas.drawPath(mPath, mPaint); canvas.restore(); }
From source file:com.pdftron.pdf.tools.Tool.java
@Override public boolean onDrawEdgeEffects(Canvas canvas, int width, int verticalOffset) { boolean needsInvalidate = false; if (!mEdgeEffectLeft.isFinished()) { canvas.save();/*from w ww .j av a2 s . c o m*/ try { canvas.translate(0, canvas.getHeight() + verticalOffset); canvas.rotate(-90, 0, 0); mEdgeEffectLeft.setSize(canvas.getHeight(), canvas.getWidth()); if (mEdgeEffectLeft.draw(canvas)) { needsInvalidate = true; } } finally { canvas.restore(); } } if (!mEdgeEffectRight.isFinished()) { canvas.save(); try { canvas.translate(width, verticalOffset); canvas.rotate(90, 0, 0); mEdgeEffectRight.setSize(canvas.getHeight(), canvas.getWidth()); if (mEdgeEffectRight.draw(canvas)) { needsInvalidate = true; } } finally { canvas.restore(); } } return needsInvalidate; }
From source file:com.jjoe64.graphview.GridLabelRenderer.java
/** * draws the vertical axis title if//from w w w .ja va 2 s . c om * it is set * @param canvas canvas */ protected void drawVerticalAxisTitle(Canvas canvas) { if (mVerticalAxisTitle != null && mVerticalAxisTitle.length() > 0) { mPaintAxisTitle.setColor(getVerticalAxisTitleColor()); mPaintAxisTitle.setTextSize(getVerticalAxisTitleTextSize()); float x = getVerticalAxisTitleWidth(); float y = canvas.getHeight() / 2; canvas.save(); canvas.rotate(-90, x, y); canvas.drawText(mVerticalAxisTitle, x, y, mPaintAxisTitle); canvas.restore(); } }
From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java
/** * Draws the overscroll "glow" at the four edges of the chart region, if necessary. The edges * of the chart region are stored in {@link #mContentRect}. * * @see EdgeEffectCompat//from ww w. j a va2 s . c o m */ private void drawEdgeEffectsUnclipped(Canvas canvas) { // The methods below rotate and translate the canvas as needed before drawing the glow, // since EdgeEffectCompat always draws a top-glow at 0,0. boolean needsInvalidate = false; if (!mEdgeEffectTop.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(mContentRect.left, mContentRect.top); mEdgeEffectTop.setSize(mContentRect.width(), mContentRect.height()); if (mEdgeEffectTop.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (!mEdgeEffectBottom.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(2 * mContentRect.left - mContentRect.right, mContentRect.bottom); canvas.rotate(180, mContentRect.width(), 0); mEdgeEffectBottom.setSize(mContentRect.width(), mContentRect.height()); if (mEdgeEffectBottom.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (!mEdgeEffectLeft.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(mContentRect.left, mContentRect.bottom); canvas.rotate(-90, 0, 0); mEdgeEffectLeft.setSize(mContentRect.height(), mContentRect.width()); if (mEdgeEffectLeft.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (!mEdgeEffectRight.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(mContentRect.right, mContentRect.top); canvas.rotate(90, 0, 0); mEdgeEffectRight.setSize(mContentRect.height(), mContentRect.width()); if (mEdgeEffectRight.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.lovejjfg.demo.TouchCircleView.java
public void drawTriangle(Canvas c, float startAngle, float sweepAngle) { if (mArrow == null) { mArrow = new Path(); mArrow.setFillType(Path.FillType.EVEN_ODD); } else {/*from www . ja v a 2s . co m*/ mArrow.reset(); } // Adjust the position of the triangle so that it is inset as // much as the arc, but also centered on the arc. // float inset = (int) mStrokeInset / 2 * mArrowScale; float x = (float) (mRingCenterRadius * Math.cos(0) + innerRectf.centerX()); float y = (float) (mRingCenterRadius * Math.sin(0) + innerRectf.centerY()); // Update the path each time. This works around an issue in SKIA // where concatenating a rotation matrix to a scale matrix // ignored a starting negative rotation. This appears to have // been fixed as of API 21. mArrow.moveTo(0, 0); mArrow.lineTo(ARROW_WIDTH * mArrowScale, 0); mArrow.lineTo((ARROW_WIDTH * mArrowScale / 2), (ARROW_HEIGHT * mArrowScale)); mArrow.offset(x, y); mArrow.close(); // draw a triangle c.rotate(startAngle + sweepAngle, innerRectf.centerX(), innerRectf.centerY()); c.drawPath(mArrow, innerPaint); }
From source file:cn.ieclipse.af.view.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 .java 2 s . co m*/ 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); } } }
From source file:com.morninz.ninepinview.widget.NinePINView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // draw circles around center points and connection line int drawnCount = mDrawnPoints.size(); for (int j = 0; j < drawnCount; j++) { Point p1 = mDrawnPoints.get(j); canvas.drawCircle(p1.x, p1.y, mCircleRadius, mCirclePaint); if (j + 1 < drawnCount) { Point p2 = mDrawnPoints.get(j + 1); canvas.drawCircle(p2.x, p2.y, mCircleRadius, mCirclePaint); canvas.drawLine(p1.x, p1.y, p2.x, p2.y, mLinePaint); if (mWillDrawWrongTriangle) { // compute the wrong triangle's direction of this point. float angle = 0.f; if (p2.y == p1.y) {// x-axis angle = p2.x > p1.x ? 0.f : 180.f; } else if (p2.x == p1.x) { // y-axis angle = p2.y > p1.y ? 90.f : -90.f; } else {// in quadrants double tanA = ((double) p2.y - (double) p1.y) / ((double) p2.x - (double) p1.x); // in 1 or 4 quadrant angle = (float) (Math.atan(tanA) * 180 / Math.PI); // in 2 or 3 quadrant if (p2.x < p1.x) { angle += 180.f;/*from www.j ava 2 s. c o m*/ } } Log.d(TAG, "angle " + angle); canvas.save(); canvas.rotate(angle, p1.x, p1.y); canvas.drawPath(mWrongPaths[p1.index], mWrongPaint); canvas.restore(); } } } // draw extra connection line if (mLastDrawnPoint != null) { canvas.drawLine(mLastDrawnPoint.x, mLastDrawnPoint.y, mCurrX, mCurrY, mLinePaint); } // draw 9 center points for (int i = 0; i < POINT_COUNT; i++) { Point p = mCenterPoints[i]; canvas.drawCircle(p.x, p.y, mPointSize, mPointPaint); } }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void drawScale(Canvas canvas, Boolean Colors, int Count, int Max) { RectF faceRect = new RectF(); faceRect.set(10, 10, 190, 190);//from w w w. j a va 2 s. c om Paint scalePaint = new Paint(); scalePaint.setStyle(Paint.Style.STROKE); scalePaint.setColor(getResources().getColor(R.color.WarningGreen)); scalePaint.setStrokeWidth(1); scalePaint.setAntiAlias(true); scalePaint.setTextSize(12); scalePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf")); scalePaint.setTextAlign(Paint.Align.CENTER); float scalePosition = 10; RectF scaleRect = new RectF(); scaleRect.set(faceRect.left + scalePosition, faceRect.top + scalePosition, faceRect.right - scalePosition, faceRect.bottom - scalePosition); if (!Colors) scalePaint.setColor(Color.WHITE); scalePaint.setStrokeWidth(2); canvas.save(Canvas.MATRIX_SAVE_FLAG); for (int i = 0; i < Max; ++i) { if (Colors) { if (i > 20) scalePaint.setColor(getResources().getColor(R.color.WarningYellow)); if (i > 40) scalePaint.setColor(getResources().getColor(R.color.WarningOrange)); if (i > 60) scalePaint.setColor(getResources().getColor(R.color.WarningRed)); } canvas.drawLine(100, 20, 100, 18, scalePaint); int divisor = 5; if (Max > 100) divisor = 25; if (i % divisor == 0) { canvas.drawText(Integer.toString(i), 100, 16, scalePaint); } canvas.rotate((360.0f / Max), 100, 100); } canvas.restore(); }