Example usage for android.graphics Path Path

List of usage examples for android.graphics Path Path

Introduction

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

Prototype

public Path() 

Source Link

Document

Create an empty path

Usage

From source file:com.astuetz.PagerSlidingTriangleStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from   www  .ja  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);
    }

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

    //
    float x1 = (lineRight + lineLeft) / 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);
    path.lineTo(x3, y3);
    path.lineTo(x1, y1);

    //
    //        rectPaint.setStyle(Style.STROKE);
    //        rectPaint.setStrokeWidth(2);

    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.breel.wearables.shadowclock.graphics.ShapeShadow.java

public void addVertex(float x, float y) {
    x = x * (scale);/*from  w  w w. j  av  a  2 s. c o m*/
    y = y * (scale);

    if (x > maxX) {
        maxX = x;
    }
    if (y > maxY) {
        maxY = y;
    }
    if (x < minX) {
        minX = x;
    }
    if (y < minY) {
        minY = y;
    }
    medX = (maxX - minX) / 2 + positionX + minX;
    medY = (maxY - minY) / 2 + positionY;

    x += positionX;
    y += positionY;
    vertexArray.add(new AVector(x, y));
    shadowPaths.add(new Path());
}

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

/**
 * Draw a heart//  w  w  w .  j a  v  a  2s .c  o  m
 * @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.chj.indicator.lib.TriangleSlidingIndicator.java

/**
 * //from  w  w  w  . jav  a  2s .  co  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.bob.googleplay.view.PagerSlidingTriangleStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*  w  ww  .  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);
    }

    // 
    // 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:com.astuetz.PagerSlidingTabStripMy.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*ww w .jav 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);
    }

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

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from  w w w  .j  av  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);
    }
    /*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.lovejjfg.demo.TouchCircleView.java

private void initPaintPath() {

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);/*ww w . ja va  2s.  c  om*/
    paint.setStrokeWidth(20);
    paint.setColor(Color.RED);
    paint.setStrokeCap(Paint.Cap.SQUARE);

    secPaint = new Paint(paint);
    secPaint.setColor(Color.GREEN);

    mixPaint = new Paint(paint);
    innerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    innerPaint.setStyle(Paint.Style.STROKE);
    innerPaint.setAntiAlias(true);
    innerPaint.setColor(Color.WHITE);
    innerPaint.setStrokeWidth(mBorderWidth);

    mHookPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHookPaint.setStyle(Paint.Style.STROKE);
    mHookPaint.setStrokeCap(Paint.Cap.ROUND);
    mHookPaint.setStrokeWidth(mBorderWidth);
    mHookPaint.setColor(Color.WHITE);

    path = new Path();
    mArrow = new Path();
    mHook = new Path();
    mError = new Path();
}

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  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);
    }
    //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:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw a spade/*from   w ww.j av a  2s. c  o  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);
}