Search in sources :

Example 1 with PostProcess

use of com.koushikdutta.ion.bitmap.PostProcess in project ion by koush.

the class BitmapCallback method getBitmapSnapshot.

public static void getBitmapSnapshot(final Ion ion, final String transformKey, final ArrayList<PostProcess> postProcess) {
    // don't do this if this is already loading
    if (ion.bitmapsPending.tag(transformKey) != null)
        return;
    final BitmapCallback callback = new LoadBitmapBase(ion, transformKey, true);
    Ion.getBitmapLoadExecutorService().execute(new Runnable() {

        @Override
        public void run() {
            if (ion.bitmapsPending.tag(transformKey) != callback) {
                // Log.d("IonBitmapLoader", "Bitmap cache load cancelled (no longer needed)");
                return;
            }
            try {
                File file = ion.responseCache.getFileCache().getFile(transformKey);
                Bitmap bitmap = IonBitmapCache.loadBitmap(file, null);
                if (bitmap == null)
                    throw new Exception("Bitmap failed to load");
                BitmapInfo info = new BitmapInfo(transformKey, "image/jpeg", bitmap, null);
                info.servedFrom = ResponseServedFrom.LOADED_FROM_CACHE;
                if (postProcess != null) {
                    for (PostProcess p : postProcess) {
                        p.postProcess(info);
                    }
                }
                callback.report(null, info);
            } catch (OutOfMemoryError e) {
                callback.report(new Exception(e), null);
            } catch (Exception e) {
                callback.report(e, null);
                try {
                    ion.responseCache.getFileCache().remove(transformKey);
                } catch (Exception ex) {
                }
            }
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) PostProcess(com.koushikdutta.ion.bitmap.PostProcess) File(java.io.File) CancellationException(java.util.concurrent.CancellationException) BitmapInfo(com.koushikdutta.ion.bitmap.BitmapInfo)

Aggregations

Bitmap (android.graphics.Bitmap)1 BitmapInfo (com.koushikdutta.ion.bitmap.BitmapInfo)1 PostProcess (com.koushikdutta.ion.bitmap.PostProcess)1 File (java.io.File)1 CancellationException (java.util.concurrent.CancellationException)1