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.chj.indicator.lib.TriangleSlidingIndicator.java

/**
 * //from  w w  w  .j  av a 2 s  .  c  o m
 */
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates
    // between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    // 
    // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight,
    // height, rectPaint);

    float left = lineLeft;
    float top = height - indicatorHeight;
    float right = lineRight;
    float bottom = height;

    // TODO:
    Path path = new Path();
    float x1 = (right - left) / 2 + left;// :(right+left)/2
    float y1 = top;

    float x2 = x1 - triangleWidth / 2;
    float y2 = bottom;

    float x3 = x1 + triangleWidth / 2;
    float y3 = bottom;
    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x1, y1);
    path.close();

    rectPaint.setColor(Color.RED);// ?

    canvas.drawPath(path, rectPaint);

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:com.astuetz.PagerSlidingTabStripMy.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from w  w w .  java 2  s  . c  o m*/
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    //canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

    // draw underline

    //
    Path path = new Path();
    float len = 30;

    //????
    float x1 = lineLeft + (lineRight - lineLeft) / 2;
    float y1 = height - indicatorHeight;
    float x2 = x1 + len / 2;
    float y2 = height;
    float x3 = x1 - len / 2;
    float y3 = height;

    path.moveTo(x1, y1);
    path.lineTo(x2, y3);
    path.lineTo(x3, y3);
    path.lineTo(x1, y1);
    canvas.drawPath(path, rectPaint);

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

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;//from ww w.  j a v a 2 s.  c om

    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.gx.appstore.lib.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//  www .j av  a 2 s.com
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    // 
    // 
    /**
     x1 = lineLeft+(lineRight-lineLeft)/2;
     y1 = height - indicatorHeight;
            
     x2 = x1 + triangleWidth/2;
     y2 = height;
            
     x3 = x1 - triangleWidth/2;
     y3 = height
     */
    Path path = new Path();
    float x1 = lineLeft + (lineRight - lineLeft) / 2;
    float y1 = height - indicatorHeight;

    int triangleWidth = 30;
    float x2 = x1 + triangleWidth / 2;
    float y2 = height;

    float x3 = x1 - triangleWidth / 2;
    float y3 = height;

    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x1, y1);

    //        canvas.drawPath(path, rectPaint);
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:com.astuetz.PagerSlidingTabStripExtends.java

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

    if (isInEditMode() || tabCount == 0) {
        return;// w w w  .j a v  a2 s  .c  o  m
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }
    //indicator
    //        canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
    Path path = new Path();
    float x1 = (lineRight + lineLeft) / 2;
    float y1 = height - indicatorHeight;
    //
    int triangleWidth = (int) ((lineRight - lineLeft) * 0.40f);
    float x2 = x1 + triangleWidth / 2;
    float y2 = height;
    float x3 = x1 - triangleWidth / 2;
    float y3 = height;

    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x1, y1);
    canvas.drawPath(path, rectPaint);

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_polygon(Paint paint, int[] c) {
    paint.setStrokeWidth(c[0]);//from  w w w.j  a v  a2 s  . c  o  m
    paint.setARGB(c[1], c[2], c[3], c[4]);
    paint.setStyle(Paint.Style.FILL);
    //paint.setAntiAlias(true);
    //paint.setStrokeWidth(0);
    Path path = new Path();
    path.moveTo(c[5], c[6]);
    for (int i = 7; i < c.length; i += 2) {
        path.lineTo(c[i], c[i + 1]);
    }
    //global_path.close();
    draw_canvas.drawPath(path, paint);
}

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_polyline(Paint paint, int[] c) {
    paint.setStrokeWidth(c[0]);//  w  w w.  j a v  a2  s.  c o m
    paint.setARGB(c[1], c[2], c[3], c[4]);
    paint.setStyle(Paint.Style.STROKE);
    //paint.setAntiAlias(true);
    //paint.setStrokeWidth(0);
    int ndashes = c[5];
    float[] intervals = new float[ndashes + (ndashes % 2)];
    for (int i = 0; i < ndashes; i++) {
        intervals[i] = c[6 + i];
    }

    if ((ndashes % 2) == 1) {
        intervals[ndashes] = intervals[ndashes - 1];
    }

    if (ndashes > 0) {
        paint.setPathEffect(new android.graphics.DashPathEffect(intervals, 0.0f));
    }

    Path path = new Path();
    path.moveTo(c[6 + ndashes], c[7 + ndashes]);
    for (int i = 8 + ndashes; i < c.length; i += 2) {
        path.lineTo(c[i], c[i + 1]);
    }
    //global_path.close();
    draw_canvas.drawPath(path, paint);
    paint.setPathEffect(null);
}

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);// www . j  a va2 s. c  om
        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: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   ww  w .  j  a v  a 2  s  .  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.wanikani.androidnotifier.graph.TYPlot.java

/**
 * Draws a segment containins samples/*www  .  j a va2 s.c  om*/
 * @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);
}