19fc12334a7d14347cd6951d0653264b2597bd3a0Sam Juddpackage com.bumptech.glide.request.target;
233943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd
333943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Juddimport android.graphics.drawable.Drawable;
42896f4261b305efc0da164314fb90eb75bf5a234Sam Judd
5d8eac4cec0fe1fa9b496998cfac858fd603f4f32Sam Juddimport com.bumptech.glide.manager.LifecycleListener;
69fc12334a7d14347cd6951d0653264b2597bd3a0Sam Juddimport com.bumptech.glide.request.Request;
72896f4261b305efc0da164314fb90eb75bf5a234Sam Juddimport com.bumptech.glide.request.animation.GlideAnimation;
833943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd
933943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd/**
102896f4261b305efc0da164314fb90eb75bf5a234Sam Judd * An interface that Glide can load a resource into and notify of relevant lifecycle events during a load.
112896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *
122896f4261b305efc0da164314fb90eb75bf5a234Sam Judd * <p>
132896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *     The lifecycle events in this class are as follows:
142896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *     <ul>
152896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *         <li>onLoadStarted</li>
162896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *         <li>onResourceReady</li>
172896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *         <li>onLoadCleared</li>
182896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *         <li>onLoadFailed</li>
192896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *     </ul>
202896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *
212896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *     The typical lifecycle is onLoadStarted -> onResourceReady or onLoadFailed -> onLoadCleared. However, there are no
222896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *     guarantees. onLoadStarted may not be called if the resource is in memory or if the load will fail because of a
232896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *     null model object. onLoadCleared similarly may never be called if the target is never cleared. See the docs for
242896f4261b305efc0da164314fb90eb75bf5a234Sam Judd *     the individual methods for details.
252896f4261b305efc0da164314fb90eb75bf5a234Sam Judd * </p>
26ba414a3eba45ab6566a94c48babace5c1d6d721fSam Judd *
27da4ce795221e0fd9a3d11c84f018b3b5d6a10421Sam Judd * @param <R> The type of resource the target can display.
2833943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd */
29d8eac4cec0fe1fa9b496998cfac858fd603f4f32Sam Juddpublic interface Target<R> extends LifecycleListener {
3033943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd
3133943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd    /**
322896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * A lifecycle callback that is called when a load is started.
332896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *
342896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * <p>
352896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *     Note - This may not be called for every load, it is possible for example for loads to fail before the load
362896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *     starts (when the model object is null).
372896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * </p>
382896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *
392896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * <p>
402896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *     Note - This method may be called multiple times before any other lifecycle method is called. Loads can be
412896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *     paused and restarted due to lifecycle or connectivity events and each restart may cause a call here.
422896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * </p>
432896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *
442896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * @param placeholder The placeholder drawable to optionally show, or null.
452896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     */
465ba19a0e69ad3a651b8f13ba45de48a56b56ce36Sam Judd    void onLoadStarted(Drawable placeholder);
472896f4261b305efc0da164314fb90eb75bf5a234Sam Judd
482896f4261b305efc0da164314fb90eb75bf5a234Sam Judd    /**
492896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * A lifecycle callback that is called when a load fails.
502896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *
512896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * <p>
522896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *     Note - This may be called before {@link #onLoadStarted(android.graphics.drawable.Drawable)} if the model
532896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *     object is null.
542896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * </p>
552896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *
562896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * @param e The exception causing the load to fail, or null if no exception occurred (usually because a decoder
572896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     *          simply returned null).
582896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * @param errorDrawable The error drawable to optionally show, or null.
5933943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd     */
605ba19a0e69ad3a651b8f13ba45de48a56b56ce36Sam Judd    void onLoadFailed(Exception e, Drawable errorDrawable);
6133943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd
6233943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd    /**
632896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * The method that will be called when the resource load has finished.
64fe090f50f3040f4d478143a3e0ffa8cdf813fefcSam Judd     *
65ba414a3eba45ab6566a94c48babace5c1d6d721fSam Judd     * @param resource the loaded resource.
6633943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd     */
675ba19a0e69ad3a651b8f13ba45de48a56b56ce36Sam Judd    void onResourceReady(R resource, GlideAnimation<? super R> glideAnimation);
6833943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd
6933943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd    /**
702896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * A lifecycle callback that is called when a load is cancelled and its resources are freed.
7133943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd     *
722896f4261b305efc0da164314fb90eb75bf5a234Sam Judd     * @param placeholder The placeholder drawable to optionally show, or null.
7333943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd     */
745ba19a0e69ad3a651b8f13ba45de48a56b56ce36Sam Judd    void onLoadCleared(Drawable placeholder);
7533943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd
7633943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd    /**
77fe090f50f3040f4d478143a3e0ffa8cdf813fefcSam Judd     * A method to retrieve the size of this target.
78fe090f50f3040f4d478143a3e0ffa8cdf813fefcSam Judd     *
7933943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd     * @param cb The callback that must be called when the size of the target has been determined
8033943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd     */
815ba19a0e69ad3a651b8f13ba45de48a56b56ce36Sam Judd    void getSize(SizeReadyCallback cb);
8233943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd
835f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd    /**
845f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd     * Sets the current request for this target to retain, should not be called outside of Glide.
855f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd     */
865ba19a0e69ad3a651b8f13ba45de48a56b56ce36Sam Judd    void setRequest(Request request);
870ba0245a97116b2f2c7bd67213961ac4e2dc3e56Sam Judd
885f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd    /**
895f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd     * Retrieves the current request for this target, should not be called outside of Glide.
905f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd     */
915ba19a0e69ad3a651b8f13ba45de48a56b56ce36Sam Judd    Request getRequest();
9233943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd}
93