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.github.jorgecastillo.FillableLoader.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (!hasToDraw()) {
        return;/*  w ww  .j  a v a 2  s  .  co m*/
    }

    long elapsedTime = System.currentTimeMillis() - initialTime;

    float phase = MathUtil.constrain(0, 1, elapsedTime * 1f / strokeDrawingDuration);
    float distance = animInterpolator.getInterpolation(phase) * pathData.length;

    dashPaint.setPathEffect(getDashPathForDistance(distance));
    canvas.drawPath(pathData.path, dashPaint);

    if (isStrokeTotallyDrawn(elapsedTime)) {
        if (drawingState < State.FILL_STARTED) {
            changeState(State.FILL_STARTED);
        }

        float fillPhase = MathUtil.constrain(0, 1, (elapsedTime - strokeDrawingDuration) * 1f / fillDuration);

        clippingTransform.transform(canvas, fillPhase, this);
        canvas.drawPath(pathData.path, fillPaint);
    }

    if (hasToKeepDrawing(elapsedTime)) {
        ViewCompat.postInvalidateOnAnimation(this);
    } else {
        changeState(State.FINISHED);
    }
}

From source file:com.ruesga.rview.widget.ActivityStatsChart.java

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

    // Draw the grid lines
    float gap = mViewArea.height() / (MAX_Y_TICKS_LABELS * 1f);
    float y = mViewArea.top + gap;
    for (int i = 0; i < MAX_Y_TICKS_LABELS; i++) {
        canvas.drawLine(mViewArea.left, y, mViewArea.right, y, mGridLinesPaint);
        y += gap;//from   ww w  .j av  a2  s  .  co  m
    }

    // Draw the points data
    canvas.drawPath(mAreaPath, mAreaPaint);
    canvas.drawPath(mLinePath, mLinePaint);

    if (mDataAvailable) {
        // Draw ticks labels
        float margin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2f,
                getResources().getDisplayMetrics());
        y = mViewArea.top + gap;
        for (int i = 0; i < MAX_Y_TICKS_LABELS; i++) {
            canvas.drawText(mYTicksLabels[i], mViewArea.right - margin, y - margin, mTicksPaint);
            y += gap;
        }
    }
}

From source file:chinanurse.cn.nurse.list.WaveView.java

@Override
protected void onDraw(Canvas canvas) {
    //???????????
    canvas.drawPath(mWavePath, mShadowPaint);
    canvas.drawPath(mWavePath, mPaint);//w  w w .  ja  va 2s  .  c o  m
    mWavePath.reset();

    //??????
    mDropTangentPath.reset();
    mDropCirclePath.reset();
    float circleCenterY = (Float) mDropCircleAnimator.getAnimatedValue();
    float circleCenterX = mWidth / 2.f;
    mDropRect.setEmpty();
    //?RectF??
    float scale = (Float) mDisappearCircleAnimator.getAnimatedValue();
    float vertical = (Float) mDropBounceVerticalAnimator.getAnimatedValue();
    float horizontal = (Float) mDropBounceHorizontalAnimator.getAnimatedValue();
    mDropRect.set(
            circleCenterX - mDropCircleRadius * (1 + vertical) * scale + mDropCircleRadius * horizontal / 2,
            circleCenterY + mDropCircleRadius * (1 + horizontal) * scale - mDropCircleRadius * vertical / 2,
            circleCenterX + mDropCircleRadius * (1 + vertical) * scale - mDropCircleRadius * horizontal / 2,
            circleCenterY - mDropCircleRadius * (1 + horizontal) * scale + mDropCircleRadius * vertical / 2);
    float vertex = (Float) mDropVertexAnimator.getAnimatedValue();
    mDropTangentPath.moveTo(circleCenterX, vertex);
    //?(p1,q),(p2,q)
    double q = (Math.pow(mDropCircleRadius, 2) + circleCenterY * vertex - Math.pow(circleCenterY, 2))
            / (vertex - circleCenterY);
    //2????????
    double b = -2.0 * mWidth / 2;
    double c = Math.pow(q - circleCenterY, 2) + Math.pow(circleCenterX, 2) - Math.pow(mDropCircleRadius, 2);
    double p1 = (-b + Math.sqrt(b * b - 4 * c)) / 2;
    double p2 = (-b - Math.sqrt(b * b - 4 * c)) / 2;
    mDropTangentPath.lineTo((float) p1, (float) q);
    mDropTangentPath.lineTo((float) p2, (float) q);
    mDropTangentPath.close();
    mShadowPath.set(mDropTangentPath);
    mShadowPath.addOval(mDropRect, Path.Direction.CCW);
    mDropCirclePath.addOval(mDropRect, Path.Direction.CCW);
    if (mDropVertexAnimator.isRunning()) {
        canvas.drawPath(mShadowPath, mShadowPaint);
    } else {
        canvas.drawPath(mDropCirclePath, mShadowPaint);
    }
    canvas.drawPath(mDropTangentPath, mPaint);
    canvas.drawPath(mDropCirclePath, mPaint);
}

From source file:com.gosuncn.core.ui.widget.BezierView.java

@Override
protected void onDraw(Canvas canvas) {

    bezierWidth = getWidth();/*from ww  w  . ja  v a 2 s .  c  o  m*/
    bezierHeight = getHeight();

    /**
     * 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:cn.appsdream.nestrefresh.matetialstyle.WaveView.java

@Override
protected void onDraw(Canvas canvas) {
    //???????????
    canvas.drawPath(mWavePath, mShadowPaint);
    canvas.drawPath(mWavePath, mPaint);//from   ww w. ja  va 2s .  c om
    mWavePath.rewind();

    //??????
    mDropTangentPath.rewind();
    mDropCirclePath.rewind();
    float circleCenterY = (Float) mDropCircleAnimator.getAnimatedValue();
    float circleCenterX = mWidth / 2.f;
    mDropRect.setEmpty();
    //?RectF??
    float scale = (Float) mDisappearCircleAnimator.getAnimatedValue();
    float vertical = (Float) mDropBounceVerticalAnimator.getAnimatedValue();
    float horizontal = (Float) mDropBounceHorizontalAnimator.getAnimatedValue();
    mDropRect.set(
            circleCenterX - mDropCircleRadius * (1 + vertical) * scale + mDropCircleRadius * horizontal / 2,
            circleCenterY + mDropCircleRadius * (1 + horizontal) * scale - mDropCircleRadius * vertical / 2,
            circleCenterX + mDropCircleRadius * (1 + vertical) * scale - mDropCircleRadius * horizontal / 2,
            circleCenterY - mDropCircleRadius * (1 + horizontal) * scale + mDropCircleRadius * vertical / 2);
    float vertex = (Float) mDropVertexAnimator.getAnimatedValue();
    mDropTangentPath.moveTo(circleCenterX, vertex);
    //?(p1,q),(p2,q)
    double q = (Math.pow(mDropCircleRadius, 2) + circleCenterY * vertex - Math.pow(circleCenterY, 2))
            / (vertex - circleCenterY);
    //2????????
    double b = -2.0 * mWidth / 2;
    double c = Math.pow(q - circleCenterY, 2) + Math.pow(circleCenterX, 2) - Math.pow(mDropCircleRadius, 2);
    double p1 = (-b + Math.sqrt(b * b - 4 * c)) / 2;
    double p2 = (-b - Math.sqrt(b * b - 4 * c)) / 2;
    mDropTangentPath.lineTo((float) p1, (float) q);
    mDropTangentPath.lineTo((float) p2, (float) q);
    mDropTangentPath.close();
    mShadowPath.set(mDropTangentPath);
    mShadowPath.addOval(mDropRect, Path.Direction.CCW);
    mDropCirclePath.addOval(mDropRect, Path.Direction.CCW);
    if (mDropVertexAnimator.isRunning()) {
        canvas.drawPath(mShadowPath, mShadowPaint);
    } else {
        canvas.drawPath(mDropCirclePath, mShadowPaint);
    }
    canvas.drawPath(mDropTangentPath, mPaint);
    canvas.drawPath(mDropCirclePath, mPaint);
}

From source file:piuk.blockchain.android.util.ViewPagerTabs.java

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

    final int viewWidth = getWidth();
    final int viewHalfWidth = viewWidth / 2;
    final int viewBottom = getHeight();

    final float density = getResources().getDisplayMetrics().density;
    final float spacing = 32 * density;

    final Path path = new Path();
    path.moveTo(viewHalfWidth, viewBottom - 5 * density);
    path.lineTo(viewHalfWidth + 5 * density, viewBottom);
    path.lineTo(viewHalfWidth - 5 * density, viewBottom);
    path.close();/*www  .  j  a v  a 2s  . com*/

    paint.setColor(Color.WHITE);
    canvas.drawPath(path, paint);

    paint.setTypeface(Typeface.DEFAULT_BOLD);
    final float y = getPaddingTop() + -paint.getFontMetrics().top;

    for (int i = 0; i < labels.size(); i++) {
        final String label = labels.get(i);

        paint.setTypeface(i == pagePosition ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
        paint.setColor(i == pagePosition ? Color.BLACK : Color.DKGRAY);

        final float x = viewHalfWidth + (maxWidth + spacing) * (i - pageOffset);
        final float labelWidth = paint.measureText(label);
        final float labelHalfWidth = labelWidth / 2;

        final float labelLeft = x - labelHalfWidth;
        final float labelVisibleLeft = labelLeft >= 0 ? 1f : 1f - (-labelLeft / labelWidth);

        final float labelRight = x + labelHalfWidth;
        final float labelVisibleRight = labelRight < viewWidth ? 1f
                : 1f - ((labelRight - viewWidth) / labelWidth);

        final float labelVisible = Math.min(labelVisibleLeft, labelVisibleRight);

        paint.setAlpha((int) (labelVisible * 255));

        canvas.drawText(label, labelLeft, y, paint);
    }
}

From source file:jp.co.recruit_lifestyle.android.widget.WaveView.java

@Override
protected void onDraw(Canvas canvas) {
    //?????????????    canvas.drawPath(mWavePath, mShadowPaint);
    canvas.drawPath(mWavePath, mPaint);
    mWavePath.reset();//from ww w  .  j  a  v  a 2s.  c om

    //??????
    mDropTangentPath.reset();
    mDropCirclePath.reset();
    float circleCenterY = (Float) mDropCircleAnimator.getAnimatedValue();
    float circleCenterX = mWidth / 2.f;
    mDropRect.setEmpty();
    //?RectF???    
    float scale = (Float) mDisappearCircleAnimator.getAnimatedValue();
    float vertical = (Float) mDropBounceVerticalAnimator.getAnimatedValue();
    float horizontal = (Float) mDropBounceHorizontalAnimator.getAnimatedValue();
    mDropRect.set(
            circleCenterX - mDropCircleRadius * (1 + vertical) * scale + mDropCircleRadius * horizontal / 2,
            circleCenterY + mDropCircleRadius * (1 + horizontal) * scale - mDropCircleRadius * vertical / 2,
            circleCenterX + mDropCircleRadius * (1 + vertical) * scale - mDropCircleRadius * horizontal / 2,
            circleCenterY - mDropCircleRadius * (1 + horizontal) * scale + mDropCircleRadius * vertical / 2);
    float vertex = (Float) mDropVertexAnimator.getAnimatedValue();
    mDropTangentPath.moveTo(circleCenterX, vertex);
    //?(p1,q),(p2,q)
    double q = (Math.pow(mDropCircleRadius, 2) + circleCenterY * vertex - Math.pow(circleCenterY, 2))
            / (vertex - circleCenterY);
    //2????????    
    double b = -2.0 * mWidth / 2;
    double c = Math.pow(q - circleCenterY, 2) + Math.pow(circleCenterX, 2) - Math.pow(mDropCircleRadius, 2);
    double p1 = (-b + Math.sqrt(b * b - 4 * c)) / 2;
    double p2 = (-b - Math.sqrt(b * b - 4 * c)) / 2;
    mDropTangentPath.lineTo((float) p1, (float) q);
    mDropTangentPath.lineTo((float) p2, (float) q);
    mDropTangentPath.close();
    mShadowPath.set(mDropTangentPath);
    mShadowPath.addOval(mDropRect, Path.Direction.CCW);
    mDropCirclePath.addOval(mDropRect, Path.Direction.CCW);
    if (mDropVertexAnimator.isRunning()) {
        canvas.drawPath(mShadowPath, mShadowPaint);
    } else {
        canvas.drawPath(mDropCirclePath, mShadowPaint);
    }
    canvas.drawPath(mDropTangentPath, mPaint);
    canvas.drawPath(mDropCirclePath, mPaint);
}

From source file:biz.wiz.android.wallet.util.ViewPagerTabs.java

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

    final int viewWidth = getWidth();
    final int viewHalfWidth = viewWidth / 2;
    final int viewBottom = getHeight();

    final float density = getResources().getDisplayMetrics().density;
    final float spacing = 32 * density;

    path.reset();/*from w ww.  ja va 2s . c o m*/
    path.moveTo(viewHalfWidth, viewBottom - 5 * density);
    path.lineTo(viewHalfWidth + 5 * density, viewBottom);
    path.lineTo(viewHalfWidth - 5 * density, viewBottom);
    path.close();

    paint.setColor(Color.WHITE);
    canvas.drawPath(path, paint);

    paint.setTypeface(Typeface.DEFAULT_BOLD);
    final float y = getPaddingTop() + -paint.getFontMetrics().top;

    for (int i = 0; i < labels.size(); i++) {
        final String label = labels.get(i);

        paint.setTypeface(i == pagePosition ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
        paint.setColor(i == pagePosition ? Color.BLACK : Color.DKGRAY);

        final float x = viewHalfWidth + (maxWidth + spacing) * (i - pageOffset);
        final float labelWidth = paint.measureText(label);
        final float labelHalfWidth = labelWidth / 2;

        final float labelLeft = x - labelHalfWidth;
        final float labelVisibleLeft = labelLeft >= 0 ? 1f : 1f - (-labelLeft / labelWidth);

        final float labelRight = x + labelHalfWidth;
        final float labelVisibleRight = labelRight < viewWidth ? 1f
                : 1f - ((labelRight - viewWidth) / labelWidth);

        final float labelVisible = Math.min(labelVisibleLeft, labelVisibleRight);

        paint.setAlpha((int) (labelVisible * 255));

        canvas.drawText(label, labelLeft, y, paint);
    }
}

From source file:com.kncwallet.wallet.util.ViewPagerTabs.java

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

    final int viewWidth = getWidth();
    final int viewHalfWidth = viewWidth / 2;
    final int viewBottom = getHeight();

    final float density = getResources().getDisplayMetrics().density;
    final float spacing = 32 * density;

    path.reset();/* ww w.j a v a 2 s .co m*/
    path.moveTo(viewHalfWidth, viewBottom - 5 * density);
    path.lineTo(viewHalfWidth + 5 * density, viewBottom);
    path.lineTo(viewHalfWidth - 5 * density, viewBottom);
    path.close();

    paint.setColor(Color.TRANSPARENT);
    canvas.drawPath(path, paint);

    paint.setTypeface(Typeface.DEFAULT_BOLD);
    final float y = getPaddingTop() + -paint.getFontMetrics().top;

    for (int i = 0; i < labels.size(); i++) {
        final String label = labels.get(i);

        paint.setTypeface(i == pagePosition ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
        paint.setColor(i == pagePosition ? Color.WHITE : Color.WHITE);

        final float x = viewHalfWidth + (maxWidth + spacing) * (i - pageOffset);
        final float labelWidth = paint.measureText(label);
        final float labelHalfWidth = labelWidth / 2;

        final float labelLeft = x - labelHalfWidth;
        final float labelVisibleLeft = labelLeft >= 0 ? 1f : 1f - (-labelLeft / labelWidth);

        final float labelRight = x + labelHalfWidth;
        final float labelVisibleRight = labelRight < viewWidth ? 1f
                : 1f - ((labelRight - viewWidth) / labelWidth);

        final float labelVisible = Math.min(labelVisibleLeft, labelVisibleRight);

        paint.setAlpha((int) (labelVisible * 255));

        canvas.drawText(label, labelLeft, y, paint);
    }
}

From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java

public void drawTrueNorthArrow(Canvas canvas, float drawnAngle) {
    trueNorthArrowPaint.reset();//from w w  w . ja  v  a  2 s .c o m
    trueNorthArrowPaint.setColor(Color.RED);
    trueNorthArrowPaint.setStyle(Paint.Style.FILL);
    trueNorthArrowPaint.setAlpha(100);
    int r = Radius / 12;
    // Construct a wedge-shaped path
    mPath.reset();
    mPath.moveTo(px, py - px);
    mPath.lineTo(px - r, py);
    mPath.lineTo(px, py + r);
    mPath.lineTo(px + r, py);
    mPath.addCircle(px, py, r, Path.Direction.CCW);
    mPath.close();
    canvas.drawPath(mPath, trueNorthArrowPaint);
    dashedPaint.setColor(Color.RED);
    canvas.drawLine(px, py - px, px, py + Radius, dashedPaint);
    canvas.drawCircle(px, py, 5, dashedPaint);
    canvas.restore();
}