Example usage for android.graphics Path addRoundRect

List of usage examples for android.graphics Path addRoundRect

Introduction

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

Prototype

public void addRoundRect(RectF rect, float[] radii, Direction dir) 

Source Link

Document

Add a closed round-rectangle contour to the path.

Usage

From source file:Main.java

private static void drawRoundRect(Canvas canvas, RectF rect, Paint paint, int radius, boolean leftTop,
        boolean rightTop, boolean leftBottom, boolean rightBottom) {
    float roundRadius[] = new float[8];
    roundRadius[0] = leftTop ? 0 : radius;
    roundRadius[1] = leftTop ? 0 : radius;
    roundRadius[2] = rightTop ? 0 : radius;
    roundRadius[3] = rightTop ? 0 : radius;
    roundRadius[4] = rightBottom ? 0 : radius;
    roundRadius[5] = rightBottom ? 0 : radius;
    roundRadius[6] = leftBottom ? 0 : radius;
    roundRadius[7] = leftBottom ? 0 : radius;

    Path path = new Path();
    path.addRoundRect(rect, roundRadius, Direction.CCW);
    canvas.drawPath(path, paint);// w  w w . java2 s. co m
}

From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.MarkerDrawable.java

private void computePath(Rect bounds) {
    final float currentScale = mCurrentScale;
    final Path path = mPath;
    final RectF rect = mRect;
    final Matrix matrix = mMatrix;

    path.reset();/*from  www  . j  av a 2 s.  c  o  m*/
    int totalSize = Math.min(bounds.width(), bounds.height());

    float initial = mClosedStateSize;
    float destination = totalSize;
    float currentSize = initial + (destination - initial) * currentScale;

    float halfSize = currentSize / 2f;
    float inverseScale = 1f - currentScale;
    float cornerSize = halfSize * inverseScale;
    float[] corners = new float[] { halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize,
            cornerSize };
    rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
    path.addRoundRect(rect, corners, Path.Direction.CCW);
    matrix.reset();
    matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
    matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
    float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
    matrix.postTranslate(0, hDiff);
    path.transform(matrix);
}