@Test public void testTrimMemory() { BitmapPool bitmapPool = mock(BitmapPool.class); MemoryCache memoryCache = mock(MemoryCache.class); Glide glide = new GlideBuilder().setBitmapPool(bitmapPool).setMemoryCache(memoryCache) .build(getContext()); final int level = 123; glide.trimMemory(level); verify(bitmapPool).trimMemory(eq(level)); verify(memoryCache).trimMemory(eq(level)); }
public Engine(MemoryCache memoryCache, DiskCache.Factory diskCacheFactory, GlideExecutor diskCacheExecutor, GlideExecutor sourceExecutor, GlideExecutor sourceUnlimitedExecutor, GlideExecutor animationExecutor) { this( memoryCache, diskCacheFactory, diskCacheExecutor, sourceExecutor, sourceUnlimitedExecutor, animationExecutor, /*jobs=*/ null, /*keyFactory=*/ null, /*activeResources=*/ null, /*engineJobFactory=*/ null, /*decodeJobFactory=*/ null, /*resourceRecycler=*/ null); }
public GlideModule(@NonNull Glide glide) { if (!HAS_GLIDE) { throw new RuntimeException("Glide dependency is not found"); } this.glide = glide; try { final Class<?> glideClass = glide.getClass(); final Field field = glideClass.getDeclaredField("memoryCache"); field.setAccessible(true); this.memoryCache = (MemoryCache) field.get(glide); } catch (Throwable t) { throw new RuntimeException("Incompatible Glide version", t); } }
BitmapPreFillRunner(BitmapPool bitmapPool, MemoryCache memoryCache, PreFillQueue allocationOrder, Clock clock, Handler handler) { this.bitmapPool = bitmapPool; this.memoryCache = memoryCache; this.toPrefill = allocationOrder; this.clock = clock; this.handler = handler; }
public Engine(MemoryCache memoryCache, DiskCache.Factory diskCacheFactory, GlideExecutor diskCacheExecutor, GlideExecutor sourceExecutor, GlideExecutor sourceUnlimitedExecutor) { this(memoryCache, diskCacheFactory, diskCacheExecutor, sourceExecutor, sourceUnlimitedExecutor, null, null, null, null, null, null); }
@Test public void testCanSetMemoryCategory() { MemoryCache memoryCache = mock(MemoryCache.class); BitmapPool bitmapPool = mock(BitmapPool.class); MemoryCategory memoryCategory = MemoryCategory.NORMAL; Glide glide = new GlideBuilder().setMemoryCache(memoryCache).setBitmapPool(bitmapPool) .build(getContext()); glide.setMemoryCategory(memoryCategory); verify(memoryCache).setSizeMultiplier(eq(memoryCategory.getMultiplier())); verify(bitmapPool).setSizeMultiplier(eq(memoryCategory.getMultiplier())); }
@Test public void testClearMemory() { BitmapPool bitmapPool = mock(BitmapPool.class); MemoryCache memoryCache = mock(MemoryCache.class); Glide glide = new GlideBuilder().setBitmapPool(bitmapPool).setMemoryCache(memoryCache) .build(getContext()); glide.clearMemory(); verify(bitmapPool).clearMemory(); verify(memoryCache).clearMemory(); }
@Override public void applyOptions(Context context, GlideBuilder builder) { // Run all tasks on the main thread so they complete synchronously. GlideExecutor executor = MockGlideExecutor.newMainThreadExecutor(); DiskCache.Factory diskCacheFactory = mock(DiskCache.Factory.class); when(diskCacheFactory.build()).thenReturn(mock(DiskCache.class)); builder.setMemoryCache(mock(MemoryCache.class)).setDiskCache(diskCacheFactory) .setResizeExecutor(executor).setDiskCacheExecutor(executor); }
@VisibleForTesting BitmapPreFillRunner(BitmapPool bitmapPool, MemoryCache memoryCache, PreFillQueue allocationOrder, Clock clock, Handler handler) { this.bitmapPool = bitmapPool; this.memoryCache = memoryCache; this.toPrefill = allocationOrder; this.clock = clock; this.handler = handler; }
Glide(Engine engine, RequestQueue requestQueue, MemoryCache memoryCache, BitmapPool bitmapPool, Context context) { this.engine = engine; this.requestQueue = requestQueue; this.bitmapPool = bitmapPool; this.memoryCache = memoryCache; dataLoadProviderFactory = new DataLoadProviderFactory(); dataLoadProviderFactory.register(InputStream.class, Bitmap.class, new StreamBitmapDataLoadProvider(bitmapPool)); dataLoadProviderFactory.register(ParcelFileDescriptor.class, Bitmap.class, new FileDescriptorBitmapDataLoadProvider(bitmapPool)); ImageVideoDataLoadProvider imageVideoDataLoadProvider = new ImageVideoDataLoadProvider(bitmapPool); dataLoadProviderFactory.register(ImageVideoWrapper.class, Bitmap.class, imageVideoDataLoadProvider); GifDataLoadProvider gifDataLoadProvider = new GifDataLoadProvider(context, bitmapPool); dataLoadProviderFactory.register(ImageVideoWrapper.class, GifBitmapWrapper.class, new ImageVideoGifDataLoadProvider(imageVideoDataLoadProvider, gifDataLoadProvider)); register(File.class, ParcelFileDescriptor.class, new FileDescriptorFileLoader.Factory()); register(File.class, InputStream.class, new StreamFileLoader.Factory()); register(Integer.class, ParcelFileDescriptor.class, new FileDescriptorResourceLoader.Factory()); register(Integer.class, InputStream.class, new StreamResourceLoader.Factory()); register(String.class, ParcelFileDescriptor.class, new FileDescriptorStringLoader.Factory()); register(String.class, InputStream.class, new StreamStringLoader.Factory()); register(Uri.class, ParcelFileDescriptor.class, new FileDescriptorUriLoader.Factory()); register(Uri.class, InputStream.class, new StreamUriLoader.Factory()); register(URL.class, InputStream.class, new StreamUrlLoader.Factory()); register(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(requestQueue)); transcoderFactory.register(Bitmap.class, BitmapDrawable.class, new BitmapDrawableTranscoder(context.getResources(), bitmapPool)); transcoderFactory.register(GifBitmapWrapper.class, Drawable.class, new GifBitmapDrawableTranscoder(context)); }
public EngineJob(Key key, MemoryCache cache, Handler mainHandler, boolean isCacheable, EngineJobListener listener) { this.key = key; this.cache = cache; this.isCacheable = isCacheable; this.listener = listener; this.mainHandler = mainHandler; }
Engine(ResourceRunnerFactory factory, MemoryCache cache, Map<Key, ResourceRunner> runners, KeyFactory keyFactory) { this.factory = factory; this.cache = cache; this.runners = runners; this.keyFactory = keyFactory; cache.setResourceRemovedListener(this); }
public DefaultResourceRunnerFactory(MemoryCache memoryCache, DiskCache diskCache, Handler mainHandler, ExecutorService service, Handler bgHandler ) { this.memoryCache = memoryCache; this.diskCache = diskCache; this.mainHandler = mainHandler; this.service = service; this.bgHandler = bgHandler; }
public BitmapPreFiller(MemoryCache memoryCache, BitmapPool bitmapPool, DecodeFormat defaultFormat) { this.memoryCache = memoryCache; this.bitmapPool = bitmapPool; this.defaultFormat = defaultFormat; }
public BitmapPreFillRunner(BitmapPool bitmapPool, MemoryCache memoryCache, PreFillQueue allocationOrder) { this(bitmapPool, memoryCache, allocationOrder, DEFAULT_CLOCK, new Handler(Looper.getMainLooper())); }
Engine(MemoryCache cache, DiskCache.Factory diskCacheFactory, GlideExecutor diskCacheExecutor, GlideExecutor sourceExecutor, GlideExecutor sourceUnlimitedExecutor, Map<Key, EngineJob<?>> jobs, EngineKeyFactory keyFactory, Map<Key, WeakReference<EngineResource<?>>> activeResources, EngineJobFactory engineJobFactory, DecodeJobFactory decodeJobFactory, ResourceRecycler resourceRecycler) { this.cache = cache; this.diskCacheProvider = new LazyDiskCacheProvider(diskCacheFactory); if (activeResources == null) { activeResources = new HashMap<>(); } this.activeResources = activeResources; if (keyFactory == null) { keyFactory = new EngineKeyFactory(); } this.keyFactory = keyFactory; if (jobs == null) { jobs = new HashMap<>(); } this.jobs = jobs; if (engineJobFactory == null) { engineJobFactory = new EngineJobFactory(diskCacheExecutor, sourceExecutor, sourceUnlimitedExecutor, this); } this.engineJobFactory = engineJobFactory; if (decodeJobFactory == null) { decodeJobFactory = new DecodeJobFactory(diskCacheProvider); } this.decodeJobFactory = decodeJobFactory; if (resourceRecycler == null) { resourceRecycler = new ResourceRecycler(); } this.resourceRecycler = resourceRecycler; cache.setResourceRemovedListener(this); }
@SuppressWarnings("WeakerAccess") public BitmapPreFillRunner(BitmapPool bitmapPool, MemoryCache memoryCache, PreFillQueue allocationOrder) { this(bitmapPool, memoryCache, allocationOrder, DEFAULT_CLOCK, new Handler(Looper.getMainLooper())); }
@VisibleForTesting Engine(MemoryCache cache, DiskCache.Factory diskCacheFactory, GlideExecutor diskCacheExecutor, GlideExecutor sourceExecutor, GlideExecutor sourceUnlimitedExecutor, GlideExecutor animationExecutor, Map<Key, EngineJob<?>> jobs, EngineKeyFactory keyFactory, ActiveResources activeResources, EngineJobFactory engineJobFactory, DecodeJobFactory decodeJobFactory, ResourceRecycler resourceRecycler) { this.cache = cache; this.diskCacheProvider = new LazyDiskCacheProvider(diskCacheFactory); if (activeResources == null) { activeResources = new ActiveResources(); } this.activeResources = activeResources; activeResources.setListener(this); if (keyFactory == null) { keyFactory = new EngineKeyFactory(); } this.keyFactory = keyFactory; if (jobs == null) { jobs = new HashMap<>(); } this.jobs = jobs; if (engineJobFactory == null) { engineJobFactory = new EngineJobFactory( diskCacheExecutor, sourceExecutor, sourceUnlimitedExecutor, animationExecutor, this); } this.engineJobFactory = engineJobFactory; if (decodeJobFactory == null) { decodeJobFactory = new DecodeJobFactory(diskCacheProvider); } this.decodeJobFactory = decodeJobFactory; if (resourceRecycler == null) { resourceRecycler = new ResourceRecycler(); } this.resourceRecycler = resourceRecycler; cache.setResourceRemovedListener(this); }
public GlideBuilder setMemoryCache(MemoryCache memoryCache) { this.memoryCache = memoryCache; return this; }
public EngineBuilder(MemoryCache memoryCache, DiskCache diskCache) { this.memoryCache = memoryCache; this.diskCache = diskCache; }
/** * Sets the {@link com.bumptech.glide.load.engine.cache.MemoryCache} implementation to store * {@link com.bumptech.glide.load.engine.Resource}s that are not currently in use. * * @param memoryCache The cache to use. * @return This builder. */ public GlideBuilder setMemoryCache(MemoryCache memoryCache) { this.memoryCache = memoryCache; return this; }