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.semfapp.adamdilger.semf.Take5PdfDocument.java

/**
 * Draw headers, for sec 3,4,5//from   ww w  .ja  v a 2  s .c  om
 * @param xLoc left location
 * @param yLoc top location
 * @param string header string
 * @param index header index
 */
private void drawSmallCircle(int xLoc, int yLoc, String string, int index) {
    int RADIUS = 14;
    float INNER_RADIUS = 13;
    int centre = yLoc + RADIUS;
    int width = xLoc + 176;
    Paint paint = new Paint();
    Paint paintW = new Paint();
    paintW.setTypeface(impact);
    paint.setTypeface(impact);
    paintW.setColor(Color.WHITE);
    paintW.setTextSize(FONT12);
    paint.setTextSize(FONT12);

    can.drawCircle(xLoc + RADIUS, centre, RADIUS, paint);
    can.drawRect(xLoc + RADIUS, centre - RADIUS, width, centre + RADIUS, paint);
    can.drawCircle(width, centre, RADIUS, paint);
    can.drawCircle(xLoc + RADIUS, centre, INNER_RADIUS, paintW);
    can.drawText(string, xLoc + 29, centre + 4.5f, paintW);
    paint.setTextSize(FONT16);
    can.drawText(String.valueOf(index), xLoc + RADIUS - 4, centre + 6, paint);

    //drawSmallCircle(8, 331, "Assess the level of risk", 3);
    drawText(mCheckBoxSectionThree.get(index - 3).getHeading(), xLoc + 8, yLoc + 35, FONT12, carlitoBold);

    drawText("YES", xLoc + 95, yLoc + 35, FONT14, impact);
    drawText("NO", xLoc + 138, yLoc + 35, FONT14, impact);

    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(.5f);
    can.drawRect(xLoc + 118, yLoc + 36, xLoc + 118 + 14, yLoc + 36 + 14, paint);

    paint.setStrokeWidth(1.5f);
    can.drawRect(xLoc + 156, yLoc + 36, xLoc + 156 + 14, yLoc + 36 + 14, paint);

    Take5Data.CheckValue isYes = mCheckBoxSectionThree.get(index - 3).getCheckValue();
    if (isYes == Take5Data.CheckValue.YES) {
        drawCheck(xLoc + 118, yLoc + 36, paint);
    } else if (isYes == Take5Data.CheckValue.NO) {
        drawCheck(xLoc + 156, yLoc + 36, paint);
    }
}

From source file:com.google.blockly.android.ui.AbstractBlockView.java

/**
 * This is a developer testing function subclasses can call to draw dots at the model's location
 * of all connections on this block.  Never called by default.
 *
 * @param c The canvas to draw on./*from w  w  w  .  j  a  v  a2s . c  om*/
 */
protected void drawConnectorCenters(Canvas c) {
    List<Connection> connections = mBlock.getAllConnections();
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    for (int i = 0; i < connections.size(); i++) {
        Connection conn = connections.get(i);
        if (conn.inDragMode()) {
            if (conn.isConnected()) {
                paint.setColor(Color.RED);
            } else {
                paint.setColor(Color.MAGENTA);
            }
        } else {
            if (conn.isConnected()) {
                paint.setColor(Color.GREEN);
            } else {
                paint.setColor(Color.CYAN);
            }
        }

        // Compute connector position relative to this view from its offset to block origin in
        // Workspace coordinates.
        mTempWorkspacePoint.set(conn.getPosition().x - mBlock.getPosition().x,
                conn.getPosition().y - mBlock.getPosition().y);
        mHelper.workspaceToVirtualViewDelta(mTempWorkspacePoint, mTempConnectionPosition);
        if (mHelper.useRtl()) {
            // In RTL mode, add block view size to x coordinate. This is counter-intuitive, but
            // equivalent to "x = size - (-x)", with the inner negation "-x" undoing the
            // side-effect of workspaceToVirtualViewDelta reversing the x coordinate. This is,
            // the addition mirrors the re-negated in-block x coordinate w.r.t. the right-hand
            // side of the block view, which is the origin of the block in RTL mode.
            mTempConnectionPosition.x += mBlockViewSize.x;
        }
        c.drawCircle(mTempConnectionPosition.x, mTempConnectionPosition.y, 10, paint);
    }
}

From source file:com.dgnt.dominionCardPicker.view.DynamicListView.java

/** Draws a black border over the screenshot of the view passed in. */
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.colorAccent));

    can.drawBitmap(bitmap, 0, 0, null);/* w  w w.  j a  v a 2 s. co  m*/
    can.drawRect(rect, paint);

    return bitmap;
}

From source file:de.uni.stuttgart.informatik.ToureNPlaner.UI.Activities.MapScreen.MapScreen.java

private void setupWayOverlay() {
    Path p = new Path();
    p.moveTo(4.f, 0.f);//from   w  w w.  j  a  v  a  2 s  .  c  om
    p.lineTo(0.f, -4.f);
    p.lineTo(8.f, -4.f);
    p.lineTo(12.f, 0.f);
    p.lineTo(8.f, 4.f);
    p.lineTo(0.f, 4.f);

    Paint fastWayOverlayColor = new Paint(Paint.ANTI_ALIAS_FLAG);
    fastWayOverlayColor.setStyle(Paint.Style.STROKE);
    fastWayOverlayColor.setColor(Color.BLUE);
    fastWayOverlayColor.setAlpha(160);
    fastWayOverlayColor.setStrokeWidth(5.f);
    fastWayOverlayColor.setStrokeJoin(Paint.Join.ROUND);
    fastWayOverlayColor.setPathEffect(new ComposePathEffect(
            new PathDashPathEffect(p, 12.f, 0.f, PathDashPathEffect.Style.ROTATE), new CornerPathEffect(30.f)));

    // create the WayOverlay and add the ways
    this.fastWayOverlay = new FastWayOverlay(session, fastWayOverlayColor);
    mapView.getOverlays().add(this.fastWayOverlay);
    Result result = session.getResult();
    if (result != null) {
        addPathToMap(result.getWay());
    }
}

From source file:com.concavenp.artistrymuse.BaseAppCompatActivity.java

private BitmapImageViewTarget createBitmapImageViewTarget(final ImageView imageView) {

    return new BitmapImageViewTarget(imageView) {
        @Override/*w w  w .j  a v a2  s  .  c o m*/
        protected void setResource(Bitmap bitmap) {

            int bitmapWidth = bitmap.getWidth();
            int bitmapHeight = bitmap.getHeight();
            int borderWidthHalf = 10;
            int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight);
            int newBitmapSquare = bitmapSquareWidth + borderWidthHalf;

            Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquare, newBitmapSquare,
                    Bitmap.Config.ARGB_8888);

            // Initialize a new Canvas to draw empty bitmap
            Canvas canvas = new Canvas(roundedBitmap);

            // Calculation to draw bitmap at the circular bitmap center position
            int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth;
            int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight;

            canvas.drawBitmap(bitmap, x, y, null);

            // Initializing a new Paint instance to draw circular border
            Paint borderPaint = new Paint();
            borderPaint.setStyle(Paint.Style.STROKE);
            borderPaint.setStrokeWidth(borderWidthHalf * 2);
            borderPaint.setColor(ResourcesCompat.getColor(getResources(), R.color.myApp_accent_700, null));

            canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquare / 2, borderPaint);

            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(),
                    roundedBitmap);
            circularBitmapDrawable.setCircular(true);
            imageView.setImageDrawable(circularBitmapDrawable);

        }
    };
}

From source file:ch.ethz.dcg.jukefox.manager.libraryimport.AndroidAlbumCoverFetcherThread.java

private void drawTextOnBitmap(CompleteAlbum album, Bitmap bitmapHigh, int bitmapSize, float textHeight) {
    Canvas canvas = new Canvas(bitmapHigh);
    canvas.drawARGB(0, 125, 125, 125);//from  ww  w  . ja  v a  2s.c o m
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setTypeface(Typeface.SERIF);
    paint.setSubpixelText(true);
    paint.setTextSize(textHeight);
    paint.setAntiAlias(true);
    String artist = album.getArtists().get(0).getName();
    String shortenedText = new String(artist);

    int textLength = artist.length();
    if (textLength > 18) {
        shortenedText = artist.substring(0, 15) + "...";
        textLength = 18;
    } else if (textLength < 8) {
        while (shortenedText.length() < 8) {
            shortenedText = " " + shortenedText + " ";
        }
    }
    float pixelLength = paint.measureText(shortenedText);
    paint.setTextSize(textHeight * (bitmapSize * 2 / 3) / pixelLength);

    canvas.drawText(shortenedText, bitmapSize / 6, bitmapSize / 3, paint);

    shortenedText = album.getName();
    textLength = album.getName().length();
    if (textLength > 18) {
        shortenedText = album.getName().substring(0, 15) + "...";
        textLength = 18;
    } else if (textLength < 8) {
        while (shortenedText.length() < 8) {
            shortenedText = " " + shortenedText + " ";
        }
    }
    paint.setTextSize(bitmapSize / 10f);
    pixelLength = paint.measureText(shortenedText);
    textHeight = textHeight * bitmapSize * 2f / 3f / pixelLength;
    paint.setTextSize(textHeight);

    canvas.drawText(shortenedText, bitmapSize / 6f, bitmapSize * 2 / 3f + textHeight, paint);
}

From source file:com.crazyapk.util.bitmap.ImageWorker.java

public Bitmap toRoundCorner(Bitmap bitmap, int pixels) {

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;
    paint.setAntiAlias(true);//from w w  w .j a v a  2s .  c  o m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;

}

From source file:com.nextgis.maplibui.fragment.ReorderedLayerView.java

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

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

    canvas.drawBitmap(bitmap, 0, 0, null);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(LINE_THICKNESS);

    int accentColor = ControlHelper.getColor(getContext(), R.attr.colorAccent);

    paint.setColor(accentColor);
    canvas.drawRect(rect, paint);

    return bitmap;
}

From source file:com.mappn.gfan.ui.HomeTabActivity.java

private Bitmap drawText(DisplayMetrics dm, Resources res, Bitmap bm, int num) {
    final int height = bm.getScaledHeight(dm);
    final int width = bm.getScaledWidth(dm);
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    canvas.drawBitmap(bm, new Matrix(), new Paint());
    Paint textPainter = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPainter.setColor(res.getColor(R.color.tab_app_num));
    textPainter.setTextSize(dm.scaledDensity * 12);
    textPainter.setTypeface(Typeface.DEFAULT_BOLD);
    float textWidth = textPainter.measureText(String.valueOf(num)) / 2;
    canvas.drawText(String.valueOf(num), width / 2 - textWidth, height / 2 + (dm.scaledDensity * 6),
            textPainter);//from   w w  w.  j  a  v a2 s  . c o  m
    canvas.save();
    return newBitmap;
}