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.astuetz.PagerSlidingTrilateralStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;// w  w  w  .ja  v 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);
    }
    /*modify by HJ begin ??*/
    //
    //canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
    // ->
    float x1 = (lineLeft + lineRight) / 2;
    float y1 = height - indicatorHeight;

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

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

    Path path = new Path();
    path.moveTo(x1, y1);//
    path.lineTo(x2, y2);//2
    path.lineTo(x3, y3);//3
    path.lineTo(x1, y1);//1

    canvas.drawPath(path, rectPaint);

    /*modify by HJ end ??*/
    // 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.bob.googleplay.view.PagerSlidingTriangleStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from w w  w.  j a  va  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);

    // -->
    float x1 = (lineRight - lineLeft) / 2 + lineLeft;
    float y1 = height - indicatorHeight;

    float x2 = x1 - triangleWidth / 2f;
    float y2 = height;

    float x3 = x1 + triangleWidth / 2f;
    float y3 = height;

    Path path = new Path();
    path.moveTo(x1, y1);// 
    path.lineTo(x2, y2);// 
    path.lineTo(x3, y3);// 
    path.lineTo(x1, y1);// 

    //      rectPaint.setStyle(Style.STROKE);
    //      rectPaint.setStrokeWidth(width)
    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:wm.xmwei.ui.view.indicator.PagerSlidingTabIndicator.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from w ww. ja va 2 s.  co m
    }

    final int height = getHeight();
    final int width = getWidth();

    // 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);
        nextTab.setBackgroundResource(Color.TRANSPARENT);
        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 center = (lineLeft + lineRight) / 2;

    // ,??  
    // Path path = new Path();
    //path.moveTo(center,height - indicatorHeight);//   

    BigDecimal a = BigDecimal.valueOf(1.736);
    BigDecimal b = BigDecimal.valueOf(3);
    BigDecimal bigDecimal = a.divide(b, BigDecimal.ROUND_HALF_UP);
    float result = bigDecimal.floatValue() * indicatorHeight;

    //path.lineTo(center-result-2, height);  
    // path.lineTo(center+result+2, height);
    //path.close(); // ??  
    // canvas.drawPath(path, rectPaint);

    Path path2 = new Path();
    path2.moveTo(0, 0);//   
    path2.lineTo(0, height);
    path2.lineTo(center - result - 5, height);
    path2.lineTo(center, height - indicatorHeight);
    path2.lineTo(center + result + 5, height);
    path2.lineTo(tabsContainer.getWidth(), height);
    path2.lineTo(tabsContainer.getWidth(), 0);

    path2.close(); // ??  
    canvas.drawPath(path2, bgPaint);
    // 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.kmagic.solitaire.DrawMaster.java

/**
 * Draw a heart//from  www . j  a va2 s. com
 * @param canvas canvas to draw on
 * @param width width of the heart
 * @param height height of the heart
 */
public void drawHeart(final Canvas canvas, final float width, final float height) {
    final Paint paint = getRedPaint();
    final float width_half = width / 2;
    final float width_quarter = width / 4;
    final float height_quarter = height / 4;
    final float height_third = height / 3;
    canvas.drawCircle(width_quarter, height_quarter, width_quarter, paint);
    canvas.drawCircle(width_quarter * 3, height_quarter, width_quarter, paint);
    final Path path = new Path();
    path.moveTo(0, height_third);
    path.lineTo(width_half, height);
    path.lineTo(width, height_third);
    path.lineTo(0, height_third);
    path.close();
    canvas.drawPath(path, paint);
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw a spade/*from  w  ww.  j a va 2s  .  co m*/
 * @param canvas canvas to draw on
 * @param width width of the spade
 * @param height height of the spade
 */
public void drawSpade(final Canvas canvas, final float width, final float height) {
    final Paint paint = getBlackPaint();
    final float width_half = width / 2;
    final float width_quarter = width / 4;
    final float width_fifth = width / 5;
    final float width_25th = width / 25;
    final float height_3_5th = height / 5 * 3;
    final Path path = new Path();
    path.moveTo(width_half, 0);
    path.lineTo(width - width_25th, height_3_5th);
    path.lineTo(width_25th, height_3_5th);
    path.lineTo(width_half, 0);
    path.close();
    canvas.drawPath(path, paint);
    canvas.drawCircle(width_quarter, height_3_5th, width_fifth, paint);
    canvas.drawCircle(width_quarter * 3, height_3_5th, width_fifth, paint);
    drawPedestal(canvas, width, height);
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw a pedestal ( clubs and spades stand on this )
 * @param canvas canvas to draw on/*from www .j ava2  s  . co  m*/
 * @param width width of the pedestal
 * @param height height of the pedestal
 */
public void drawPedestal(final Canvas canvas, final float width, final float height) {
    final Paint paint = getBlackPaint();
    final float width_half = width / 2;
    final float width_fifth = width / 5;
    final float width_3_5ths = width_fifth * 3;
    final float height_5th = height / 5;
    canvas.drawRect(width_3_5ths, height_5th, width - width_3_5ths, height, paint);
    final Path path = new Path();
    path.moveTo(width_fifth, height);
    path.lineTo(width_half, height - height_5th);
    path.lineTo(width - width_fifth, height);
    path.lineTo(width_fifth, height);
    path.close();
    canvas.drawPath(path, paint);
}

From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java

private Path createPath(int width, int height) {
    // Log.i(TAG, "pathCreate(" + width + "," + height + ")");

    Path path = null;

    for (PointF point : getPoints(width, height)) {
        // Log.i(TAG, "  point = " + point.x + ", " + point.y);

        if (path == null) {
            path = new Path();
            path.moveTo(point.x, point.y);
        } else {//from   ww  w .  ja  v  a  2 s .c o  m
            path.lineTo(point.x, point.y);
        }
    }

    if (path != null) {
        path.close();
    }

    return path;
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw a diamond//from  w w w  .j  a va 2 s .com
 * @param canvas canvas to draw on
 * @param width width of the diamond
 * @param height height of the diamond
 */
public void drawDiamond(final Canvas canvas, final float width, final float height) {
    final Paint paint = getRedPaint();
    final Path path = new Path();
    path.moveTo(width / 2, 0);
    final float offset = height / 5;
    path.lineTo(offset, height / 2);
    path.lineTo(width / 2, height);
    path.lineTo(width - offset, height / 2);
    path.lineTo(width / 2, 0);
    path.close();
    canvas.drawPath(path, paint);
}

From source file:com.hobby.uiframework.widget.PagerSlidingTab.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from   ww  w.  j a  va 2 s  . c o  m
    }

    final int height = getHeight();

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

    // 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);
    }
    if (lineIndicator) {
        canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
    } else {
        rectPaint.setStyle(Style.FILL);
        Path path = new Path();
        float mid = (lineLeft + lineRight) * 0.5f;
        float triangleheight = getContext().getResources().getDimension(R.dimen.indicator_triangle_height);
        float left = mid - triangleheight;
        float right = mid + triangleheight;
        path.moveTo(left, height);
        path.lineTo(mid, height - triangleheight);
        path.lineTo(right, height);
        path.close();
        canvas.drawPath(path, 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.semfapp.adamdilger.semf.Take5PdfDocument.java

public PdfDocument createDocument() {
    //create new document
    PdfDocument document = new PdfDocument();

    // crate a page description
    PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(A4_WIDTH, A4_HEIGHT, 1).create();

    // start a page
    PdfDocument.Page page = document.startPage(pageInfo);

    can = page.getCanvas();//from ww  w .j  a  v  a  2s .c  om
    Paint paint = new Paint();
    paint.setStrokeWidth(0.5f);
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.STROKE);
    can.drawRect(1, 1, 594, 395, paint);

    /**
     * Page one Text Fields
     */
    drawText("Job Reference:", 9, 21, FONT14, carlitoBold);
    drawText("Date:", 354, 21, FONT14, carlitoBold);
    drawText("Time:", 473, 21, FONT14, carlitoBold);
    drawText("Location:", 9, 48, FONT14, carlitoBold);
    drawText("Task:", 261, 48, FONT14, carlitoBold);

    paint.setPathEffect(new DashPathEffect(new float[] { 1.5f, 1 }, 0));
    can.drawLine(85, 36, 350, 36, paint);
    can.drawLine(386, 36, 468, 36, paint);
    can.drawLine(506, 36, 585, 36, paint);
    can.drawLine(59, 60, 256, 60, paint);
    can.drawLine(291, 60, 585, 60, paint);

    if (mEditTextValues[0] != null) {
        drawText(mEditTextValues[0], 98, 19, FONT14, roboto);
    }
    if (mEditTextValues[1] != null) {
        drawText(mEditTextValues[1], 65, 44, FONT14, roboto);
    }
    if (mEditTextValues[2] != null) {
        drawText(mEditTextValues[2], 297, 44, FONT14, roboto);
    }
    drawText(mDateString, 390, 19, FONT14, roboto);
    drawText(mTimeString, 509, 19, FONT14, roboto);

    /**
     * Section One (Stop, step back...)
     */
    drawHeader1(8, 69, 202, "Stop, step back and think", 1);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(0.35f);
    paint.setPathEffect(null);
    int left, top;

    //draw left boxes
    left = 177;
    top = 108;
    for (int x = 0; x < mCheckBoxSectionOne.size(); x++) {
        Take5Data.CheckValue isYes = mCheckBoxSectionOne.get(x).getCheckValue();
        float topLoc = top + (x * 33);

        if (x < 1) { //allowing for different 1st row size
            drawBox(left, topLoc, paint, true, isYes);
        } else {
            float newTop = topLoc - 6;
            if (x < 3) {
                drawBox(left, newTop, paint, false, isYes);
            } else {
                drawBox(left, newTop, paint, true, isYes);
            }
        }
    }

    DashPathEffect pathEffect = new DashPathEffect(new float[] { 1, 1.5f }, 0);

    drawText(mCheckBoxSectionOne.get(0).getHeading(), 13, 113, FONT12, carlitoBold);

    for (int x = 1; x < mCheckBoxSectionOne.size(); x++) {
        int height = 132 + ((x - 1) * 33);
        drawText(mCheckBoxSectionOne.get(x).getHeading(), 13, height, FONT12, carlitoBold);
        paint.setPathEffect(pathEffect);
        can.drawLine(10, height - 6, 222, height - 6, paint);
        paint.setPathEffect(null);
    }

    /**
     * Section Two (Identidy the Hazards...)
     */
    drawHeader1(230, 69, 345, "Identify the hazard(s)", 2);

    //draw right boxes
    left = 542;
    top = 104;
    for (int x = 0; x < mCheckBoxSectionTwo.size(); x++) {
        float topLoc = top + (x * 20.7f);
        Take5Data.CheckValue isYes = mCheckBoxSectionTwo.get(x).getCheckValue();
        drawBox(left, topLoc, paint, false, isYes);
    }

    for (int x = 0; x < mCheckBoxSectionTwo.size(); x++) {
        float height = 105 + (x * 20.7f);
        drawText(mCheckBoxSectionTwo.get(x).getHeading(), 238, height + 3, FONT12, carlitoBold);
        if (x > 0) {
            paint.setPathEffect(pathEffect);
            can.drawLine(238, height - 4, 581, height - 4, paint);
            paint.setPathEffect(null);
        }
    }

    /**
     * draw section 3,4,5 (including checkboxes)
     */
    drawSmallCircle(8, 331, "Assess the level of risk", 3);
    drawSmallCircle(202, 331, "Control the hazards", 4);
    drawSmallCircle(398, 331, "Proceed safely", 5);

    /**
     * Draw Page Two
     */
    int xLoc = 7;
    int yLoc = 420;
    int height;
    int width = 565;
    int RADIUS = 14;
    float INNER_RADIUS = 13;
    int centre = yLoc + 7 + RADIUS;
    width = xLoc + width;
    int middle = width - 340;
    can.drawRect(1, 420, 594, 420 + 395, paint);

    paint.setStyle(Paint.Style.FILL);
    paint.setTypeface(impact);
    paint.setTextSize(12);

    can.drawCircle(xLoc + RADIUS, centre, RADIUS, paint);
    can.drawRect(xLoc + RADIUS, centre - RADIUS, width, centre + RADIUS, paint);
    can.drawCircle(width, centre, RADIUS, paint);
    paint.setColor(Color.WHITE);
    can.drawCircle(xLoc + RADIUS, centre, INNER_RADIUS, paint);
    can.drawCircle(width, centre, INNER_RADIUS, paint);
    can.drawRect(middle, centre - INNER_RADIUS, width, centre + INNER_RADIUS, paint);
    paint.setColor(Color.BLACK);
    can.drawCircle(middle, centre, RADIUS, paint);

    paint.setColor(Color.WHITE);
    can.drawText("SAFE WORK METHOD STATEMENT (SWMS)", xLoc + 31, centre + 5, paint);
    paint.setTextSize(16);
    paint.setColor(Color.BLACK);
    can.drawText(String.valueOf(4), xLoc + RADIUS - 4, centre + 6, paint);

    height = 50;
    drawText("What are the hazards and risks?", 25, yLoc + height, FONT12, carlitoBold);
    drawText("Risk\nRating", 267, yLoc + 47, FONT12, carlitoBold);
    drawText("How will hazards and risks be controlled?", 319, yLoc + height, FONT12, carlitoBold);

    paint.setPathEffect(pathEffect);
    can.drawLine(262, yLoc + 45, 262, yLoc + 320, paint);
    can.drawLine(302, yLoc + 45, 302, yLoc + 320, paint);
    paint.setPathEffect(null);

    float currentItemHeight = yLoc + 75;
    float padding = 5;

    for (int x = 0; x < mRiskElements.size(); x++) {
        int textHeight = (int) currentItemHeight;
        float totalItemHeight = drawRiskElement(textHeight, mRiskElements.get(x));
        currentItemHeight += totalItemHeight + padding;
    }

    paint.setPathEffect(pathEffect);
    height = yLoc + 350;
    drawText("Name/s:", 12, height, FONT12, carlitoBold);
    drawText(mEditTextValues[3], 55, height - 3, FONT14, roboto);
    paint.setPathEffect(pathEffect);
    can.drawLine(50, height + 12, 580, height + 12, paint);
    paint.setPathEffect(null);

    height = yLoc + 372;
    drawText("Signatures:", 12, height, FONT12, carlitoBold);
    drawText("Date:", 468, height, FONT12, carlitoBold);
    drawText(mDateString, 497, height - 3, FONT14, roboto);
    paint.setPathEffect(pathEffect);
    can.drawLine(60, height + 12, 464, height + 12, paint);
    can.drawLine(492, height + 12, 580, height + 12, paint);
    paint.setPathEffect(null);

    // finish the page
    document.finishPage(page);

    int imagePageCount = 2;

    for (Take5RiskElement risk : mRiskElements) {

        if (risk.imagePath != null) {

            // crate a page description
            PdfDocument.PageInfo pageInfo1 = new PdfDocument.PageInfo.Builder(A4_WIDTH, A4_HEIGHT,
                    imagePageCount).create();

            PdfDocument.Page imagePage = document.startPage(pageInfo1);
            Canvas canvas = imagePage.getCanvas();

            try {

                Bitmap original = BitmapFactory.decodeFile(risk.imagePath);

                Bitmap b = resize(original, canvas.getWidth() - 100, canvas.getHeight() - 100);
                canvas.drawBitmap(b, 50, 60, new Paint());
                //                    canvas.drawText(risk.getOne(), 50, 40, new Paint());

                Path textPath = new Path();
                textPath.moveTo(50, 50);
                textPath.lineTo(canvas.getWidth() - 100, 50);

                canvas.drawTextOnPath(risk.getOne(), textPath, 0, 0, new Paint());

            } catch (Exception e) {
                e.printStackTrace();
            }

            document.finishPage(imagePage);

            imagePageCount++;

            new File(risk.imagePath).delete();
        }
    }

    // add more pages
    return document;
}