Example usage for android.graphics Path arcTo

List of usage examples for android.graphics Path arcTo

Introduction

In this page you can find the example usage for android.graphics Path arcTo.

Prototype

public void arcTo(RectF oval, float startAngle, float sweepAngle) 

Source Link

Document

Append the specified arc to the path as a new contour.

Usage

From source file:android.support.wear.widget.util.ArcSwipe.java

private float[][] interpolate(float[] start, float[] end, int steps, boolean isClockwise) {
    float startAngle = getAngle(start[0], start[1]);
    float endAngle = getAngle(end[0], end[1]);

    Path path = new Path();
    PathMeasure pathMeasure = new PathMeasure();
    path.moveTo(start[0], start[1]);//from   ww  w.  ja v  a  2  s  .c  om
    path.arcTo(mBounds, startAngle, getSweepAngle(startAngle, endAngle, isClockwise));
    pathMeasure.setPath(path, false);
    float pathLength = pathMeasure.getLength();

    float[][] res = new float[steps][2];
    float[] mPathTangent = new float[2];

    for (int i = 1; i < steps + 1; i++) {
        pathMeasure.getPosTan((pathLength * i) / (steps + 2f), res[i - 1], mPathTangent);
    }

    return res;
}

From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java

private void makePathBubble() {

    if (mPathBubble == null) {
        mPathBubble = new Path();
    }/*from   w  w  w .j a v  a 2 s .c  om*/

    int width = mBubbleWidth;
    int height = mBubbleHeight;
    int arrowWidth = width / 3;

    //Rect r = new Rect(Math.max(getPaddingLeft()-width/2-arrowWidth/4, mProgress*mWidth/100-width/2-arrowWidth/4), mHeight/2-height + calculatedeltaY(), Math.max(getPaddingLeft()+width/2-arrowWidth/4, mProgress*mWidth/100+width/2-arrowWidth/4), mHeight/2+height-height + calculatedeltaY());
    Rect r = new Rect((int) (Math.max(getPaddingLeft() - width / 2, mProgress * mWidth / 100 - width / 2)),
            (int) (mHeight / 2 - height + calculateDeltaY()),
            (int) (Math.max(getPaddingLeft() + width / 2, mProgress * mWidth / 100 + width / 2)),
            (int) (mHeight / 2 + height - height + calculateDeltaY()));
    int arrowHeight = (int) (arrowWidth / 1.5f);
    int radius = 8;

    Path path = new Path();

    // Down arrow
    path.moveTo(r.left + r.width() / 2 - arrowWidth / 2, r.top + r.height() - arrowHeight);
    bubbleAnchorX = r.left + r.width() / 2;
    bubbleAnchorY = r.top + r.height();
    path.lineTo(bubbleAnchorX, bubbleAnchorY);
    path.lineTo(r.left + r.width() / 2 + arrowWidth / 2, r.top + r.height() - arrowHeight);

    // Go to bottom-right
    path.lineTo(r.left + r.width() - radius, r.top + r.height() - arrowHeight);

    // Bottom-right arc
    path.arcTo(new RectF(r.left + r.width() - 2 * radius, r.top + r.height() - arrowHeight - 2 * radius,
            r.left + r.width(), r.top + r.height() - arrowHeight), 90, -90);

    // Go to upper-right
    path.lineTo(r.left + r.width(), r.top + arrowHeight);

    // Upper-right arc
    path.arcTo(new RectF(r.left + r.width() - 2 * radius, r.top, r.right, r.top + 2 * radius), 0, -90);

    // Go to upper-left
    path.lineTo(r.left + radius, r.top);

    // Upper-left arc
    path.arcTo(new RectF(r.left, r.top, r.left + 2 * radius, r.top + 2 * radius), 270, -90);

    // Go to bottom-left
    path.lineTo(r.left, r.top + r.height() - arrowHeight - radius);

    // Bottom-left arc
    path.arcTo(new RectF(r.left, r.top + r.height() - arrowHeight - 2 * radius, r.left + 2 * radius,
            r.top + r.height() - arrowHeight), 180, -90);

    path.close();

    mPathBubble.set(path);
}

From source file:de.telekom.pde.codelibrary.ui.layout.PDESwipeRefreshLayout.java

private void drawTrigger(Canvas canvas, int cx, int cy) {
    float innerRadius;
    float outerRadius;
    Path circlePath;

    if (mTriggerPercentage < 0.05f)
        return;//www.  j  av  a  2 s . c o  m

    innerRadius = 0.7f * PDEBuildingUnits.BU();
    outerRadius = 0.9f * PDEBuildingUnits.BU();

    canvas.drawCircle(cx, cy, PDEBuildingUnits.BU(), mPaint);

    circlePath = new Path();

    circlePath.moveTo(cx, cy - innerRadius);
    circlePath.lineTo(cx, cy - outerRadius);

    circlePath.arcTo(new RectF(cx - outerRadius, cy - outerRadius, cx + outerRadius, cy + outerRadius), -90.0f,
            mTriggerPercentage * 360.0f);

    circlePath.lineTo((float) (cx + Math.sin(degreesToRadians(mTriggerPercentage * 360.0f)) * innerRadius),
            (float) (cy - Math.cos(degreesToRadians(mTriggerPercentage * 360.0f)) * innerRadius));

    circlePath.arcTo(new RectF(cx - innerRadius, cy - innerRadius, cx + innerRadius, cy + innerRadius),
            -90.0f + mTriggerPercentage * 360.0f, -mTriggerPercentage * 360.0f);

    canvas.drawPath(circlePath, mWhitePaint);

}

From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java

private static void drawArc(Path p, float lastX, float lastY, float x, float y, float rx, float ry, float theta,
        int largeArc, int sweepArc) {
    // Log.d("drawArc", "from (" + lastX + "," + lastY + ") to (" + x + ","+
    // y + ") r=(" + rx + "," + ry +
    // ") theta=" + theta + " flags="+ largeArc + "," + sweepArc);

    // http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes

    if (rx == 0 || ry == 0) {
        p.lineTo(x, y);//w ww  .j av  a 2s .co  m
        return;
    }

    if (x == lastX && y == lastY) {
        return; // nothing to draw
    }

    rx = Math.abs(rx);
    ry = Math.abs(ry);

    final float thrad = theta * (float) Math.PI / 180;
    final float st = FloatMath.sin(thrad);
    final float ct = FloatMath.cos(thrad);

    final float xc = (lastX - x) / 2;
    final float yc = (lastY - y) / 2;
    final float x1t = ct * xc + st * yc;
    final float y1t = -st * xc + ct * yc;

    final float x1ts = x1t * x1t;
    final float y1ts = y1t * y1t;
    float rxs = rx * rx;
    float rys = ry * ry;

    float lambda = (x1ts / rxs + y1ts / rys) * 1.001f; // add 0.1% to be
    // sure that no out
    // of range occurs
    // due to
    // limited precision
    if (lambda > 1) {
        float lambdasr = FloatMath.sqrt(lambda);
        rx *= lambdasr;
        ry *= lambdasr;
        rxs = rx * rx;
        rys = ry * ry;
    }

    final float R = FloatMath.sqrt((rxs * rys - rxs * y1ts - rys * x1ts) / (rxs * y1ts + rys * x1ts))
            * ((largeArc == sweepArc) ? -1 : 1);
    final float cxt = R * rx * y1t / ry;
    final float cyt = -R * ry * x1t / rx;
    final float cx = ct * cxt - st * cyt + (lastX + x) / 2;
    final float cy = st * cxt + ct * cyt + (lastY + y) / 2;

    final float th1 = angle(1, 0, (x1t - cxt) / rx, (y1t - cyt) / ry);
    float dth = angle((x1t - cxt) / rx, (y1t - cyt) / ry, (-x1t - cxt) / rx, (-y1t - cyt) / ry);

    if (sweepArc == 0 && dth > 0) {
        dth -= 360;
    } else if (sweepArc != 0 && dth < 0) {
        dth += 360;
    }

    // draw
    if ((theta % 360) == 0) {
        // no rotate and translate need
        arcRectf.set(cx - rx, cy - ry, cx + rx, cy + ry);
        p.arcTo(arcRectf, th1, dth);
    } else {
        // this is the hard and slow part :-)
        arcRectf.set(-rx, -ry, rx, ry);

        arcMatrix.reset();
        arcMatrix.postRotate(theta);
        arcMatrix.postTranslate(cx, cy);
        arcMatrix.invert(arcMatrix2);

        p.transform(arcMatrix2);
        p.arcTo(arcRectf, th1, dth);
        p.transform(arcMatrix);
    }
}