com.bumptech.glide.request
Class RequestFutureTarget<T,R>

java.lang.Object
  extended by com.bumptech.glide.request.RequestFutureTarget<T,R>
Type Parameters:
T - The type of the data to load.
R - The type of the resource that will be loaded.
All Implemented Interfaces:
LifecycleListener, FutureTarget<R>, Target<R>, Runnable, Future<R>

public class RequestFutureTarget<T,R>
extends Object
implements FutureTarget<R>, Runnable

A 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:

     RequestFutureTarget target = Glide.load("")...
     Object resource = target.get();
     // Do something with resource, and when finished:
     Glide.clear(target);
     
     
The Glide.clear(FutureTarget) call will make sure any resources used are recycled.


Field Summary
 
Fields inherited from interface com.bumptech.glide.request.target.Target
SIZE_ORIGINAL
 
Constructor Summary
RequestFutureTarget(Handler mainHandler, int width, int height)
          Constructor for a RequestFutureTarget.
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
           
 void clear()
          Can be safely called from either the main thread or a background thread to cleanup the resources used by this target.
 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(Exception e, 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, GlideAnimation<? super R> glideAnimation)
          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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestFutureTarget

public RequestFutureTarget(Handler mainHandler,
                           int width,
                           int height)
Constructor for a RequestFutureTarget. Should not be used directly.

Method Detail

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Specified by:
cancel in interface Future<R>

isCancelled

public boolean isCancelled()
Specified by:
isCancelled in interface Future<R>

isDone

public boolean isDone()
Specified by:
isDone in interface Future<R>

get

public R get()
      throws InterruptedException,
             ExecutionException
Specified by:
get in interface Future<R>
Throws:
InterruptedException
ExecutionException

get

public R get(long time,
             TimeUnit timeUnit)
      throws InterruptedException,
             ExecutionException,
             TimeoutException
Specified by:
get in interface Future<R>
Throws:
InterruptedException
ExecutionException
TimeoutException

getSize

public void getSize(SizeReadyCallback cb)
A callback that should never be invoked directly.

Specified by:
getSize in interface Target<R>
Parameters:
cb - The callback that must be called when the size of the target has been determined

setRequest

public void setRequest(Request request)
Description copied from interface: Target
Sets the current request for this target to retain, should not be called outside of Glide.

Specified by:
setRequest in interface Target<R>

getRequest

public Request getRequest()
Description copied from interface: Target
Retrieves the current request for this target, should not be called outside of Glide.

Specified by:
getRequest in interface Target<R>

onLoadCleared

public void onLoadCleared(Drawable placeholder)
A callback that should never be invoked directly.

Specified by:
onLoadCleared in interface Target<R>
Parameters:
placeholder - The placeholder drawable to optionally show, or null.

onLoadStarted

public void onLoadStarted(Drawable placeholder)
A callback that should never be invoked directly.

Specified by:
onLoadStarted in interface Target<R>
Parameters:
placeholder - The placeholder drawable to optionally show, or null.

onLoadFailed

public void onLoadFailed(Exception e,
                         Drawable errorDrawable)
A callback that should never be invoked directly.

Specified by:
onLoadFailed in interface Target<R>
Parameters:
e - The exception causing the load to fail, or null if no exception occurred (usually because a decoder simply returned null).
errorDrawable - The error drawable to optionally show, or null.

onResourceReady

public void onResourceReady(R resource,
                            GlideAnimation<? super R> glideAnimation)
A callback that should never be invoked directly.

Specified by:
onResourceReady in interface Target<R>
Parameters:
resource - the loaded resource.

run

public void run()
A callback that should never be invoked directly.

Specified by:
run in interface Runnable

clear

public void clear()
Can be safely called from either the main thread or a background thread to cleanup the resources used by this target.

Specified by:
clear in interface FutureTarget<R>

onStart

public void onStart()
Description copied from interface: LifecycleListener
Callback for when Fragment.onStart()} or Activity.onStart() is called.

Specified by:
onStart in interface LifecycleListener

onStop

public void onStop()
Description copied from interface: LifecycleListener
Callback for when Fragment.onStop()} or Activity.onStop()} is called.

Specified by:
onStop in interface LifecycleListener

onDestroy

public void onDestroy()
Description copied from interface: LifecycleListener
Callback for when Fragment.onDestroy()} or Activity.onDestroy() is called.

Specified by:
onDestroy in interface LifecycleListener