Android Open Source - android-deferred-object Deferred Async Task From Project Back to project page android-deferred-object .
License The source code is released under:
GNU General Public License
If you think the Android project android-deferred-object 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 org.codeandmagic.deferredobject.android;
/ * f r o m w w w . j a v a 2 s . c o m * /
import org.codeandmagic.deferredobject.AbstractPromise;
import android.os.AsyncTask;
public abstract class DeferredAsyncTask<Resolved, Rejected, Progress> extends
AbstractPromise<Resolved, Rejected, Progress> {
public final AsyncTask<Void, Progress, Resolved> task;
private Exception exception;
public DeferredAsyncTask() {
task = new AsyncTask<Void, Progress, Resolved>() {
@Override
protected void onCancelled() {
DeferredAsyncTask.this.fail(null);
}
@Override
protected void onPostExecute(Resolved resolved) {
if (null == resolved) DeferredAsyncTask.this
.reject(convertExceptionToFailure(exception));
else {
final Rejected rejected = convertResultToFailure(resolved);
if (null == rejected) DeferredAsyncTask.this.resolve(resolved);
else DeferredAsyncTask.this.reject(rejected);
}
}
@Override
protected void onProgressUpdate(Progress... progress) {
DeferredAsyncTask.this.notify(progress[0]);
}
@Override
protected Resolved doInBackground(Void... params) {
try {
return DeferredAsyncTask.this.doInBackground();
}
catch (Exception e) {
exception = e;
return null;
}
}
}.execute();
}
protected abstract Resolved doInBackground() throws Exception;
protected Rejected convertResultToFailure(Resolved resolved) {
return null;
}
protected Rejected convertExceptionToFailure(Exception exception) {
return null;
}
public static class TaskException extends RuntimeException {
private static final long serialVersionUID = -4400838550293270727L;
public TaskException(Throwable cause) {
super (cause);
}
}
}
Java Source Code List org.codeandmagic.deferredobject.AbstractPromise.java org.codeandmagic.deferredobject.CompleteCallback.java org.codeandmagic.deferredobject.DeferredObject.java org.codeandmagic.deferredobject.MainActivity.java org.codeandmagic.deferredobject.MergedPromiseTracker.java org.codeandmagic.deferredobject.PipedPromise.java org.codeandmagic.deferredobject.ProgressCallback.java org.codeandmagic.deferredobject.PromiseProxy.java org.codeandmagic.deferredobject.Promise.java org.codeandmagic.deferredobject.RejectCallback.java org.codeandmagic.deferredobject.ResolveCallback.java org.codeandmagic.deferredobject.android.DeferredAsyncTask.java org.codeandmagic.deferredobject.android.DeferredHttpUrlConnection.java org.codeandmagic.deferredobject.android.HttpProgress.java org.codeandmagic.deferredobject.merge.MergedPromise2.java org.codeandmagic.deferredobject.merge.MergedPromise3.java org.codeandmagic.deferredobject.merge.MergedPromise4.java org.codeandmagic.deferredobject.merge.MergedPromise5.java org.codeandmagic.deferredobject.merge.MergedPromiseN.java org.codeandmagic.deferredobject.merge.MergedPromiseProgress.java org.codeandmagic.deferredobject.merge.MergedPromiseReject.java org.codeandmagic.deferredobject.merge.MergedPromiseResult2.java org.codeandmagic.deferredobject.merge.MergedPromiseResult3.java org.codeandmagic.deferredobject.merge.MergedPromiseResult4.java org.codeandmagic.deferredobject.merge.MergedPromiseResult5.java org.codeandmagic.deferredobject.merge.MergedPromise.java org.codeandmagic.deferredobject.pipe.PassThroughProgressFilter.java org.codeandmagic.deferredobject.pipe.PassThroughRejectFilter.java org.codeandmagic.deferredobject.pipe.PassThroughResolveFilter.java org.codeandmagic.deferredobject.pipe.ProgressFilter.java org.codeandmagic.deferredobject.pipe.RejectFilter.java org.codeandmagic.deferredobject.pipe.ResolveFilter.java org.codeandmagic.deferredobject.pipe.ResolvePipe.java