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:krt.com.cityguide.Fragments.PageMapFragment.java

public void addObjectMarker(ObjectModel objectModel) {
    //     googleMap.addCircle(new CircleOptions().center(new LatLng(objectModel.getLat(), objectModel.getLon()))
    //     .fillColor(0x000000).radius(1));
    //      if (objectModel == null || googleMap == null) return;
    try {//from w w  w  . j a v a 2 s.  c o  m
        Bitmap.Config conf = Bitmap.Config.ARGB_8888;
        Bitmap bmp = Bitmap.createBitmap(20, 20, conf);
        Canvas canvas1 = new Canvas(bmp);

        // paint defines the text color, stroke width and size
        Paint color = new Paint();
        color.setTextSize(35);
        color.setColor(Color.BLACK);
        canvas1.drawCircle(10, 10, 10, color);
        googleMap.addMarker(new MarkerOptions().position(new LatLng(objectModel.getLat(), objectModel.getLon()))
                .title(objectModel.getName()).snippet("snippet").icon(BitmapDescriptorFactory.fromBitmap(bmp)));
    } catch (NullPointerException e) {
        Log.d("error", e.getMessage());
    }

}

From source file:ggikko.me.steppertest.stepper.RoundedView.java

private void drawText(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size));

    Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());

    RectF bounds = new RectF(areaRect);

    bounds.right = paint.measureText(text, 0, text.length());

    bounds.bottom = paint.descent() - paint.ascent();

    bounds.left += (areaRect.width() - bounds.right) / 2.0f;
    bounds.top += (areaRect.height() - bounds.bottom) / 2.0f;

    paint.setColor(Color.WHITE);/*from   ww  w.  j a  v  a  2 s  .com*/
    canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint);
}

From source file:com.android.cts.verifier.managedprovisioning.NfcTestActivity.java

/**
 * Creates a Bitmap image that contains red on white text with a specified margin.
 * @param text Text to be displayed in the image.
 * @return A Bitmap image with the above specification.
 *///from w ww  .j  a  va2  s.  c o  m
private Bitmap createSampleImage(String text) {
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setTextSize(TEXT_SIZE);
    Rect rect = new Rect();
    paint.getTextBounds(text, 0, text.length(), rect);
    int w = 2 * MARGIN + rect.right - rect.left;
    int h = 2 * MARGIN + rect.bottom - rect.top;
    Bitmap dest = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas();
    canvas.setBitmap(dest);
    paint.setColor(Color.WHITE);
    canvas.drawPaint(paint);
    paint.setColor(Color.RED);
    canvas.drawText(text, MARGIN - rect.left, MARGIN - rect.top, paint);
    return dest;
}

From source file:com.sun.toy.widget.CalendarView.java

private Paint makePaint(int color) {
    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setColor(color);//www .  j  a v  a  2s.  c  o m
    p.setTextSize(mDefaultTextSize);
    return p;
}

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);/*from w w w  .  j  a v a  2 s  .  c om*/
    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 void DrawText(Canvas canvas, JSONArray prim, float sx, float sy) {
    try {/*from   w  ww  .  jav a 2 s.c o  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.silentcircle.contacts.ContactPhotoManager.java

/**
 * If necessary, decodes bytes stored in the holder to Bitmap.  As long as the
 * bitmap is held either by {@link #mBitmapCache} or by a soft reference in
 * the holder, it will not be necessary to decode the bitmap.
 *//*from   w  ww  .ja v  a2 s.  c  o m*/
private static void inflateBitmap(BitmapHolder holder, int requestedExtent) {
    final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent);
    byte[] bytes = holder.bytes;
    if (bytes == null || bytes.length == 0) {
        return;
    }

    if (sampleSize == holder.decodedSampleSize) {
        // Check the soft reference.  If will be retained if the bitmap is also
        // in the LRU cache, so we don't need to check the LRU cache explicitly.
        if (holder.bitmapRef != null) {
            holder.bitmap = holder.bitmapRef.get();
            if (holder.bitmap != null) {
                return;
            }
        }
    }

    try {
        Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize);

        // make bitmap mutable and draw size onto it
        if (DEBUG_SIZES) {
            Bitmap original = bitmap;
            bitmap = bitmap.copy(bitmap.getConfig(), true);
            original.recycle();
            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.setTextSize(16);
            paint.setColor(Color.BLUE);
            paint.setStyle(Style.FILL);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint);
            paint.setColor(Color.WHITE);
            paint.setAntiAlias(true);
            canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint);
        }

        holder.decodedSampleSize = sampleSize;
        holder.bitmap = bitmap;
        holder.bitmapRef = new SoftReference<Bitmap>(bitmap);
        if (DEBUG) {
            int bCount = (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1)
                    ? bitmap.getRowBytes() * bitmap.getHeight()
                    : bitmap.getByteCount();
            Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x"
                    + bitmap.getHeight() + ", " + btk(bCount));
        }
    } catch (OutOfMemoryError e) {
        // Do nothing - the photo will appear to be missing
    }
}

From source file:com.appyvet.rangebar.PinView.java

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

    float textSize = paint.measureText(text);
    float estimatedFontSize = boxWidth * 8 / textSize / mDensity;

    if (estimatedFontSize < mMinPinFont) {
        estimatedFontSize = mMinPinFont;
    } else if (estimatedFontSize > mMaxPinFont) {
        estimatedFontSize = mMaxPinFont;
    }/*w w  w  .j a  v  a2  s . c  o m*/
    Log.d("pin", "size = " + estimatedFontSize * mDensity);
    paint.setTextSize(estimatedFontSize * mDensity);
}

From source file:com.huahcoding.metrojam.BackTrackActivity.java

/**
 * This is where we can add markers or lines, add listeners or move the camera. In this case, we
 * just add a marker near Africa./*w  ww .  j a  v  a 2  s  . co  m*/
 * <p>
 * This should only be called once and when we are sure that {@link #mMap} is not null.
 */
private void setUpMap() {
    mMap.getUiSettings().setZoomControlsEnabled(false);

    // Show Lima
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(chileLatLng, 15));

    mMap.setOnMapLongClickListener(this);
    mMap.setMyLocationEnabled(true);
    mMap.setTrafficEnabled(true);

    // Instantiates a new Polyline object and adds points to define a rectangle
    PolylineOptions rectOptions = new PolylineOptions();
    double[] route = RouteTestData.getChilePoints3();
    for (int i = 0; i < route.length - 1; i += 2) {
        LatLng ll = new LatLng(route[i], route[i + 1]);
        if (i > 1) {
            double lat = (route[i] + route[i - 2]) / 2.0;
            double lng = (route[i + 1] + route[i + 1 - 2]) / 2.0;
            double dist = distance(route[i], route[i + 1], route[i - 2], route[i + 1 - 2]);
            String pretty = getPrettyDistance(dist);

            LatLng ll2 = new LatLng(lat, lng);
            String strText = pretty;
            Rect boundsText = new Rect();
            Paint textPaint = new Paint();
            textPaint.setTextSize(18);
            textPaint.getTextBounds(strText, 0, strText.length(), boundsText);

            textPaint.setColor(Color.RED);

            Bitmap.Config conf = Bitmap.Config.ARGB_8888;
            Bitmap bmpText = Bitmap.createBitmap(boundsText.width() * 3, boundsText.height(), conf);

            Canvas canvasText = new Canvas(bmpText);
            canvasText.drawText(strText, canvasText.getWidth() / 2, canvasText.getHeight(), textPaint);

            MarkerOptions markerOptions = new MarkerOptions().position(ll2)
                    .icon(BitmapDescriptorFactory.fromBitmap(bmpText)).anchor(0.5f, 1);
            mMap.addMarker(markerOptions);
        }
        rectOptions.add(ll);
    }
    //         rectOptions.
    // Get back the mutable Polyline
    mMap.addPolyline(rectOptions);
}

From source file:airfree.xprojets.airfree.PinView.java

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

    float textSize = paint.measureText(text);
    float estimatedFontSize = boxWidth * 8 / textSize / mDensity;

    if (estimatedFontSize < mMinPinFont) {
        estimatedFontSize = mMinPinFont;
    } else if (estimatedFontSize > mMaxPinFont) {
        estimatedFontSize = mMaxPinFont;
    }/*from  w w  w.  j a  v a  2 s.c  o  m*/
    paint.setTextSize(estimatedFontSize * mDensity);
}