use of android.graphics.Canvas in project NotificationPeekPort by lzanita09.
the class WallpaperFactory method drawableToBitmap.
/**
* Convert drawable to bitmap.
*
* @param drawable Drawable object to be converted.
* @return converted bitmap.
*/
private Bitmap drawableToBitmap(Drawable drawable, int width) {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
bitmap = cropBitmap(bitmap, width);
return bitmap;
}
use of android.graphics.Canvas in project NotificationPeekPort by lzanita09.
the class WallpaperFactory method getPrefSystemWallpaper.
/**
* Create a bitmap that is blurred and dimmed with the amount that user has selected.
*
* @return Background bitmap.
*/
public Bitmap getPrefSystemWallpaper() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
float radius = preferences.getFloat(PreferenceKeys.PREF_RADIUS, ImageBlurrer.MAX_SUPPORTED_BLUR_PIXELS);
int dim = preferences.getInt(PreferenceKeys.PREF_DIM, DEFAULT_MAX_DIM);
DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
// Blur
ImageBlurrer imageBlurrer = new ImageBlurrer(mContext);
Bitmap blurred = imageBlurrer.blurBitmap(drawableToBitmap(mWallpaperManager.getFastDrawable(), displayMetrics.widthPixels), radius);
// Dim
Canvas c = new Canvas(blurred);
c.drawColor(Color.argb(255 - dim, 0, 0, 0));
return blurred;
}
use of android.graphics.Canvas in project robolectric by robolectric.
the class ShadowView method visualize.
/**
* Returns a textual representation of the appearance of the object.
*
* @param view the view to visualize
* @return Textual representation of the appearance of the object.
*/
public static String visualize(View view) {
Canvas canvas = new Canvas();
view.draw(canvas);
return shadowOf(canvas).getDescription();
}
use of android.graphics.Canvas in project robolectric by robolectric.
the class ShadowBitmapDrawableTest method withColorFilterSet_draw_shouldCopyDescriptionToCanvas.
@Test
public void withColorFilterSet_draw_shouldCopyDescriptionToCanvas() throws Exception {
BitmapDrawable drawable = (BitmapDrawable) resources.getDrawable(R.drawable.an_image);
drawable.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix()));
Canvas canvas = new Canvas();
drawable.draw(canvas);
assertThat(shadowOf(canvas).getDescription()).isEqualTo("Bitmap for resource:org.robolectric:drawable/an_image with ColorMatrixColorFilter<1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0>");
}
use of android.graphics.Canvas in project robolectric by robolectric.
the class ShadowBitmapTest method shouldReceiveDescriptionWhenDrawingToCanvasWithBitmapAndMatrixAndPaint.
@Test
public void shouldReceiveDescriptionWhenDrawingToCanvasWithBitmapAndMatrixAndPaint() throws Exception {
Bitmap bitmap1 = create("Bitmap One", 100, 100);
Bitmap bitmap2 = create("Bitmap Two", 100, 100);
Canvas canvas = new Canvas(bitmap1);
canvas.drawBitmap(bitmap2, new Matrix(), null);
assertThat(shadowOf(bitmap1).getDescription()).isEqualTo("Bitmap One\nBitmap Two transformed by Matrix[pre=[], set={}, post=[]]");
}
Aggregations