Search in sources :

Example 6 with GlideBuilder

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

the class DrawableTransformationTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    transformation = new DrawableTransformation(bitmapTransformation, /*isRequired=*/
    true);
    context = RuntimeEnvironment.application;
    bitmapPool = new BitmapPoolAdapter();
    Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
}
Also used : GlideBuilder(com.bumptech.glide.GlideBuilder) BitmapPoolAdapter(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter) Before(org.junit.Before)

Example 7 with GlideBuilder

use of com.bumptech.glide.GlideBuilder in project anitrend-app by AniTrend.

the class GlideAppModule method applyOptions.

@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
    boolean isLowRamDevice = CompatUtil.isLowRamDevice(context);
    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).setMemoryCacheScreens(isLowRamDevice ? 2 : 3).build();
    // Increasing cache & pool by 25% - default is 250MB
    int memoryCacheSize = (int) (1.25 * calculator.getMemoryCacheSize());
    int bitmapPoolSize = (int) (1.25 * calculator.getBitmapPoolSize());
    int storageCacheSize = 1024 * 1024 * 350;
    if (context.getExternalCacheDir() != null) {
        long total = context.getExternalCacheDir().getTotalSpace();
        storageCacheSize = (int) (total * 0.2);
    }
    builder.setMemoryCache(new LruResourceCache(memoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(bitmapPoolSize));
    builder.setDiskCache(new ExternalPreferredCacheDiskCacheFactory(context, storageCacheSize));
    // Setting default params for glide
    RequestOptions options = new RequestOptions().format(isLowRamDevice ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888).timeout(KeyUtil.GLIDE_REQUEST_TIMEOUT).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).error(CompatUtil.getDrawable(context, R.drawable.ic_broken_image_white_48dp, R.color.colorStateOrange));
    builder.setDefaultRequestOptions(options);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) MemorySizeCalculator(com.bumptech.glide.load.engine.cache.MemorySizeCalculator) GlideBuilder(com.bumptech.glide.GlideBuilder) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) ExternalPreferredCacheDiskCacheFactory(com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache)

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