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.madgag.android.lazydrawables.samples.DemoListActivity.java

private ImageResourceDownloader<String, Bitmap> slowImageMaker() {
    return new ImageResourceDownloader<String, Bitmap>() {
        public Bitmap get(String key) {
            Log.d(TAG, "Asked to download " + key);
            try {
                Thread.sleep(4000L);
            } catch (InterruptedException e) {
            }//from  ww  w.  j  av a2 s.  c  om
            Bitmap bitmap = Bitmap.createBitmap(80, 80, Bitmap.Config.ARGB_8888);
            Canvas c = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.setColor(0xff0000ff);
            c.drawCircle(0, 0, 50, paint);

            paint.setColor(0xffff007f);
            paint.setStyle(Paint.Style.FILL);
            paint.setAntiAlias(true);
            paint.setTextSize(30);
            c.drawText(key, 0, 3, 0, 60, paint);
            Log.d(TAG, "Done drawing... " + key);
            return bitmap;
        }
    };
}

From source file:com.androidmapsextensions.DefaultClusterOptionsProvider.java

private Paint createTextPaint(Resources resources) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(resources.getColor(R.color.ame_default_cluster_text_color));
    shadowBlurRadius = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_blur_radius);
    if (shadowBlurRadius > 0.0f) {
        shadowOffsetX = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_offset_x);
        shadowOffsetY = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_offset_y);
        int shadowColor = resources.getColor(R.color.ame_default_cluster_text_shadow_color);
        paint.setShadowLayer(shadowBlurRadius, shadowOffsetX, shadowOffsetY, shadowColor);
    }/*from w w w . j  av a2  s .  c  om*/
    paint.setTextSize(resources.getDimension(R.dimen.ame_default_cluster_text_size));
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    return paint;
}

From source file:com.kth.baasio.baassample.BaseActivity.java

/**
 * Sets the icon color using some fancy blending mode trickery.
 *//*from   w w w.  ja v  a  2s. co m*/
protected void setActionBarColor(int color) {
    if (color == 0) {
        color = 0xffffffff;
    }

    final Resources res = getResources();
    Drawable maskDrawable = res.getDrawable(R.drawable.actionbar_icon_mask);
    if (!(maskDrawable instanceof BitmapDrawable)) {
        return;
    }

    Bitmap maskBitmap = ((BitmapDrawable) maskDrawable).getBitmap();
    final int width = maskBitmap.getWidth();
    final int height = maskBitmap.getHeight();

    Bitmap outBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(outBitmap);
    canvas.drawBitmap(maskBitmap, 0, 0, null);

    Paint maskedPaint = new Paint();
    maskedPaint.setColor(color);
    maskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));

    canvas.drawRect(0, 0, width, height, maskedPaint);

    BitmapDrawable outDrawable = new BitmapDrawable(res, outBitmap);
    getSupportActionBar().setIcon(outDrawable);
}

From source file:io.github.hidroh.materialistic.widget.AsteriskSpan.java

@Override
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y,
        int bottom, @NonNull Paint paint) {
    float radius = mPadding;
    float centerX = x + radius + mPadding;
    float centerY = top + radius + mPadding;
    paint.setColor(mBackgroundColor);
    canvas.drawCircle(centerX, centerY, radius, paint);
    paint.setColor(mTextColor);//w ww. jav  a  2s .c  o m
    canvas.drawText(text, start, end, x + mPadding * 2, y, paint);
}

From source file:foam.jellyfish.StarwispCanvas.java

@Override
public void onDraw(Canvas canvas) {
    float sx = getWidth() / 320.0f;
    float sy = getHeight() / 200.0f;

    Paint myPaint = new Paint();
    myPaint.setStrokeWidth(0);//from w  w  w .  j  a v a2  s  .  c o  m
    myPaint.setColor(Color.rgb(127, 127, 127));
    canvas.drawRect(0, 0, getWidth(), getHeight(), myPaint);

    try {
        for (int i = 0; i < m_Drawlist.length(); i++) {
            JSONArray prim = m_Drawlist.getJSONArray(i);
            if (prim.getString(0).equals("line")) {
                DrawLine(canvas, prim, sx, sy);
            }
            if (prim.getString(0).equals("text")) {
                DrawText(canvas, prim, sx, sy);
            }
        }
    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing data " + e.toString());
    }
}

From source file:com.sebible.cordova.videosnapshot.VideoSnapshot.java

private void drawTimestamp(Bitmap bm, String prefix, long timeMs, int textSize) {
    float w = bm.getWidth(), h = bm.getHeight();
    float size = (float) (textSize * bm.getWidth()) / 1280;
    float margin = (float) (w < h ? w : h) * 0.05f;

    Canvas c = new Canvas(bm);
    Paint p = new Paint();
    p.setColor(Color.WHITE);
    p.setStrokeWidth((int) (size / 10));
    p.setTextSize((int) size); // Text Size
    p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text Overlapping Pattern

    long second = (timeMs / 1000) % 60;
    long minute = (timeMs / (1000 * 60)) % 60;
    long hour = (timeMs / (1000 * 60 * 60)) % 24;

    String text = String.format("%s %02d:%02d:%02d", prefix, hour, minute, second);
    Rect r = new Rect();
    p.getTextBounds(text, 0, text.length(), r);
    //c.drawBitmap(originalBitmap, 0, 0, paint);
    c.drawText(text, bm.getWidth() - r.width() - margin, bm.getHeight() - r.height() - margin, p);
}

From source file:foam.jellyfish.StarwispCanvas.java

public Paint getPaint(Canvas canvas, JSONArray prim) {
    try {//from   w  ww  .  j a  v  a  2  s .c o  m
        Paint myPaint = new Paint();
        JSONArray c = prim.getJSONArray(1);
        myPaint.setColor(Color.rgb(c.getInt(0), c.getInt(1), c.getInt(2)));
        myPaint.setStrokeWidth(prim.getInt(2));
        return myPaint;
    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing data " + e.toString());
        return null;
    }
}

From source file:foam.jellyfish.StarwispCanvas.java

public void DrawText(Canvas canvas, JSONArray prim, float sx, float sy) {
    try {//from  w  ww . ja  va2  s.  co  m
        canvas.save();
        if (prim.getString(6).equals("vertical"))
            canvas.rotate(-90, prim.getInt(2) * sx, prim.getInt(3) * sy);

        Paint myPaint = new Paint();
        JSONArray c = prim.getJSONArray(4);
        myPaint.setColor(Color.rgb(c.getInt(0), c.getInt(1), c.getInt(2)));
        myPaint.setTextSize(prim.getInt(5));
        myPaint.setTypeface(m_Typeface);
        canvas.drawText(prim.getString(1), prim.getInt(2) * sx, prim.getInt(3) * sy, myPaint);
        canvas.restore();
    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing data " + e.toString());
    }
}

From source file:com.nextgis.maplib.display.SimpleMarkerStyle.java

protected void onDraw(GeoPoint pt, GISDisplay display) {
    if (null == pt)
        return;/*  w  ww.  j  ava 2 s  .  c  o  m*/

    switch (mType) {
    case MarkerStylePoint:
        Paint ptPaint = new Paint();
        ptPaint.setColor(mColor);
        ptPaint.setStrokeWidth((float) (mSize / display.getScale()));
        ptPaint.setStrokeCap(Paint.Cap.ROUND);
        ptPaint.setAntiAlias(true);

        display.drawPoint((float) pt.getX(), (float) pt.getY(), ptPaint);
        break;
    case MarkerStyleCircle:
        Paint fillCirclePaint = new Paint();
        fillCirclePaint.setColor(mColor);
        fillCirclePaint.setStrokeCap(Paint.Cap.ROUND);

        display.drawCircle((float) pt.getX(), (float) pt.getY(), mSize, fillCirclePaint);

        Paint outCirclePaint = new Paint();
        outCirclePaint.setColor(mOutColor);
        outCirclePaint.setStrokeWidth((float) (mWidth / display.getScale()));
        outCirclePaint.setStyle(Paint.Style.STROKE);
        outCirclePaint.setAntiAlias(true);
        display.drawCircle((float) pt.getX(), (float) pt.getY(), mSize, outCirclePaint);

        break;
    case MarkerStyleDiamond:
        break;
    case MarkerStyleCross:
        break;
    case MarkerStyleTriangle:
        break;
    case MarkerStyleBox:
        break;
    }
}

From source file:im.neon.util.VectorUtils.java

/**
 * Create an avatar bitmap from a text.//from ww  w .  ja v a 2 s .co  m
 *
 * @param backgroundColor the background color.
 * @param text            the text to display.
 * @param pixelsSide      the avatar side in pixels
 * @return the generated bitmap
 */
private static Bitmap createAvatar(int backgroundColor, String text, int pixelsSide) {
    android.graphics.Bitmap.Config bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;

    Bitmap bitmap = Bitmap.createBitmap(pixelsSide, pixelsSide, bitmapConfig);
    Canvas canvas = new Canvas(bitmap);

    canvas.drawColor(backgroundColor);

    // prepare the text drawing
    Paint textPaint = new Paint();
    textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
    textPaint.setColor(Color.WHITE);
    // the text size is proportional to the avatar size.
    // by default, the avatar size is 42dp, the text size is 28 dp (not sp because it has to be fixed).
    textPaint.setTextSize(pixelsSide * 2 / 3);

    // get its size
    Rect textBounds = new Rect();
    textPaint.getTextBounds(text, 0, text.length(), textBounds);

    // draw the text in center
    canvas.drawText(text, (canvas.getWidth() - textBounds.width() - textBounds.left) / 2,
            (canvas.getHeight() + textBounds.height() - textBounds.bottom) / 2, textPaint);

    // Return the avatar
    return bitmap;
}