Search in sources :

Example 36 with Implementation

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;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Implementation(org.robolectric.annotation.Implementation)

Example 37 with Implementation

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;
}
Also used : Bitmap(android.graphics.Bitmap) Implementation(org.robolectric.annotation.Implementation)

Example 38 with Implementation

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;
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Implementation(org.robolectric.annotation.Implementation)

Example 39 with Implementation

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);
}
Also used : Paint(android.graphics.Paint) Implementation(org.robolectric.annotation.Implementation)

Example 40 with Implementation

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;
}
Also used : Bitmap(android.graphics.Bitmap) Point(android.graphics.Point) NamedStream(org.robolectric.util.NamedStream) Implementation(org.robolectric.annotation.Implementation)

Aggregations

Implementation (org.robolectric.annotation.Implementation)114 Bitmap (android.graphics.Bitmap)17 HiddenApi (org.robolectric.annotation.HiddenApi)10 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 View (android.view.View)6 IOException (java.io.IOException)6 ContentProvider (android.content.ContentProvider)5 IContentProvider (android.content.IContentProvider)5 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)5 Rect (android.graphics.Rect)4 Message (android.os.Message)4 RealObject (org.robolectric.annotation.RealObject)4 FileTypedResource (org.robolectric.res.FileTypedResource)4 Point (android.graphics.Point)3 AccessibilityWindowInfo (android.view.accessibility.AccessibilityWindowInfo)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 LinkedList (java.util.LinkedList)3 Activity (android.app.Activity)2 Dialog (android.app.Dialog)2