Example usage for android.graphics Paint Paint

List of usage examples for android.graphics Paint Paint

Introduction

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

Prototype

public Paint() 

Source Link

Document

Create a new paint with default settings.

Usage

From source file:org.jared.synodroid.ds.utils.Utils.java

/**
 * Create a rounded bitmap//from   w w  w.  ja  va 2 s.  c  om
 * 
 * @param bitmap
 *            The original bitmap
 * @return
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
    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);

    paint.setAntiAlias(true);
    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:cc.softwarefactory.lokki.android.utilities.Utils.java

public static Bitmap getDefaultAvatarInitials(Context context, String text) {

    Log.e(TAG, "getDefaultAvatarInitials");

    String initials = getInitials(text);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);// ww w .j a va2  s. c  om
    paint.setTextSize(36);
    paint.setStrokeWidth(4);
    paint.setTextAlign(Paint.Align.CENTER);

    Bitmap bm = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bm);
    canvas.drawColor(context.getResources().getColor(R.color.material_blue_300));

    int distanceFromBaseline = (int) ((paint.descent() + paint.ascent()) / 2);
    int xPos = (canvas.getWidth() / 2);
    int yPos = (canvas.getHeight() / 2) - distanceFromBaseline;
    canvas.drawText(initials, xPos, yPos, paint);

    return bm;
}

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

@SuppressWarnings("unused")
private Bitmap RenderLineGraph() {
    Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888);

    int width = emptyBmap.getWidth();
    int height = emptyBmap.getHeight();
    Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(charty);
    final int color = 0xff0B0B61;
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);//from w w w.  jav  a  2  s.  co m

    //if(warningEvents > )
    canvas.drawText("100", 0, 10, paint);

    //y
    canvas.drawLine(25, 0, 25, 289, paint);
    //x
    canvas.drawLine(25, 149, 289, 149, paint);

    int CritArray[] = { 5, 4, 6, 10, 10, 6, 4, 4 };
    int curX = 25;

    int divisor = 148 / 10;
    paint.setColor(Color.RED);
    int curY = 148 - (CritArray[0] * divisor);

    for (int a : CritArray) {
        canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint);
        curX += 32;
        curY = 148 - (a * divisor);
    }

    int ErrArray[] = { 1, 2, 2, 2, 4, 2, 1, 0 };
    curX = 25;

    paint.setColor(Color.rgb(255, 102, 0));
    curY = 148 - (ErrArray[0] * divisor);

    for (int a : ErrArray) {
        canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint);
        curX += 32;
        curY = 148 - (a * divisor);
    }

    int WarnArray[] = { 0, 2, 4, 8, 10, 4, 2, 2 };
    curX = 25;

    paint.setColor(Color.YELLOW);
    curY = 148 - (WarnArray[0] * divisor);

    Path myPath = new Path();

    for (int a : WarnArray) {
        canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint);
        curX += 32;
        curY = 148 - (a * divisor);
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    charty.compress(CompressFormat.PNG, 50, out);

    return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size());
}

From source file:com.github.barcodeeye.scan.CaptureActivity.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of
 * the barcode./*from  w ww  .  ja va  2  s.  c  om*/
 *
 * @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 static void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult, int color) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
        Canvas canvas = new Canvas(barcode);
        Paint paint = new Paint();
        paint.setColor(color);
        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:com.ridgelineapps.wallpaper.Utils.java

public static Paint createPaint(int alpha, int r, int g, int b) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);//from  ww w  .  j  a  v a2s. c  om
    paint.setARGB(alpha, r, g, b);
    return paint;
}

From source file:app.android.datetimepicker.date.SimpleMonthView.java

/**
 * Sets up the text and style properties for painting. Override this if you
 * want to use a different paint./*from w w w.  ja  va  2 s  . c o  m*/
 */
protected void initView() {
    mMonthTitlePaint = new Paint();
    mMonthTitlePaint.setFakeBoldText(true);
    mMonthTitlePaint.setAntiAlias(true);
    mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
    mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
    mMonthTitlePaint.setColor(mDayTextColor);
    mMonthTitlePaint.setTextAlign(Align.CENTER);
    mMonthTitlePaint.setStyle(Style.FILL);

    mMonthTitleBGPaint = new Paint();
    mMonthTitleBGPaint.setFakeBoldText(true);
    mMonthTitleBGPaint.setAntiAlias(true);
    mMonthTitleBGPaint.setColor(mMonthTitleBGColor);
    mMonthTitleBGPaint.setTextAlign(Align.CENTER);
    mMonthTitleBGPaint.setStyle(Style.FILL);

    mSelectedCirclePaint = new Paint();
    mSelectedCirclePaint.setFakeBoldText(true);
    mSelectedCirclePaint.setAntiAlias(true);
    mSelectedCirclePaint.setColor(mTodayNumberColor);
    mSelectedCirclePaint.setTextAlign(Align.CENTER);
    mSelectedCirclePaint.setStyle(Style.FILL);
    mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);

    mMonthDayLabelPaint = new Paint();
    mMonthDayLabelPaint.setAntiAlias(true);
    mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
    mMonthDayLabelPaint.setColor(mDayTextColor);
    mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
    mMonthDayLabelPaint.setStyle(Style.FILL);
    mMonthDayLabelPaint.setTextAlign(Align.CENTER);
    mMonthDayLabelPaint.setFakeBoldText(true);

    mMonthNumPaint = new Paint();
    mMonthNumPaint.setAntiAlias(true);
    mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
    mMonthNumPaint.setStyle(Style.FILL);
    mMonthNumPaint.setTextAlign(Align.CENTER);
    mMonthNumPaint.setFakeBoldText(false);
}

From source file:com.ridgelineapps.wallpaper.Utils.java

public static Paint createPaint(int r, int g, int b) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);//from   w  w  w.j a v a  2  s  . c om
    paint.setARGB(255, r, g, b);
    return paint;
}

From source file:org.cocos2dx.lib.Cocos2dxBitmap.java

private static Paint newPaint(String fontName, int fontSize, int alignment) {
    Paint paint = new Paint();
    paint.setColor(Color.WHITE);//from w  ww . jav a  2s.c o m
    paint.setTextSize(fontSize);
    paint.setAntiAlias(true);

    /*
     * Set type face for paint, now it support .ttf file.
     */
    if (fontName.endsWith(".ttf")) {
        try {
            //Typeface typeFace = Typeface.createFromAsset(context.getAssets(), fontName);
            Typeface typeFace = Cocos2dxTypefaces.get(context, fontName);
            paint.setTypeface(typeFace);
        } catch (Exception e) {
            Log.e("Cocos2dxBitmap", "error to create ttf type face: " + fontName);

            /*
             * The file may not find, use system font
             */
            paint.setTypeface(Typeface.create(fontName, Typeface.NORMAL));
        }
    } else {
        paint.setTypeface(Typeface.create(fontName, Typeface.NORMAL));
    }

    int hAlignment = alignment & 0x0F;
    switch (hAlignment) {
    case HALIGNCENTER:
        paint.setTextAlign(Align.CENTER);
        break;

    case HALIGNLEFT:
        paint.setTextAlign(Align.LEFT);
        break;

    case HALIGNRIGHT:
        paint.setTextAlign(Align.RIGHT);
        break;

    default:
        paint.setTextAlign(Align.LEFT);
        break;
    }

    return paint;
}

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  w  w  .  ja  v a 2s  .  c om*/
    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:gov.sfmta.sfpark.AnnotationsOverlay.java

public void draw(Canvas canvas, MapView mapv, boolean shadow) {
    if (shadow) {
        return;//from w  w w . ja  v  a  2 s  .  c  o m
    }

    Projection projection = mapv.getProjection();

    Point from = new Point();
    Point to = new Point();

    Paint mPaint = new Paint();
    mPaint.setStyle(Style.STROKE);
    mPaint.setAntiAlias(true);
    mPaint.setStrokeWidth(6);
    mPaint.setStrokeCap(Paint.Cap.ROUND);

    // could have NPE:
    try {
        for (MyAnnotation a : MainScreenActivity.annotations) {
            if (a.onStreet) {
                projection.toPixels(a.nw, from);
                projection.toPixels(a.se, to);
                if (MainScreenActivity.showPrice) {
                    mPaint.setColor(a.blockColorPrice);
                    canvas.drawLine(from.x, from.y, to.x, to.y, mPaint);
                } else {
                    // new: no more availability data on blockfaces.
                    // mPaint.setColor(a.blockColorAvailability);
                }
            }
        }
    } catch (NullPointerException npe) {
        // oh sadface! just ignore.
    }

    super.draw(canvas, mapv, shadow);
}