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:uk.org.ngo.squeezer.util.ImageWorker.java

/**
 * Adds a debug swatch to a canvas. The marker is a triangle pointing north-west
 * on the top left corner, the edges are 25% of the canvas' width and height.
 *
 * @param canvas The canvas to draw on.//w w  w.j a  v  a  2 s .c  o m
 * @param color The colour to use for the swatch.
 */
public static void addDebugSwatch(Canvas canvas, int color) {
    float width = canvas.getWidth();
    float height = canvas.getHeight();

    Path path = new Path();
    path.lineTo(width / 4, 0);
    path.lineTo(0, height / 4);
    path.lineTo(0, 0);

    // Draw the swatch.
    mCacheDebugPaint.setColor(color);
    mCacheDebugPaint.setStyle(Paint.Style.FILL);
    canvas.drawPath(path, mCacheDebugPaint);

    // Stroke the swatch with a white hairline.
    mCacheDebugPaint.setColor(Color.WHITE);
    mCacheDebugPaint.setStyle(Paint.Style.STROKE);
    mCacheDebugPaint.setStrokeWidth(0);
    canvas.drawPath(path, mCacheDebugPaint);
}

From source file:Main.java

/**
 * Returns a path with a given set of peeks in a 'randomly' handrawn style
 * //from  ww  w . j  a v  a  2  s  .  c om
 * @param peek_x
 *            array of X locations of the peeks
 * @param peek_y
 *            array of Y locations of the peeks
 * @return constructed path
 */
public static Path peeks(float[] peek_x, float[] peek_y, float offset) {
    final Path p = new Path();

    p.moveTo(-offset, 0);

    float diff = 0;
    float cdiff = 0;
    int cp = 0;
    for (float x = -offset + RESOLUTION; x < 1 + offset; x += RESOLUTION) {

        if (x >= peek_x[cp]) {
            if (cp == peek_x.length - 1) {
                diff = 0;
                cdiff = 0;
            } else {
                diff = (peek_y[cp] - peek_y[cp + 1]) / ((peek_x[cp + 1] - peek_x[cp]) / RESOLUTION);
                if (diff == 0) {
                    cdiff = 0;
                }
                ++cp;
            }
        }
        cdiff += diff;

        float to_y = cdiff
                + (randomizer.nextBoolean() ? 1 : -1) * randomizer.nextFloat() * (diff == 0 ? 0.003f : 0.01f);
        if (to_y < -MAX) {
            to_y = 0;
        }
        p.lineTo(x, -to_y);
    }

    p.lineTo(1 + offset, 0);

    return p;
}

From source file:com.mtomczak.nausicaa.DockingView.java

/**
 * Encode a list of x,y coords into a path
 *
 * @param points Points to encode//from  w  ww  .  j a  v  a  2s  . com
 * @return The encoded path
 */
private Path encodePath(float[] points) {
    Path path = new Path();
    path.moveTo(points[0], points[1]);
    for (int i = 2; i < points.length; i += 2) {
        path.lineTo(points[i], points[i + 1]);
    }
    path.close();
    path.setFillType(Path.FillType.WINDING);
    return path;
}

From source file:piuk.blockchain.android.util.ViewPagerTabs.java

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

    final int viewWidth = getWidth();
    final int viewHalfWidth = viewWidth / 2;
    final int viewBottom = getHeight();

    final float density = getResources().getDisplayMetrics().density;
    final float spacing = 32 * density;

    final Path path = new Path();
    path.moveTo(viewHalfWidth, viewBottom - 5 * density);
    path.lineTo(viewHalfWidth + 5 * density, viewBottom);
    path.lineTo(viewHalfWidth - 5 * density, viewBottom);
    path.close();//from w  ww  .ja v  a  2s  . co m

    paint.setColor(Color.WHITE);
    canvas.drawPath(path, paint);

    paint.setTypeface(Typeface.DEFAULT_BOLD);
    final float y = getPaddingTop() + -paint.getFontMetrics().top;

    for (int i = 0; i < labels.size(); i++) {
        final String label = labels.get(i);

        paint.setTypeface(i == pagePosition ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
        paint.setColor(i == pagePosition ? Color.BLACK : Color.DKGRAY);

        final float x = viewHalfWidth + (maxWidth + spacing) * (i - pageOffset);
        final float labelWidth = paint.measureText(label);
        final float labelHalfWidth = labelWidth / 2;

        final float labelLeft = x - labelHalfWidth;
        final float labelVisibleLeft = labelLeft >= 0 ? 1f : 1f - (-labelLeft / labelWidth);

        final float labelRight = x + labelHalfWidth;
        final float labelVisibleRight = labelRight < viewWidth ? 1f
                : 1f - ((labelRight - viewWidth) / labelWidth);

        final float labelVisible = Math.min(labelVisibleLeft, labelVisibleRight);

        paint.setAlpha((int) (labelVisible * 255));

        canvas.drawText(label, labelLeft, y, paint);
    }
}

From source file:com.github.czy1121.view.CornerLabelView.java

private Path calcPath() {
    Path path = new Path();
    path.moveTo(-mHeight, 0);//from   ww w. j av  a 2 s .  c  o m
    path.lineTo(mHeight, 0);
    int factor = mIsTop ? -1 : 1;
    if (mIsTriangle) {
        path.lineTo(0, factor * mHeight);
    } else {
        int lineHeight = factor * (int) (mPaddingCenter + mPaddingBottom + mText1.height);
        path.lineTo(mHeight + lineHeight, lineHeight);
        path.lineTo(-mHeight + lineHeight, lineHeight);
    }
    path.close();
    return path;
}

From source file:com.journeyapps.barcodescanner.WXViewfinderView.java

@SuppressLint("DrawAllocation")
@Override// w  w  w .  j  a  v  a2  s  .c o  m
public void onDraw(Canvas canvas) {
    refreshSizes();
    if (framingRect == null || previewFramingRect == null) {
        return;
    }

    Rect frame = framingRect;
    Rect previewFrame = previewFramingRect;

    int width = canvas.getWidth();
    int height = canvas.getHeight();

    maskPaint.setColor(maskColor);
    canvas.drawRect(0, 0, width, frame.top, maskPaint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, maskPaint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, maskPaint);
    canvas.drawRect(0, frame.bottom + 1, width, height, maskPaint);
    //drawable the border
    canvas.drawRect(frame.left + 1, frame.top + 1, frame.right, frame.bottom, borderPaint);
    int halfWidth = (int) (cornerWidth / 2);
    //draw four corner
    Path corner1 = new Path();
    corner1.moveTo(frame.left, frame.top + cornerLength);
    corner1.lineTo(frame.left, frame.top);
    corner1.lineTo(frame.left + cornerLength, frame.top);
    Matrix translate1 = new Matrix();
    translate1.setTranslate(halfWidth, halfWidth);
    corner1.transform(translate1);
    canvas.drawPath(corner1, cornerPaint);

    Path corner2 = new Path();
    corner2.moveTo(frame.right + 1 - cornerLength, frame.top);
    corner2.lineTo(frame.right + 1, frame.top);
    corner2.lineTo(frame.right + 1, frame.top + cornerLength);
    Matrix translate2 = new Matrix();
    translate2.setTranslate(-halfWidth, halfWidth);
    corner2.transform(translate2);
    canvas.drawPath(corner2, cornerPaint);

    Path corner3 = new Path();
    corner3.moveTo(frame.left, frame.bottom + 1 - cornerLength);
    corner3.lineTo(frame.left, frame.bottom + 1);
    corner3.lineTo(frame.left + cornerLength, frame.bottom + 1);
    Matrix translate3 = new Matrix();
    translate3.setTranslate(halfWidth, -halfWidth);
    corner3.transform(translate3);
    canvas.drawPath(corner3, cornerPaint);

    Path corner4 = new Path();
    corner4.moveTo(frame.right + 1 - cornerLength, frame.bottom + 1);
    corner4.lineTo(frame.right + 1, frame.bottom + 1);
    corner4.lineTo(frame.right + 1, frame.bottom + 1 - cornerLength);
    Matrix translate4 = new Matrix();
    translate4.setTranslate(-halfWidth, -halfWidth);
    corner4.transform(translate4);
    canvas.drawPath(corner4, cornerPaint);

    offset += speed;
    if (offset >= frame.bottom - frame.top) {
        offset = 0;
    }
    Rect rect = new Rect();
    rect.left = frame.left + 1 + laserPadding;
    rect.top = frame.top + 1 + offset;
    rect.right = frame.right - laserPadding;
    rect.bottom = frame.top + 1 + offset + 3;

    Bitmap laserBitmap = ((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.scan_laser,
            null)).getBitmap();
    canvas.drawBitmap(laserBitmap, null, rect, linePaint);

    textPaint.setTextAlign(Paint.Align.CENTER);

    canvas.drawText(statusText, (frame.right + frame.left) / 2,
            frame.bottom + statusTextPadding + statusTextSize, textPaint);

    postInvalidateDelayed(animationDelay, frame.left, frame.top, frame.right, frame.bottom);

}

From source file:com.rks.musicx.misc.widgets.DiagonalLayout.java

private Path createOutlinePath(float perpendicularHeight) {
    Path path = new Path();
    if (settings.isBottom()) {
        if (settings.isGravityLeft()) {
            path.moveTo(getPaddingLeft(), getPaddingRight());
            path.lineTo(width - getPaddingRight(), getPaddingTop());
            path.lineTo(width - getPaddingRight(), height - perpendicularHeight - getPaddingBottom());
            path.lineTo(getPaddingLeft(), height - getPaddingBottom());
            path.close();//from   ww w.j a  v a2s. co m
        } else {
            path.moveTo(width - getPaddingRight(), height - getPaddingBottom());
            path.lineTo(getPaddingLeft(), height - perpendicularHeight - getPaddingBottom());
            path.lineTo(getPaddingLeft(), getPaddingTop());
            path.lineTo(width - getPaddingRight(), getPaddingTop());
            path.close();
        }
    } else {
        if (settings.isGravityLeft()) {
            path.moveTo(width - getPaddingRight(), height - getPaddingBottom());
            path.lineTo(width - getPaddingRight(), getPaddingTop() + perpendicularHeight);
            path.lineTo(getPaddingLeft(), getPaddingTop());
            path.lineTo(getPaddingLeft(), height - getPaddingBottom());
            path.close();
        } else {
            path.moveTo(width - getPaddingRight(), height - getPaddingBottom());
            path.lineTo(width - getPaddingRight(), getPaddingTop());
            path.lineTo(getPaddingLeft(), getPaddingTop() + perpendicularHeight);
            path.lineTo(getPaddingLeft(), height - getPaddingBottom());
            path.close();
        }
    }
    return path;
}

From source file:android.example.com.visualizerpreferences.AudioVisuals.VisualizerView.java

public VisualizerView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mBytes = null;/*from   w ww. j  av  a2  s  . com*/
    TrailedShape.setMinSize(MIN_SIZE_DEFAULT);

    // Create each of the shapes and define how they are drawn on screen
    // Make bass circle
    mBassCircle = new TrailedShape(BASS_MULTIPLIER) {
        @Override
        protected void drawThisShape(float shapeCenterX, float shapeCenterY, float currentSize, Canvas canvas,
                Paint paint) {
            canvas.drawCircle(shapeCenterX, shapeCenterY, currentSize, paint);
        }
    };

    // Make midrange square
    mMidSquare = new TrailedShape(MID_MULTIPLIER) {
        @Override
        protected void drawThisShape(float shapeCenterX, float shapeCenterY, float currentSize, Canvas canvas,
                Paint paint) {
            canvas.drawRect(shapeCenterX - currentSize, shapeCenterY - currentSize, shapeCenterX + currentSize,
                    shapeCenterY + currentSize, paint);
        }
    };

    // Make treble triangle
    mTrebleTriangle = new TrailedShape(TREBLE_MULTIPLIER) {
        @Override
        protected void drawThisShape(float shapeCenterX, float shapeCenterY, float currentSize, Canvas canvas,
                Paint paint) {
            Path trianglePath = new Path();
            trianglePath.moveTo(shapeCenterX, shapeCenterY - currentSize);
            trianglePath.lineTo(shapeCenterX + currentSize, shapeCenterY + currentSize / 2);
            trianglePath.lineTo(shapeCenterX - currentSize, shapeCenterY + currentSize / 2);
            trianglePath.lineTo(shapeCenterX, shapeCenterY - currentSize);
            canvas.drawPath(trianglePath, paint);
        }
    };
}

From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java

private void makePathWhite() {

    if (mPathWhite == null) {
        mPathWhite = new Path();
    }//from w w  w.j a v a2  s  .  c  o m

    Path p = new Path();
    p.moveTo(getPaddingLeft(), mHeight / 2);
    p.lineTo(Math.max(getPaddingLeft(), mProgress * mWidth / 100), mHeight / 2 + calculateDeltaY());

    mPathWhite.set(p);
}

From source file:com.frapim.windwatch.Notifier.java

private Path getArrowPath(float degrees) {
    Path path = new Path();
    int leftX = (mBigIconSize / 2) - (mArrowWidth / 2);
    int leftHeadX = leftX - mArrowWidth;
    int rightX = (mBigIconSize / 2) + (mArrowWidth / 2);
    int rightHeadX = rightX + mArrowWidth;
    path.moveTo(leftX, mArrowHeight); // bottom left
    path.lineTo(leftX, mArrowHeadHeight); // left, arrow head start
    path.lineTo(leftHeadX, mArrowHeadHeight); //  left, arrow head end 
    path.lineTo(mBigIconSize / 2, 0); // top
    path.lineTo(rightHeadX, mArrowHeadHeight); // right, arrow head end
    path.lineTo(rightX, mArrowHeadHeight); // right, arrow head start
    path.lineTo(rightX, mArrowHeight); // bottom right
    path.lineTo(leftX, mArrowHeight); // bottom left
    path.close();//  ww  w . j a v  a  2  s.co  m
    Matrix translateMatrix = new Matrix();
    translateMatrix.postTranslate(0, 30);
    path.transform(translateMatrix);
    RectF bounds = new RectF();
    path.computeBounds(bounds, true);
    Matrix rotateMatrix = new Matrix();
    rotateMatrix.postRotate(degrees, (bounds.right + bounds.left) / 2, (bounds.bottom + bounds.top) / 2);
    path.transform(rotateMatrix);
    return path;
}