/** * Helper constructor that accepts an {@link FragmentActivity}. */ public RecyclerViewPreloader(@NonNull FragmentActivity fragmentActivity, @NonNull PreloadModelProvider<T> preloadModelProvider, @NonNull PreloadSizeProvider<T> preloadDimensionProvider, int maxPreload) { this(Glide.with(fragmentActivity), preloadModelProvider, preloadDimensionProvider, maxPreload); }
@Override public void run() { Glide.get(context).clearMemory(); } });
@SuppressWarnings("unused") public VideoBitmapDecoder(Context context) { this(Glide.get(context).getBitmapPool()); }
@SuppressWarnings("unused") public ByteBufferGifDecoder(Context context) { this(context, Glide.get(context).getRegistry().getImageHeaderParsers(), Glide.get(context).getBitmapPool(), Glide.get(context).getArrayPool()); }
GifFrameLoader( Glide glide, GifDecoder gifDecoder, int width, int height, Transformation<Bitmap> transformation, Bitmap firstFrame) { this( glide.getBitmapPool(), Glide.with(glide.getContext()), gifDecoder, null /*handler*/, getRequestBuilder(Glide.with(glide.getContext()), width, height), transformation, firstFrame); }
@Test public void loadOpaquePngResource_withNoOtherLoaders_decodesResource() { Glide.get(context).getRegistry() .prepend( Object.class, InputStream.class, new FakeModelLoader<>(ResourceIds.raw.canonical_png)); Bitmap bitmap = concurrency.get( Glide.with(context) .asBitmap() .load(new Object()) .submit()); assertThat(bitmap).isNotNull(); }
@Test public void load_withWideGamutImage_bitmapInPoolWithSizeAndConfig_usesBitmapFromPool() { int bitmapDimension = 1000; Glide.init( context, new GlideBuilder() .setBitmapPool(new LruBitmapPool(bitmapDimension * bitmapDimension * 8 * 4))); Bitmap expected = Bitmap.createBitmap(bitmapDimension, bitmapDimension, Bitmap.Config.RGBA_F16); Glide.get(context) .getBitmapPool() .put(expected); Bitmap bitmap = concurrency.get( Glide.with(context) .asBitmap() .load(ResourceIds.raw.webkit_logo_p3) .submit()); assertThat(bitmap).isSameAs(expected); }
@Test public void load_withSmallerWideGamutInPool_decodesBitmap() { BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); Bitmap toPut = Bitmap.createBitmap(300, 298, Config.RGBA_F16); bitmapPool.put(toPut); // Add a second Bitmap to account for the InputStream decode. bitmapPool.put(Bitmap.createBitmap(toPut)); Bitmap wideGamut = Bitmap.createBitmap(300, 300, Config.RGBA_F16); byte[] data = asPng(wideGamut); Bitmap bitmap = concurrency.get( Glide.with(context) .asBitmap() .load(data) .submit()); assertThat(bitmap).isNotNull(); }
@SuppressWarnings("unchecked") private <T> void registerMockStreamModelLoader(final Class<T> modelClass) { ModelLoader<T, InputStream> modelLoader = mockStreamModelLoader(modelClass); ModelLoaderFactory<T, InputStream> modelLoaderFactory = mock(ModelLoaderFactory.class); when(modelLoaderFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(modelLoader); Glide.get(context).getRegistry() .prepend(modelClass, InputStream.class, modelLoaderFactory); }
private static Glide getGlideSingleton() { return Glide.get(RuntimeEnvironment.application); }
@Override public void onLowMemory() { clearMemory(); } }
@NonNull private static RequestManagerRetriever getRetriever(@Nullable Context context) { // Context could be null for other reasons (ie the user passes in null), but in practice it will // only occur due to errors with the Fragment lifecycle. Preconditions.checkNotNull( context, "You cannot start a load on a not yet attached View or a Fragment where getActivity() " + "returns null (which usually occurs when getActivity() is called before the Fragment " + "is attached or after the Fragment is destroyed)."); return Glide.get(context).getRequestManagerRetriever(); }
@After public void tearDown() { Glide.get(context).clearDiskCache(); Glide.tearDown(); }
private static ThumbFetcher build(Context context, Uri uri, ThumbnailQuery query) { ArrayPool byteArrayPool = Glide.get(context).getArrayPool(); ThumbnailStreamOpener opener = new ThumbnailStreamOpener( Glide.get(context).getRegistry().getImageHeaderParsers(), query, byteArrayPool, context.getContentResolver()); return new ThumbFetcher(uri, opener); }
public void clearCache(View v) { Log.w(TAG, "clearing cache"); GlideRequests glideRequests = GlideApp.with(this); glideRequests.clear(imageViewRes); glideRequests.clear(imageViewNet); GlideApp.get(this).clearMemory(); File cacheDir = Preconditions.checkNotNull(Glide.getPhotoCacheDir(this)); if (cacheDir.isDirectory()) { for (File child : cacheDir.listFiles()) { if (!child.delete()) { Log.w(TAG, "cannot delete: " + child); } } } reload(); }
@Test public void loadJpegResource_withNoOtherLoaders_decodesResource() { Glide.get(context).getRegistry() .prepend( Object.class, InputStream.class, new FakeModelLoader<>(ResourceIds.raw.canonical)); Bitmap bitmap = concurrency.get( Glide.with(context) .asBitmap() .load(new Object()) .submit()); assertThat(bitmap).isNotNull(); }
@Test public void loadWideGamutImage_withArgb888OfSufficientSizeInPool_usesArgb8888Bitmap() { Bitmap wideGamut = Bitmap.createBitmap(100, 50, Bitmap.Config.RGBA_F16); byte[] data = asPng(wideGamut); Bitmap argb8888 = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Glide.init(context, new GlideBuilder() .setBitmapPool(new LruBitmapPool(wideGamut.getAllocationByteCount() * 5))); Glide.get(context).getBitmapPool().put(argb8888); Bitmap result = concurrency.get( Glide.with(context) .asBitmap() .load(data) .submit()); assertThat(result).isSameAs(argb8888); }
/** * @deprecated Use {@link #obtain(Resources, Resource)} instead, it can be unsafe to extract * {@link Bitmap}s from their wrapped {@link Resource}. */ @Deprecated public static LazyBitmapDrawableResource obtain(Context context, Bitmap bitmap) { return (LazyBitmapDrawableResource) obtain( context.getResources(), BitmapResource.obtain(bitmap, Glide.get(context).getBitmapPool())); }
public static synchronized <T> WaitModel<T> waitOn(T model) { @SuppressWarnings("unchecked") ModelLoaderFactory<WaitModel<T>, InputStream> streamFactory = new Factory<>((Class<T>) model.getClass(), InputStream.class); Glide.get(InstrumentationRegistry.getTargetContext()) .getRegistry() .replace(WaitModel.class, InputStream.class, streamFactory); return new WaitModel<>(model); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); glide = Glide.get(RuntimeEnvironment.application); context = RuntimeEnvironment.application; }