List of usage examples for android.graphics Canvas rotate
public final void rotate(float degrees, float px, float py)
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
public void drawMoon(Canvas canvas) { moonPaint.reset();//from ww w . j av a2 s . com moonPaint.setColor(Color.WHITE); moonPaint.setStyle(Paint.Style.FILL_AND_STROKE); moonPaintB.reset();// moon Paint Black moonPaintB.setColor(Color.BLACK); moonPaintB.setStyle(Paint.Style.FILL_AND_STROKE); moonPaintO.reset();// moon Paint for Oval moonPaintO.setColor(Color.WHITE); moonPaintO.setStyle(Paint.Style.FILL_AND_STROKE); moonPaintD.reset();// moon Paint for Diameter // draw moonPaintD.setColor(Color.GRAY); moonPaintD.setStyle(Paint.Style.STROKE); double moonPhase = sunMoonPosition.getMoonPhase(); if (moonPosition.getElevation() > -5) { canvas.rotate((float) moonPosition.getAzimuth() - 360, px, py); int eOffset = (int) ((moonPosition.getElevation() / 90) * Radius); // elevation Offset 0 for 0 degree; r for 90 degree moonRect.set(px - r, py + eOffset - Radius - r, px + r, py + eOffset - Radius + r); canvas.drawArc(moonRect, 90, 180, false, moonPaint); canvas.drawArc(moonRect, 270, 180, false, moonPaintB); int arcWidth = (int) ((moonPhase - 0.5) * (4 * r)); moonPaintO.setColor(arcWidth < 0 ? Color.BLACK : Color.WHITE); moonOval.set(px - Math.abs(arcWidth) / 2, py + eOffset - Radius - r, px + Math.abs(arcWidth) / 2, py + eOffset - Radius + r); canvas.drawArc(moonOval, 0, 360, false, moonPaintO); canvas.drawArc(moonRect, 0, 360, false, moonPaintD); moonPaintD.setPathEffect(dashPath); canvas.drawLine(px, py - Radius, px, py + Radius, moonPaintD); moonPaintD.setPathEffect(null); canvas.restore(); } }
From source file:com.emmaguy.todayilearned.PanView.java
/** * Draws the overscroll "glow" at the four edges, if necessary * * @see EdgeEffect// w w w. ja v a 2 s .co m */ private void drawEdgeEffects(Canvas canvas) { // The methods below rotate and translate the canvas as needed before drawing the glow, // since EdgeEffect always draws a top-glow at 0,0. boolean needsInvalidate = false; if (!mEdgeEffectTop.isFinished()) { final int restoreCount = canvas.save(); mEdgeEffectTop.setSize(mWidth, mHeight); if (mEdgeEffectTop.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (!mEdgeEffectBottom.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(-mWidth, mHeight); canvas.rotate(180, mWidth, 0); mEdgeEffectBottom.setSize(mWidth, mHeight); if (mEdgeEffectBottom.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (!mEdgeEffectLeft.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(0, mHeight); canvas.rotate(-90, 0, 0); //noinspection SuspiciousNameCombination mEdgeEffectLeft.setSize(mHeight, mWidth); if (mEdgeEffectLeft.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (!mEdgeEffectRight.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(mWidth, 0); canvas.rotate(90, 0, 0); //noinspection SuspiciousNameCombination mEdgeEffectRight.setSize(mHeight, mWidth); if (mEdgeEffectRight.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (needsInvalidate) { invalidate(); } }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw card value and small suit below value * in both top left and bottom right corners * bottom right is reversed/upside down//from w ww.j av a 2 s . co m * @param paint paint styled for card value and small suit * @param canvas canvas to draw on * @param value card value * @param smallSuit small card suit * @param suitIdx suit index */ private void drawCardValue(final Paint paint, final Canvas canvas, final String value, final Bitmap smallSuit, final int suitIdx) { if ((suitIdx & 1) == 1) { paint.setARGB(255, 255, 0, 0); } else { paint.setARGB(255, 0, 0, 0); } canvas.drawText(value, mSuitsSize4th, mSuitsSize, paint); canvas.drawBitmap(smallSuit, mSuitsSize4th, mSuitsSize4th + mSuitsSize, mSuitPaint); canvas.save(); canvas.rotate(180, Card.WIDTH / 2, Card.HEIGHT / 2); canvas.drawBitmap(smallSuit, mSuitsSize4th, mSuitsSize4th + mSuitsSize, mSuitPaint); canvas.drawText(value, mSuitsSize4th, mSuitsSize, paint); canvas.restore(); }
From source file:de.telekom.pde.codelibrary.ui.layout.PDESwipeRefreshLayout.java
@Override public void draw(@NonNull Canvas canvas) { super.draw(canvas); int width = mBounds.width(); int height = mBounds.height(); int cx = width / 2; int cy = height / 2; int restoreCount = canvas.save(); canvas.clipRect(mBounds);/* ww w . j av a 2s.c o m*/ if (mRunning) { long now = AnimationUtils.currentAnimationTimeMillis(); long elapsed = (now - mStartTime) % mAnimationDuration; float currentAngle = (elapsed / (mAnimationDuration / 100f)) * 3.6f; canvas.drawCircle(cx, cy, PDEBuildingUnits.BU(), mPaint); canvas.save(); canvas.rotate(currentAngle, cx, cy); canvas.drawPath(mCirclePath, mWhitePaint); canvas.restore(); ViewCompat.postInvalidateOnAnimation(this); } else { // Otherwise if we're in the middle of a trigger, draw that. if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) { drawTrigger(canvas, cx, cy); } } canvas.restoreToCount(restoreCount); }
From source file:devlight.io.library.ArcProgressStackView.java
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); // Save and rotate to start angle canvas.save();/*from ww w . java 2 s.c o m*/ final float radius = mSize * 0.5F; canvas.rotate(mStartAngle, radius, radius); // Draw all of progress for (int i = 0; i < mModels.size(); i++) { final Model model = mModels.get(i); // Get progress for current model float progressFraction = mIsAnimated && !isInEditMode() ? (model.mLastProgress + (mAnimatedFraction * (model.getProgress() - model.mLastProgress))) / MAX_PROGRESS : model.getProgress() / MAX_PROGRESS; if (i != mActionMoveModelIndex && mActionMoveModelIndex != ANIMATE_ALL_INDEX) progressFraction = model.getProgress() / MAX_PROGRESS; final float progress = progressFraction * mSweepAngle; // Check if model have gradient final boolean isGradient = model.getColors() != null; // Set width of progress mProgressPaint.setStrokeWidth(mProgressModelSize); // Set model arc progress model.mPath.reset(); model.mPath.addArc(model.mBounds, 0.0F, progress); // Draw gradient progress or solid resetShadowLayer(); mProgressPaint.setShader(null); mProgressPaint.setStyle(Paint.Style.STROKE); if (mIsModelBgEnabled) { //noinspection ResourceAsColor mProgressPaint.setColor(isInEditMode() ? mPreviewModelBgColor : model.getBgColor()); canvas.drawArc(model.mBounds, 0.0F, mSweepAngle, false, mProgressPaint); if (!isInEditMode()) mProgressPaint.clearShadowLayer(); } // Check if gradient for draw shadow at first and then gradient progress if (isGradient) { if (!mIsModelBgEnabled) { canvas.drawPath(model.mPath, mProgressPaint); if (!isInEditMode()) mProgressPaint.clearShadowLayer(); } mProgressPaint.setShader(model.mSweepGradient); } else mProgressPaint.setColor(model.getColor()); // Here we draw main progress mProgressPaint.setAlpha(255); canvas.drawPath(model.mPath, mProgressPaint); // Preview mode if (isInEditMode()) continue; // Get model title bounds mTextPaint.setTextSize(mProgressModelSize * 0.5F); mTextPaint.getTextBounds(model.getTitle(), 0, model.getTitle().length(), model.mTextBounds); // Draw title at start with offset final float titleHorizontalOffset = model.mTextBounds.height() * 0.5F; final float progressLength = (float) (Math.PI / 180.0F) * progress * model.mBounds.width() * 0.5F; final String title = (String) TextUtils.ellipsize(model.getTitle(), mTextPaint, progressLength - titleHorizontalOffset * 2, TextUtils.TruncateAt.END); canvas.drawTextOnPath(title, model.mPath, mIsRounded ? 0.0F : titleHorizontalOffset, titleHorizontalOffset, mTextPaint); // Get pos and tan at final path point model.mPathMeasure.setPath(model.mPath, false); model.mPathMeasure.getPosTan(model.mPathMeasure.getLength(), model.mPos, model.mTan); // Get title width final float titleWidth = model.mTextBounds.width(); // Create model progress like : 23% final String percentProgress = String.format("%d%%", (int) model.getProgress()); // Get progress text bounds mTextPaint.setTextSize(mProgressModelSize * 0.35f); mTextPaint.getTextBounds(percentProgress, 0, percentProgress.length(), model.mTextBounds); // Get pos tan with end point offset and check whether the rounded corners for offset final float progressHorizontalOffset = mIndicatorOrientation == IndicatorOrientation.VERTICAL ? model.mTextBounds.height() * 0.5F : model.mTextBounds.width() * 0.5F; final float indicatorProgressOffset = (mIsRounded ? progressFraction : 1.0F) * (-progressHorizontalOffset - titleHorizontalOffset - (mIsRounded ? model.mTextBounds.height() * 2.0F : 0.0F)); model.mPathMeasure.getPosTan(model.mPathMeasure.getLength() + indicatorProgressOffset, model.mPos, mIndicatorOrientation == IndicatorOrientation.VERTICAL && !mIsRounded ? new float[2] : model.mTan); // Check if there available place for indicator if ((titleWidth + model.mTextBounds.height() + titleHorizontalOffset * 2.0F) - indicatorProgressOffset < progressLength) { // Get rotate indicator progress angle for progress value float indicatorProgressAngle = (float) (Math.atan2(model.mTan[1], model.mTan[0]) * (180.0F / Math.PI)); // Get arc angle of progress indicator final float indicatorLengthProgressAngle = ((progressLength + indicatorProgressOffset) / (model.mBounds.width() * 0.5F)) * (float) (180.0F / Math.PI); // Detect progress indicator position : left or right and then rotate if (mIndicatorOrientation == IndicatorOrientation.VERTICAL) { // Get X point of arc angle progress indicator final float x = (float) (model.mBounds.width() * 0.5F * (Math.cos((indicatorLengthProgressAngle + mStartAngle) * Math.PI / 180.0F))) + model.mBounds.centerX(); indicatorProgressAngle += (x > radius) ? -90.0F : 90.0F; } else { // Get Y point of arc angle progress indicator final float y = (float) (model.mBounds.height() * 0.5F * (Math.sin((indicatorLengthProgressAngle + mStartAngle) * Math.PI / 180.0F))) + model.mBounds.centerY(); indicatorProgressAngle += (y > radius) ? 180.0F : 0.0F; } // Draw progress value canvas.save(); canvas.rotate(indicatorProgressAngle, model.mPos[0], model.mPos[1]); canvas.drawText(percentProgress, model.mPos[0] - model.mTextBounds.exactCenterX(), model.mPos[1] - model.mTextBounds.exactCenterY(), mTextPaint); canvas.restore(); } // Check if gradient and have rounded corners, because we must to create elevation effect // for start progress corner if ((isGradient || mIsLeveled) && mIsRounded && progress != 0) { model.mPathMeasure.getPosTan(0.0F, model.mPos, model.mTan); // Set paint for overlay rounded gradient with shadow setLevelShadowLayer(); //noinspection ResourceAsColor mLevelPaint.setColor(isGradient ? model.getColors()[0] : model.getColor()); // Get bounds of start pump final float halfSize = mProgressModelSize * 0.5F; final RectF arcRect = new RectF(model.mPos[0] - halfSize, model.mPos[1] - halfSize, model.mPos[0] + halfSize, model.mPos[1] + halfSize + 2.0F); canvas.drawArc(arcRect, 0.0F, -180.0F, true, mLevelPaint); } } // Restore after drawing canvas.restore(); }
From source file:com.example.nitish.welcomapp.widgetpt.PeriodicTableView.java
/** * Draw the edge effects to the supplied Canvas. * * @param canvas The Canvas// w w w .ja v a 2s . co m */ private void drawEdgeEffects(@NonNull Canvas canvas) { boolean invalidate = false; if (!mEdgeEffectTop.isFinished()) { mEdgeEffectTop.draw(canvas); invalidate = true; } if (!mEdgeEffectBottom.isFinished()) { canvas.save(); canvas.rotate(180, getWidth() / 2, getHeight() / 2); mEdgeEffectBottom.draw(canvas); canvas.restore(); invalidate = true; } if (!mEdgeEffectLeft.isFinished()) { canvas.save(); canvas.translate(0, getHeight()); canvas.rotate(-90); mEdgeEffectLeft.draw(canvas); canvas.restore(); invalidate = true; } if (!mEdgeEffectRight.isFinished()) { canvas.save(); canvas.translate(getWidth(), 0); canvas.rotate(90, 0, 0); mEdgeEffectRight.draw(canvas); canvas.restore(); invalidate = true; } if (invalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java
/** * MARK: Overrides// w w w. j a va2s.c o m */ @Override protected void onDraw(Canvas canvas) { if (mPathWhite != null && mPathBlack != null) { float textX = Math.max(getPaddingLeft() - (int) (mBubbleWidth / 4.0f), mProgress * mWidth / 100 - (int) (mBubbleWidth / 4.0f)); float textY = mHeight / 2 - mBubbleHeight / 2 + calculateDeltaY(); switch (mState) { case STATE_WORKING: // Save and restore prevent the rest of the canvas to not be rotated canvas.save(); float speed = (getProgress() - mTarget) / 20; mBubbleAngle += speed * 10; if (mBubbleAngle > 20) { mBubbleAngle = 20; } if (mBubbleAngle < -20) { mBubbleAngle = -20; } if (Math.abs(speed) < 1) { mSpeedAngle -= mBubbleAngle / 20; mSpeedAngle *= .9f; } mBubbleAngle += mSpeedAngle; canvas.rotate(mBubbleAngle, bubbleAnchorX, bubbleAnchorY); canvas.drawPath(mPathBubble, mPaintBubble); canvas.drawText(String.valueOf((int) mProgress) + " %", textX, textY, mPaintText); canvas.restore(); break; case STATE_FAILED: canvas.save(); canvas.rotate(mFailAngle, bubbleAnchorX, bubbleAnchorY); canvas.drawPath(mPathBubble, mPaintBubble); canvas.rotate(mFailAngle, bubbleAnchorX, textY - mBubbleHeight / 7); // mPaintText.setColor(getResources().getColor(R.color.red_wine)); textX = Math.max(getPaddingLeft() - (int) (mBubbleWidth / 3.2f), mProgress * mWidth / 100 - (int) (mBubbleWidth / 3.2f)); canvas.drawText(getResources().getString(R.string.failed), textX, textY, mPaintText); canvas.restore(); break; case STATE_SUCCESS: canvas.save(); // mPaintText.setColor(getResources().getColor(R.color.green_grass)); textX = Math.max(getPaddingLeft() - (int) (mBubbleWidth / 3.2f), mProgress * mWidth / 100 - (int) (mBubbleWidth / 3.2f)); Matrix flipMatrix = new Matrix(); flipMatrix.setScale(mFlipFactor, 1, bubbleAnchorX, bubbleAnchorY); canvas.concat(flipMatrix); canvas.drawPath(mPathBubble, mPaintBubble); canvas.concat(flipMatrix); canvas.drawText(getResources().getString(R.string.done), textX, textY, mPaintText); canvas.restore(); break; } canvas.drawPath(mPathBlack, mPaintBlack); canvas.drawPath(mPathWhite, mPaintWhite); } }
From source file:com.example.stickablelistview.StickListView.java
/** Draws the overscroll edge glow effect on the left and right sides of the horizontal list */ private void drawEdgeGlow(Canvas canvas) { if (mEdgeGlowTop != null && !mEdgeGlowTop.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 width = getWidth(); canvas.rotate(-90, 0, 0); canvas.translate(0, -width + getPaddingRight()); mEdgeGlowTop.setSize(getRenderWidth(), getRenderHeight()); if (mEdgeGlowTop.draw(canvas)) { invalidate();/*w w w. j a v a 2s . c o m*/ } canvas.restoreToCount(restoreCount); } else if (mEdgeGlowBottom != null && !mEdgeGlowBottom.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); mEdgeGlowBottom.setSize(getRenderWidth(), getRenderHeight()); if (mEdgeGlowBottom.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } }
From source file:com.simon.catkins.views.HorizontalListView.java
/** Draws the overscroll edge glow effect on the top and bottom sides of the vertical list */ 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 top 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();//w ww . ja v a 2 s. com } 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 bottom 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:aksha.upcomingdemo.HorizontalListView.java
/** Draws the overscroll edge glow effect on the left and right sides of the horizontal list */ 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();//w ww.java 2 s. c om } 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); } }