Example usage for android.graphics Path addRect

List of usage examples for android.graphics Path addRect

Introduction

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

Prototype

public void addRect(float left, float top, float right, float bottom, Direction dir) 

Source Link

Document

Add a closed rectangle contour to the path

Usage

From source file:com.artioml.practice.activities.LicenseActivity.java

public BitmapDrawable drawParallelogramLine(int width) {
    Matrix matrix = new Matrix();
    Path path = new Path();
    path.addRect(0, 0, (4 * width) / 40, (4 * width) / 200, Path.Direction.CW);
    Path pathStamp = new Path();
    Paint p;//from  w  w w . jav a 2s  . c om
    Bitmap bitmap;

    p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setStyle(Paint.Style.FILL);

    bitmap = Bitmap.createBitmap(width / 4, width / 80 * 2 + (4 * width) / 200, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    p.setColor(ContextCompat.getColor(this, R.color.colorPrimaryLight));

    matrix.reset();
    matrix.setTranslate(0, 0);
    matrix.postSkew(-1f, 0.0f, 0, (4 * width) / 200);
    path.transform(matrix, pathStamp);
    canvas.drawPath(pathStamp, p);

    p.setColor(ContextCompat.getColor(this, R.color.colorAccent));

    matrix.reset();
    matrix.setTranslate(width / 8, 0);
    matrix.postSkew(-1f, 0.0f, width / 8, (4 * width) / 200);
    path.transform(matrix, pathStamp);
    canvas.drawPath(pathStamp, p);

    BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
    bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);

    return bitmapDrawable;
}