Example usage for android.graphics Paint setTextSize

List of usage examples for android.graphics Paint setTextSize

Introduction

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

Prototype

public void setTextSize(float textSize) 

Source Link

Document

Set the paint's text size.

Usage

From source file:comingle.dragracing.TrackActivity.java

private void initEndFlag() {
    Paint text_paint = new Paint();
    text_paint.setColor(Color.BLACK);
    text_paint.setTextSize(20);
    switch (lanes) {
    case 1:/*from ww  w  . ja v a  2  s .  co  m*/
    case 2:
    case 3:

        track_canvas.drawRect(780, 250, 800, 380, text_paint);
        break;
    case 4:
        track_canvas.drawRect(780, 250, 800, 420, text_paint);
        break;
    case 5:
        track_canvas.drawRect(780, 250, 800, 460, text_paint);
        break;
    case 6:
        track_canvas.drawRect(780, 250, 800, 500, text_paint);
        break;
    }
}

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);/*from   w w w. ja  va 2  s.  com*/
    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:comingle.dragracing.TrackActivity.java

private void initMarkers(LinkedList<Integer> locs) {
    Paint text_paint = new Paint();
    text_paint.setColor(Color.BLACK);
    text_paint.setTextSize(20);

    String prev = "Start";
    String next = "End";
    int x = locs.indexOf(getLocation());

    if (x == locs.size() - 1) {
        initEndFlag();/*from  w ww.  jav  a 2 s. c  o  m*/
    }

    if (x == 0) {
        initStartFlag();
    }

    if (x > 0) {
        prev = String.format("<< %s", INTERVAL_MARKERS[x - 1]);
    }

    if (x < locs.size() - 1) {
        next = String.format("%s >>", INTERVAL_MARKERS[x]);
    }

    //adjusted placement of markers
    track_canvas.drawText(prev, 20, TOP_MARGIN - 70, text_paint);
    track_canvas.drawText(next, 800 - 50, TOP_MARGIN - 70, text_paint);

}

From source file:comingle.dragracing.TrackActivity.java

private void initStartFlag() {
    Paint text_paint = new Paint();
    text_paint.setColor(Color.BLACK);
    text_paint.setTextSize(20);

    switch (lanes) {
    case 1://from w  ww  .ja va2 s.co m
    case 2:
    case 3:
        for (int j = 0; j <= 50; j = j + 50) {
            for (int i = 250; i <= 380; i = i + 40) {
                track_canvas.drawRect(j, i, j + 25, i + 20, text_paint);
            }
        }
        for (int k = 270; k <= 400; k = k + 40) {
            track_canvas.drawRect(25, k, 50, k + 20, text_paint);
        }
        break;
    case 4:
        for (int j = 0; j <= 50; j = j + 50) {
            for (int i = 250; i <= 420; i = i + 40) {
                track_canvas.drawRect(j, i, j + 25, i + 20, text_paint);
            }
        }
        for (int k = 270; k <= 440; k = k + 40) {
            track_canvas.drawRect(25, k, 50, k + 20, text_paint);
        }
        ;
        break;
    case 5:
        for (int j = 0; j <= 50; j = j + 50) {
            for (int i = 250; i <= 460; i = i + 40) {
                track_canvas.drawRect(j, i, j + 25, i + 20, text_paint);
            }
        }
        for (int k = 270; k <= 480; k = k + 40) {
            track_canvas.drawRect(25, k, 50, k + 20, text_paint);
        }
        ;
        break;
    case 6:
        for (int j = 0; j <= 50; j = j + 50) {
            for (int i = 250; i <= 500; i = i + 40) {
                track_canvas.drawRect(j, i, j + 25, i + 20, text_paint);
            }
        }
        for (int k = 270; k <= 520; k = k + 40) {
            track_canvas.drawRect(25, k, 50, k + 20, text_paint);
        }
        ;
        break;
    }
}

From source file:jp.gr.java_conf.piropiroping.bluetoothcommander.MainActivity.java

private void convertBitmapCommand(String command, int start, int stop) {
    //???//  ww w .j av a 2 s.  c o  m
    Paint objPaint = new Paint();
    Bitmap objBitmap;
    Canvas objCanvas;
    int textSize = 40;
    int textWidth = textSize * command.length(), textHeight = textSize;

    objPaint.setAntiAlias(true);
    objPaint.setColor(Color.BLUE);
    objPaint.setTextSize(textSize);
    Paint.FontMetrics fm = objPaint.getFontMetrics();
    objPaint.getTextBounds(command, 0, command.length(), new Rect(0, 0, textWidth, textHeight));

    //?
    textWidth = (int) objPaint.measureText(command);
    textHeight = (int) (Math.abs(fm.top) + fm.bottom);
    objBitmap = Bitmap.createBitmap(textWidth, textHeight, Bitmap.Config.ARGB_8888);

    //???
    objCanvas = new Canvas(objBitmap);
    objCanvas.drawText(command, 0, Math.abs(fm.top), objPaint);

    Editable editable = mOutEditText.getText();
    SpannableStringBuilder ssb = (SpannableStringBuilder) editable;
    ImageSpan is = new ImageSpan(getApplicationContext(), objBitmap);
    ssb.setSpan(is, start, stop + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:com.tealeaf.TeaLeaf.java

public Bitmap getBitmapFromView(EditText view) {
    //Define a bitmap with the same size as the view
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    //Bind a canvas to it
    Canvas canvas = new Canvas(returnedBitmap);
    //Get the view's background
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {
        //has background drawable, then draw it on the canvas
        bgDrawable.draw(canvas);/*from w ww .j  a  v a2 s  . c o m*/
    }
    // draw the view on the canvas
    view.draw(canvas);
    Paint p = new Paint();
    p.setColor(Color.BLACK);
    p.setTextSize(24);
    canvas.drawText("'ello mate", 0, 0, p);
    //return the bitmap
    return returnedBitmap;
}

From source file:io.doist.datetimepicker.time.RadialTimePickerView.java

/**
 * Using the trigonometric Unit Circle, calculate the positions that the text will need to be
 * drawn at based on the specified circle radius. Place the values in the textGridHeights and
 * textGridWidths parameters./* ww w  .j  a v  a 2 s  .c  o m*/
 */
private static void calculateGridSizes(Paint paint, float numbersRadius, float xCenter, float yCenter,
        float textSize, float[] textGridHeights, float[] textGridWidths) {
    /*
     * The numbers need to be drawn in a 7x7 grid, representing the points on the Unit Circle.
     */
    final float offset1 = numbersRadius;
    // cos(30) = a / r => r * cos(30)
    final float offset2 = numbersRadius * COSINE_30_DEGREES;
    // sin(30) = o / r => r * sin(30)
    final float offset3 = numbersRadius * SINE_30_DEGREES;

    paint.setTextSize(textSize);
    // We'll need yTextBase to be slightly lower to account for the text's baseline.
    yCenter -= (paint.descent() + paint.ascent()) / 2;

    textGridHeights[0] = yCenter - offset1;
    textGridWidths[0] = xCenter - offset1;
    textGridHeights[1] = yCenter - offset2;
    textGridWidths[1] = xCenter - offset2;
    textGridHeights[2] = yCenter - offset3;
    textGridWidths[2] = xCenter - offset3;
    textGridHeights[3] = yCenter;
    textGridWidths[3] = xCenter;
    textGridHeights[4] = yCenter + offset3;
    textGridWidths[4] = xCenter + offset3;
    textGridHeights[5] = yCenter + offset2;
    textGridWidths[5] = xCenter + offset2;
    textGridHeights[6] = yCenter + offset1;
    textGridWidths[6] = xCenter + offset1;
}

From source file:com.example.angel.parkpanda.MainActivity.java

public Bitmap drawTextToBitmap(int gResId, String gText) {
    Resources resources = getResources();
    float scale = resources.getDisplayMetrics().density;
    Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId);
    android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();

    if (bitmapConfig == null) {
        bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
    }//from www  . j a  v a  2  s  .co  m
    bitmap = bitmap.copy(bitmapConfig, true);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.rgb(0, 0, 0));
    paint.setTextSize((int) (15 * scale));
    paint.setShadowLayer(1f, 0f, 1f, Color.BLACK);

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

    return bitmap;
}

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy, int bgcolor) {
    int oldcolor = paint.getColor();
    Path path = null;//from  w  w  w.jav a2  s. c o m

    paint.setTextSize(size / 15);
    paint.setStyle(Paint.Style.FILL);

    if (dx != 0x10000 || dy != 0) {
        path = new Path();
        path.moveTo(x, y);
        path.rLineTo(dx, dy);
        paint.setTextAlign(android.graphics.Paint.Align.LEFT);
    }

    if (bgcolor != 0) {
        paint.setStrokeWidth(3);
        paint.setColor(bgcolor);
        paint.setStyle(Paint.Style.STROKE);
        if (path == null) {
            draw_canvas.drawText(text, x, y, paint);
        } else {
            draw_canvas.drawTextOnPath(text, path, 0, 0, paint);
        }
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(oldcolor);
    }

    if (path == null) {
        draw_canvas.drawText(text, x, y, paint);
    } else {
        draw_canvas.drawTextOnPath(text, path, 0, 0, paint);
    }
    paint.clearShadowLayer();
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private void initText(Paint paint, int height, int color, Paint.Align align) {
    paint.setColor(color);/*w  w  w . j a v  a  2s .co m*/
    paint.setTextSize(height);
    paint.setTextAlign(align);
}