Search in sources :

Example 16 with PaintFlagsDrawFilter

use of android.graphics.PaintFlagsDrawFilter in project android_frameworks_base by crdroidandroid.

the class DetailedWeatherView method overlay.

private Drawable overlay(Resources resources, Drawable image, String min, String max, String tempUnits) {
    final Canvas canvas = new Canvas();
    canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG, Paint.FILTER_BITMAP_FLAG));
    final float density = resources.getDisplayMetrics().density;
    final int footerHeight = Math.round(18 * density);
    final int imageWidth = image.getIntrinsicWidth();
    final int imageHeight = image.getIntrinsicHeight();
    Log.d("maxwen", "" + imageWidth + " " + imageHeight);
    final TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    Typeface font = Typeface.create("sans-serif-condensed", Typeface.NORMAL);
    textPaint.setTypeface(font);
    textPaint.setColor(resources.getColor(R.color.omni_jaws_detailed_temperature_color));
    textPaint.setTextAlign(Paint.Align.LEFT);
    final int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14f, resources.getDisplayMetrics());
    textPaint.setTextSize(textSize);
    final int height = imageHeight + footerHeight;
    final int width = imageWidth;
    final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    canvas.setBitmap(bmp);
    image.setBounds(0, 0, imageWidth, imageHeight);
    image.draw(canvas);
    String str = null;
    if (max != null) {
        str = min + "/" + max + tempUnits;
    } else {
        str = min + tempUnits;
    }
    Rect bounds = new Rect();
    textPaint.getTextBounds(str, 0, str.length(), bounds);
    canvas.drawText(str, width / 2 - bounds.width() / 2, height - textSize / 2, textPaint);
    return new BitmapDrawable(resources, bmp);
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Typeface(android.graphics.Typeface) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PaintFlagsDrawFilter(android.graphics.PaintFlagsDrawFilter) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint)

Aggregations

PaintFlagsDrawFilter (android.graphics.PaintFlagsDrawFilter)16 Paint (android.graphics.Paint)13 Bitmap (android.graphics.Bitmap)8 Canvas (android.graphics.Canvas)8 BitmapDrawable (android.graphics.drawable.BitmapDrawable)7 Rect (android.graphics.Rect)5 Point (android.graphics.Point)4 Typeface (android.graphics.Typeface)3 TextPaint (android.text.TextPaint)3 TypedArray (android.content.res.TypedArray)2 AbsListView (android.widget.AbsListView)2 ImageView (android.widget.ImageView)2 GeoPointImpl (carnero.cgeo.mapinterfaces.GeoPointImpl)2 MapFactory (carnero.cgeo.mapinterfaces.MapFactory)2 SuppressLint (android.annotation.SuppressLint)1 Resources (android.content.res.Resources)1 Config (android.graphics.Bitmap.Config)1 RectF (android.graphics.RectF)1 Location (android.location.Location)1 DisplayMetrics (android.util.DisplayMetrics)1