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.cleverzone.zhizhi.capture.CaptureActivity.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of the barcode.
 *
 * @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.
 *///from w  w w.  j a  va2s  .  c  om
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:Steps.StepsFragment.java

private void setBackgroundGlow(ImageView imgview, int imageicon, int r, int g, int b) {
    // An added margin to the initial image
    int margin = 50;
    int halfMargin = margin / 2;
    // the glow radius
    int glowRadius = 90;

    // the glow color
    int glowColor = Color.rgb(r, g, b);

    // The original image to use reduced(re-sampled)
    Bitmap src = SampleImage.decodeSampledBitmapFromResource(getResources(), imageicon, 250, 250);

    // extract the alpha from the source image
    Bitmap alpha = src.extractAlpha();//w w w .  jav  a  2 s.c  o  m

    // The output bitmap (with the icon + glow)
    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin, src.getHeight() + margin,
            Bitmap.Config.ARGB_8888);

    // The canvas to paint on the image
    Canvas canvas = new Canvas(bmp);

    Paint paint = new Paint();
    paint.setColor(glowColor);

    // outer glow
    paint.setMaskFilter(new BlurMaskFilter(glowRadius, BlurMaskFilter.Blur.OUTER));//For Inner glow set Blur.INNER
    canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);

    // original icon
    canvas.drawBitmap(src, halfMargin, halfMargin, null);

    imgview.setImageBitmap(bmp);

}

From source file:com.semfapp.adamdilger.semf.Take5PdfDocument.java

public PdfDocument createDocument() {
    //create new document
    PdfDocument document = new PdfDocument();

    // crate a page description
    PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(A4_WIDTH, A4_HEIGHT, 1).create();

    // start a page
    PdfDocument.Page page = document.startPage(pageInfo);

    can = page.getCanvas();/*from   w w  w.  j a  v a2 s  .  c o  m*/
    Paint paint = new Paint();
    paint.setStrokeWidth(0.5f);
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.STROKE);
    can.drawRect(1, 1, 594, 395, paint);

    /**
     * Page one Text Fields
     */
    drawText("Job Reference:", 9, 21, FONT14, carlitoBold);
    drawText("Date:", 354, 21, FONT14, carlitoBold);
    drawText("Time:", 473, 21, FONT14, carlitoBold);
    drawText("Location:", 9, 48, FONT14, carlitoBold);
    drawText("Task:", 261, 48, FONT14, carlitoBold);

    paint.setPathEffect(new DashPathEffect(new float[] { 1.5f, 1 }, 0));
    can.drawLine(85, 36, 350, 36, paint);
    can.drawLine(386, 36, 468, 36, paint);
    can.drawLine(506, 36, 585, 36, paint);
    can.drawLine(59, 60, 256, 60, paint);
    can.drawLine(291, 60, 585, 60, paint);

    if (mEditTextValues[0] != null) {
        drawText(mEditTextValues[0], 98, 19, FONT14, roboto);
    }
    if (mEditTextValues[1] != null) {
        drawText(mEditTextValues[1], 65, 44, FONT14, roboto);
    }
    if (mEditTextValues[2] != null) {
        drawText(mEditTextValues[2], 297, 44, FONT14, roboto);
    }
    drawText(mDateString, 390, 19, FONT14, roboto);
    drawText(mTimeString, 509, 19, FONT14, roboto);

    /**
     * Section One (Stop, step back...)
     */
    drawHeader1(8, 69, 202, "Stop, step back and think", 1);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(0.35f);
    paint.setPathEffect(null);
    int left, top;

    //draw left boxes
    left = 177;
    top = 108;
    for (int x = 0; x < mCheckBoxSectionOne.size(); x++) {
        Take5Data.CheckValue isYes = mCheckBoxSectionOne.get(x).getCheckValue();
        float topLoc = top + (x * 33);

        if (x < 1) { //allowing for different 1st row size
            drawBox(left, topLoc, paint, true, isYes);
        } else {
            float newTop = topLoc - 6;
            if (x < 3) {
                drawBox(left, newTop, paint, false, isYes);
            } else {
                drawBox(left, newTop, paint, true, isYes);
            }
        }
    }

    DashPathEffect pathEffect = new DashPathEffect(new float[] { 1, 1.5f }, 0);

    drawText(mCheckBoxSectionOne.get(0).getHeading(), 13, 113, FONT12, carlitoBold);

    for (int x = 1; x < mCheckBoxSectionOne.size(); x++) {
        int height = 132 + ((x - 1) * 33);
        drawText(mCheckBoxSectionOne.get(x).getHeading(), 13, height, FONT12, carlitoBold);
        paint.setPathEffect(pathEffect);
        can.drawLine(10, height - 6, 222, height - 6, paint);
        paint.setPathEffect(null);
    }

    /**
     * Section Two (Identidy the Hazards...)
     */
    drawHeader1(230, 69, 345, "Identify the hazard(s)", 2);

    //draw right boxes
    left = 542;
    top = 104;
    for (int x = 0; x < mCheckBoxSectionTwo.size(); x++) {
        float topLoc = top + (x * 20.7f);
        Take5Data.CheckValue isYes = mCheckBoxSectionTwo.get(x).getCheckValue();
        drawBox(left, topLoc, paint, false, isYes);
    }

    for (int x = 0; x < mCheckBoxSectionTwo.size(); x++) {
        float height = 105 + (x * 20.7f);
        drawText(mCheckBoxSectionTwo.get(x).getHeading(), 238, height + 3, FONT12, carlitoBold);
        if (x > 0) {
            paint.setPathEffect(pathEffect);
            can.drawLine(238, height - 4, 581, height - 4, paint);
            paint.setPathEffect(null);
        }
    }

    /**
     * draw section 3,4,5 (including checkboxes)
     */
    drawSmallCircle(8, 331, "Assess the level of risk", 3);
    drawSmallCircle(202, 331, "Control the hazards", 4);
    drawSmallCircle(398, 331, "Proceed safely", 5);

    /**
     * Draw Page Two
     */
    int xLoc = 7;
    int yLoc = 420;
    int height;
    int width = 565;
    int RADIUS = 14;
    float INNER_RADIUS = 13;
    int centre = yLoc + 7 + RADIUS;
    width = xLoc + width;
    int middle = width - 340;
    can.drawRect(1, 420, 594, 420 + 395, paint);

    paint.setStyle(Paint.Style.FILL);
    paint.setTypeface(impact);
    paint.setTextSize(12);

    can.drawCircle(xLoc + RADIUS, centre, RADIUS, paint);
    can.drawRect(xLoc + RADIUS, centre - RADIUS, width, centre + RADIUS, paint);
    can.drawCircle(width, centre, RADIUS, paint);
    paint.setColor(Color.WHITE);
    can.drawCircle(xLoc + RADIUS, centre, INNER_RADIUS, paint);
    can.drawCircle(width, centre, INNER_RADIUS, paint);
    can.drawRect(middle, centre - INNER_RADIUS, width, centre + INNER_RADIUS, paint);
    paint.setColor(Color.BLACK);
    can.drawCircle(middle, centre, RADIUS, paint);

    paint.setColor(Color.WHITE);
    can.drawText("SAFE WORK METHOD STATEMENT (SWMS)", xLoc + 31, centre + 5, paint);
    paint.setTextSize(16);
    paint.setColor(Color.BLACK);
    can.drawText(String.valueOf(4), xLoc + RADIUS - 4, centre + 6, paint);

    height = 50;
    drawText("What are the hazards and risks?", 25, yLoc + height, FONT12, carlitoBold);
    drawText("Risk\nRating", 267, yLoc + 47, FONT12, carlitoBold);
    drawText("How will hazards and risks be controlled?", 319, yLoc + height, FONT12, carlitoBold);

    paint.setPathEffect(pathEffect);
    can.drawLine(262, yLoc + 45, 262, yLoc + 320, paint);
    can.drawLine(302, yLoc + 45, 302, yLoc + 320, paint);
    paint.setPathEffect(null);

    float currentItemHeight = yLoc + 75;
    float padding = 5;

    for (int x = 0; x < mRiskElements.size(); x++) {
        int textHeight = (int) currentItemHeight;
        float totalItemHeight = drawRiskElement(textHeight, mRiskElements.get(x));
        currentItemHeight += totalItemHeight + padding;
    }

    paint.setPathEffect(pathEffect);
    height = yLoc + 350;
    drawText("Name/s:", 12, height, FONT12, carlitoBold);
    drawText(mEditTextValues[3], 55, height - 3, FONT14, roboto);
    paint.setPathEffect(pathEffect);
    can.drawLine(50, height + 12, 580, height + 12, paint);
    paint.setPathEffect(null);

    height = yLoc + 372;
    drawText("Signatures:", 12, height, FONT12, carlitoBold);
    drawText("Date:", 468, height, FONT12, carlitoBold);
    drawText(mDateString, 497, height - 3, FONT14, roboto);
    paint.setPathEffect(pathEffect);
    can.drawLine(60, height + 12, 464, height + 12, paint);
    can.drawLine(492, height + 12, 580, height + 12, paint);
    paint.setPathEffect(null);

    // finish the page
    document.finishPage(page);

    int imagePageCount = 2;

    for (Take5RiskElement risk : mRiskElements) {

        if (risk.imagePath != null) {

            // crate a page description
            PdfDocument.PageInfo pageInfo1 = new PdfDocument.PageInfo.Builder(A4_WIDTH, A4_HEIGHT,
                    imagePageCount).create();

            PdfDocument.Page imagePage = document.startPage(pageInfo1);
            Canvas canvas = imagePage.getCanvas();

            try {

                Bitmap original = BitmapFactory.decodeFile(risk.imagePath);

                Bitmap b = resize(original, canvas.getWidth() - 100, canvas.getHeight() - 100);
                canvas.drawBitmap(b, 50, 60, new Paint());
                //                    canvas.drawText(risk.getOne(), 50, 40, new Paint());

                Path textPath = new Path();
                textPath.moveTo(50, 50);
                textPath.lineTo(canvas.getWidth() - 100, 50);

                canvas.drawTextOnPath(risk.getOne(), textPath, 0, 0, new Paint());

            } catch (Exception e) {
                e.printStackTrace();
            }

            document.finishPage(imagePage);

            imagePageCount++;

            new File(risk.imagePath).delete();
        }
    }

    // add more pages
    return document;
}

From source file:org.chromium.chrome.browser.download.DownloadNotificationService.java

private Bitmap getLargeNotificationIcon(Bitmap bitmap) {
    Resources resources = mContext.getResources();
    int height = (int) resources.getDimension(android.R.dimen.notification_large_icon_height);
    int width = (int) resources.getDimension(android.R.dimen.notification_large_icon_width);
    final OvalShape circle = new OvalShape();
    circle.resize(width, height);/*from w  w  w . j  a va2s  .  c o m*/
    final Paint paint = new Paint();
    paint.setColor(ApiCompatibilityUtils.getColor(resources, R.color.google_blue_grey_500));

    final Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    circle.draw(canvas, paint);
    float leftOffset = (width - bitmap.getWidth()) / 2f;
    float topOffset = (height - bitmap.getHeight()) / 2f;
    if (leftOffset >= 0 && topOffset >= 0) {
        canvas.drawBitmap(bitmap, leftOffset, topOffset, null);
    } else {
        // Scale down the icon into the notification icon dimensions
        canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
                new Rect(0, 0, width, height), null);
    }
    return result;
}

From source file:nu.yona.app.customview.graph.SpreadGraph.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    this.mCanvas = canvas;
    float fullWidth = canvas.getWidth();

    float heightOfbar = GraphUtils.convertSizeToDeviceDependent(mContext, graphHeight);
    //first bar/*from ww  w. j  a v a 2s. co  m*/
    float mXStart = 0, mYStart = heightOfbar; // basically (X1, Y1)

    float bottom = heightOfbar; // height (distance from Y1 to Y2)

    mStartPoint = 0;
    mMiddlePoint = (fullWidth / 2);

    float spreadtime = fullWidth;

    float mPartSize = spreadtime / mNoParts;

    //todraw text from height
    float heightDraw = bottom + (GraphUtils.MARGIN_TOP * scaleFactor);

    //draw graphics of sun and moon
    Bitmap moonBitmap = drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon));
    float bitmapWidth = moonBitmap.getWidth() / 2;
    mCanvas.drawBitmap(moonBitmap, mStartPoint - (5 * scaleFactor), bottom + (5 * scaleFactor), null);
    mCanvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icn_sun)),
            mMiddlePoint - bitmapWidth, bottom + (5 * scaleFactor), null);

    float textPoint = (mMiddlePoint / 2) / 2;
    mCanvas.drawText(mContext.getString(R.string.four_hours), textPoint, heightDraw + scaleFactor,
            getFontStyle());
    float textPoint2 = textPoint * 2 + ((textPoint / 2));
    mCanvas.drawText(mContext.getString(R.string.eight_hours), textPoint2, heightDraw + scaleFactor,
            getFontStyle());
    float textPoint3 = textPoint * 5;
    mCanvas.drawText(mContext.getString(R.string.sixteen_hours), textPoint3 - bitmapWidth,
            heightDraw + scaleFactor, getFontStyle());
    float textPoint4 = textPoint * 6 + ((textPoint / 2));
    mCanvas.drawText(mContext.getString(R.string.twenty_hours), textPoint4 - bitmapWidth,
            heightDraw + scaleFactor, getFontStyle());
    float textPoint5 = textPoint * 7 + ((textPoint / 2));
    mCanvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon)), textPoint5,
            bottom + (5 * scaleFactor), null);

    if (mListZoneSpread != null && mListZoneSpread.size() > 0) {
        float currentStartPos;
        float currentEndPos;
        Paint barGraphPaint = new Paint();
        barGraphPaint.setStyle(Paint.Style.STROKE);
        barGraphPaint.setStrokeWidth(5);
        boolean skipThis;
        for (TimeZoneSpread timeZoneSpread : mListZoneSpread) {
            skipThis = false;
            currentStartPos = (float) timeZoneSpread.getIndex() * mPartSize;
            Path barPath = new Path();
            if (timeZoneSpread.getColor() == GraphUtils.COLOR_PINK
                    || timeZoneSpread.getColor() == GraphUtils.COLOR_BLUE) {
                currentEndPos = timeZoneSpread.getUsedValue();
                barGraphPaint.setColor(timeZoneSpread.getColor());
            } else if (timeZoneSpread.getColor() == GraphUtils.COLOR_GREEN) {
                if (timeZoneSpread.getUsedValue() == 15) {
                    currentEndPos = startEndPoint;
                    barGraphPaint.setColor(GraphUtils.COLOR_BULLET_DOT);
                } else {
                    currentEndPos = startEndPoint;
                    barGraphPaint.setColor(GraphUtils.COLOR_BLUE);
                }
            } else if (timeZoneSpread.getUsedValue() != 15
                    && timeZoneSpread.getColor() == GraphUtils.COLOR_BULLET_LIGHT_DOT) {
                currentEndPos = startEndPoint;
                barGraphPaint.setColor(timeZoneSpread.getColor());
                skipThis = true;
            } else {
                currentEndPos = startEndPoint;
                barGraphPaint.setColor(timeZoneSpread.getColor());
            }
            if (!skipThis) {
                float newXPos = mXStart + currentStartPos;
                barPath.moveTo(newXPos + 2, mYStart);
                float noPartsHeight = heightOfbar / 15;
                barPath.lineTo(currentStartPos + 2, mYStart - (currentEndPos * noPartsHeight) - 1);
                canvas.drawPath(barPath, barGraphPaint);
            }
        }

    }

}

From source file:com.spatialnetworks.fulcrum.widget.DynamicListView.java

/**
 * Draws a black border over the screenshot of the view passed in.
 *///w ww  .ja  va  2 s.  c o  m
private Bitmap getBitmapWithBorder(View v) {
    Bitmap bitmap = getBitmapFromView(v);
    Canvas can = new Canvas(bitmap);

    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(LINE_THICKNESS);
    paint.setColor(ContextCompat.getColor(getContext(), R.color.gray_230));

    can.drawBitmap(bitmap, 0, 0, null);
    can.drawRect(rect, paint);

    return bitmap;
}

From source file:net.gsantner.opoc.util.ContextUtils.java

/**
 * Draw text in the center of the given {@link DrawableRes}
 * This may be useful for e.g. badge counts
 *//*from w w w .ja  va  2 s .c  om*/
public Bitmap drawTextOnDrawable(@DrawableRes int drawableRes, String text, int textSize) {
    Resources resources = _context.getResources();
    float scale = resources.getDisplayMetrics().density;
    Bitmap bitmap = drawableToBitmap(drawableRes);

    bitmap = bitmap.copy(bitmap.getConfig(), true);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.rgb(61, 61, 61));
    paint.setTextSize((int) (textSize * scale));
    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    int x = (bitmap.getWidth() - bounds.width()) / 2;
    int y = (bitmap.getHeight() + bounds.height()) / 2;
    canvas.drawText(text, x, y, paint);

    return bitmap;
}

From source file:comingle.dragracing.TrackActivity.java

private void initSelfInfo() {
    Paint text_paint = new Paint();
    text_paint.setColor(Color.BLACK);
    text_paint.setTextSize(20);/*from  ww w  .j  av  a2s.  c o m*/

    track_canvas.drawText("YOU:", 20, LEGEND_MARGIN - 20, text_paint);
    track_canvas.drawText("THE BAD & UGLY:", 520, LEGEND_MARGIN - 20, text_paint);

    placeCarAvailable(myLocation(), 0, 0);
}

From source file:comingle.dragracing.TrackActivity.java

public void moveCar(Car car, int time_prev, int time_curr) {
    Paint bg_paint = new Paint();
    bg_paint.setColor(BG_COLOR);
    track_canvas.drawRect(car.getSprite(), bg_paint);
    int new_pos = RacerLib.newPos(car.getSprite().left, time_prev, time_curr);

    if (new_pos < TRACK_LENGTH) {
        car.move(new_pos);
        track_canvas.drawRect(car.getSprite(), car.getPaint());
    } else {/*from   ww  w  . ja  v a2  s.  c o m*/
        removeCar(car.getOwner());
        dragracingRuntime.getRewriteMachine().addExiting(car.getOwner());
    }
}

From source file:comingle.dragracing.TrackActivity.java

public void removeCar(int loc) {
    for (int x = 0; x < cars.size(); x++) {
        Car car = cars.get(x);//w  ww . j a v a  2s.c o m
        if (car.getOwner() == loc) {
            Paint bg_paint = new Paint();
            bg_paint.setColor(BG_COLOR);
            track_canvas.drawRect(car.getSprite(), bg_paint);
            cars.remove(x);
            return;
        }
    }
}