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:pl.mg6.newmaps.demo.MarkersExampleActivity.java

private Bitmap prepareBitmap() {
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_left);
    bitmap = bitmap.copy(Config.ARGB_8888, true);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);//from  ww w . ja  v a2 s  .  c  om
    paint.setColor(Color.WHITE);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(getResources().getDimension(R.dimen.text_size));
    String text = "mg6";
    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    float x = bitmap.getWidth() / 2.0f;
    float y = (bitmap.getHeight() - bounds.height()) / 2.0f - bounds.top;
    canvas.drawText(text, x, y, paint);
    return bitmap;
}

From source file:br.com.mauker.materialseekbar.PinView.java

private void calibrateTextSize(Paint paint, String text, float boxWidth) {
    paint.setTextSize(mMinPinFont);

    float textSize = paint.measureText(text);
    Log.d("pin", "textSize: " + textSize);
    float estimatedFontSize = boxWidth * 8 / textSize / mDensity;

    if (estimatedFontSize < mMinPinFont) {
        estimatedFontSize = mMinPinFont;
        Log.d("pin", "< mMinPinFont - Value: " + estimatedFontSize);
    } else if (estimatedFontSize > mMaxPinFont) {
        estimatedFontSize = mMaxPinFont;
        Log.d("pin", "> mMaxPinFont - Value: " + estimatedFontSize);
    }/* w w w .  j a v  a 2  s .  co  m*/
    //        Log.d("pin","estimatedSize: " + estimatedFontSize);
    //        Log.d("pin","size: " + estimatedFontSize * mDensity);
    paint.setTextSize(estimatedFontSize * mDensity * 1.5f);
}

From source file:org.stockchart.core.Appearance.java

public void applyText(Paint p) {
    p.reset();/*from ww  w  .  j  a  v  a 2 s  .c  om*/
    p.setTextSize(fFont.getSize());
    p.setColor(fFont.getColor());
    p.setTypeface(fFont.getTypeface());
    p.setAntiAlias(fIsAntialias);
    p.setPathEffect(null);
    p.setStyle(Style.FILL);
}

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) {
            }// w  w  w .  ja va  2s.c o  m
            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.ifoer.util.NetPOSPrinter.java

public Bitmap drawBitFirst() {
    this.nBitmapFirst = Bitmap.createBitmap(PRINT_WIDTH, 85, Config.RGB_565);
    Canvas canvas = new Canvas(this.nBitmapFirst);
    canvas.drawColor(-1);/*w  w w . ja  v a  2  s  .  co m*/
    Paint p = new Paint();
    p.setColor(DefaultRenderer.BACKGROUND_COLOR);
    p.setTextSize(20.0f);
    canvas.drawText(this.mContext.getResources().getString(C0136R.string.print_launch), 0.0f, 20.0f, p);
    canvas.drawLine(0.0f, 40.0f, 384.0f, 40.0f, p);
    canvas.drawText(
            this.mContext.getResources().getString(C0136R.string.print_automobile_fault_diagnosis_test_report),
            20.0f, 70.0f, p);
    canvas.drawLine(0.0f, 80.0f, 384.0f, 80.0f, p);
    return this.nBitmapFirst;
}

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

/**
 * Create an avatar bitmap from a text./*from ww w  .  j a v  a2s .  c  om*/
 *
 * @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;
}

From source file:de.treichels.hott.ui.android.html.AndroidCurveImageGenerator.java

private Bitmap getBitmap(final Curve curve, final float scale, final boolean description) {
    final boolean pitchCurve = curve.getPoint()[0].getPosition() == 0;
    final float scale1 = scale * 0.75f; // smaller images on the android
    // platform/* w  w  w . ja  v a2 s .  c o  m*/

    final Bitmap image = Bitmap.createBitmap((int) (10 + 200 * scale1), (int) (10 + 250 * scale1),
            Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(image);

    final Paint backgroundPaint = new Paint();
    backgroundPaint.setColor(Color.WHITE);
    backgroundPaint.setStyle(Style.FILL);

    final Paint forgroundPaint = new Paint();
    forgroundPaint.setColor(Color.BLACK);
    forgroundPaint.setStyle(Style.STROKE);
    forgroundPaint.setStrokeWidth(1.0f);
    forgroundPaint.setStrokeCap(Cap.BUTT);
    forgroundPaint.setStrokeJoin(Join.ROUND);
    forgroundPaint.setStrokeMiter(0.0f);

    final Paint curvePaint = new Paint(forgroundPaint);
    curvePaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    curvePaint.setStrokeWidth(2.0f);

    final Paint pointPaint = new Paint(curvePaint);
    pointPaint.setStrokeWidth(5.0f);
    pointPaint.setStyle(Style.FILL_AND_STROKE);

    final Paint helpLinePaint = new Paint(forgroundPaint);
    helpLinePaint.setColor(Color.GRAY);
    helpLinePaint.setPathEffect(new DashPathEffect(new float[] { 5.0f, 5.0f }, 2.5f));

    final Paint textPaint = new Paint(forgroundPaint);
    textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
    textPaint.setTextSize(12.0f);
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setStyle(Style.FILL);

    canvas.drawRect(0, 0, 10 + 200 * scale1, 10 + 250 * scale1, backgroundPaint);
    canvas.drawRect(5, 5, 5 + 200 * scale1, 5 + 250 * scale1, forgroundPaint);

    canvas.drawLine(5, 5 + 25 * scale1, 5 + 200 * scale1, 5 + 25 * scale1, helpLinePaint);
    canvas.drawLine(5, 5 + 225 * scale1, 5 + 200 * scale1, 5 + 225 * scale1, helpLinePaint);
    if (!pitchCurve) {
        canvas.drawLine(5, 5 + 125 * scale1, 5 + 200 * scale1, 5 + 125 * scale1, helpLinePaint);
        canvas.drawLine(5 + 100 * scale1, 5, 5 + 100 * scale1, 5 + 250 * scale1, helpLinePaint);
    }

    if (curve.getPoint() != null) {
        int numPoints = 0;
        for (final CurvePoint p : curve.getPoint()) {
            if (p.isEnabled()) {
                numPoints++;
            }
        }

        final double[] xVals = new double[numPoints];
        final double[] yVals = new double[numPoints];

        int i = 0;
        for (final CurvePoint p : curve.getPoint()) {
            if (p.isEnabled()) {
                if (i == 0) {
                    xVals[i] = pitchCurve ? 0 : -100;
                } else if (i == numPoints - 1) {
                    xVals[i] = 100;
                } else {
                    xVals[i] = p.getPosition();
                }
                yVals[i] = p.getValue();

                if (description) {
                    float x0;
                    float y0;
                    if (pitchCurve) {
                        x0 = (float) (5 + xVals[i] * 2 * scale1);
                        y0 = (float) (5 + (225 - yVals[i] * 2) * scale1);
                    } else {
                        x0 = (float) (5 + (100 + xVals[i]) * scale1);
                        y0 = (float) (5 + (125 - yVals[i]) * scale1);
                    }

                    canvas.drawPoint(x0, y0, pointPaint);
                    if (y0 < 5 + 125 * scale1) {
                        canvas.drawRect(x0 - 4, y0 + 5, x0 + 3, y0 + 18, backgroundPaint);
                        canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 + 16, textPaint);
                    } else {
                        canvas.drawRect(x0 - 4, y0 - 5, x0 + 3, y0 - 18, backgroundPaint);
                        canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 - 7, textPaint);
                    }
                }

                i++;
            }
        }

        if (numPoints > 2 && curve.isSmoothing()) {
            final SplineInterpolator s = new SplineInterpolator();
            final PolynomialSplineFunction function = s.interpolate(xVals, yVals);

            float x0 = 5;
            float y0;
            if (pitchCurve) {
                y0 = (float) (5 + (225 - yVals[0] * 2) * scale1);
            } else {
                y0 = (float) (5 + (125 - yVals[0]) * scale1);
            }

            while (x0 < 4 + 200 * scale1) {
                final float x1 = x0 + 1;
                float y1;
                if (pitchCurve) {
                    y1 = (float) (5 + (225 - function.value((x1 - 5) / scale1 / 2) * 2) * scale1);
                } else {
                    y1 = (float) (5 + (125 - function.value((x1 - 5) / scale1 - 100)) * scale1);
                }

                canvas.drawLine(x0, y0, x1, y1, curvePaint);

                x0 = x1;
                y0 = y1;
            }
        } else {
            for (i = 0; i < numPoints - 1; i++) {
                float x0, y0, x1, y1;

                if (pitchCurve) {
                    x0 = (float) (5 + xVals[i] * 2 * scale1);
                    y0 = (float) (5 + (225 - yVals[i] * 2) * scale1);

                    x1 = (float) (5 + xVals[i + 1] * 2 * scale1);
                    y1 = (float) (5 + (225 - yVals[i + 1] * 2) * scale1);
                } else {
                    x0 = (float) (5 + (100 + xVals[i]) * scale1);
                    y0 = (float) (5 + (125 - yVals[i]) * scale1);

                    x1 = (float) (5 + (100 + xVals[i + 1]) * scale1);
                    y1 = (float) (5 + (125 - yVals[i + 1]) * scale1);
                }

                canvas.drawLine(x0, y0, x1, y1, curvePaint);
            }
        }
    }

    return image;
}

From source file:pl.itiner.nutiteq.NutiteqMap.java

public Bitmap createMissingTileBitmap(final int tileSize, final String bitmapText, Resources res) {
    Bitmap canvasBitmap = Bitmap.createBitmap(tileSize, tileSize, Bitmap.Config.RGB_565);
    Canvas imageCanvas = new Canvas(canvasBitmap);

    Paint textPaint = new Paint();
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setTextSize(16f);

    Paint backgroundPaint = new Paint();
    backgroundPaint.setColor(Color.WHITE);
    backgroundPaint.setStrokeWidth(3);//from w w  w . j a va2 s. c  o  m
    imageCanvas.drawRect(0, 0, tileSize, tileSize, backgroundPaint);

    imageCanvas.drawText(bitmapText, tileSize / 2, tileSize / 2, textPaint);

    BitmapDrawable finalImage = new BitmapDrawable(res, canvasBitmap);
    return finalImage.getBitmap();
}

From source file:com.pipit.agc.adapter.DayPickerAdapter.java

private void refitText(TextView txtv, int targetheight) {
    if (targetheight <= 0)
        return;/*from  ww w.ja va  2s . c om*/
    Paint mTestPaint = new Paint();
    mTestPaint.set(txtv.getPaint());
    float hi = 100;
    float lo = 2;
    final float threshold = 0.5f; // How close we have to be

    while ((hi - lo) > threshold) {
        float size = (hi + lo) / 2;
        mTestPaint.setTextSize(size);
        if (mTestPaint.measureText((String) txtv.getText()) >= targetheight)
            hi = size; // too big
        else
            lo = size; // too small
    }
    // Use lo so that we undershoot rather than overshoot
    txtv.setTextSize(TypedValue.COMPLEX_UNIT_PX, lo);
}

From source file:ch.carteggio.ui.ConversationIconLoader.java

/**
 * Calculates a bitmap with a color and a capital letter for contacts without picture.
 *///from   w ww. j  av  a2 s  .c  o m
private Bitmap calculateFallbackBitmap(String emails[]) {
    Bitmap result = Bitmap.createBitmap(mPictureSizeInPx, mPictureSizeInPx, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(result);

    int rgb = CONTACT_DUMMY_COLORS_ARGB[0];

    if (emails.length > 0) {
        calcUnknownContactColor(emails[0]);
    }

    result.eraseColor(rgb);

    String letter = FALLBACK_CONTACT_LETTER;

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setARGB(255, 255, 255, 255);
    paint.setTextSize(mPictureSizeInPx * 3 / 4); // just scale this down a bit
    Rect rect = new Rect();
    paint.getTextBounds(letter, 0, 1, rect);
    float width = paint.measureText(letter);
    canvas.drawText(letter, (mPictureSizeInPx / 2f) - (width / 2f),
            (mPictureSizeInPx / 2f) + (rect.height() / 2f), paint);

    return result;
}