DataType - The type of the data, which is bound to viewsKeyType - The type of the keys, which allow to uniquely identify already loaded dataViewType - The type of the views, which are used to display dataParamType - The type of parameters, which can be passed when loading datapublic abstract class AbstractDataBinder<DataType,KeyType,ViewType,ParamType>
extends android.os.Handler
The binder supports to use adapter views, which might be recycled while data is still loaded. In such case, the recycled view is prevented from showing the data once loading has finished, because it is already used for other purposes.
| Modifier and Type | Class and Description |
|---|---|
static interface |
AbstractDataBinder.Listener<DataType,KeyType,ViewType,ParamType>
Defines the interface, a class, which should be notified about the progress of a
AbstractDataBinder must implement. |
| Modifier and Type | Field and Description |
|---|---|
static int |
CACHE_SIZE
The number of items, which are stored by a cached, by default.
|
| Constructor and Description |
|---|
AbstractDataBinder(android.content.Context context)
Creates a new data binder.
|
AbstractDataBinder(android.content.Context context,
<any> cache)
Creates a new data binder, which uses a specific cache.
|
AbstractDataBinder(android.content.Context context,
java.util.concurrent.ExecutorService threadPool)
Creates a new data binder, which uses a specific executor service.
|
AbstractDataBinder(android.content.Context context,
java.util.concurrent.ExecutorService threadPool,
<any> cache)
Creates a new data binder, which uses a specifc executor service and cache.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(AbstractDataBinder.Listener<DataType,KeyType,ViewType,ParamType> listener)
Adds a new listener, which should be notified about the events of the data binder.
|
void |
cancel()
Cancels loading the data.
|
void |
clearCache()
Clears the cache.
|
protected abstract DataType |
doInBackground(KeyType key,
ParamType... params)
The method, which is invoked on implementing subclasses, in order to load the data, which
corresponds to a specific key.
|
android.content.Context |
getContext()
Returns the context, which is used by the data binder.
|
LogLevel |
getLogLevel()
Returns the log level, which is used for logging.
|
void |
handleMessage(android.os.Message msg) |
boolean |
isCached(KeyType key)
Returns, whether the data, which corresponds to a specific key, is currently cached, or not.
|
boolean |
isCacheUsed()
Returns, whether data is cached, or not.
|
boolean |
isCanceled()
Returns, whether loading the data has been canceled, or not.
|
void |
load(KeyType key,
ViewType view,
boolean async,
ParamType... params)
Loads the the data, which corresponds to a specific key, and displays it in a specific view.
|
void |
load(KeyType key,
ViewType view,
ParamType... params)
Loads the the data, which corresponds to a specific key, and displays it in a specific view.
|
protected abstract void |
onPostExecute(ViewType view,
DataType data,
long duration,
ParamType... params)
The method, which is invoked on implementing subclasses, in order to display data after it
has been loaded.
|
protected void |
onPreExecute(ViewType view,
ParamType... params)
The method, which is invoked on implementing subclasses prior to loading any data.
|
void |
removeListener(AbstractDataBinder.Listener<DataType,KeyType,ViewType,ParamType> listener)
Removes a specific listener, which should not be notified about the events of the data
binder, anymore.
|
void |
setLogLevel(LogLevel logLevel)
Sets the log level, which should be used for logging.
|
void |
useCache(boolean useCache)
Sets, whether data should be cached, or not.
|
dispatchMessage, dump, getLooper, getMessageName, hasMessages, hasMessages, obtainMessage, obtainMessage, obtainMessage, obtainMessage, obtainMessage, post, postAtFrontOfQueue, postAtTime, postAtTime, postDelayed, removeCallbacks, removeCallbacks, removeCallbacksAndMessages, removeMessages, removeMessages, sendEmptyMessage, sendEmptyMessageAtTime, sendEmptyMessageDelayed, sendMessage, sendMessageAtFrontOfQueue, sendMessageAtTime, sendMessageDelayed, toStringpublic static final int CACHE_SIZE
public AbstractDataBinder(android.content.Context context)
CACHE_SIZE items. The executor service, which
is used to manage asynchronous tasks, is created by using the static method
Executors.newCachedThreadPool. Such executor services are meant to be used when
many short-living tasks are executed and reuse previously created threads.context - The context, which should be used by the data binder, as an instance of the class
Context. The context may not be nullpublic AbstractDataBinder(android.content.Context context,
java.util.concurrent.ExecutorService threadPool)
CACHE_SIZE items.context - The context, which should be used by the data binder, as an instance of the class
Context. The context may not be nullthreadPool - The executor service, which should be used to manage asynchronous tasks, as an
instance of the type ExecutorService. The executor service may not be nullpublic AbstractDataBinder(android.content.Context context,
<any> cache)
Executors.newCachedThreadPool. Such executor services are meant to be
used when many short-living tasks are executed and reuse previously created threads.context - The context, which should be used by the data binder, as an instance of the class
Context. The context may not be nullcache - The LRU cache, which should be used to cache already loaded data, as an instance of
the class LruCache. The cache may not be nullpublic AbstractDataBinder(android.content.Context context,
java.util.concurrent.ExecutorService threadPool,
<any> cache)
context - The context, which should be used by the data binder, as an instance of the class
Context. The context may not be nullthreadPool - The executor service, which should be used to manage asynchronous tasks, as an
instance of the type ExecutorService. The executor service may not be nullcache - The LRU cache, which should be used to cache already loaded data, as an instance of
the class LruCache. The cache may not be nullprotected void onPreExecute(ViewType view, ParamType... params)
view - The view, which should be used to display the data, as an instance of the generic
type ViewType. The view may not be nullparams - An array, which contains optional parameters, as an array of the type ParamType or an
empty array, if no parameters should be usedprotected abstract DataType doInBackground(KeyType key, ParamType... params)
key - The key of the data, which should be loaded, as an instance of the generic type
KeyType. The key may not be nullparams - An array, which contains optional parameters, as an array of the type ParamType or an
empty array, if no parameters should be usedprotected abstract void onPostExecute(ViewType view, DataType data, long duration, ParamType... params)
view - The view, which should be used to display the data, as an instance of the generic
type ViewType. The view may not be nulldata - The data, which should be displayed, as an instance of the generic type DataType or
null, if no data should be displayedduration - The duration of the loading process in milliseconds as a Long valueparams - An array, which contains optional parameters, as an array of the type ParamType or an
empty array, if no parameters should be usedpublic final android.content.Context getContext()
Context. The context may not be nullpublic final LogLevel getLogLevel()
LogLevel.
The log level may not be nullpublic final void setLogLevel(LogLevel logLevel)
logLevel - The log level, which should be set, as a value of the enum LogLevel. The log
level may not be nullpublic final void addListener(AbstractDataBinder.Listener<DataType,KeyType,ViewType,ParamType> listener)
listener - The listener, which should be added, as an instance of the type AbstractDataBinder.Listener. The
listener may not be nullpublic final void removeListener(AbstractDataBinder.Listener<DataType,KeyType,ViewType,ParamType> listener)
listener - The listener, which should be removed, as an instance of the type AbstractDataBinder.Listener.
The listener may not be null@SafeVarargs public final void load(KeyType key, ViewType view, ParamType... params)
key - The key of the data, which should be loaded, as an instance of the generic type
KeyType. The key may not be nullview - The view, which should be used to display the data, as an instance of the generic
type ViewType. The view may not be nullparams - An array, which contains optional parameters, as an array of the type ParamType or an
empty array, if no parameters should be used@SafeVarargs public final void load(KeyType key, ViewType view, boolean async, ParamType... params)
key - The key of the data, which should be loaded, as an instance of the generic type
KeyType. The key may not be nullview - The view, which should be used to display the data, as an instance of the generic
type ViewType. The view may not be nullasync - True, if the data should be loaded in a background thread, false otherwiseparams - An array, which contains optional parameters, as an array of the type ParamType or an
empty array, if no parameters should be usedpublic final void cancel()
public final boolean isCanceled()
public final boolean isCached(KeyType key)
key - The key, which corresponds to the data, which should be checked, as an instance of
the generic type KeyType. The key may not be nullpublic final boolean isCacheUsed()
public final void useCache(boolean useCache)
useCache - True, if data should be cached, false otherwise.public final void clearCache()
public final void handleMessage(android.os.Message msg)
handleMessage in class android.os.Handler