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);
}
Aggregations