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:net.droidsolutions.droidcharts.core.plot.Marker.java

/**
 * Constructs a new marker./*  ww  w.  j av  a  2s.  co m*/
 * 
 * @param paint
 *            the paint (<code>null</code> not permitted).
 * @param stroke
 *            the stroke (<code>null</code> not permitted).
 * @param outlinePaint
 *            the outline paint (<code>null</code> permitted).
 * @param outlineStroke
 *            the outline stroke (<code>null</code> permitted).
 * @param alpha
 *            the alpha transparency (must be in the range 0.0f to 1.0f).
 * 
 * @throws IllegalArgumentException
 *             if <code>paint</code> or <code>stroke</code> is
 *             <code>null</code>, or <code>alpha</code> is not in the
 *             specified range.
 */
protected Marker(int paint, float stroke, int outlinePaint, float outlineStroke, int alpha) {

    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setColor(paint);
    this.paint = p;
    this.stroke = stroke;
    p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setColor(outlinePaint);
    this.outlinePaint = p;
    this.outlineStroke = outlineStroke;
    this.alpha = alpha;

    this.labelFont = new Font("SansSerif", Typeface.NORMAL, 9);
    p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setColor(Color.BLACK);
    this.labelPaint = p;
    this.labelAnchor = RectangleAnchor.TOP_LEFT;
    this.labelOffset = new RectangleInsets(3.0, 3.0, 3.0, 3.0);
    this.labelOffsetType = LengthAdjustmentType.CONTRACT;
    this.labelTextAnchor = TextAnchor.CENTER;

}

From source file:de.vanita5.twittnuker.view.ShapedImageView.java

private void updateShadowBitmap() {
    if (USE_OUTLINE)
        return;/*from   w  w w .ja  v  a  2  s  . c o m*/
    final int width = getWidth(), height = getHeight();
    if (width <= 0 || height <= 0)
        return;
    final int contentLeft = getPaddingLeft(), contentTop = getPaddingTop(),
            contentRight = width - getPaddingRight(), contentBottom = height - getPaddingBottom();
    final int contentWidth = contentRight - contentLeft, contentHeight = contentBottom - contentTop;
    final float radius = mShadowRadius, dy = radius * 1.5f / 2;
    final int size = Math.round(Math.min(contentWidth, contentHeight) + radius * 2);
    mShadowBitmap = Bitmap.createBitmap(size, Math.round(size + dy), Config.ARGB_8888);
    Canvas canvas = new Canvas(mShadowBitmap);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.WHITE);
    paint.setShadowLayer(radius, 0, radius * 1.5f / 2, SHADOW_START_COLOR);
    final RectF rect = new RectF(radius, radius, size - radius, size - radius);
    canvas.drawOval(rect, paint);
    paint.setShadowLayer(0, 0, 0, 0);
    paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
    canvas.drawOval(rect, paint);
    invalidate();
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void drawGaugeTitle(Canvas canvas, String Title) {
    Paint titlePaint = new Paint();
    titlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    titlePaint.setColor(Color.LTGRAY);//0x9f004d0f
    titlePaint.setStrokeWidth(1);//0.005f
    titlePaint.setAntiAlias(true);/*from   ww  w  . ja va  2s  .c o  m*/
    titlePaint.setTextSize(14);
    titlePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf"));

    /*Path titlePath = new Path();
    titlePath.addArc(new RectF(40, 90, 196, 155), -180.0f, -180.0f);
    canvas.drawTextOnPath(Title, titlePath, 0.0f,0.0f, titlePaint);*/

    canvas.drawText(Title, 60, 160, titlePaint);
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void DrawEvents() {
    Bitmap charty = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
    Canvas EventsCanvas = new Canvas(charty);
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(getResources().getColor(R.color.DarkBlue));
    paint.setAntiAlias(true);//from  www  .j av a  2  s  .  c om
    EventsCanvas.drawOval(new RectF(1, 1, 199, 199), paint);

    RadialGradient gradient = new RadialGradient(200, 200, 200, 0xFF6b7681, 0xFF000000,
            android.graphics.Shader.TileMode.CLAMP);
    paint.setDither(true);
    paint.setShader(gradient);
    EventsCanvas.drawOval(new RectF(6, 6, 194, 194), paint);

    //Special Bits
    int Scale = 100;

    if (EventCount > 100)
        ;
    Scale = EventCount + 50;

    drawScale(EventsCanvas, true, EventCount, Scale);
    drawGaugeTitle(EventsCanvas, "Events Count");
    drawGaugeNeedle(EventsCanvas, EventCount, Scale);
    //drawGloss(EventsCanvas);

    ((ImageView) findViewById(R.id.EventsGauge)).setImageBitmap(charty);
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void DrawDevices() {
    Bitmap charty = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
    Canvas DeviceCanvas = new Canvas(charty);
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(getResources().getColor(R.color.DarkBlue));
    paint.setAntiAlias(true);/*from w ww .ja  va 2s  .c  o m*/
    DeviceCanvas.drawOval(new RectF(1, 1, 199, 199), paint);

    RadialGradient gradient = new RadialGradient(100, 50, 150, 0xFF6b7681, 0xFF000000,
            android.graphics.Shader.TileMode.CLAMP);
    paint.setDither(true);
    paint.setShader(gradient);
    DeviceCanvas.drawOval(new RectF(6, 6, 194, 194), paint);

    int Scale = 10;

    //Special Bits
    if (DeviceCount < 500)
        Scale = 750;

    if (DeviceCount < 250)
        Scale = 350;

    if (DeviceCount < 100)
        Scale = 150;

    if (DeviceCount < 50)
        Scale = 50;
    try {
        drawScale(DeviceCanvas, false, DeviceCount, Scale);
        drawGaugeTitle(DeviceCanvas, "Device Count");
        drawGaugeNeedle(DeviceCanvas, DeviceCount, Scale);
        //drawGloss(EventsCanvas);
        ((ImageView) findViewById(R.id.DeviceGauge)).setImageBitmap(charty);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.catrobat.catroid.ui.fragment.AddBrickFragment.java

public ImageView getGlowingBorder(Bitmap bitmap) {
    ImageView imageView = new ImageView(getActivity());
    imageView.setBackgroundColor(Color.TRANSPARENT);
    imageView.setId(R.id.drag_and_drop_list_view_image_view);

    Bitmap glowingBitmap = Bitmap.createBitmap(bitmap.getWidth() + 30, bitmap.getHeight() + 30,
            Bitmap.Config.ARGB_8888);// w  w w. j a  v  a2s.co m
    Canvas glowingCanvas = new Canvas(glowingBitmap);
    Bitmap alpha = bitmap.extractAlpha();
    Paint paintBlur = new Paint();
    paintBlur.setColor(Color.WHITE);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    BlurMaskFilter blurMaskFilter = new BlurMaskFilter(15.0f, BlurMaskFilter.Blur.OUTER);
    paintBlur.setMaskFilter(blurMaskFilter);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    paintBlur.setMaskFilter(null);
    glowingCanvas.drawBitmap(bitmap, 15, 15, paintBlur);

    imageView.setImageBitmap(glowingBitmap);

    return imageView;
}

From source file:org.madmatrix.zxing.android.CaptureActivity.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of
 * the barcode./*from   w w  w. j a  va  2s  . 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(getResources().getColor(R.color.result_points));
        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) {
                if (point != null) {
                    canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint);
                }
            }
        }
    }
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void drawScale(Canvas canvas, Boolean Colors, int Count, int Max) {
    RectF faceRect = new RectF();
    faceRect.set(10, 10, 190, 190);/*from ww  w . j a v  a 2  s  .c o  m*/

    Paint scalePaint = new Paint();
    scalePaint.setStyle(Paint.Style.STROKE);
    scalePaint.setColor(getResources().getColor(R.color.WarningGreen));
    scalePaint.setStrokeWidth(1);
    scalePaint.setAntiAlias(true);

    scalePaint.setTextSize(12);
    scalePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf"));
    scalePaint.setTextAlign(Paint.Align.CENTER);

    float scalePosition = 10;
    RectF scaleRect = new RectF();
    scaleRect.set(faceRect.left + scalePosition, faceRect.top + scalePosition, faceRect.right - scalePosition,
            faceRect.bottom - scalePosition);

    if (!Colors)
        scalePaint.setColor(Color.WHITE);

    scalePaint.setStrokeWidth(2);
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    for (int i = 0; i < Max; ++i) {
        if (Colors) {
            if (i > 20)
                scalePaint.setColor(getResources().getColor(R.color.WarningYellow));

            if (i > 40)
                scalePaint.setColor(getResources().getColor(R.color.WarningOrange));

            if (i > 60)
                scalePaint.setColor(getResources().getColor(R.color.WarningRed));
        }

        canvas.drawLine(100, 20, 100, 18, scalePaint);
        int divisor = 5;

        if (Max > 100)
            divisor = 25;

        if (i % divisor == 0) {
            canvas.drawText(Integer.toString(i), 100, 16, scalePaint);
        }

        canvas.rotate((360.0f / Max), 100, 100);
    }

    canvas.restore();
}

From source file:org.getlantern.firetweet.view.ShapedImageView.java

private void updateShadowBitmap() {
    if (USE_OUTLINE)
        return;//from w ww.jav  a2  s .  co  m
    final int width = getWidth(), height = getHeight();
    if (width <= 0 || height <= 0)
        return;
    final int contentLeft = getPaddingLeft(), contentTop = getPaddingTop(),
            contentRight = width - getPaddingRight(), contentBottom = height - getPaddingBottom();
    final int contentWidth = contentRight - contentLeft, contentHeight = contentBottom - contentTop;
    final float radius = mShadowRadius, dy = radius * 1.5f / 2;
    final int size = Math.round(Math.min(contentWidth, contentHeight) + radius * 2);
    mShadowBitmap = Bitmap.createBitmap(size, Math.round(size + dy), Config.ARGB_8888);
    Canvas canvas = new Canvas(mShadowBitmap);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(0xFF000000 | mBackgroundPaint.getColor());
    paint.setShadowLayer(radius, 0, radius * 1.5f / 2, SHADOW_START_COLOR);
    final RectF rect = new RectF(radius, radius, size - radius, size - radius);
    if (getStyle() == SHAPE_CIRCLE) {
        canvas.drawOval(rect, paint);
        paint.setShadowLayer(0, 0, 0, 0);
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        canvas.drawOval(rect, paint);
    } else {
        final float cr = getCalculatedCornerRadius();
        canvas.drawRoundRect(rect, cr, cr, paint);
        paint.setShadowLayer(0, 0, 0, 0);
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        canvas.drawRoundRect(rect, cr, cr, paint);
    }
    invalidate();
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void drawGaugeNeedle(Canvas canvas, int count, int Scale) {
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    float divisor = 360.0f / Scale;

    canvas.rotate((float) (divisor * count), 100, 100);

    //Inside//from www . j  av a  2  s  .c o m
    Paint needleInsidePaint = new Paint();
    needleInsidePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    needleInsidePaint.setColor(Color.WHITE);
    needleInsidePaint.setStrokeWidth(4);
    needleInsidePaint.setAntiAlias(true);

    Paint needleEdgePaint = new Paint();
    needleEdgePaint.setStyle(Paint.Style.STROKE);
    needleEdgePaint.setColor(Color.DKGRAY);
    needleEdgePaint.setStrokeWidth(0.5f);
    needleEdgePaint.setAntiAlias(true);

    canvas.drawOval(new RectF(95, 95, 105, 105), needleInsidePaint);
    canvas.drawOval(new RectF(95, 96, 105, 105), needleEdgePaint);

    Path needleInside = new Path();
    needleInside.moveTo(98, 98);
    needleInside.lineTo(100, 20);
    needleInside.lineTo(102, 102);
    canvas.drawPath(needleInside, needleInsidePaint);

    Path needleEdge = new Path();
    needleInside.moveTo(99, 99);
    needleInside.lineTo(99, 19);
    needleInside.lineTo(103, 103);

    canvas.drawPath(needleEdge, needleEdgePaint);
    canvas.restore();
}