use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowBitmap method createBitmap.
@Implementation
public static Bitmap createBitmap(Bitmap src, int x, int y, int width, int height, Matrix matrix, boolean filter) {
if (x == 0 && y == 0 && width == src.getWidth() && height == src.getHeight() && (matrix == null || matrix.isIdentity())) {
// Return the original.
return src;
}
if (x + width > src.getWidth()) {
throw new IllegalArgumentException("x + width must be <= bitmap.width()");
}
if (y + height > src.getHeight()) {
throw new IllegalArgumentException("y + height must be <= bitmap.height()");
}
Bitmap newBitmap = ReflectionHelpers.callConstructor(Bitmap.class);
ShadowBitmap shadowBitmap = shadowOf(newBitmap);
shadowBitmap.appendDescription(shadowOf(src).getDescription());
shadowBitmap.appendDescription(" at (" + x + "," + y + ")");
shadowBitmap.appendDescription(" with width " + width + " and height " + height);
if (matrix != null) {
shadowBitmap.appendDescription(" using matrix " + shadowOf(matrix).getDescription());
// Adjust width and height by using the matrix.
RectF mappedRect = new RectF();
matrix.mapRect(mappedRect, new RectF(0, 0, width, height));
width = Math.round(mappedRect.width());
height = Math.round(mappedRect.height());
}
if (filter) {
shadowBitmap.appendDescription(" with filter");
}
shadowBitmap.createdFromBitmap = src;
shadowBitmap.createdFromX = x;
shadowBitmap.createdFromY = y;
shadowBitmap.createdFromWidth = width;
shadowBitmap.createdFromHeight = height;
shadowBitmap.createdFromMatrix = matrix;
shadowBitmap.createdFromFilter = filter;
shadowBitmap.width = width;
shadowBitmap.height = height;
return newBitmap;
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowBitmap method copy.
@Implementation
public Bitmap copy(Bitmap.Config config, boolean isMutable) {
Bitmap newBitmap = ReflectionHelpers.callConstructor(Bitmap.class);
ShadowBitmap shadowBitmap = shadowOf(newBitmap);
shadowBitmap.createdFromBitmap = realBitmap;
shadowBitmap.config = config;
shadowBitmap.mutable = isMutable;
return newBitmap;
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowBitmapDrawable method mutate.
@Implementation
public Drawable mutate() {
Bitmap bitmap = realBitmapDrawable.getBitmap();
BitmapDrawable real = ReflectionHelpers.callConstructor(BitmapDrawable.class, ClassParameter.from(Bitmap.class, bitmap));
ShadowBitmapDrawable shadow = shadowOf(real);
shadow.colorFilter = this.colorFilter;
shadow.drawableCreateFromStreamSource = drawableCreateFromStreamSource;
return real;
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowBitmapDrawable method draw.
/**
* Draws the contained bitmap onto the canvas at 0,0 with a default {@code Paint}
*
* @param canvas the canvas to draw on
*/
@Implementation
public void draw(Canvas canvas) {
Paint paint = new Paint();
paint.setColorFilter(colorFilter);
canvas.drawBitmap(realBitmapDrawable.getBitmap(), 0, 0, paint);
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowBitmapFactory method decodeStream.
@Implementation
public static Bitmap decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts) {
String name = is instanceof NamedStream ? is.toString().replace("stream for ", "") : null;
Point imageSize = is instanceof NamedStream ? null : ImageUtil.getImageSizeFromStream(is);
Bitmap bitmap = create(name, opts, imageSize);
ShadowBitmap shadowBitmap = Shadows.shadowOf(bitmap);
shadowBitmap.createdFromStream = is;
return bitmap;
}
Aggregations