If you think the Android project RZAndroidBaseUtils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.raizlabs.tasks;
/*www.java2s.com*/import java.util.LinkedList;
import java.util.List;
/**
* Class which represents Events for {@link RZAsyncTask}s.
* @author Dylan James
*
* @param <Result> The Result type of the {@link RZAsyncTask}.
*/publicclass RZAsyncTaskEvent<Progress, Result> {
private List<RZAsyncTaskListener<Progress, Result>> listeners;
/**
* Creates a new RZAsyncTaskEvent.
*/public RZAsyncTaskEvent() {
listeners = new LinkedList<RZAsyncTaskListener<Progress, Result>>();
}
/**
* Adds an RZAsyncTaskListener to be notified when AsyncTaskEvents happen.
* @param listener The listener to be notified.
*/publicvoid addListener(RZAsyncTaskListener<Progress, Result> listener) {
if (listener != null) {
synchronized (listeners) {
listeners.add(listener);
}
}
}
/**
* Removes an RZEventListener so it will no longer be notified of these
* events.
* @param listener The RZAsyncTaskListener to be removed.
* @return True if the listener was removed, false if it wasn't found.
*/publicboolean removeListener(RZAsyncTaskListener<Progress, Result> listener) {
synchronized (listeners) {
return listeners.remove(listener);
}
}
publicvoid raiseCancelled(Result result) {
synchronized (listeners) {
for (RZAsyncTaskListener<Progress, Result> listener : listeners) {
listener.onCancelled(result);
}
}
}
/**
* Raises the PreExecute event on all listeners.
* @see RZAsyncTask#doPreExecute()
* @param isInstant true if the task will be fast.
*/publicvoid raisePreExecute(boolean isInstant) {
synchronized (listeners) {
for (RZAsyncTaskListener<Progress, Result> listener : listeners) {
listener.onPreExecute(isInstant);
}
}
}
/**
* Raises the PostExecute event on all listeners.
* @param result The result arguments to be passed to the listeners.
*/publicvoid raisePostExecute(Result result) {
synchronized (listeners) {
for (RZAsyncTaskListener<Progress, Result> listener : listeners) {
listener.onPostExecute(result);
}
}
}
/**
* Publishes progress to all listeners.
* @param progress The progress to be passed to the listeners.
*/publicvoid publishProgress(Progress... progress) {
synchronized (listeners) {
for (RZAsyncTaskListener<Progress, Result> listener: listeners) {
listener.onUpdateProgress(progress);
}
}
}
}