Search in sources :

Example 6 with LruBitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project LeafPic by HoraApps.

the class CustomGlideModule method applyOptions.

@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // Apply options to the builder here.
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);
    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
    int cacheSize100MegaBytes = 104857600;
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes));
}
Also used : MemorySizeCalculator(com.bumptech.glide.load.engine.cache.MemorySizeCalculator) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) InternalCacheDiskCacheFactory(com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory)

Example 7 with LruBitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.

the class BitmapPreFillRunnerTest method allocate_whenBitmapPoolIsAtCapacity_doesNotLogWithRecycledBitmap.

@Test
public void allocate_whenBitmapPoolIsAtCapacity_doesNotLogWithRecycledBitmap() {
    ShadowLog.setLoggable(BitmapPreFillRunner.TAG, Log.VERBOSE);
    int dimensions = 10;
    Bitmap.Config config = Bitmap.Config.ARGB_8888;
    int bitmapByteSize = Util.getBitmapByteSize(dimensions, dimensions, config);
    PreFillType preFillType = new PreFillType.Builder(dimensions).setConfig(config).build();
    Map<PreFillType, Integer> allocationOrder = new HashMap<>();
    allocationOrder.put(preFillType, 1);
    PreFillQueue queue = new PreFillQueue(allocationOrder);
    BitmapPreFillRunner runner = new BitmapPreFillRunner(new LruBitmapPool(bitmapByteSize - 1), new MemoryCacheAdapter(), queue);
    runner.allocate();
}
Also used : CreateBitmap(com.bumptech.glide.tests.Util.CreateBitmap) Bitmap(android.graphics.Bitmap) HashMap(java.util.HashMap) MemoryCacheAdapter(com.bumptech.glide.load.engine.cache.MemoryCacheAdapter) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) Test(org.junit.Test)

Example 8 with LruBitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project MVPArms by JessYanCoding.

the class GlideConfiguration method applyOptions.

@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {

        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            File cacheDirectory = new File(DataHelper.getCacheFile(UiUtils.getContext()), "Glide");
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(cacheDirectory), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);
    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
}
Also used : MemorySizeCalculator(com.bumptech.glide.load.engine.cache.MemorySizeCalculator) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) DiskCache(com.bumptech.glide.load.engine.cache.DiskCache) File(java.io.File)

Example 9 with LruBitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.

the class LoadBitmapTest method loadFromRequestBuilder_asBitmap_withBitmap_doesNotLoadFromDiskCache.

@Test
public void loadFromRequestBuilder_asBitmap_withBitmap_doesNotLoadFromDiskCache() {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
    Glide.init(context, new GlideBuilder().setMemoryCache(new LruResourceCache(Util.getBitmapByteSize(bitmap) * 10)).setBitmapPool(new LruBitmapPool(Util.getBitmapByteSize(bitmap) * 10)));
    Target<Bitmap> target = concurrency.wait(GlideApp.with(context).asBitmap().load(bitmap).centerCrop().submit(100, 100));
    Glide.with(context).clear(target);
    assertThat(bitmap.isRecycled()).isFalse();
    concurrency.runOnMainThread(new Runnable() {

        @Override
        public void run() {
            Glide.get(context).clearMemory();
        }
    });
    concurrency.wait(GlideApp.with(context).asBitmap().load(bitmap).centerCrop().listener(bitmapListener).submit(100, 100));
    verify(bitmapListener).onResourceReady(anyBitmap(), any(), anyBitmapTarget(), eq(DataSource.LOCAL), anyBoolean());
}
Also used : Matchers.anyBitmap(com.bumptech.glide.test.Matchers.anyBitmap) Bitmap(android.graphics.Bitmap) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) Test(org.junit.Test)

Example 10 with LruBitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.

the class LoadBitmapTest method loadFromRequestBuilder_asBitmap_withBitmapAndStrategyBeforeLoad_notFromCache.

@Test
public void loadFromRequestBuilder_asBitmap_withBitmapAndStrategyBeforeLoad_notFromCache() {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
    Glide.init(context, new GlideBuilder().setMemoryCache(new LruResourceCache(Util.getBitmapByteSize(bitmap) * 10)).setBitmapPool(new LruBitmapPool(Util.getBitmapByteSize(bitmap) * 10)));
    Target<Bitmap> target = concurrency.wait(GlideApp.with(context).asBitmap().diskCacheStrategy(DiskCacheStrategy.ALL).load(bitmap).centerCrop().submit(100, 100));
    Glide.with(context).clear(target);
    assertThat(bitmap.isRecycled()).isFalse();
    concurrency.runOnMainThread(new Runnable() {

        @Override
        public void run() {
            Glide.get(context).clearMemory();
        }
    });
    concurrency.wait(GlideApp.with(context).asBitmap().load(bitmap).centerCrop().listener(bitmapListener).submit(100, 100));
    verify(bitmapListener).onResourceReady(anyBitmap(), any(), anyBitmapTarget(), eq(DataSource.LOCAL), anyBoolean());
}
Also used : Matchers.anyBitmap(com.bumptech.glide.test.Matchers.anyBitmap) Bitmap(android.graphics.Bitmap) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) Test(org.junit.Test)

Aggregations

LruBitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool)17 LruResourceCache (com.bumptech.glide.load.engine.cache.LruResourceCache)14 Bitmap (android.graphics.Bitmap)11 Test (org.junit.Test)11 Drawable (android.graphics.drawable.Drawable)6 Matchers.anyDrawable (com.bumptech.glide.test.Matchers.anyDrawable)6 MemorySizeCalculator (com.bumptech.glide.load.engine.cache.MemorySizeCalculator)5 Matchers.anyBitmap (com.bumptech.glide.test.Matchers.anyBitmap)5 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 File (java.io.File)3 DiskCache (com.bumptech.glide.load.engine.cache.DiskCache)2 InternalCacheDiskCacheFactory (com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory)2 GlideBuilder (com.bumptech.glide.GlideBuilder)1 Engine (com.bumptech.glide.load.engine.Engine)1 BitmapPoolAdapter (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter)1 LruArrayPool (com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool)1 ExternalPreferredCacheDiskCacheFactory (com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory)1 MemoryCacheAdapter (com.bumptech.glide.load.engine.cache.MemoryCacheAdapter)1 DefaultConnectivityMonitorFactory (com.bumptech.glide.manager.DefaultConnectivityMonitorFactory)1 RequestOptions (com.bumptech.glide.request.RequestOptions)1