R - The type of the resource that will be loaded.public class RequestFutureTarget<R> extends Object implements FutureTarget<R>, Runnable
Future implementation for Glide that can be used to load resources
in a blocking manner on background threads.
Note - Unlike most targets, RequestFutureTargets can be used once and only once. Attempting to reuse a RequestFutureTarget will probably result in undesirable behavior or exceptions. Instead of reusing objects of this class, the pattern should be:
FutureTarget<File> target = null;
RequestManager requestManager = Glide.with(context);
try {
target = requestManager
.downloadOnly()
.load(model)
.submit();
File downloadedFile = target.get();
// ... do something with the file (usually throws IOException)
} catch (ExecutionException | InterruptedException | IOException e) {
// ... bug reporting or recovery
} finally {
// make sure to cancel pending operations and free resources
if (target != null) {
target.cancel(true); // mayInterruptIfRunning
}
}
The cancel(boolean) call will cancel pending operations and
make sure that any resources used are recycled.
SIZE_ORIGINAL| Constructor and Description |
|---|
RequestFutureTarget(Handler mainHandler,
int width,
int height)
Constructor for a RequestFutureTarget.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
R |
get() |
R |
get(long time,
TimeUnit timeUnit) |
Request |
getRequest()
Retrieves the current request for this target, should not be called outside of Glide.
|
void |
getSize(SizeReadyCallback cb)
A callback that should never be invoked directly.
|
boolean |
isCancelled() |
boolean |
isDone() |
void |
onDestroy()
Callback for when
Fragment.onDestroy()} or Activity.onDestroy() is called. |
void |
onLoadCleared(Drawable placeholder)
A callback that should never be invoked directly.
|
void |
onLoadFailed(Drawable errorDrawable)
A callback that should never be invoked directly.
|
void |
onLoadStarted(Drawable placeholder)
A callback that should never be invoked directly.
|
void |
onResourceReady(R resource,
Transition<? super R> transition)
A callback that should never be invoked directly.
|
void |
onStart()
Callback for when
Fragment.onStart()} or Activity.onStart() is called. |
void |
onStop()
Callback for when
Fragment.onStop()} or Activity.onStop()} is called. |
void |
removeCallback(SizeReadyCallback cb)
Removes the given callback from the pending set if it's still retained.
|
void |
run()
A callback that should never be invoked directly.
|
void |
setRequest(Request request)
Sets the current request for this target to retain, should not be called outside of Glide.
|
public RequestFutureTarget(Handler mainHandler, int width, int height)
public boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
isCancelled in interface Future<R>public R get() throws InterruptedException, ExecutionException
get in interface Future<R>InterruptedExceptionExecutionExceptionpublic R get(long time, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException
get in interface Future<R>InterruptedExceptionExecutionExceptionTimeoutExceptionpublic void getSize(SizeReadyCallback cb)
public void removeCallback(SizeReadyCallback cb)
TargetremoveCallback in interface Target<R>cb - The callback to remove.public void setRequest(@Nullable Request request)
setRequest in interface Target<R>@Nullable public Request getRequest()
TargetgetRequest in interface Target<R>public void onLoadCleared(Drawable placeholder)
onLoadCleared in interface Target<R>placeholder - The placeholder drawable to optionally show, or null.public void onLoadStarted(Drawable placeholder)
onLoadStarted in interface Target<R>placeholder - The placeholder drawable to optionally show, or null.public void onLoadFailed(Drawable errorDrawable)
onLoadFailed in interface Target<R>errorDrawable - The error drawable to optionally show, or null.public void onResourceReady(R resource, Transition<? super R> transition)
onResourceReady in interface Target<R>resource - the loaded resource.public void run()
public void onStart()
LifecycleListenerFragment.onStart()} or Activity.onStart() is called.onStart in interface LifecycleListenerpublic void onStop()
LifecycleListenerFragment.onStop()} or Activity.onStop()} is called.onStop in interface LifecycleListenerpublic void onDestroy()
LifecycleListenerFragment.onDestroy()} or Activity.onDestroy() is called.onDestroy in interface LifecycleListener