1package com.bumptech.glide.request; 2 3import com.bumptech.glide.request.target.Target; 4 5/** 6 * A class for monitoring the status of a request while images load. 7 * 8 * @param <T> The type of the model being loaded. 9 * @param <R> The type of resource being loaded. 10 */ 11public interface RequestListener<T, R> { 12 13 /** 14 * Called when an exception occurs during a load. Will only be called if we currently want to display an image 15 * for the given model in the given target. It is recommended to create a single instance per activity/fragment 16 * rather than instantiate a new object for each call to {@code Glide.load()} to avoid object churn. 17 * 18 * <p> 19 * It is safe to reload this or a different model or change what is displayed in the target at this point. 20 * For example: 21 * <pre> 22 * <code> 23 * public void onException(Exception e, ModelType model, Target target) { 24 * target.setPlaceholder(R.drawable.a_specific_error_for_my_exception); 25 * Glide.load(model).into(target); 26 * } 27 * </code> 28 * </pre> 29 * </p> 30 * 31 * <p> 32 * Note - if you want to reload this or any other model after an exception, you will need to include all 33 * relevant builder calls (like centerCrop, placeholder etc). 34 * </p> 35 * 36 * @param e The exception, or null 37 * @param model The model we were trying to load when the exception occurred 38 * @param target The {@link Target} we were trying to load the image into 39 * @return True if the listener has handled updating the target for the given exception, false to allow 40 * Glide's request to update the target. 41 */ 42 public abstract boolean onException(Exception e, T model, Target target, boolean isFirstImage); 43 44 /** 45 * Called when a load completes successfully, immediately after {@link Target#onResourceReady(Object)}. 46 * 47 * @param resource The resource that was loaded for the target. 48 * @param model The specific model that was used to load the image. 49 * @param target The target the model was loaded into. 50 * @param isFromMemoryCache True if the load completed synchronously (useful for determining whether or not to 51 * animate) 52 * @param isFirstResource True if this is the first resource to in this load to be loaded into the target. For 53 * example when loading a thumbnail and a fullsize image, this will be true for the first 54 * image to load and false for the second. 55 * @return True if the listener has handled setting the resource on the target (including any animations), false to 56 * allow Glide's request to update the target (again including animations). 57 */ 58 public abstract boolean onResourceReady(R resource, T model, Target target, boolean isFromMemoryCache, 59 boolean isFirstResource); 60} 61