Example usage for android.graphics Canvas drawPath

List of usage examples for android.graphics Canvas drawPath

Introduction

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

Prototype

public void drawPath(@NonNull Path path, @NonNull Paint paint) 

Source Link

Document

Draw the specified path using the specified paint.

Usage

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

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mPath.reset();/*from w  w  w. j a v  a2 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:org.telegram.ui.Cells.BotHelpCell.java

@Override
protected void onDraw(Canvas canvas) {
    int x = (canvas.getWidth() - width) / 2;
    int y = AndroidUtilities.dp(4);
    Theme.backgroundMediaDrawableIn.setBounds(x, y, width + x, height + y);
    Theme.backgroundMediaDrawableIn.draw(canvas);
    canvas.save();//from   w w  w. ja v  a  2 s  .  c  om
    canvas.translate(textX = AndroidUtilities.dp(2 + 9) + x, textY = AndroidUtilities.dp(2 + 9) + y);
    if (pressedLink != null) {
        canvas.drawPath(urlPath, urlPaint);
    }
    if (textLayout != null) {
        textLayout.draw(canvas);
    }
    canvas.restore();
}

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

@Override
public void onDraw(Canvas canvas) {
    if (mRotateDrawable == null) {
        return;//from w  w  w .j  a v a  2  s  . com
    }

    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  w  w.  j a  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.ickphum.android.isoview.IsoCanvas.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.translate(-mOriginX, -mOriginY);

    for (int x = 0; x < 100; x++) {
        for (int y = 0; y < 100; y++) {
            canvas.save();// w  w w  .j  a va2  s .  c  o m
            canvas.translate(-x * 7, -y * 7);
            canvas.drawPath(mPaths[0], mPaints[0]);
            //canvas.drawRect(0.0f, 0.0f, 5.0f, 5.0f, mPaints[0]);
            canvas.restore();
        }
    }

    canvas.drawLine(mContentRect.left, mContentRect.top, mContentRect.right, mContentRect.bottom,
            mBackgroundLinePaint);
    canvas.drawLine(mContentRect.left, mContentRect.bottom, mContentRect.right, mContentRect.top,
            mBackgroundLinePaint);

    for (int x = -1000; x < 1000; x += 200) {
        for (int y = -1000; y < 1000; y += 200) {
            canvas.drawText(x + "," + y, x, y, mBackgroundLinePaint);
        }
    }
}

From source file:com.luseen.spacenavigation.BezierView.java

@Override
protected void onDraw(Canvas canvas) {

    /**/*from ww w  .j  av a 2 s  .  co m*/
     * Reset path before drawing
     */
    path.reset();

    /**
     * Start point for drawing
     */
    path.moveTo(0, bezierHeight);

    /**
     * Seth half path of bezier view
     */
    path.cubicTo(bezierWidth / 4, bezierHeight, bezierWidth / 4, 0, bezierWidth / 2, 0);

    /**
     * Seth second part of bezier view
     */
    path.cubicTo((bezierWidth / 4) * 3, 0, (bezierWidth / 4) * 3, bezierHeight, bezierWidth, bezierHeight);

    /**
     * Draw our bezier view
     */
    canvas.drawPath(path, paint);
}

From source file:org.stockchart.series.LinearSeries.java

@Override
protected void postDraw(Canvas c) {
    if (fPoints.size() == 0)
        return;//w  ww . j  av a 2 s.co  m

    int h = c.getClipBounds().bottom;

    PointF firstPoint = fPoints.get(0);
    PointF lastPoint = fPoints.get(fPoints.size() - 1);

    fFillPath.lineTo(lastPoint.x, h);
    fFillPath.lineTo(firstPoint.x, h);
    fFillPath.close();

    this.fTempRectF.set(firstPoint.x, minY, lastPoint.x, h);
    this.getAppearance().applyFill(fPaint, fTempRectF);
    c.drawPath(fFillPath, fPaint);

    this.getAppearance().applyOutline(fPaint);
    c.drawPath(fLinePath, fPaint);

    if (fPointsVisible) {
        for (PointF p : fPoints) {
            float r = fDistanceBetweenPoints * fPointSizeInPercents * 0.5f;
            drawPoint(c, p.x, p.y, r);
        }
        //drawPoint(c, prevX,prevY,r);
    }
}

From source file:com.karthikb351.vitinfo2.customwidget.TimeLineView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    width = getWidth();//from   w ww.  java  2  s .  c o  m
    height = getHeight();
    cx = width / 2;
    cy = PADDING_TOP + CIRCLE_RADIUS;

    switch (widgetState) {
    case STATE_CURRENT:
        rectF.set(cx - BORDER_THICKNESS, cy - BORDER_THICKNESS, cx + BORDER_THICKNESS, cy + BORDER_THICKNESS);
        mPath.reset();
        for (int i = 0; i <= 360; i++) {
            mPath.addArc(rectF, i, 1);
        }
        canvas.drawPath(mPath, paintBorder);
    case STATE_SCHEDULED:
        rectF.set(cx - CIRCLE_RADIUS, cy - CIRCLE_RADIUS, cx + CIRCLE_RADIUS, cy + CIRCLE_RADIUS);
        mPath.reset();
        for (int i = 0; i <= 360; i += 1) {
            mPath.addArc(rectF, i, 1);
        }
        canvas.drawPath(mPath, paintRing);
        break;
    case STATE_FINISHED:
        canvas.drawCircle(cx, cy, CIRCLE_RADIUS, paintDot);
        break;
    }

    switch (widgetType) {
    case TYPE_INITIAL:
        canvas.drawLine(cx, cy + (11 * density), cx, height, paintLine);
        break;
    case TYPE_INNER:
        canvas.drawLine(cx, cy - (11 * density), cx, 0, paintLine);
        canvas.drawLine(cx, cy + (11 * density), cx, height, paintLine);
        break;
    case TYPE_END:
        canvas.drawLine(cx, cy - (11 * density), cx, 0, paintLine);
        break;
    }

}

From source file:com.nextgis.maplibui.formcontrol.Sign.java

@Override
protected void onDraw(Canvas canvas) {
    if (mNotInitialized && mPreviousSignBitmap != null)
        canvas.drawBitmap(mPreviousSignBitmap, 0, 0, null);

    int posX = canvas.getWidth() - mClearImageSize - mClearBuff;
    mCleanImage.setBounds(posX, mClearBuff, posX + mClearImageSize, mClearImageSize + mClearBuff);
    mCleanImage.draw(canvas);/*www  .j a v a  2 s.  c  om*/

    if (!mNotInitialized)
        for (Path path : mPaths)
            canvas.drawPath(path, mPaint);
}

From source file:me.lizheng.deckview.helpers.FakeShadowDrawable.java

private void drawShadow(Canvas canvas) {
    final float edgeShadowTop = -mCornerRadius - mShadowSize;
    final float inset = mCornerRadius + mInsetShadow + mRawShadowSize / 2;
    final boolean drawHorizontalEdges = mCardBounds.width() - 2 * inset > 0;
    final boolean drawVerticalEdges = mCardBounds.height() - 2 * inset > 0;
    // LT/*from   ww w.j av  a 2 s.co  m*/
    int saved = canvas.save();
    canvas.translate(mCardBounds.left + inset, mCardBounds.top + inset);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawHorizontalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.width() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // RB
    saved = canvas.save();
    canvas.translate(mCardBounds.right - inset, mCardBounds.bottom - inset);
    canvas.rotate(180f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawHorizontalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.width() - 2 * inset, -mCornerRadius + mShadowSize,
                mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // LB
    saved = canvas.save();
    canvas.translate(mCardBounds.left + inset, mCardBounds.bottom - inset);
    canvas.rotate(270f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawVerticalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // RT
    saved = canvas.save();
    canvas.translate(mCardBounds.right - inset, mCardBounds.top + inset);
    canvas.rotate(90f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawVerticalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
}