public class DecodeTask extends AsyncTask<Void,Void,ReusableBitmap>
DecodeTask.DecodeCallback
client may be notified on decode begin and completion.
This class uses BitmapRegionDecoder
when possible to minimize unnecessary decoding
and allow bitmap reuse on Jellybean 4.1 and later.
GIFs are supported, but their decode does not reuse bitmaps at all. The resulting
ReusableBitmap
will be marked as not reusable
(ReusableBitmap.isEligibleForPooling()
will return false).
Modifier and Type | Class and Description |
---|---|
static interface |
DecodeTask.DecodeCallback
Callback interface for clients to be notified of decode state changes and completion.
|
static class |
DecodeTask.DecodeOptions
Parameters to pass to the DecodeTask.
|
AsyncTask.Status
Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG |
SERIAL_EXECUTOR, THREAD_POOL_EXECUTOR
Constructor and Description |
---|
DecodeTask(RequestKey requestKey,
DecodeTask.DecodeOptions decodeOpts,
RequestKey.FileDescriptorFactory factory,
DecodeTask.DecodeCallback callback,
BitmapCache cache)
Create new DecodeTask.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel() |
ReusableBitmap |
decode() |
protected ReusableBitmap |
doInBackground(Void... params)
Override this method to perform a computation on a background thread.
|
protected void |
onCancelled(ReusableBitmap result)
Runs on the UI thread after
AsyncTask.cancel(boolean) is invoked and
AsyncTask.doInBackground(Object[]) has finished. |
void |
onPostExecute(ReusableBitmap result)
Runs on the UI thread after
AsyncTask.doInBackground(Params...) . |
protected void |
onProgressUpdate(Void... values)
Runs on the UI thread after
AsyncTask.publishProgress(Progress...) is invoked. |
cancel, execute, execute, executeOnExecutor, get, get, getStatus, isCancelled, onCancelled, onPreExecute, publishProgress, setDefaultExecutor
public static final boolean DEBUG
public DecodeTask(RequestKey requestKey, DecodeTask.DecodeOptions decodeOpts, RequestKey.FileDescriptorFactory factory, DecodeTask.DecodeCallback callback, BitmapCache cache)
requestKey
- The request to decode, also the key to use for the cache.decodeOpts
- The decode options.factory
- The factory to obtain file descriptors to decode from. If this factory is
null, then we will decode from requestKey.createInputStream().callback
- The callback to notify of decode state changes.cache
- The cache and pool.protected ReusableBitmap doInBackground(Void... params)
AsyncTask
AsyncTask.execute(Params...)
by the caller of this task.
This method can call AsyncTask.publishProgress(Progress...)
to publish updates
on the UI thread.doInBackground
in class AsyncTask<Void,Void,ReusableBitmap>
params
- The parameters of the task.AsyncTask.onPreExecute()
,
AsyncTask.onPostExecute(Result)
,
AsyncTask.publishProgress(Progress...)
public ReusableBitmap decode()
public void cancel()
protected void onProgressUpdate(Void... values)
AsyncTask
AsyncTask.publishProgress(Progress...)
is invoked.
The specified values are the values passed to AsyncTask.publishProgress(Progress...)
.onProgressUpdate
in class AsyncTask<Void,Void,ReusableBitmap>
values
- The values indicating progress.AsyncTask.publishProgress(Progress...)
,
AsyncTask.doInBackground(Params...)
public void onPostExecute(ReusableBitmap result)
AsyncTask
Runs on the UI thread after AsyncTask.doInBackground(Params...)
. The
specified result is the value returned by AsyncTask.doInBackground(Params...)
.
This method won't be invoked if the task was cancelled.
onPostExecute
in class AsyncTask<Void,Void,ReusableBitmap>
result
- The result of the operation computed by AsyncTask.doInBackground(Params...)
.AsyncTask.onPreExecute()
,
AsyncTask.doInBackground(Params...)
,
AsyncTask.onCancelled(Object)
protected void onCancelled(ReusableBitmap result)
AsyncTask
Runs on the UI thread after AsyncTask.cancel(boolean)
is invoked and
AsyncTask.doInBackground(Object[])
has finished.
The default implementation simply invokes AsyncTask.onCancelled()
and
ignores the result. If you write your own implementation, do not call
super.onCancelled(result)
.
onCancelled
in class AsyncTask<Void,Void,ReusableBitmap>
result
- The result, if any, computed in
AsyncTask.doInBackground(Object[])
, can be nullAsyncTask.cancel(boolean)
,
AsyncTask.isCancelled()