Example usage for android.graphics Canvas rotate

List of usage examples for android.graphics Canvas rotate

Introduction

In this page you can find the example usage for android.graphics Canvas rotate.

Prototype

public final void rotate(float degrees, float px, float py) 

Source Link

Document

Preconcat the current matrix with the specified rotation.

Usage

From source file:com.beijing.fun.view.refreshLayout.BGAStickinessRefreshView.java

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mPath.reset();//  ww w.j  a va 2  s.  c om

    mTopBound.round(mRotateDrawableBound);
    mRotateDrawable.setBounds(mRotateDrawableBound);
    if (mIsRotating) {
        mPath.addOval(mTopBound, Path.Direction.CW);
        canvas.drawPath(mPath, mPaint);
        canvas.save();
        canvas.rotate(mCurrentDegree, mRotateDrawable.getBounds().centerX(),
                mRotateDrawable.getBounds().centerY());
        mRotateDrawable.draw(canvas);
        canvas.restore();
    } else {
        // drawable
        mPath.moveTo(mTopBound.left, mTopBound.top + mTopSize / 2);
        // drawable?
        mPath.arcTo(mTopBound, 180, 180);
        // ?
        //            mPath.quadTo(mTopBound.right - mTopSize / 8, mTopBound.bottom, mBottomBound.right, mBottomBound.bottom - mBottomBound.height() / 2);

        // mCurrentBottomHeight   0  mMaxBottomHeight
        // scale                  0.2  1
        float scale = Math.max(mCurrentBottomHeight * 1.0f / mMaxBottomHeight, 0.2f);

        float bottomControlXOffset = mTopSize * ((3 + (float) Math.pow(scale, 7) * 16) / 32);
        float bottomControlY = mTopBound.bottom / 2 + mCenterPoint.y / 2;
        // ???
        mPath.cubicTo(mTopBound.right - mTopSize / 8, mTopBound.bottom, mTopBound.right - bottomControlXOffset,
                bottomControlY, mBottomBound.right, mBottomBound.bottom - mBottomBound.height() / 2);

        mPath.arcTo(mBottomBound, 0, 180);

        //            mPath.quadTo(mTopBound.left + mTopSize / 8, mTopBound.bottom, mTopBound.left, mTopBound.bottom - mTopSize / 2);
        mPath.cubicTo(mTopBound.left + bottomControlXOffset, bottomControlY, mTopBound.left + mTopSize / 8,
                mTopBound.bottom, mTopBound.left, mTopBound.bottom - mTopSize / 2);

        canvas.drawPath(mPath, mPaint);

        mRotateDrawable.draw(canvas);
    }
}

From source file:cn.bingoogolapple.refreshlayout.BGAStickinessRefreshView.java

@Override
public void onDraw(Canvas canvas) {
    if (mRotateDrawable == null) {
        return;// w  w  w .  ja v  a2s  .  co  m
    }

    mPath.reset();

    mTopBound.round(mRotateDrawableBound);
    mRotateDrawable.setBounds(mRotateDrawableBound);
    if (mIsRotating) {
        mPath.addOval(mTopBound, Path.Direction.CW);
        canvas.drawPath(mPath, mPaint);
        canvas.save();
        canvas.rotate(mCurrentDegree, mRotateDrawable.getBounds().centerX(),
                mRotateDrawable.getBounds().centerY());
        mRotateDrawable.draw(canvas);
        canvas.restore();
    } else {
        // drawable
        mPath.moveTo(mTopBound.left, mTopBound.top + mTopSize / 2);
        // drawable?
        mPath.arcTo(mTopBound, 180, 180);
        // ?
        //            mPath.quadTo(mTopBound.right - mTopSize / 8, mTopBound.bottom, mBottomBound.right, mBottomBound.bottom - mBottomBound.height() / 2);

        // mCurrentBottomHeight   0  mMaxBottomHeight
        // scale                  0.2  1
        float scale = Math.max(mCurrentBottomHeight * 1.0f / mMaxBottomHeight, 0.2f);

        float bottomControlXOffset = mTopSize * ((3 + (float) Math.pow(scale, 7) * 16) / 32);
        float bottomControlY = mTopBound.bottom / 2 + mCenterPoint.y / 2;
        // ???
        mPath.cubicTo(mTopBound.right - mTopSize / 8, mTopBound.bottom, mTopBound.right - bottomControlXOffset,
                bottomControlY, mBottomBound.right, mBottomBound.bottom - mBottomBound.height() / 2);

        mPath.arcTo(mBottomBound, 0, 180);

        //            mPath.quadTo(mTopBound.left + mTopSize / 8, mTopBound.bottom, mTopBound.left, mTopBound.bottom - mTopSize / 2);
        mPath.cubicTo(mTopBound.left + bottomControlXOffset, bottomControlY, mTopBound.left + mTopSize / 8,
                mTopBound.bottom, mTopBound.left, mTopBound.bottom - mTopSize / 2);

        canvas.drawPath(mPath, mPaint);

        mRotateDrawable.draw(canvas);
    }
}

From source file:com.nicodelee.ptr.header.StickinessView.java

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mRotateDrawable == null) {
        return;/*from   w  ww. j  a va2 s .co  m*/
    }
    mPath.reset();
    mTopBound.round(mRotateDrawableBound);
    mRotateDrawable.setBounds(mRotateDrawableBound);
    if (mIsRotating) {
        mPath.addOval(mTopBound, Path.Direction.CW);
        canvas.drawPath(mPath, mPaint);
        canvas.save();
        canvas.rotate(mCurrentDegree, mRotateDrawable.getBounds().centerX(),
                mRotateDrawable.getBounds().centerY());
        mRotateDrawable.draw(canvas);
        canvas.restore();
    } else {
        // drawable
        mPath.moveTo(mTopBound.left, mTopBound.top + mTopSize / 2);
        // drawable?
        mPath.arcTo(mTopBound, 180, 180);
        // ?
        //            mPath.quadTo(mTopBound.right - mTopSize / 8, mTopBound.bottom, mBottomBound.right, mBottomBound.bottom - mBottomBound.height() / 2);

        // mCurrentBottomHeight   0  mMaxBottomHeight
        // scale                  0.2  1
        float scale = Math.max(mCurrentBottomHeight * 1.0f / mMaxBottomHeight, 0.2f);

        float bottomControlXOffset = mTopSize * ((3 + (float) Math.pow(scale, 7) * 16) / 32);
        float bottomControlY = mTopBound.bottom / 2 + mCenterPoint.y / 2;
        // ???
        mPath.cubicTo(mTopBound.right - mTopSize / 8, mTopBound.bottom, mTopBound.right - bottomControlXOffset,
                bottomControlY, mBottomBound.right, mBottomBound.bottom - mBottomBound.height() / 2);

        mPath.arcTo(mBottomBound, 0, 180);

        //            mPath.quadTo(mTopBound.left + mTopSize / 8, mTopBound.bottom, mTopBound.left, mTopBound.bottom - mTopSize / 2);
        mPath.cubicTo(mTopBound.left + bottomControlXOffset, bottomControlY, mTopBound.left + mTopSize / 8,
                mTopBound.bottom, mTopBound.left, mTopBound.bottom - mTopSize / 2);

        canvas.drawPath(mPath, mPaint);

        mRotateDrawable.draw(canvas);
    }
}

From source file:com.mobility.android.ui.widget.MaterialProgressDrawable.java

@Override
public void draw(@NonNull Canvas c) {
    Rect bounds = getBounds();/* w w  w .j  a v  a2 s. co m*/
    int saveCount = c.save();
    c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
    mRing.draw(c, bounds);
    c.restoreToCount(saveCount);
}

From source file:com.xfzbd.cqi.widget.srl.ShyaringanProgressDrawable.java

@Override
public void draw(Canvas c) {
    final Rect bounds = getBounds();
    final int saveCount = c.save();
    c.rotate(0f, bounds.exactCenterX(), bounds.exactCenterY());
    mRing.draw(c, bounds);/*  w  ww .j  a v a 2 s  . c om*/
    c.restoreToCount(saveCount);
}

From source file:cn.spinsoft.wdq.widget.swipe.MaterialProgressDrawable.java

@Override
public void draw(Canvas c) {
    final Rect bounds = getBounds();
    final int saveCount = c.save();
    c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
    mRing.draw(c, bounds);//from   w ww.j  a va2 s .  c o m
    c.restoreToCount(saveCount);
}

From source file:android.support.design.widget.CircularBorderDrawable.java

@Override
public void draw(Canvas canvas) {
    if (mInvalidateShader) {
        mPaint.setShader(createGradientShader());
        mInvalidateShader = false;//  w  ww. j  a v  a2s. c om
    }

    final float halfBorderWidth = mPaint.getStrokeWidth() / 2f;
    final RectF rectF = mRectF;

    // We need to inset the oval bounds by half the border width. This is because stroke draws
    // the center of the border on the dimension. Whereas we want the stroke on the inside.
    copyBounds(mRect);
    rectF.set(mRect);
    rectF.left += halfBorderWidth;
    rectF.top += halfBorderWidth;
    rectF.right -= halfBorderWidth;
    rectF.bottom -= halfBorderWidth;

    canvas.save();
    canvas.rotate(mRotation, rectF.centerX(), rectF.centerY());
    // Draw the oval
    canvas.drawOval(rectF, mPaint);
    canvas.restore();
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw face card bitmap, with its top/left corner at (x,y),
 * using the specified paint/*from  www  .  ja  v  a 2 s .c  om*/
 * @param canvas canvas to draw on
 * @param bitmap bitmap image to draw
 * @param left left side of the bitmap being drawn (y)
 * @param top top side of the bitmap being drawn (x)
 * @param paint paint used to draw the bitmap
 */
public void drawFaceBitmap(final Canvas canvas, final Bitmap bitmap, final float left, final float top,
        final Paint paint) {
    canvas.drawBitmap(bitmap, left, top, paint);
    canvas.rotate(180, Card.WIDTH / 2, Card.HEIGHT / 2);
    canvas.drawBitmap(bitmap, left, top, paint);
}

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. ja v  a2 s.c o  m*/
        canvas.scale(-1f, 1f, mDrawBound.centerX(), mDrawBound.centerY());

    canvas.rotate(degrees, mDrawBound.centerX(), mDrawBound.centerY());
    canvas.drawPath(mPath, mPaint);
    canvas.restoreToCount(restoreCount);
}

From source file:android.wuliqing.com.mylibrary.header.MaterialProgressDrawable.java

@Override
public void draw(Canvas c) {
    if (mShadow != null) {
        mShadow.getPaint().setColor(mBackgroundColor);
        mShadow.draw(c);//from  www .  j a va  2s  .  c  om
    }

    final Rect bounds = getBounds();
    final int saveCount = c.save();
    c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
    mRing.draw(c, bounds);
    c.restoreToCount(saveCount);
}