com.koushikdutta.ion.BitmapCallback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ion Show documentation
Show all versions of ion Show documentation
Android Asynchronous Networking Made Easy
package com.koushikdutta.ion;
import android.graphics.Point;
import com.koushikdutta.async.AsyncServer;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;
import com.koushikdutta.ion.bitmap.BitmapInfo;
import java.util.ArrayList;
abstract class BitmapCallback {
String key;
Ion ion;
protected BitmapCallback(Ion ion, String key, boolean put) {
this.key = key;
this.put = put;
this.ion = ion;
ion.bitmapsPending.tag(key, this);
}
boolean put;
boolean put() {
return put;
}
protected void onReported() {
ion.processDeferred();
}
protected void report(final Exception e, final BitmapInfo info) {
AsyncServer.post(Ion.mainHandler, new Runnable() {
@Override
public void run() {
BitmapInfo result = info;
if (result == null) {
// cache errors
result = new BitmapInfo(key, null, new Point());
result.exception = e;
ion.getBitmapCache().put(result);
} else if (put()) {
ion.getBitmapCache().put(result);
}
final ArrayList> callbacks = ion.bitmapsPending.remove(key);
if (callbacks == null || callbacks.size() == 0) {
onReported();
return;
}
for (FutureCallback callback : callbacks) {
callback.onCompleted(e, result);
}
onReported();
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy