List of usage examples for android.graphics Canvas scale
public final void scale(float sx, float sy, float px, float py)
From source file:chrisrenke.drawerarrowdrawable.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { if (flip) {/*from ww w . ja v a 2s. c o m*/ canvas.save(); canvas.scale(1f, -1f, getIntrinsicWidth() / 2, getIntrinsicHeight() / 2); } topLine.draw(canvas); middleLine.draw(canvas); bottomLine.draw(canvas); if (flip) canvas.restore(); }
From source file:com.flyn.smartandroid.views.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { if (flip) {/*from www . j a va2s. co m*/ canvas.save(); canvas.scale(1f, -1f, getIntrinsicWidth() / 2, getIntrinsicHeight() / 2); } topLine.draw(canvas); middleLine.draw(canvas); bottomLine.draw(canvas); if (flip) { canvas.restore(); } }
From source file:com.metinkale.prayerapp.vakit.PrefsView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); canvas.scale(0.8f, 0.8f, canvas.getWidth() / 2, canvas.getHeight() / 2); Object o = getValue();/*ww w.j a va2 s . co m*/ boolean active = ((o instanceof Boolean) && o.equals(true)) || ((o instanceof Integer) && !o.equals(0)) || ((o instanceof String) && !((String) o).startsWith("silent")); if (mPref == Pref.Vibration2) { active = !o.equals(-1); } mPaint.setColor(active ? 0xff03A9F4 : 0xffe0e0e0); int w = getHeight(); canvas.drawCircle(w / 2, w / 2, w / 2, mPaint); int p = w / 7; mDrawable.setBounds(p, p, w - p, w - p); mDrawable.setColorFilter(active ? sCFActive : sCFInactive); mDrawable.draw(canvas); if ((mPref == Pref.Time) || (mPref == Pref.SabahTime) || (mPref == Pref.Silenter)) { int s = (Integer) getValue(); if (s != 0) { mPaint.setColor(getResources().getColor(R.color.colorPrimaryDark)); canvas.drawCircle(getWidth() * 0.78f, getHeight() * 0.78f, getWidth() / 4, mPaint); mPaint.setColor(Color.WHITE); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(w / 5); mPaint.setTypeface(Typeface.DEFAULT_BOLD); canvas.drawText(s + "", w * 0.78f, w * 0.87f, mPaint); } } else if (mPref == Pref.Vibration2) { int s = (Integer) getValue(); String txt = ""; if (s == 0) { txt = "8"; } else if (s == 1) { txt = "1"; } mPaint.setColor(Color.BLACK); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(w / 2); mPaint.setTypeface(Typeface.DEFAULT_BOLD); if (s == 0) { canvas.rotate(90, canvas.getWidth() / 2, canvas.getHeight() / 2); canvas.drawText(txt, w / 2, (w * 2) / 3, mPaint); canvas.rotate(-90, canvas.getWidth() / 2, canvas.getHeight() / 2); } else { canvas.drawText(txt, w / 2, w * 2 / 3, mPaint); } } }
From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java
@Override public void draw(Canvas canvas) { Rect bounds = getBounds();/*w w w . ja v a 2 s .c o m*/ if (mIsRtl) { canvas.save(); canvas.scale(-1, 1, bounds.centerX(), bounds.centerY()); } float pct = drawArc(canvas, bounds); if (pct < 0) { pct = 0; } else if (pct > 1) { pct = 1; } int y = bounds.bottom - mBottomOffset; canvas.drawLine(bounds.left + mLeftOffset / 2, y, bounds.right - mRightOffset / 2, y, mLinePaint); drawSun(canvas, pct); if (mIsRtl) { canvas.restore(); } }
From source file:im.ene.ribbon.FixedActionTabView.java
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); canvas.save();//from ww w .j a v a 2 s .c o m canvas.translate(0, iconTranslation); icon.draw(canvas); drawBadge(canvas); canvas.restore(); canvas.save(); canvas.scale(canvasTextScale, canvasTextScale, textCenterX, textCenterY); canvas.drawText(getAction().getTitle(), textX, textY, textPaint); canvas.restore(); }
From source file:com.example.brendan.learningandroid2.SeekArc.java
@Override protected void onDraw(Canvas canvas) { if (!mClockwise) { canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY()); }/*from w w w.j a va 2 s. c om*/ // Draw the arcs final int arcStart = mStartAngle + mAngleOffset + mRotation; final int arcSweep = mSweepAngle; canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint); canvas.drawArc(mArcRect, arcStart, mProgressSweep, false, mProgressPaint); // Draw the thumb nail canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos); // mThumb.draw(canvas); }
From source file:com.kadavelil.jossy.mapalarm.SeekArc.java
@Override protected void onDraw(Canvas canvas) { if (!mClockwise) { canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY()); }/*from ww w. j a v a 2 s . c o m*/ // Draw the arcs final int arcStart = mStartAngle + mAngleOffset + mRotation; final int arcSweep = mSweepAngle; canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint); canvas.drawArc(mArcRect, arcStart, mProgressSweep, false, mProgressPaint); // Draw the thumb nail canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos); mThumb.draw(canvas); }
From source file:com.triggertrap.seekarc.SeekArc.java
@Override protected void onDraw(Canvas canvas) { if (!mClockwise) { canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY()); }// w w w . j av a 2 s . c o m // Draw the arcs final int arcStart = mStartAngle + mAngleOffset + mRotation; final int arcSweep = mSweepAngle; canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint); canvas.drawArc(mArcRect, arcStart, mProgressSweep, false, mProgressPaint); if (mEnabled) { // Draw the thumb nail canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos); mThumb.draw(canvas); } }
From source file:com.brian.common.view.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { if (mIsCirculate) { if (mProgress >= .995) { flipped = true;/*from w w w . ja v a 2 s . c om*/ } else if (mProgress <= .005) { flipped = false; } if (flipped) { canvas.save(); canvas.scale(1f, -1f, getIntrinsicWidth() / 2, getIntrinsicHeight() / 2); } } Rect bounds = getBounds(); final boolean flipToPointRight; switch (mDirection) { case ARROW_DIRECTION_LEFT: flipToPointRight = false; break; case ARROW_DIRECTION_RIGHT: flipToPointRight = true; break; default: flipToPointRight = false; break; } // Interpolated widths of arrow bars float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2); arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress); final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress); // Interpolated size of middle bar final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, 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(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress); final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation)); final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation)); mPath.rewind(); final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress); final float arrowEdge = -arrowShaftLength / 2; // draw middle bar mPath.moveTo(arrowEdge + arrowShaftCut, 0); mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0); // bottom bar mPath.moveTo(arrowEdge, topBottomBarOffset); mPath.rLineTo(arrowWidth, arrowHeight); // top bar mPath.moveTo(arrowEdge, -topBottomBarOffset); mPath.rLineTo(arrowWidth, -arrowHeight); 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. final float barThickness = mPaint.getStrokeWidth(); final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2); float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2. yOffset += barThickness * 1.5 + mBarGap; canvas.translate(bounds.centerX(), yOffset); if (mSpin) { canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1)); } else if (flipToPointRight) { canvas.rotate(180); } canvas.drawPath(mPath, mPaint); canvas.restore(); }
From source file:com.github.shareme.gwsmaterialuikit.library.material.drawable.LineMorphingDrawable.java
@Override public void draw(Canvas canvas) { int restoreCount = canvas.save(); float degrees = (mClockwise ? 180 : -180) * ((mPrevState < mCurState ? 0f : 1f) + mAnimProgress); if (mIsRtl)/*from w w w . j a v a 2s . c om*/ canvas.scale(-1f, 1f, mDrawBound.centerX(), mDrawBound.centerY()); canvas.rotate(degrees, mDrawBound.centerX(), mDrawBound.centerY()); canvas.drawPath(mPath, mPaint); canvas.restoreToCount(restoreCount); }