Example usage for android.graphics Paint setTypeface

List of usage examples for android.graphics Paint setTypeface

Introduction

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

Prototype

public Typeface setTypeface(Typeface typeface) 

Source Link

Document

Set or clear the typeface object.

Usage

From source file:com.cssweb.android.view.FinanceMini.java

public void drawHKPrice(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/*  w ww.  j a v a  2 s .  c o m*/
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2, -DY * 4);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint);
            canvas.translate(0, DY);
            //            if(jo.getDouble("wb")<0)
            //               paint.setColor(GlobalColor.colorPriceDown);
            //            else if(jo.getDouble("wb")>0)
            //               paint.setColor(GlobalColor.colorpriceUp);
            //            else 
            //               paint.setColor(GlobalColor.colorPriceEqual);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("wb")*100, 1)+"%", x-tips, y, paint);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjje"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("msgs"), true), x - tips, y, paint);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, -DY * 3);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            //            canvas.drawText("", x, y, paint);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 3);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint);
            canvas.translate(0, DY);
            //            if(jo.getDouble("wc")<0) {
            //               paint.setColor(GlobalColor.colorPriceDown);
            //               canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x-tips, y, paint);
            //            }
            //            else if(jo.getDouble("wc")>0) {
            //               paint.setColor(GlobalColor.colorpriceUp);
            //               canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint);
            //            }
            //            else {
            //               paint.setColor(GlobalColor.colorPriceEqual);
            //               canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint);
            //            }
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.drawText("", x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint);
            //            paint.setColor(GlobalColor.colorStockName);
            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x-tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

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

/**
 * Draw Section titles for sec 1 and 2/*w  ww.  ja  va2s.  com*/
 * @param xLoc left location
 * @param yLoc top location
 * @param width size from xLoc, to middle of end circle
 * @param string header string
 * @param index header number
 */
private void drawHeader1(int xLoc, int yLoc, int width, String string, int index) {
    int RADIUS = 14;
    float INNER_RADIUS = 13;
    int centre = yLoc + RADIUS;
    width = xLoc + width;
    int middle = width - 54;
    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.drawCircle(width, centre, INNER_RADIUS, paintW);
    can.drawRect(middle, centre - INNER_RADIUS, width, centre + INNER_RADIUS, paintW);
    can.drawCircle(middle, centre, RADIUS, paint);

    can.drawText(string, xLoc + 31, centre + 5, paintW);
    can.drawText("YES   NO", width - 35, centre + 5, paint);
    paint.setTextSize(FONT16);
    can.drawText(String.valueOf(index), xLoc + RADIUS - 4, centre + 6, paint);

}

From source file:com.cssweb.android.view.FinanceMini.java

private void drawQihuo(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);//from  w w w  . j  a  v a 2 s.  c  o m
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText(" ", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2, -DY * 4);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint);

            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrjs"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zt"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrcc"), 0, jo.getInt("tp")), x - tips, y, paint);

            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0), x-tips, y, paint);

            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x, y, paint);

            canvas.translate(0, -DY * 4);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);

            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText(" ", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            canvas.translate(width / 2, -DY * 5);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), false), x - tips, y, paint);

            paint.setColor(GlobalColor.colorPriceEqual);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zrjs"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("dt"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zc"), 0, jo.getInt("tp")), x - tips, y, paint);

            //            paint.setColor(GlobalColor.colorStockName);
            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0), x-tips, y, paint);   

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

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

/**
 * Draw headers, for sec 3,4,5/*from   ww w . j av  a 2  s. co m*/
 * @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.grottworkshop.gwsindiaink.TypefaceHelper.java

/**
 * Set the typeface to the target paint.
 * @param paint the set typeface.//from  w  w w.  j  av  a  2 s .c  o m
 * @param typefaceName typeface name.
 */
public void setTypeface(Paint paint, String typefaceName) {
    Typeface typeface = mCache.get(typefaceName);
    paint.setTypeface(typeface);
}

From source file:com.cssweb.android.view.FinanceMini.java

public void drawPrice(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);// w ww  . j a v a2s.c  om
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            int syjd = jo.getInt("syjd");
            switch (syjd) {
            case 1:
                canvas.drawText("()", x, y, paint);
                break;
            case 2:
                canvas.drawText("()", x, y, paint);
                break;
            case 3:
                canvas.drawText("()", x, y, paint);
                break;
            case 4:
                canvas.drawText("()", x, y, paint);
                break;
            default:
                canvas.drawText("", x, y, paint);
                break;
            }

            if (jo.getDouble("wb") < 0)
                paint.setColor(GlobalColor.colorPriceDown);
            else if (jo.getDouble("wb") > 0)
                paint.setColor(GlobalColor.colorpriceUp);
            else
                paint.setColor(GlobalColor.colorPriceEqual);
            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 5);
            if (jo.getInt("tp") == 1)
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(Utils.dataFormation(jo.getDouble("wb") * 100, 1) + "%", x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("hs") * 100, 1) + "%", x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jz"), 1), x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("mgsy"), 2), x - tips, y, paint);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, -DY * 5);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            if (NameRule.isBond(type))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText("PE()", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 5);
            if (jo.getDouble("wc") < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
                canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x - tips, y,
                        paint);
            } else if (jo.getDouble("wc") > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
                canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x - tips, y, paint);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
                canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), false), x - tips, y, paint);
            }
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint);
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("gb"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("ltsl") * 100, true), x - tips, y, paint);
            canvas.translate(0, DY);
            if (NameRule.isBond(type)) {
                canvas.drawText(Utils.dataFormation(jo.getDouble("fullprice"), 1), x - tips, y, paint);
            } else {
                canvas.drawText(Utils.dataFormation(jo.getDouble("sy"), 1), x - tips, y, paint);
            }
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

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   w w w . j a  v a2  s.  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: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  va2 s  . co  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: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 av  a 2  s  . c  om*/

    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:com.slushpupie.deskclock.DeskClock.java

private Rect getBoundingBox(String text, Typeface font, float size) {
    Rect r = new Rect(0, 0, 0, 0);
    float widths[] = new float[text.length()];
    float width = 0;
    Paint paint = new Paint(0);
    paint.setTypeface(font);
    paint.setTextSize(size);/* w  w  w  . j a  va2s .  c  o m*/
    paint.getTextBounds(text, 0, text.length(), r);
    paint.getTextWidths(text, widths);
    for (float w : widths)
        width += w;
    r.right = (int) width;
    return r;
}