Example usage for android.graphics Path moveTo

List of usage examples for android.graphics Path moveTo

Introduction

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

Prototype

public void moveTo(float x, float y) 

Source Link

Document

Set the beginning of the next contour to the point (x,y).

Usage

From source file:com.acceleratedio.pac_n_zoom.DrawSVG.java

public static void ld_pth_pnts(ArrayList<Integer[]> pnts, Path path) {

    int pnt_nmbr = pnts.size();
    Integer[] crt_pnt = pnts.get(0);
    path.moveTo(crt_pnt[0], crt_pnt[1]);

    // Loop through the points of a path
    for (int pnt_mbr = 1; pnt_mbr < pnt_nmbr; pnt_mbr += 1) {

        crt_pnt = pnts.get(pnt_mbr);/* w w w .ja  v a2  s .c om*/
        path.lineTo(crt_pnt[0], crt_pnt[1]);
    }
}

From source file:ee.ioc.phon.android.speak.Utils.java

static Bitmap bytesToBitmap(byte[] byteBuffer, int w, int h, int startPosition, int endPosition) {
    final ShortBuffer waveBuffer = ByteBuffer.wrap(byteBuffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
    final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    final Canvas c = new Canvas(b);
    final Paint paint = new Paint();
    paint.setColor(0xFFFFFFFF); // 0xAARRGGBB
    paint.setAntiAlias(true);/*from   w w  w .  j  av  a2  s.c om*/
    paint.setStyle(Paint.Style.STROKE);
    paint.setAlpha(80);

    final PathEffect effect = new CornerPathEffect(3);
    paint.setPathEffect(effect);

    final int numSamples = waveBuffer.remaining();
    int endIndex;
    if (endPosition == 0) {
        endIndex = numSamples;
    } else {
        endIndex = Math.min(endPosition, numSamples);
    }

    int startIndex = startPosition - 2000; // include 250ms before speech
    if (startIndex < 0) {
        startIndex = 0;
    }
    final int numSamplePerWave = 200; // 8KHz 25ms = 200 samples
    final float scale = 10.0f / 65536.0f;

    final int count = (endIndex - startIndex) / numSamplePerWave;
    final float deltaX = 1.0f * w / count;
    int yMax = h / 2;
    Path path = new Path();
    c.translate(0, yMax);
    float x = 0;
    path.moveTo(x, 0);
    for (int i = 0; i < count; i++) {
        final int avabs = getAverageAbs(waveBuffer, startIndex, i, numSamplePerWave);
        int sign = ((i & 01) == 0) ? -1 : 1;
        final float y = Math.min(yMax, avabs * h * scale) * sign;
        path.lineTo(x, y);
        x += deltaX;
        path.lineTo(x, y);
    }
    if (deltaX > 4) {
        paint.setStrokeWidth(2);
    } else {
        paint.setStrokeWidth(Math.max(0, (int) (deltaX - .05)));
    }
    c.drawPath(path, paint);
    return b;
}

From source file:Main.java

@NonNull
public static Path createBezierArcRadians(@NonNull PointF center, float radius, double startAngleRadians,
        double sweepAngleRadians, int pointsOnCircle, boolean overlapPoints, @Nullable Path addToPath) {
    final Path path = addToPath != null ? addToPath : new Path();
    if (sweepAngleRadians == 0d) {
        return path;
    }/*from  www .  jav  a 2s . co  m*/

    if (pointsOnCircle >= 1) {
        final double threshold = FULL_CIRCLE_RADIANS / pointsOnCircle;
        if (abs(sweepAngleRadians) > threshold) {
            double angle = normalizeRadians(startAngleRadians);
            PointF end, start = pointFromAngleRadians(center, radius, angle);
            path.moveTo(start.x, start.y);
            if (overlapPoints) {
                final boolean cw = sweepAngleRadians > 0; // clockwise?
                final double angleEnd = angle + sweepAngleRadians;
                while (true) {
                    double next = (cw ? ceil(angle / threshold) : floor(angle / threshold)) * threshold;
                    if (angle == next) {
                        next += threshold * (cw ? 1d : -1d);
                    }
                    final boolean isEnd = cw ? angleEnd <= next : angleEnd >= next;
                    end = pointFromAngleRadians(center, radius, isEnd ? angleEnd : next);
                    addBezierArcToPath(path, center, start, end, false);
                    if (isEnd) {
                        break;
                    }
                    angle = next;
                    start = end;
                }
            } else {
                final int n = abs((int) ceil(sweepAngleRadians / threshold));
                final double sweep = sweepAngleRadians / n;
                for (int i = 0; i < n; i++, start = end) {
                    angle += sweep;
                    end = pointFromAngleRadians(center, radius, angle);
                    addBezierArcToPath(path, center, start, end, false);
                }
            }
            return path;
        }
    }

    final PointF start = pointFromAngleRadians(center, radius, startAngleRadians);
    final PointF end = pointFromAngleRadians(center, radius, startAngleRadians + sweepAngleRadians);
    addBezierArcToPath(path, center, start, end, true);
    return path;
}

From source file:com.facebook.keyframes.util.KFPathInterpolator.java

public KFPathInterpolator(float controlX1, float controlY1, float controlX2, float controlY2) {
    Path path = new Path();
    path.moveTo(0, 0);
    path.cubicTo(controlX1, controlY1, controlX2, controlY2, 1f, 1f);
    final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */);
    final float pathLength = pathMeasure.getLength();
    final int numPoints = (int) (pathLength / PRECISION) + 1;
    mX = new float[numPoints];
    mY = new float[numPoints];
    final float[] position = new float[2];
    for (int i = 0; i < numPoints; ++i) {
        final float distance = (i * pathLength) / (numPoints - 1);
        pathMeasure.getPosTan(distance, position, null /* tangent */);
        mX[i] = position[0];/*  ww w.  jav a2s  . co  m*/
        mY[i] = position[1];
    }
}

From source file:com.mtomczak.nausicaa.DockingView.java

/**
 * Encode a list of x,y coords into a path
 *
 * @param points Points to encode//w ww  .ja  va2s.co m
 * @return The encoded path
 */
private Path encodePath(float[] points) {
    Path path = new Path();
    path.moveTo(points[0], points[1]);
    for (int i = 2; i < points.length; i += 2) {
        path.lineTo(points[i], points[i + 1]);
    }
    path.close();
    path.setFillType(Path.FillType.WINDING);
    return path;
}

From source file:com.imczy.customactivitytransition.transition.ShareElemReturnChangePosition.java

public ShareElemReturnChangePosition() {
    setPathMotion(new PathMotion() {
        @Override/*from  w  w w  .  j  a  v  a2 s.  c om*/
        public Path getPath(float startX, float startY, float endX, float endY) {
            Path path = new Path();
            path.moveTo(startX, startY);

            float controlPointX = (startX + endX) / 3;
            float controlPointY = (startY + endY) / 2;

            path.quadTo(controlPointX, controlPointY, endX, endY);
            return path;
        }
    });
}

From source file:com.imczy.customactivitytransition.transition.ChangePosition.java

public ChangePosition() {
    // ? ???//from   w  w  w. j  a  v a2s .c o  m
    setPathMotion(new PathMotion() {
        @Override
        public Path getPath(float startX, float startY, float endX, float endY) {
            Path path = new Path();
            path.moveTo(startX, startY);

            float controlPointX = (startX + endX) / 3;
            float controlPointY = (startY + endY) / 2;

            // ??, (controlPointX, controlPointY) 
            path.quadTo(controlPointX, controlPointY, endX, endY);
            return path;
        }
    });
}

From source file:net.yanzm.actionbarprogress.MaterialIndeterminateProgressDrawable.java

public MaterialIndeterminateProgressDrawable(int trackColor, int accentColor) {
    this.trackColor = trackColor;
    this.accentColor = accentColor;

    {//ww w . j  av a  2 s.c  om
        Path path = new Path();
        path.moveTo(0, 0);
        path.cubicTo(0.0375f, 0f, 0.128764607715f, 0.0895380946618f, 0.25f, 0.218553507947f);
        path.cubicTo(0.322410320025f, 0.295610602487f, 0.436666666667f, 0.417591408114f, 0.483333333333f,
                0.489826169306f);
        path.cubicTo(0.69f, 0.80972296795f, 0.793333333333f, 0.950016125212f, 1.0f, 1.0f);
        translateInterpolator2 = PathInterpolatorCompat.create(path);
    }
    {
        Path path = new Path();
        path.moveTo(0, 0);
        path.cubicTo(0.06834272400867f, 0.01992566661414f, 0.19220331656133f, 0.15855429260523f,
                0.33333333333333f, 0.34926160892842f);
        path.cubicTo(0.38410433133433f, 0.41477913453861f, 0.54945792615267f, 0.68136029463551f,
                0.66666666666667f, 0.68279962777002f);
        path.cubicTo(0.752586273196f, 0.68179620963216f, 0.737253971954f, 0.878896194318f, 1f, 1f);
        scaleInterpolator2 = PathInterpolatorCompat.create(path);
    }
    {
        Path path = new Path();
        path.moveTo(0, 0);
        path.lineTo(0.2f, 0f);
        path.cubicTo(0.3958333333336f, 0.0f, 0.474845090492f, 0.206797621729f, 0.5916666666664f,
                0.417082932942f);
        path.cubicTo(0.7151610251224f, 0.639379624869f, 0.81625f, 0.974556908664f, 1.0f, 1.0f);
        translateInterpolator1 = PathInterpolatorCompat.create(path);
    }
    {
        Path path = new Path();
        path.moveTo(0, 0);
        path.lineTo(0.3665f, 0f);
        path.cubicTo(0.47252618112021f, 0.062409910275f, 0.61541608570164f, 0.5f, 0.68325f, 0.5f);
        path.cubicTo(0.75475061236836f, 0.5f, 0.75725829093844f, 0.814510098964f, 1f, 1f);
        scaleInterpolator1 = PathInterpolatorCompat.create(path);
    }
}

From source file:com.jaspersoft.android.jaspermobile.widget.AnnotationView.java

private void addPath() {
    Paint annotationPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    annotationPaint.setColor(mColor);//from w  ww . j  av  a 2s.c om
    annotationPaint.setStyle(Paint.Style.STROKE);
    annotationPaint.setStrokeJoin(Paint.Join.ROUND);
    annotationPaint.setStrokeCap(Paint.Cap.ROUND);

    DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    int strokeSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mSize, metrics);
    annotationPaint.setStrokeWidth(strokeSize);

    Path annotationPath = new Path();
    annotationPath.moveTo(mStartX, mStartY);

    mDrawingCache.add(new Pair<>(annotationPaint, annotationPath));
}

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();//from   w w w  .  j ava 2 s .c  o m

    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);
    }
}