/** * Preloads the resource into the cache using the given width and height. * * <p> Pre-loading is useful for making sure that resources you are going to to want in the near * future are available quickly. </p> * * @param width The desired width in pixels, or {@link Target#SIZE_ORIGINAL}. This will be * overridden by * {@link com.bumptech.glide.request.RequestOptions#override(int, int)} if * previously called. * @param height The desired height in pixels, or {@link Target#SIZE_ORIGINAL}. This will be * overridden by * {@link com.bumptech.glide.request.RequestOptions#override(int, int)}} if * previously called). * @return A {@link Target} that can be used to cancel the load via * {@link RequestManager#clear(Target)}. * @see com.bumptech.glide.ListPreloader */ @NonNull public Target<TranscodeType> preload(int width, int height) { final PreloadTarget<TranscodeType> target = PreloadTarget.obtain(requestManager, width, height); return into(target); }
/** * Returns a PreloadTarget. * * @param width The width in pixels of the desired resource. * @param height The height in pixels of the desired resource. * @param <Z> The type of the desired resource. */ public static <Z> PreloadTarget<Z> obtain(RequestManager requestManager, int width, int height) { return new PreloadTarget<>(requestManager, width, height); }
@Override public boolean handleMessage(Message message) { if (message.what == MESSAGE_CLEAR) { ((PreloadTarget<?>) message.obj).clear(); return true; } return false; } });
@Test public void testClearsTargetInOnResourceReady() { Request request = mock(Request.class); PreloadTarget<Object> target = PreloadTarget.obtain(requestManager, 100, 100); target.setRequest(request); target.onResourceReady(new Object(), null); verify(requestManager).clear(eq(target)); } }
@Test public void testCallsSizeReadyWithGivenDimensions() { int width = 1234; int height = 456; PreloadTarget<Object> target = PreloadTarget.obtain(requestManager, width, height); SizeReadyCallback cb = mock(SizeReadyCallback.class); target.getSize(cb); verify(cb).onSizeReady(eq(width), eq(height)); }
/** * Preloads the resource into the cache using the given width and height. * * <p> * Pre-loading is useful for making sure that resources you are going to to want in the near future are * available quickly. * </p> * * * @see ListPreloader * * @param width The desired width in pixels, or {@link Target#SIZE_ORIGINAL}. This will be overridden by * {@link #override * (int, int)} if previously called. * @param height The desired height in pixels, or {@link Target#SIZE_ORIGINAL}. This will be overridden by * {@link #override * (int, int)}} if previously called). * @return A {@link Target} that can be used to cancel the load via * {@link Glide#clear(Target)}. */ public Target<TranscodeType> preload(int width, int height) { final PreloadTarget<TranscodeType> target = PreloadTarget.obtain(width, height); return into(target); }
/** * Returns a PreloadTarget. * * @param width The width in pixels of the desired resource. * @param height The height in pixels of the desired resource. * @param <Z> The type of the desired resource. */ public static <Z> PreloadTarget<Z> obtain(int width, int height) { return new PreloadTarget<Z>(width, height); }
/** * Preloads the resource into the cache using the given width and height. * * <p> Pre-loading is useful for making sure that resources you are going to to want in the near * future are available quickly. </p> * * @param width The desired width in pixels, or {@link Target#SIZE_ORIGINAL}. This will be * overridden by * {@link com.bumptech.glide.request.RequestOptions#override(int, int)} if * previously called. * @param height The desired height in pixels, or {@link Target#SIZE_ORIGINAL}. This will be * overridden by * {@link com.bumptech.glide.request.RequestOptions#override(int, int)}} if * previously called). * @return A {@link Target} that can be used to cancel the load via * {@link RequestManager#clear(Target)}. * @see com.bumptech.glide.ListPreloader */ public Target<TranscodeType> preload(int width, int height) { final PreloadTarget<TranscodeType> target = PreloadTarget.obtain(requestManager, width, height); return into(target); }
/** * Returns a PreloadTarget. * * @param width The width in pixels of the desired resource. * @param height The height in pixels of the desired resource. * @param <Z> The type of the desired resource. */ public static <Z> PreloadTarget<Z> obtain(RequestManager requestManager, int width, int height) { return new PreloadTarget<>(requestManager, width, height); }