Class ViewTarget<T extends android.view.View,Z>
- java.lang.Object
-
- com.bumptech.glide.request.target.BaseTarget<Z>
-
- com.bumptech.glide.request.target.ViewTarget<T,Z>
-
- Type Parameters:
T- The specific subclass of view wrapped by this target.Z- The resource type this target will receive.
- All Implemented Interfaces:
LifecycleListener,Target<Z>
- Direct Known Subclasses:
ImageViewTarget
@Deprecated public abstract class ViewTarget<T extends android.view.View,Z> extends BaseTarget<Z>
Deprecated.UseCustomViewTarget. Using this class is unsafe without implementingonLoadCleared(android.graphics.drawable.Drawable)and results in recycled bitmaps being referenced from the UI and hard to root-cause crashes.A baseTargetfor loadingBitmaps intoViews that provides default implementations for most most methods and can determine the size of views using aViewTreeObserver.OnDrawListener.To detect
Viewreuse inListViewor anyViewGroupthat reuses views, this class uses theView.setTag(Object)method to store some metadata so that if a view is reused, any previous loads or resources from previous loads can be cancelled or reused.Any calls to
View.setTag(Object)} on a View given to this class will result in excessive allocations and and/orIllegalArgumentExceptions. If you must callView.setTag(Object)on a view, usesetTagId(int)to specify a custom tag for Glide to use.Subclasses must call super in
onLoadCleared(Drawable)
-
-
Field Summary
Fields Modifier and Type Field Description protected TviewDeprecated.-
Fields inherited from interface com.bumptech.glide.request.target.Target
SIZE_ORIGINAL
-
-
Constructor Summary
Constructors Constructor Description ViewTarget(T view)Deprecated.Constructor that defaultswaitForLayouttofalse.ViewTarget(T view, boolean waitForLayout)Deprecated.UsewaitForLayout()instead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ViewTarget<T,Z>clearOnDetach()Deprecated.RequestgetRequest()Deprecated.Returns any stored request usingView.getTag().voidgetSize(SizeReadyCallback cb)Deprecated.Determines the size of the view by first checkingView.getWidth()andView.getHeight().TgetView()Deprecated.Returns the wrappedView.voidonLoadCleared(android.graphics.drawable.Drawable placeholder)Deprecated.A mandatory lifecycle callback that is called when a load is cancelled and its resources are freed.voidonLoadStarted(android.graphics.drawable.Drawable placeholder)Deprecated.A lifecycle callback that is called when a load is started.voidremoveCallback(SizeReadyCallback cb)Deprecated.Removes the given callback from the pending set if it's still retained.voidsetRequest(Request request)Deprecated.Stores the request usingView.setTag(Object).static voidsetTagId(int tagId)Deprecated.Glide uses it's own default tag id, so there's no need to specify your own.java.lang.StringtoString()Deprecated.ViewTarget<T,Z>waitForLayout()Deprecated.Indicates that Glide should always wait for any pending layout pass before checking for the size anView.-
Methods inherited from class com.bumptech.glide.request.target.BaseTarget
onDestroy, onLoadFailed, onStart, onStop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.bumptech.glide.request.target.Target
onResourceReady
-
-
-
-
Field Detail
-
view
protected final T extends android.view.View view
Deprecated.
-
-
Constructor Detail
-
ViewTarget
public ViewTarget(@NonNull T view)Deprecated.Constructor that defaultswaitForLayouttofalse.
-
ViewTarget
@Deprecated public ViewTarget(@NonNull T view, boolean waitForLayout)Deprecated.UsewaitForLayout()instead.- Parameters:
waitForLayout- If set totrue, Glide will always wait for any pending layout pass before checking for the size a View. If set tofalseGlide will only wait for a pending layout pass if it's unable to resolve the size from layout parameters or an existing View size. Because setting this parameter totrueforces Glide to wait for the layout pass to occur before starting the load, setting this parameter totruecan cause flashing in some cases and should be used sparingly. If layout parameters are set to fixed sizes, they will still be used instead of the View's dimensions even if this parameter is set totrue. This parameter is a fallback only.
-
-
Method Detail
-
clearOnDetach
@NonNull public final ViewTarget<T,Z> clearOnDetach()
Deprecated.Clears theView'sRequestwhen theViewis detached from itsWindowand restarts theRequestwhen theViewis re-attached from itsWindow.This is an experimental API that may be removed in a future version.
Using this method can save memory by allowing Glide to more eagerly clear resources when transitioning screens or swapping adapters in scrolling views. However it also substantially increases the odds that images will not be in memory if users subsequently return to a screen where images were previously loaded. Whether or not this happens will depend on the number of images loaded in the new screen and the size of the memory cache. Increasing the size of the memory cache can improve this behavior but it largely negates the memory benefits of using this method.
Use this method with caution and measure your memory usage to ensure that it's actually improving your memory usage in the cases you care about.
-
waitForLayout
@NonNull public final ViewTarget<T,Z> waitForLayout()
Deprecated.Indicates that Glide should always wait for any pending layout pass before checking for the size anView.By default, Glide will only wait for a pending layout pass if it's unable to resolve the size from the
ViewGroup.LayoutParamsor valid non-zero values forView.getWidth()andView.getHeight().Because calling this method forces Glide to wait for the layout pass to occur before starting loads, setting this parameter to
truecan cause Glide to asynchronous load an image even if it's in the memory cache. The load will happen asynchronously because Glide has to wait for a layout pass to occur, which won't necessarily happen in the same frame as when the image is requested. As a result, using this method can resulting in flashing in some cases and should be used sparingly.If the
ViewGroup.LayoutParamsof the wrappedVieware set to fixed sizes, they will still be used instead of theView's dimensions even if this method is called. This parameter is a fallback only.
-
onLoadStarted
@CallSuper public void onLoadStarted(@Nullable android.graphics.drawable.Drawable placeholder)Deprecated.Description copied from interface:TargetA lifecycle callback that is called when a load is started.Note - This may not be called for every load, it is possible for example for loads to fail before the load starts (when the model object is null).
Note - This method may be called multiple times before any other lifecycle method is called. Loads can be paused and restarted due to lifecycle or connectivity events and each restart may cause a call here.
- Specified by:
onLoadStartedin interfaceTarget<T extends android.view.View>- Overrides:
onLoadStartedin classBaseTarget<Z>- Parameters:
placeholder- The placeholder drawable to optionally show, or null.
-
getView
@NonNull public T getView()
Deprecated.Returns the wrappedView.
-
getSize
@CallSuper public void getSize(@NonNull SizeReadyCallback cb)Deprecated.Determines the size of the view by first checkingView.getWidth()andView.getHeight(). If one or both are zero, it then checks the view'sViewGroup.LayoutParams. If one or both of the params width and height are less than or equal to zero, it then adds anViewTreeObserver.OnPreDrawListenerwhich waits until the view has been measured before calling the callback with the view's drawn width and height.- Parameters:
cb- The callback that must be called when the size of the target has been determined
-
removeCallback
@CallSuper public void removeCallback(@NonNull SizeReadyCallback cb)Deprecated.Description copied from interface:TargetRemoves the given callback from the pending set if it's still retained.- Parameters:
cb- The callback to remove.
-
onLoadCleared
@CallSuper public void onLoadCleared(@Nullable android.graphics.drawable.Drawable placeholder)Deprecated.Description copied from interface:TargetA mandatory lifecycle callback that is called when a load is cancelled and its resources are freed.You must ensure that any current Drawable received in
Target.onResourceReady(Object, Transition)is no longer used before redrawing the container (usually a View) or changing its visibility.- Specified by:
onLoadClearedin interfaceTarget<T extends android.view.View>- Overrides:
onLoadClearedin classBaseTarget<Z>- Parameters:
placeholder- The placeholder drawable to optionally show, or null.
-
setRequest
public void setRequest(@Nullable Request request)Deprecated.Stores the request usingView.setTag(Object).- Specified by:
setRequestin interfaceTarget<T extends android.view.View>- Overrides:
setRequestin classBaseTarget<Z>- Parameters:
request-
-
getRequest
@Nullable public Request getRequest()
Deprecated.Returns any stored request usingView.getTag().For Glide to function correctly, Glide must be the only thing that calls
View.setTag(Object). If the tag is cleared or put to another object type, Glide will not be able to retrieve and cancel previous loads which will not only prevent Glide from reusing resource, but will also result in incorrect images being loaded and lots of flashing of images in lists. As a result, this will throw anIllegalArgumentExceptionifView.getTag()} returns a non null object that is not anRequest.- Specified by:
getRequestin interfaceTarget<T extends android.view.View>- Overrides:
getRequestin classBaseTarget<Z>
-
toString
public java.lang.String toString()
Deprecated.- Overrides:
toStringin classjava.lang.Object
-
setTagId
@Deprecated public static void setTagId(int tagId)
Deprecated.Glide uses it's own default tag id, so there's no need to specify your own. This method will be removed in a future version.Sets the android resource id to use in conjunction withView.setTag(int, Object)to store temporary state allowing loads to be automatically cancelled and resources re-used in scrolling lists.If no tag id is set, Glide will use
View.setTag(Object).Warning: prior to Android 4.0 tags were stored in a static map. Using this method prior to Android 4.0 may cause memory leaks and isn't recommended. If you do use this method on older versions, be sure to call
RequestManager.clear(View)on any view you start a load into to ensure that the static state is removed.- Parameters:
tagId- The android resource to use.
-
-