Example usage for android.graphics Path lineTo

List of usage examples for android.graphics Path lineTo

Introduction

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

Prototype

public void lineTo(float x, float y) 

Source Link

Document

Add a line from the last point to the specified point (x,y).

Usage

From source file:com.wanikani.androidnotifier.graph.HistogramPlot.java

protected void drawBar(Canvas canvas, Samples bar, float left, float right) {
    long base, height;
    float top, tbl;
    Paint lpaint;/*from   w  w w  .j  a v a 2s . c  o m*/
    Paint paint;
    Path path;
    RectF rect;

    top = vp.getY(vp.yMax);
    base = 0;
    for (Sample sample : bar.samples) {
        if (sample.value > 0) {
            height = sample.value;

            if (base > vp.yMax)
                ;
            else if (base + height > vp.yMax) {
                path = new Path();
                path.moveTo(left, vp.getY(base));
                path.lineTo(left, top);
                path.lineTo(left + (right - left) / 3, top - 10);
                path.lineTo(left + (right - left) * 2 / 3, top + 5);
                path.lineTo(right, top);
                path.lineTo(right, vp.getY(base));
                path.close();
                canvas.drawPath(path, pas.series.get(sample.series));
            } else {
                rect = new RectF(left, vp.getY(base + height), right, vp.getY(base));
                rect.intersect(meas.plotArea);
                paint = pas.series.get(sample.series);
                paint.setStyle(Style.FILL);
                canvas.drawRect(rect, paint);
                paint.setStyle(Style.STROKE);
                canvas.drawRect(rect, paint);
            }
            base += height;
        }
    }

    if (base <= vp.yMax) {
        lpaint = pas.levelupPaint;
        tbl = vp.getY(base) - meas.headroom / 2;
    } else {
        lpaint = pas.levelupPaintInside;
        tbl = vp.getY(vp.yMax) + meas.margin;
    }

    if (base > 0 && drawTotal)
        canvas.drawText(Long.toString(base), (left + right) / 2, tbl, lpaint);
}

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);
        return;//from   w w w . j  a  va  2s  . c  o  m
    }

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

From source file:com.wanikani.androidnotifier.graph.TYPlot.java

/**
 * Draws a segment containins samples/*from w  w w .j  a v a2 s  .  co  m*/
 * @param canvas the canvas
 * @param series the series
 * @param interval the interval
 * @param base a float array initially set to zero, and updated by this method
 * @param samples the samples 
 */
protected void drawPlot(Canvas canvas, Pager.Series series, Pager.Interval interval, float base[],
        float samples[]) {
    Path path;
    Paint p;
    int i, n;

    p = pas.series.get(series);
    n = interval.stop - interval.start + 1;
    if (p == null || samples.length == 0 || n <= 0)
        return;

    path = new Path();

    path.moveTo(vp.getRelPosition(interval.start + n), vp.getY(base[n - 1]));

    for (i = n - 1; i >= 0; i--) {
        path.lineTo(vp.getRelPosition(interval.start + i), vp.getY(base[i]));
        base[i] += samples[i];
    }

    for (i = 0; i < n; i++)
        path.lineTo(vp.getRelPosition(interval.start + i), vp.getY(base[i]));

    path.lineTo(vp.getRelPosition(interval.start + n), vp.getY(base[n - 1]));

    path.close();

    canvas.drawPath(path, p);
}

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

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

    {/*from  w  ww  . j  av  a2  s. c o  m*/
        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.acceleratedio.pac_n_zoom.AnimActivity.java

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

    Integer[] crt_pnt = pnts.get(0);
    int pnt_nmbr = pnts.size();
    int min_x = crt_pnt[0];
    int max_x = crt_pnt[0];
    int min_y = crt_pnt[1];
    int max_y = 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);//from  ww w .  j a  v a2s. c  o m
        if (crt_pnt[0] < min_x)
            min_x = crt_pnt[0];
        if (crt_pnt[0] > max_x)
            max_x = crt_pnt[0];
        if (crt_pnt[1] < min_y)
            min_y = crt_pnt[1];
        if (crt_pnt[1] > max_y)
            max_y = crt_pnt[1];
    }

    float x_dif = (float) (max_x - min_x) / orgnl_iv_wdth;
    float y_dif = (float) (max_y - min_y) / orgnl_iv_hght;
    float crt_scl;
    float ivWdth;
    float ivHght;

    if (orgnl_iv_wdth > 480)
        ivWdth = 480;
    else
        ivWdth = orgnl_iv_wdth;

    if (orgnl_iv_hght > 680)
        ivHght = 680;
    else
        ivHght = orgnl_iv_hght;

    if (x_dif >= y_dif)
        crt_scl = (float) ivWdth / svg_data.svg.width * svg_data.g_scl;
    else
        crt_scl = (float) ivHght / svg_data.svg.height * svg_data.g_scl;

    crt_pnt = pnts.get(0);
    float x_scl = crt_pnt[0] * crt_scl;
    float y_scl = crt_pnt[1] * crt_scl;
    path.moveTo(x_scl, y_scl);

    for (int pnt_mbr = 1; pnt_mbr < pnt_nmbr; pnt_mbr += 1) {

        crt_pnt = pnts.get(pnt_mbr);
        x_scl = crt_pnt[0] * crt_scl;
        y_scl = crt_pnt[1] * crt_scl;
        path.lineTo(x_scl, y_scl);
    }
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private void initGridH(ShapeDrawable drawable, Path path, int color, int width, int height) {
    path.rewind();//from   w w  w.  j  ava2  s .c o m
    float cellHeight = height / NUM_ROWS;
    for (int i = 0; i < NUM_ROWS; ++i) {
        path.moveTo(0, i * cellHeight);
        path.lineTo(width, i * cellHeight);
    }

    float offset = NUM_COLUMNS * 5;
    drawable.setShape(new PathShape(path, width, height));
    drawable.getPaint().setStyle(Paint.Style.STROKE);
    drawable.getPaint().setColor(color);
    drawable.getPaint().setPathEffect(new DashPathEffect(new float[] { 1, (width - offset) / offset }, 0));
    drawable.setBounds(0, 0, width, height);
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private void initGridV(ShapeDrawable drawable, Path path, int color, int width, int height) {
    path.rewind();//from ww  w. ja v  a2s  .  c o  m
    float cellWidth = width / NUM_COLUMNS;
    for (int i = 0; i < NUM_COLUMNS; ++i) {
        path.moveTo(i * cellWidth, 0);
        path.lineTo(i * cellWidth, height);
    }

    float offset = NUM_ROWS * 5;
    drawable.setShape(new PathShape(path, width, height));
    drawable.getPaint().setStyle(Paint.Style.STROKE);
    drawable.getPaint().setColor(color);
    drawable.getPaint().setPathEffect(new DashPathEffect(new float[] { 1, (height - offset) / offset }, 0));
    drawable.setBounds(0, 0, width, height);
}

From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java

public void parseJSON(String jsonFile) {
    if (jsonFile != null) {
        // Load all the JSONs with the numbers information
        try {/*www . j  a v  a  2 s .co  m*/
            JSONObject obj = new JSONObject(loadJSONFromAsset(jsonFile));
            Log.d(TAG, "SHAPE SHADOW JSON FILE " + jsonFile + ": LOADED");

            id = obj.getString("id");

            JSONArray jsonPathData;
            JSONArray jsonShadowData;

            if (!id.equals("5")) {
                jsonPathData = obj.getJSONArray("path");
                jsonShadowData = obj.getJSONArray("shadow");

                Log.d(TAG, "JSON PATH DATA LENGTH: " + jsonPathData.length() + "");
                Log.d(TAG, "JSON SHADOW DATA LENGTH: " + jsonShadowData.length() + "");

                shapePath.reset();
                for (int i = 0; i < jsonPathData.length(); i++) {
                    try {
                        JSONObject elem = jsonPathData.getJSONObject(i);
                        String type = elem.getString("type");
                        JSONArray data = elem.getJSONArray("data");
                        if (type.equals("move")) {
                            shapePath.moveTo((float) data.getInt(0), (float) data.getInt(1));
                        } else if (type.equals("line")) {
                            shapePath.lineTo((float) data.getInt(0), (float) data.getInt(1));
                        } else if (type.equals("bezier")) {
                            shapePath.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                    (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                    (float) data.getInt(5));
                        }
                    } catch (JSONException e) {
                        Log.d(TAG, "JSON ELEM EXCEPTION" + e.getMessage() + "");
                    }
                }
                shapePath.close();

                Random r = new Random();
                r.nextGaussian();

                JSONArray holesContainer = obj.getJSONArray("holes");
                Path holePath = new Path();
                for (int i = 0; i < holesContainer.length(); i++) {
                    JSONObject jsonInside = holesContainer.getJSONObject(i);
                    JSONArray hole = jsonInside.getJSONArray("data");
                    holePath.reset();
                    for (int j = 0; j < hole.length(); j++) {
                        try {
                            JSONObject elem = hole.getJSONObject(j);
                            String type = elem.getString("type");
                            JSONArray data = elem.getJSONArray("data");
                            if (type.equals("move")) {
                                holePath.moveTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("line")) {
                                holePath.lineTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("bezier")) {
                                holePath.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                        (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                        (float) data.getInt(5));
                            }
                        } catch (JSONException e) {
                            Log.d(TAG, "JSON HOLE EXCEPTION" + e.getMessage() + "");
                        }
                    }
                    holePath.close();
                    shapePath.op(holePath, Path.Op.DIFFERENCE);
                }

                pathTransform.reset();
                pathTransform.setScale(scale + 0.04f, scale + 0.04f);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                pathTransform.setTranslate(positionX - 0.3f, positionY - 0.3f);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                int shadowTmpX;
                int shadowTmpY;

                shadowPaths.clear();
                vertexArray.clear();

                for (int i = 0; i < jsonShadowData.length(); i += 2) {
                    shadowTmpX = jsonShadowData.getInt(i);
                    shadowTmpY = jsonShadowData.getInt(i + 1);
                    addVertex(shadowTmpX, shadowTmpY);
                }
            } else {
                jsonPathData = obj.getJSONArray("path");
                jsonShadowData = obj.getJSONArray("shadow");

                Log.d(TAG, "JSON PATH DATA LENGTH: " + jsonPathData.length() + "");
                Log.d(TAG, "JSON SHADOW DATA LENGTH: " + jsonShadowData.length() + "");

                shapePath.reset();
                for (int i = 0; i < jsonPathData.length(); i++) {
                    JSONArray cords = jsonPathData.getJSONArray(i);
                    Path chunk = new Path();
                    chunk.reset();
                    for (int j = 0; j < cords.length(); j++) {
                        try {
                            JSONObject elem = cords.getJSONObject(j);
                            String type = elem.getString("type");
                            JSONArray data = elem.getJSONArray("data");
                            if (type.equals("move")) {
                                chunk.moveTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("line")) {
                                chunk.lineTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("bezier")) {
                                chunk.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                        (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                        (float) data.getInt(5));
                            }
                        } catch (JSONException e) {
                            Log.d(TAG, "JSON 5 NUMBER ELEM EXCEPTION" + e.getMessage() + "");
                        }
                    }
                    chunk.close();
                    shapePath.op(chunk, Path.Op.UNION);
                }

                pathTransform.reset();
                pathTransform.setScale(scale, scale);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                pathTransform.setTranslate(positionX, positionY);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                shadowPaths.clear();
                vertexArray.clear();

                int shadowTmpX;
                int shadowTmpY;
                for (int i = 0; i < jsonShadowData.length(); i++) {
                    JSONArray coords = jsonShadowData.getJSONArray(i);
                    for (int j = 0; j < coords.length(); j += 2) {
                        shadowTmpX = coords.getInt(j);
                        shadowTmpY = coords.getInt(j + 1);
                        addVertex((float) shadowTmpX, (float) shadowTmpY);
                    }

                }
            }
        } catch (JSONException e) {
            Log.d(TAG, "JSON ROOT EXCEPTION" + e.getMessage() + "");
        }
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.drawable.LineMorphingDrawable.java

private void updatePathWithState(Path path, State state) {
    if (state.links != null) {
        for (int i = 0; i < state.links.length; i += 2) {
            int index1 = state.links[i] * 4;
            int index2 = state.links[i + 1] * 4;

            float x1 = getX(state.points[index1]);
            float y1 = getY(state.points[index1 + 1]);
            float x2 = getX(state.points[index1 + 2]);
            float y2 = getY(state.points[index1 + 3]);

            float x3 = getX(state.points[index2]);
            float y3 = getY(state.points[index2 + 1]);
            float x4 = getX(state.points[index2 + 2]);
            float y4 = getY(state.points[index2 + 3]);

            if (x1 == x3 && y1 == y3) {
                path.moveTo(x2, y2);/* www .  j  a v a2 s  .  c  o m*/
                path.lineTo(x1, y1);
                path.lineTo(x4, y4);
            } else if (x1 == x4 && y1 == y4) {
                path.moveTo(x2, y2);
                path.lineTo(x1, y1);
                path.lineTo(x3, y3);
            } else if (x2 == x3 && y2 == y3) {
                path.moveTo(x1, y1);
                path.lineTo(x2, y2);
                path.lineTo(x4, y4);
            } else {
                path.moveTo(x1, y1);
                path.lineTo(x2, y2);
                path.lineTo(x3, y3);
            }
        }

        for (int i = 0, count = state.points.length / 4; i < count; i++) {
            boolean exist = false;
            for (int j = 0; j < state.links.length; j++)
                if (state.links[j] == i) {
                    exist = true;
                    break;
                }

            if (exist)
                continue;

            int index = i * 4;

            path.moveTo(getX(state.points[index]), getY(state.points[index + 1]));
            path.lineTo(getX(state.points[index + 2]), getY(state.points[index + 3]));
        }
    } else {
        for (int i = 0, count = state.points.length / 4; i < count; i++) {
            int index = i * 4;

            path.moveTo(getX(state.points[index]), getY(state.points[index + 1]));
            path.lineTo(getX(state.points[index + 2]), getY(state.points[index + 3]));
        }
    }
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private int updatePath(Path path, WaveData waveData) {
    int retValue = -1;
    if (waveData == null || waveData.data == null || waveData.data.length == 0) {
        path.rewind();//w  ww  . ja va  2s.  c om
        return retValue;
    }

    retValue = 0;
    int length = Math.min(BaseScope.SAMPLE_LENGTH, waveData.data.length) - 10;
    float widthRatio = (float) (mContentWidth) / (length * DISPLAY_RATIO);
    double vScale = waveData.voltageScale;
    if (vScale == 0)
        vScale = 1.0f;

    Path newPath = new Path();
    double point = manipulatePoint(waveData.voltageOffset, vScale, waveData.data[10]);

    float j = -(length * (1 - DISPLAY_RATIO)) / 2;
    newPath.moveTo(j++ * widthRatio, (float) point);

    for (int i = 11; i < waveData.data.length; ++i, ++j) {
        point = manipulatePoint(waveData.voltageOffset, vScale, waveData.data[i]);
        newPath.lineTo(j * widthRatio, (float) point);
    }

    if (new PathMeasure(path, false).getLength() == 0) {
        path.set(newPath);
        return retValue;
    }

    if (mChangeDelay <= 0) {
        path.set(newPath);
        retValue = 1;
    } else {
        mChangeDelay--;
    }

    return retValue;
}