Search in sources :

Example 11 with PaintFlagsDrawFilter

use of android.graphics.PaintFlagsDrawFilter in project FlowingDrawer by mxn21.

the class BuildLayerFrameLayout method dispatchDraw.

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (mChanged && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        post(new Runnable() {

            @Override
            public void run() {
                if (mAttached && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    final int layerType = getLayerType();
                    // If it's already a hardware layer, it'll be built anyway.
                    if (layerType != LAYER_TYPE_HARDWARE || mFirst) {
                        mFirst = false;
                        setLayerType(LAYER_TYPE_HARDWARE, null);
                        buildLayer();
                        setLayerType(LAYER_TYPE_NONE, null);
                    }
                }
            }
        });
        mChanged = false;
    }
    PaintFlagsDrawFilter pfd = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    canvas.setDrawFilter(pfd);
}
Also used : PaintFlagsDrawFilter(android.graphics.PaintFlagsDrawFilter)

Example 12 with PaintFlagsDrawFilter

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

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();
    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)

Example 13 with PaintFlagsDrawFilter

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

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)

Example 14 with PaintFlagsDrawFilter

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

the class PenSizeArrayAdapter method createPenSizeImae.

private ImageView createPenSizeImae(int position) {
    ImageView imageView = new ImageView(getContext());
    final int width = getContext().getResources().getDimensionPixelSize(R.dimen.crop_buttons);
    final int contentWidth = getContext().getResources().getDimensionPixelSize(R.dimen.crop_buttons_inlet);
    final int penSizeValue = Integer.valueOf(mPenSizes[position]);
    final float density = getContext().getResources().getDisplayMetrics().density;
    final int penSize = Math.round(penSizeValue * density);
    final Canvas canvas = new Canvas();
    canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG, Paint.FILTER_BITMAP_FLAG));
    final Bitmap bmp = Bitmap.createBitmap(contentWidth, contentWidth, Bitmap.Config.ARGB_8888);
    canvas.setBitmap(bmp);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    paint.setStrokeWidth(penSize);
    canvas.drawLine(0, contentWidth / 2, contentWidth, contentWidth / 2, paint);
    imageView.setImageDrawable(new BitmapDrawable(getContext().getResources(), bmp));
    AbsListView.LayoutParams params = new AbsListView.LayoutParams(width, width);
    imageView.setLayoutParams(params);
    imageView.setScaleType(ScaleType.CENTER);
    return imageView;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) AbsListView(android.widget.AbsListView) ImageView(android.widget.ImageView) Paint(android.graphics.Paint) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PaintFlagsDrawFilter(android.graphics.PaintFlagsDrawFilter) Paint(android.graphics.Paint)

Example 15 with PaintFlagsDrawFilter

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

the class ScreenshotEditor method createPenSizeImage.

private BitmapDrawable createPenSizeImage(int penSize) {
    final int width = getResources().getDimensionPixelSize(R.dimen.crop_buttons_inlet);
    final Canvas canvas = new Canvas();
    canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG, Paint.FILTER_BITMAP_FLAG));
    final Bitmap bmp = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);
    canvas.setBitmap(bmp);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);
    paint.setStrokeWidth(penSize);
    canvas.drawLine(0, width / 2, width, width / 2, paint);
    return new BitmapDrawable(getResources(), bmp);
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PaintFlagsDrawFilter(android.graphics.PaintFlagsDrawFilter) Paint(android.graphics.Paint) Point(android.graphics.Point)

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