Search in sources :

Example 36 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable 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>");
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Example 37 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project robolectric by robolectric.

the class ShadowBitmapDrawableTest method constructors_shouldSetBitmap.

@Test
public void constructors_shouldSetBitmap() throws Exception {
    Bitmap bitmap = Shadow.newInstanceOf(Bitmap.class);
    BitmapDrawable drawable = new BitmapDrawable(bitmap);
    assertThat(drawable.getBitmap()).isEqualTo(bitmap);
    drawable = new BitmapDrawable(resources, bitmap);
    assertThat(drawable.getBitmap()).isEqualTo(bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Example 38 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project robolectric by robolectric.

the class ShadowBitmapDrawableTest method constructor_shouldSetTheIntrinsicWidthAndHeightToTheWidthAndHeightOfTheBitmap.

@Test
public void constructor_shouldSetTheIntrinsicWidthAndHeightToTheWidthAndHeightOfTheBitmap() throws Exception {
    Bitmap bitmap = Bitmap.createBitmap(5, 10, Bitmap.Config.ARGB_8888);
    BitmapDrawable drawable = new BitmapDrawable(RuntimeEnvironment.application.getResources(), bitmap);
    assertThat(drawable.getIntrinsicWidth()).isEqualTo(5);
    assertThat(drawable.getIntrinsicHeight()).isEqualTo(10);
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Example 39 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project robolectric by robolectric.

the class DrawableAssert method isResource.

public void isResource(int resourceId) {
    assertThat(actual).isInstanceOf(BitmapDrawable.class);
    BitmapDrawable bitmapDrawable = (BitmapDrawable) actual;
    assertThat(shadowOf(bitmapDrawable.getBitmap()).getCreatedFromResId()).isEqualTo(resourceId);
}
Also used : BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 40 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project robolectric by robolectric.

the class ShadowViewTest method shouldRecordBackgroundDrawable.

@Test
public void shouldRecordBackgroundDrawable() {
    Drawable drawable = new BitmapDrawable(BitmapFactory.decodeFile("some/fake/file"));
    view.setBackgroundDrawable(drawable);
    assertThat(view.getBackground()).isSameAs(drawable);
    assertThat(ShadowView.visualize(view)).isEqualTo("background:\nBitmap for file:some/fake/file");
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Aggregations

BitmapDrawable (android.graphics.drawable.BitmapDrawable)640 Bitmap (android.graphics.Bitmap)426 Drawable (android.graphics.drawable.Drawable)187 Canvas (android.graphics.Canvas)182 Paint (android.graphics.Paint)110 Rect (android.graphics.Rect)77 View (android.view.View)77 ImageView (android.widget.ImageView)63 ColorDrawable (android.graphics.drawable.ColorDrawable)59 TextView (android.widget.TextView)51 IOException (java.io.IOException)40 Resources (android.content.res.Resources)35 LayerDrawable (android.graphics.drawable.LayerDrawable)33 AnimationDrawable (android.graphics.drawable.AnimationDrawable)30 File (java.io.File)27 Test (org.junit.Test)24 Matrix (android.graphics.Matrix)23 Intent (android.content.Intent)22 StateListDrawable (android.graphics.drawable.StateListDrawable)22 InputStream (java.io.InputStream)22