Example usage for android.graphics Paint setColor

List of usage examples for android.graphics Paint setColor

Introduction

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

Prototype

public void setColor(@ColorInt int color) 

Source Link

Document

Set the paint's color.

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;
    Bitmap bitmap;//from  ww w  . j a v a  2  s  . c  o m

    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;
}

From source file:org.stockchart.core.Appearance.java

public void applyOutline(Paint p) {
    p.reset();//from ww  w  .  j av a2s .  co m
    p.setShader(null);
    p.setColor(fOutlineColor);
    p.setAntiAlias(fIsAntialias);
    p.setStrokeWidth(fOutlineWidth);
    p.setStyle(Style.STROKE);

    switch (fOutlineStyle) {
    case DASH:
        p.setPathEffect(DASH_EFFECT);
        break;
    default:
        p.setPathEffect(null);
    }
}

From source file:com.abhi.barcode.frag.libv2.BarcodeFragment.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of
 * the barcode./*from   w ww  .j  a v  a  2  s.com*/
 * 
 * @param barcode
 *            A bitmap of the captured image.
 * @param scaleFactor
 *            amount by which thumbnail was scaled
 * @param rawResult
 *            The decoded results which contains the points to draw.
 */
private void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
        Canvas canvas = new Canvas(barcode);
        Paint paint = new Paint();
        paint.setColor(Color.parseColor("#c099cc00"));
        if (points.length == 2) {
            paint.setStrokeWidth(4.0f);
            drawLine(canvas, paint, points[0], points[1], scaleFactor);
        } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A
                || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
            // Hacky special case -- draw two lines, for the barcode and
            // metadata
            drawLine(canvas, paint, points[0], points[1], scaleFactor);
            drawLine(canvas, paint, points[2], points[3], scaleFactor);
        } else {
            paint.setStrokeWidth(10.0f);
            for (ResultPoint point : points) {
                canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint);
            }
        }
    }
}

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

@Override
void doDraw(Canvas canvas, Paint paint) {
    if (!mPath.isEmpty()) {
        paint.setStyle(Paint.Style.FILL);
        int color = blendColors(mStartColor, mEndColor, mCurrentScale);
        paint.setColor(color);
        canvas.drawPath(mPath, paint);//from  w w w.j  a  v a 2s  .  c om
    }
}

From source file:org.stockchart.core.Appearance.java

public void applyText(Paint p) {
    p.reset();//from   w ww .  ja  v  a  2s .  c o m
    p.setTextSize(fFont.getSize());
    p.setColor(fFont.getColor());
    p.setTypeface(fFont.getTypeface());
    p.setAntiAlias(fIsAntialias);
    p.setPathEffect(null);
    p.setStyle(Style.FILL);
}

From source file:com.abhi.barcode.fragment.BarCodeFragment.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of
 * the barcode.//from w  w  w .  j a  v  a  2 s  . c  o m
 * 
 * @param barcode
 *            A bitmap of the captured image.
 * @param rawResult
 *            The decoded results which contains the points to draw.
 */
private void drawResultPoints(Bitmap barcode, Result rawResult) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
        Canvas canvas = new Canvas(barcode);
        Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.result_image_border));
        paint.setStrokeWidth(3.0f);
        paint.setStyle(Paint.Style.STROKE);
        Rect border = new Rect(2, 2, barcode.getWidth() - 2, barcode.getHeight() - 2);
        canvas.drawRect(border, paint);

        paint.setColor(getResources().getColor(R.color.result_points));
        if (points.length == 2) {
            paint.setStrokeWidth(4.0f);
            drawLine(canvas, paint, points[0], points[1]);
        } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A
                || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
            drawLine(canvas, paint, points[0], points[1]);
            drawLine(canvas, paint, points[2], points[3]);
        } else {
            paint.setStrokeWidth(10.0f);
            for (ResultPoint point : points) {
                canvas.drawPoint(point.getX(), point.getY(), paint);
            }
        }
    }
}

From source file:com.coinomi.wallet.ui.ScanActivity.java

public void handleResult(final Result scanResult, final Bitmap thumbnailImage,
        final float thumbnailScaleFactor) {
    vibrator.vibrate(VIBRATE_DURATION);/*w w  w . j av a  2  s .co m*/

    // superimpose dots to highlight the key features of the qr code
    final ResultPoint[] points = scanResult.getResultPoints();
    if (points != null && points.length > 0) {
        final Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.scan_result_dots));
        paint.setStrokeWidth(10.0f);

        final Canvas canvas = new Canvas(thumbnailImage);
        canvas.scale(thumbnailScaleFactor, thumbnailScaleFactor);
        for (final ResultPoint point : points)
            canvas.drawPoint(point.getX(), point.getY(), paint);
    }

    scannerView.drawResultBitmap(thumbnailImage);

    final Intent result = new Intent();
    result.putExtra(INTENT_EXTRA_RESULT, scanResult.getText());
    setResult(RESULT_OK, result);

    // delayed finish
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            finish();
        }
    });
}

From source file:com.fillerino.wallet.ui.ScanActivity.java

public void handleResult(final Result scanResult, final Bitmap thumbnailImage,
        final float thumbnailScaleFactor) {
    vibrator.vibrate(VIBRATE_DURATION);//from  w ww.jav  a 2 s  . c  om

    // superimpose dots to highlight the key features of the qr code
    final ResultPoint[] points = scanResult.getResultPoints();
    if (points != null && points.length > 0) {
        final Paint paint = new Paint();
        paint.setColor(getResources().getColor(com.fillerino.wallet.R.color.scan_result_dots));
        paint.setStrokeWidth(10.0f);

        final Canvas canvas = new Canvas(thumbnailImage);
        canvas.scale(thumbnailScaleFactor, thumbnailScaleFactor);
        for (final ResultPoint point : points)
            canvas.drawPoint(point.getX(), point.getY(), paint);
    }

    scannerView.drawResultBitmap(thumbnailImage);

    final Intent result = new Intent();
    result.putExtra(INTENT_EXTRA_RESULT, scanResult.getText());
    setResult(RESULT_OK, result);

    // delayed finish
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            finish();
        }
    });
}

From source file:pl.itiner.nutiteq.NutiteqMap.java

public Bitmap createMissingTileBitmap(final int tileSize, final String bitmapText, Resources res) {
    Bitmap canvasBitmap = Bitmap.createBitmap(tileSize, tileSize, Bitmap.Config.RGB_565);
    Canvas imageCanvas = new Canvas(canvasBitmap);

    Paint textPaint = new Paint();
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setTextSize(16f);//  w w  w  . j  ava 2  s  .co  m

    Paint backgroundPaint = new Paint();
    backgroundPaint.setColor(Color.WHITE);
    backgroundPaint.setStrokeWidth(3);
    imageCanvas.drawRect(0, 0, tileSize, tileSize, backgroundPaint);

    imageCanvas.drawText(bitmapText, tileSize / 2, tileSize / 2, textPaint);

    BitmapDrawable finalImage = new BitmapDrawable(res, canvasBitmap);
    return finalImage.getBitmap();
}

From source file:org.stockchart.core.Appearance.java

public void applyFill(Paint p, RectF rect) {
    p.reset();/*from w w w . j  av a  2 s .c o m*/
    p.setStyle(Style.FILL);
    p.setColor(fPrimaryFillColor);

    switch (fGradient) {
    case LINEAR_HORIZONTAL: {
        p.setShader(new LinearGradient(rect.left, rect.top, rect.right, rect.top, fPrimaryFillColor,
                fSecondaryFillColor, TileMode.MIRROR));
    }
        break;

    case LINEAR_VERTICAL: {
        p.setShader(new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, fPrimaryFillColor,
                fSecondaryFillColor, TileMode.MIRROR));
    }
        break;
    default:
        p.setShader(null);
    }
}