Search in sources :

Example 1 with GlideBuilder

use of com.bumptech.glide.GlideBuilder in project glide by bumptech.

the class DrawableTransformationTest method transform_withColorDrawable_andUnitBitmapTransformation_recycles.

@Test
public void transform_withColorDrawable_andUnitBitmapTransformation_recycles() {
    bitmapPool = mock(BitmapPool.class);
    Glide.tearDown();
    Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
    when(bitmapTransformation.transform(any(Context.class), anyBitmapResource(), anyInt(), anyInt())).thenAnswer(new ReturnGivenResource());
    ColorDrawable colorDrawable = new ColorDrawable(Color.RED);
    final Resource<Drawable> input = new SimpleResource<Drawable>(colorDrawable);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            Bitmap bitmap = (Bitmap) invocationOnMock.getArguments()[0];
            assertThat(bitmap.getWidth()).isEqualTo(100);
            assertThat(bitmap.getHeight()).isEqualTo(200);
            return null;
        }
    }).when(bitmapPool).put(any(Bitmap.class));
    when(bitmapPool.get(anyInt(), anyInt(), any(Bitmap.Config.class))).thenAnswer(new Answer<Bitmap>() {

        @Override
        public Bitmap answer(InvocationOnMock invocationOnMock) throws Throwable {
            int width = (Integer) invocationOnMock.getArguments()[0];
            int height = (Integer) invocationOnMock.getArguments()[1];
            Bitmap.Config config = (Bitmap.Config) invocationOnMock.getArguments()[2];
            return Bitmap.createBitmap(width, height, config);
        }
    });
    transformation.transform(context, input, /*outWidth=*/
    100, /*outHeight=*/
    200);
    verify(bitmapPool).put(isA(Bitmap.class));
}
Also used : Context(android.content.Context) Config(org.robolectric.annotation.Config) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GlideBuilder(com.bumptech.glide.GlideBuilder) SimpleResource(com.bumptech.glide.load.resource.SimpleResource) Test(org.junit.Test)

Example 2 with GlideBuilder

use of com.bumptech.glide.GlideBuilder in project glide by bumptech.

the class BitmapDrawableTransformationTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    bitmapToTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    BitmapDrawable drawableToTransform = new BitmapDrawable(bitmapToTransform);
    context = RuntimeEnvironment.application;
    Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
    when(drawableResourceToTransform.get()).thenReturn(drawableToTransform);
    transformation = new BitmapDrawableTransformation(wrapped);
}
Also used : GlideBuilder(com.bumptech.glide.GlideBuilder) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Before(org.junit.Before)

Example 3 with GlideBuilder

use of com.bumptech.glide.GlideBuilder in project glide by bumptech.

the class FitCenterTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    bitmapWidth = 100;
    bitmapHeight = 100;
    Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
    when(resource.get()).thenReturn(bitmap);
    BitmapPool pool = new BitmapPoolAdapter();
    context = RuntimeEnvironment.application;
    Glide.init(context, new GlideBuilder().setBitmapPool(pool));
    fitCenter = new FitCenter();
}
Also used : Bitmap(android.graphics.Bitmap) GlideBuilder(com.bumptech.glide.GlideBuilder) BitmapPoolAdapter(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) Before(org.junit.Before)

Example 4 with GlideBuilder

use of com.bumptech.glide.GlideBuilder in project glide by bumptech.

the class CircleCropTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    when(bitmapPool.get(anyInt(), anyInt(), any(Bitmap.Config.class))).thenAnswer(new Util.CreateBitmap());
    Context context = RuntimeEnvironment.application;
    Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
    circleCrop = new CircleCrop();
}
Also used : Context(android.content.Context) Config(org.robolectric.annotation.Config) GlideBuilder(com.bumptech.glide.GlideBuilder) Util(com.bumptech.glide.tests.Util) Before(org.junit.Before)

Example 5 with GlideBuilder

use of com.bumptech.glide.GlideBuilder in project glide by bumptech.

the class CenterInsideTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    bitmapWidth = 100;
    bitmapHeight = 100;
    Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
    when(resource.get()).thenReturn(bitmap);
    context = RuntimeEnvironment.application;
    BitmapPool pool = new BitmapPoolAdapter();
    Glide.init(context, new GlideBuilder().setBitmapPool(pool));
    centerInside = new CenterInside();
}
Also used : Bitmap(android.graphics.Bitmap) GlideBuilder(com.bumptech.glide.GlideBuilder) BitmapPoolAdapter(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) Before(org.junit.Before)

Aggregations

GlideBuilder (com.bumptech.glide.GlideBuilder)7 Before (org.junit.Before)5 Bitmap (android.graphics.Bitmap)3 BitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool)3 BitmapPoolAdapter (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter)3 Context (android.content.Context)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Config (org.robolectric.annotation.Config)2 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 LruBitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool)1 ExternalPreferredCacheDiskCacheFactory (com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory)1 LruResourceCache (com.bumptech.glide.load.engine.cache.LruResourceCache)1 MemorySizeCalculator (com.bumptech.glide.load.engine.cache.MemorySizeCalculator)1 SimpleResource (com.bumptech.glide.load.resource.SimpleResource)1 RequestOptions (com.bumptech.glide.request.RequestOptions)1 Util (com.bumptech.glide.tests.Util)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1