CustomTarget

abstract class CustomTarget<T> : Target<R>

A base Target for loading resources (android.graphics.Bitmap, Drawable etc) that are used outside of android.view.Views.

If you're loading a resource into a View, use into, a subclass of ImageViewTarget, or CustomViewTarget. Using this class to load resources into Views can prevent Glide from correctly cancelling any previous loads, which may result in incorrect images appearing in the view, especially in scrolling views like androidx.recyclerview.widget.RecyclerView.

You MUST implement onLoadCleared and ensure that all references to any resource passed into the target in onResourceReady are removed before onLoadCleared completes. Failing to do so can result in graphical corruption, crashes caused by recycled Bitmaps, and other undefined behavior. It is never safe to leave onLoadCleared unimplemented or empty. Even if you do not manually clear this Target, Glide may do so automatically after certain lifecycle events in androidx.fragment.app.Fragments and android.app.Activitys.

This class can only be used with SIZE_ORIGINAL or when the desired resource dimensions are known when the Target is created. If you'd like to run some asynchronous process and make full use of getSize and SizeReadyCallback, extend Target directly instead of using this class.

Parameters

<T>

The type of resource that will be loaded (e.g. Bitmap).

Constructors

Link copied to clipboard
open fun CustomTarget()
Creates a new CustomTarget that will attempt to load the resource in its original size.
Link copied to clipboard
open fun CustomTarget(width: Int, height: Int)
Creates a new CustomTarget that will return the given width and height as the requested size (unless overridden by override in the request).

Functions

Link copied to clipboard
fun getSize(cb: SizeReadyCallback)
A method to retrieve the size of this target.
Link copied to clipboard
open fun onDestroy()
Callback for when onDestroy} or onDestroy is called.
Link copied to clipboard
abstract fun onLoadCleared(placeholder: Drawable)
A mandatory lifecycle callback that is called when a load is cancelled and its resources are freed.
Link copied to clipboard
open fun onLoadFailed(errorDrawable: Drawable)
A mandatory lifecycle callback that is called when a load fails.
Link copied to clipboard
open fun onLoadStarted(placeholder: Drawable)
A lifecycle callback that is called when a load is started.
Link copied to clipboard
abstract fun onResourceReady(resource: R, transition: Transition<out Any>)
The method that will be called when the resource load has finished.
Link copied to clipboard
open fun onStart()
Callback for when onStart} or onStart is called.
Link copied to clipboard
open fun onStop()
Callback for when onStop} or onStop} is called.
Link copied to clipboard
fun removeCallback(cb: SizeReadyCallback)
Removes the given callback from the pending set if it's still retained.

Properties

Link copied to clipboard
open var request: Request
Link copied to clipboard
val SIZE_ORIGINAL: Int
Indicates that we want the resource in its original unmodified width and/or height.

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard