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.donsen.svg.ui.common.AnimatedSvgView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mState == STATE_NOT_STARTED || mGlyphData == null) {
        return;//from w  ww  . ja va2  s  .  c o  m
    }

    long t = System.currentTimeMillis() - mStartTime;

    // Draw outlines (starts as traced)
    for (int i = 0; i < mGlyphData.length; i++) {
        float phase = MathUtil.constrain(0, 1,
                (t - (mTraceTime - mTraceTimePerGlyph) * i * 1f / mGlyphData.length) * 1f / mTraceTimePerGlyph);
        float distance = INTERPOLATOR.getInterpolation(phase) * mGlyphData[i].length;
        mGlyphData[i].paint.setColor(mTraceResidueColors[i]);
        mGlyphData[i].paint
                .setPathEffect(new DashPathEffect(new float[] { distance, mGlyphData[i].length }, 0));
        canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint);

        mGlyphData[i].paint.setColor(mTraceColors[i]);
        mGlyphData[i].paint.setPathEffect(new DashPathEffect(
                new float[] { 0, distance, phase > 0 ? mMarkerLength : 0, mGlyphData[i].length }, 0));
        canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint);
    }

    if (t > mFillStart) {
        if (mState < STATE_FILL_STARTED) {
            changeState(STATE_FILL_STARTED);
        }

        // If after fill start, draw fill
        float phase = MathUtil.constrain(0, 1, (t - mFillStart) * 1f / mFillTime);
        for (int i = 0; i < mGlyphData.length; i++) {
            GlyphData glyphData = mGlyphData[i];
            mFillPaint.setARGB((int) (phase * ((float) mFillAlphas[i] / (float) 255) * 255), mFillReds[i],
                    mFillGreens[i], mFillBlues[i]);
            canvas.drawPath(glyphData.path, mFillPaint);
        }
    }

    if (t < mFillStart + mFillTime) {
        // draw next frame if animation isn't finished
        ViewCompat.postInvalidateOnAnimation(this);
    } else {
        changeState(STATE_FINISHED);
    }
}

From source file:dimchoi.com.my.widget.AnimatedSvgView.java

@SuppressLint("DrawAllocation")
@Override/*from   ww  w. ja  v  a 2 s.  co m*/
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mState == STATE_NOT_STARTED || mGlyphData == null) {
        return;
    }

    long t = System.currentTimeMillis() - mStartTime;

    // Draw outlines (starts as traced)
    for (int i = 0; i < mGlyphData.length; i++) {
        float phase = constrain(0, 1,
                (t - (mTraceTime - mTraceTimePerGlyph) * i * 1f / mGlyphData.length) * 1f / mTraceTimePerGlyph);
        float distance = INTERPOLATOR.getInterpolation(phase) * mGlyphData[i].length;
        mGlyphData[i].paint.setColor(mTraceResidueColors[i]);
        mGlyphData[i].paint
                .setPathEffect(new DashPathEffect(new float[] { distance, mGlyphData[i].length }, 0));
        canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint);

        mGlyphData[i].paint.setColor(mTraceColors[i]);
        mGlyphData[i].paint.setPathEffect(new DashPathEffect(
                new float[] { 0, distance, phase > 0 ? mMarkerLength : 0, mGlyphData[i].length }, 0));
        canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint);
    }

    if (t > mFillStart) {
        if (mState < STATE_FILL_STARTED) {
            changeState(STATE_FILL_STARTED);
        }

        // If after fill start, draw fill
        float phase = constrain(0, 1, (t - mFillStart) * 1f / mFillTime);
        for (int i = 0; i < mGlyphData.length; i++) {
            GlyphData glyphData = mGlyphData[i];
            int fillColor = mFillColors[i];
            int a = (int) (phase * ((float) Color.alpha(fillColor) / (float) 255) * 255);
            int r = Color.red(fillColor);
            int g = Color.green(fillColor);
            int b = Color.blue(fillColor);
            mFillPaint.setARGB(a, r, g, b);
            canvas.drawPath(glyphData.path, mFillPaint);
        }
    }

    if (t < mFillStart + mFillTime) {
        // draw next frame if animation isn't finished
        ViewCompat.postInvalidateOnAnimation(this);
    } else {
        changeState(STATE_FINISHED);
    }
}

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

/**
 * Draw a spade/*from   w ww . j  a  v  a  2 s  .  c o m*/
 * @param canvas canvas to draw on
 * @param width width of the spade
 * @param height height of the spade
 */
public void drawSpade(final Canvas canvas, final float width, final float height) {
    final Paint paint = getBlackPaint();
    final float width_half = width / 2;
    final float width_quarter = width / 4;
    final float width_fifth = width / 5;
    final float width_25th = width / 25;
    final float height_3_5th = height / 5 * 3;
    final Path path = new Path();
    path.moveTo(width_half, 0);
    path.lineTo(width - width_25th, height_3_5th);
    path.lineTo(width_25th, height_3_5th);
    path.lineTo(width_half, 0);
    path.close();
    canvas.drawPath(path, paint);
    canvas.drawCircle(width_quarter, height_3_5th, width_fifth, paint);
    canvas.drawCircle(width_quarter * 3, height_3_5th, width_fifth, paint);
    drawPedestal(canvas, width, height);
}

From source file:com.juce.JuceAppActivity.java

public final int[] renderGlyph (char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds)
{
    Path p = new Path();
    paint.getTextPath (String.valueOf (glyph), 0, 1, 0.0f, 0.0f, p);

    RectF boundsF = new RectF();
    p.computeBounds (boundsF, true);/*from   www.j  a  v a2s. c om*/
    matrix.mapRect (boundsF);

    boundsF.roundOut (bounds);
    bounds.left--;
    bounds.right++;

    final int w = bounds.width();
    final int h = Math.max (1, bounds.height());

    Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas (bm);
    matrix.postTranslate (-bounds.left, -bounds.top);
    c.setMatrix (matrix);
    c.drawPath (p, paint);

    final int sizeNeeded = w * h;
    if (cachedRenderArray.length < sizeNeeded)
        cachedRenderArray = new int [sizeNeeded];

    bm.getPixels (cachedRenderArray, 0, w, 0, 0, w, h);
    bm.recycle();
    return cachedRenderArray;
}

From source file:com.example.accessibility.ListenerView.java

@Override
public void onDraw(Canvas canvas) {

    paintWhite.setStrokeWidth(4);/*  ww  w  .  j  ava2 s . c  o  m*/
    paintWhite.setARGB(128, 255, 255, 255);
    paintWhite.setStyle(Paint.Style.FILL_AND_STROKE);
    paintWhite.setAntiAlias(true);

    paintBlack.setStrokeWidth(4);
    paintBlack.setARGB(128, 0, 0, 0);
    paintBlack.setStyle(Paint.Style.FILL_AND_STROKE);
    paintBlack.setAntiAlias(true);

    int left = getPaddingLeft();
    //int top = getPaddingTop();
    int right = getWidth() - getPaddingRight();
    int bottom = getHeight() - getPaddingBottom();

    //-----------------------------------------------------------------------------//
    //Drawing general buttons
    canvas.drawRect(right - 80, bottom - 90, right, bottom - 10, paintWhite);
    canvas.drawRect(right - 70, bottom - 55, right - 10, bottom - 20, paintBlack);
    canvas.drawRect(left, bottom - 90, left + 80, bottom - 10, paintWhite);

    a.set(right - 70, bottom - 55);
    b.set(right - 10, bottom - 55);
    c.set(right - 40, bottom - 80);
    path.moveTo(a.x, a.y);
    path.lineTo(b.x, b.y);
    path.lineTo(c.x, c.y);
    path.lineTo(a.x, a.y);
    path.close();
    canvas.drawPath(path, paintBlack);

    paintBlack.setStyle(Paint.Style.STROKE);
    canvas.drawRect(left + 30, bottom - 40, left + 60, bottom - 40, paintBlack);
    oval.set(left + 50, bottom - 60, left + 70, bottom - 40);
    canvas.drawArc(oval, 270, 180, true, paintBlack);
    canvas.drawRect(left + 10, bottom - 60, left + 60, bottom - 60, paintBlack);
    //canvas.drawRect(left+10, bottom-70, left+20, bottom-60, paintBlack);
    //canvas.drawRect(left+10, bottom-60, left+20, bottom-50, paintBlack);         
    a.set(left + 20, bottom - 50);
    b.set(left + 10, bottom - 60);
    c.set(left + 20, bottom - 70);
    path.moveTo(a.x, a.y);
    path.lineTo(b.x, b.y);
    path.moveTo(b.x, b.y);
    path.lineTo(c.x, c.y);
    canvas.drawPath(path, paintBlack);
    paintBlack.setStyle(Paint.Style.FILL_AND_STROKE);

}

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);//  w ww .  j  a  v a 2  s .  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:com.waz.zclient.views.images.CircularSeekBar.java

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

    canvas.translate(this.getWidth() / 2f, this.getHeight() / 2f);

    canvas.drawPath(circlePath, circlePaint);
    canvas.drawPath(circleProgressPath, circleProgressGlowPaint);
    canvas.drawPath(circleProgressPath, circleProgressPaint);

    canvas.drawPath(circlePath, circleFillPaint);

    if (showPointer) {
        canvas.drawCircle(pointerPositionXY[0], pointerPositionXY[1], pointerRadius + pointerHaloWidth,
                pointerHaloPaint);/*from w w w .  ja  va2 s  .c o  m*/
        canvas.drawCircle(pointerPositionXY[0], pointerPositionXY[1], pointerRadius, pointerPaint);
        if (userIsMovingPointer) {
            canvas.drawCircle(pointerPositionXY[0], pointerPositionXY[1],
                    pointerRadius + pointerHaloWidth + (pointerHaloBorderWidth / 2f), pointerHaloBorderPaint);
        }
    }
}

From source file:com.mukesh.OtpView.java

private void drawAnchorLine(Canvas canvas) {
    float cx = itemCenterPoint.x;
    float cy = itemCenterPoint.y;
    paint.setStrokeWidth(1);//from   w w  w  .  ja  va  2 s  . c om
    cx -= paint.getStrokeWidth() / 2;
    cy -= paint.getStrokeWidth() / 2;
    path.reset();
    path.moveTo(cx, itemBorderRect.top);
    path.lineTo(cx, itemBorderRect.top + Math.abs(itemBorderRect.height()));
    canvas.drawPath(path, paint);
    path.reset();
    path.moveTo(itemBorderRect.left, cy);
    path.lineTo(itemBorderRect.left + Math.abs(itemBorderRect.width()), cy);
    canvas.drawPath(path, paint);
    path.reset();
    paint.setStrokeWidth(lineWidth);
}

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

/**
 * Draw a pedestal ( clubs and spades stand on this )
 * @param canvas canvas to draw on/*from  w w w . jav  a 2 s  . c om*/
 * @param width width of the pedestal
 * @param height height of the pedestal
 */
public void drawPedestal(final Canvas canvas, final float width, final float height) {
    final Paint paint = getBlackPaint();
    final float width_half = width / 2;
    final float width_fifth = width / 5;
    final float width_3_5ths = width_fifth * 3;
    final float height_5th = height / 5;
    canvas.drawRect(width_3_5ths, height_5th, width - width_3_5ths, height, paint);
    final Path path = new Path();
    path.moveTo(width_fifth, height);
    path.lineTo(width_half, height - height_5th);
    path.lineTo(width - width_fifth, height);
    path.lineTo(width_fifth, height);
    path.close();
    canvas.drawPath(path, paint);
}

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

/**
 * Draw a heart/*from  w  ww.jav  a2 s. c o m*/
 * @param canvas canvas to draw on
 * @param width width of the heart
 * @param height height of the heart
 */
public void drawHeart(final Canvas canvas, final float width, final float height) {
    final Paint paint = getRedPaint();
    final float width_half = width / 2;
    final float width_quarter = width / 4;
    final float height_quarter = height / 4;
    final float height_third = height / 3;
    canvas.drawCircle(width_quarter, height_quarter, width_quarter, paint);
    canvas.drawCircle(width_quarter * 3, height_quarter, width_quarter, paint);
    final Path path = new Path();
    path.moveTo(0, height_third);
    path.lineTo(width_half, height);
    path.lineTo(width, height_third);
    path.lineTo(0, height_third);
    path.close();
    canvas.drawPath(path, paint);
}