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.morninz.ninepinview.widget.NinePINView.java

/**
 * Compute the coordinates of 9 center points and wrong triangles.
 *///w  w w.  ja  va2 s.  c  o m
protected void computePointsAndWrongTriangleCoordinate() {
    int drawWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    int drawHeight = getHeight() - getPaddingTop() - getPaddingBottom();

    float baseX = getPaddingLeft() + mCircleRadius;
    float baseY = getPaddingTop() + mCircleRadius;
    float gapX = drawWidth / 2.0f - mCircleRadius;
    float gapY = drawHeight / 2.0f - mCircleRadius;

    float r = mCircleRadius;

    for (int i = 0; i < POINT_COUNT; i++) {
        // compute center point's coordinate
        Point point = new Point();
        point.x = baseX + gapX * (i % 3);
        point.y = baseY + gapY * (i / 3);
        point.index = i;
        mCenterPoints[i] = point;
        // compute wrong triangle path of this point.
        Path path = new Path();
        float x1, y1, x2, y2, x3, y3;
        x1 = point.x + r;
        y1 = point.y;
        x2 = point.x + r * (2.0f / 3);
        y2 = point.y - r * (1.0f / 3);
        x3 = x2;
        y3 = point.y + r * (1.0f / 3);
        path.moveTo(x1, y1);
        path.lineTo(x2, y2);
        path.lineTo(x3, y3);
        path.lineTo(x1, y1);
        path.close();
        mWrongPaths[i] = path;
        Log.d(TAG,
                "[ " + x1 + ", " + y1 + " ], " + "[ " + x2 + ", " + y2 + " ], " + "[ " + x3 + ", " + y3 + " ]");
    }
}

From source file:org.mdc.chess.ChessBoard.java

private void drawMoveHints(Canvas canvas) {
    if ((moveHints == null) || blindMode) {
        return;// w  w  w .  ja v a 2  s.  c o  m
    }
    float h = (float) (sqSize / 2.0);
    float d = (float) (sqSize / 8.0);
    double v = 35 * Math.PI / 180;
    double cosv = Math.cos(v);
    double sinv = Math.sin(v);
    double tanv = Math.tan(v);
    int n = Math.min(moveMarkPaint.size(), moveHints.size());
    for (int i = 0; i < n; i++) {
        Move m = moveHints.get(i);
        if ((m == null) || (m.from == m.to)) {
            continue;
        }
        float x0 = getXCrd(Position.getX(m.from)) + h;
        float y0 = getYCrd(Position.getY(m.from)) + h;
        float x1 = getXCrd(Position.getX(m.to)) + h;
        float y1 = getYCrd(Position.getY(m.to)) + h;

        float x2 = (float) (Math.hypot(x1 - x0, y1 - y0) + d);
        float y2 = 0;
        float x3 = (float) (x2 - h * cosv);
        float y3 = (float) (y2 - h * sinv);
        float x4 = (float) (x3 - d * sinv);
        float y4 = (float) (y3 + d * cosv);
        float x5 = (float) (x4 + (-d / 2 - y4) / tanv);
        float y5 = -d / 2;
        float x6 = 0;
        float y6 = y5 / 2;
        Path path = new Path();
        path.moveTo(x2, y2);
        path.lineTo(x3, y3);
        //          path.lineTo(x4, y4);
        path.lineTo(x5, y5);
        path.lineTo(x6, y6);
        path.lineTo(x6, -y6);
        path.lineTo(x5, -y5);
        //          path.lineTo(x4, -y4);
        path.lineTo(x3, -y3);
        path.close();
        Matrix mtx = new Matrix();
        mtx.postRotate((float) (Math.atan2(y1 - y0, x1 - x0) * 180 / Math.PI));
        mtx.postTranslate(x0, y0);
        path.transform(mtx);
        Paint p = moveMarkPaint.get(i);
        canvas.drawPath(path, p);
    }
}

From source file:com.chj.indicator.lib.TriangleSlidingIndicator.java

/**
 * /*from w  ww .j av  a  2s.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.blestep.sportsbracelet.view.TimelineChartView.java

private void drawTargetLine(Canvas c) {
    if (mIsShowTargetDashedLine && mTargetValue > 0) {
        if (mTargetValue > mMaxValue) {
            Path path = new Path();
            path.moveTo(0, mTopSpaceHeight);
            path.lineTo(mGraphArea.width(), mTopSpaceHeight);
            c.drawPath(path, mGraphTargetDashedLinePaint);
        } else {/*from   w w  w. ja  v a 2s.c  o m*/
            float height = mGraphArea.height();
            float y = (float) (height - (height * ((mTargetValue * 100) / mMaxValue)) / 100) + mTopSpaceHeight;
            Path path = new Path();
            path.moveTo(0, y);
            path.lineTo(mGraphArea.width(), y);
            c.drawPath(path, mGraphTargetDashedLinePaint);
        }
    }
}

From source file:com.astuetz.PagerSlidingTabStripMy.java

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

    if (isInEditMode() || tabCount == 0) {
        return;// w  ww.j a v a2 s  .co 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:com.gx.appstore.lib.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from   w w w. j  a  v a 2 s. c om
    }

    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: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;/*ww  w .j ava  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.astuetz.PagerSlidingTabStripExtends.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from   w  ww . j  a va2  s .  c  om
    }

    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]);//www . j  av 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]);//from   ww  w.ja v  a  2 s. c om
    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);
}