Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.koushikdutta.ion;
  
  import  android.graphics.Bitmap;
  import  android.graphics.Point;
  
 
 import java.io.File;
 
 class TransformBitmap extends BitmapCallback implements FutureCallback<BitmapInfo> {
     static class PostProcessNullTransform implements Transform {
         String key;
         public PostProcessNullTransform(String key) {
             this. = key;
         }
 
         @Override
         public Bitmap transform(Bitmap b) {
             return b;
         }
 
         @Override
         public String key() {
             return ;
         }
     }
 
 
     public static void getBitmapSnapshot(final Ion ionfinal String transformKeyfinal ArrayList<PostProcesspostProcess) {
         // don't do this if this is already loading
         if (ion.bitmapsPending.tag(transformKey) != null)
             return;
         final BitmapCallback callback = new LoadBitmapBase(iontransformKeytrue);
         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(filenull);
                     if (bitmap == null)
                         throw new Exception("Bitmap failed to load");
                     Point size = new Point(bitmap.getWidth(), bitmap.getHeight());
                     BitmapInfo info = new BitmapInfo(transformKey"image/jpeg"new Bitmap[] { bitmap }, size);
                     info.loadedFrom =  ..;
 
                     if (postProcess != null) {
                         for (PostProcess ppostProcess) {
                             p.postProcess(info);
                         }
                     }
 
                     callback.report(nullinfo);
                 }
                 catch (OutOfMemoryError e) {
                     callback.report(new Exception(e), null);
                 }
                 catch (Exception e) {
                     callback.report(enull);
                     try {
                         ion.responseCache.getFileCache().remove(transformKey);
                     } catch (Exception ex) {
                     }
                 }
             }
         });
     }
 
     String downloadKey;
     public TransformBitmap(Ion ionString transformKeyString downloadKeyArrayList<TransformtransformsArrayList<PostProcesspostProcess) {
         super(iontransformKeytrue);
         this. = transforms;
         this. = downloadKey;
         this. = postProcess;
     }
 
     @Override
     public void onCompleted(Exception efinal BitmapInfo result) {
         if (e != null) {
             report(enull);
             return;
         }
 
         if (..tag() != this) {
 //            Log.d("IonBitmapLoader", "Bitmap transform cancelled (no longer needed)");
             return;
        }
        Ion.getBitmapLoadExecutorService().execute(new Runnable() {
            @Override
            public void run() {
                if (..tag() != TransformBitmap.this) {
//            Log.d("IonBitmapLoader", "Bitmap transform cancelled (no longer needed)");
                    return;
                }
                BitmapInfo info;
                try {
                    Point size = null;
                    Bitmap bitmaps[] = new Bitmap[result.bitmaps.length];
                    for (int i = 0; i < result.bitmaps.lengthi++) {
                        bitmaps[i] = result.bitmaps[i];
                        for (Transform transform : ) {
                            Bitmap bitmap = transform.transform(bitmaps[i]);
                            if (bitmap == null)
                                throw new Exception("failed to transform bitmap");
                            bitmaps[i] = bitmap;
                            if (size == null)
                                size = new Point(bitmap.getWidth(), bitmap.getHeight());
                        }
                    }
                    info = new BitmapInfo(result.mimeTypebitmapssize);
                    info.delays = result.delays;
                    info.loadedFrom = result.loadedFrom;
                    if ( != null) {
                        for (PostProcess p) {
                            p.postProcess(info);
                        }
                    }
                    report(nullinfo);
                }
                catch (OutOfMemoryError e) {
                    report(new Exception(e), null);
                    return;
                }
                catch (Exception e) {
                    report(enull);
                    return;
                }
                // the transformed bitmap was successfully load it, let's toss it into
                // the disk lru cache.
                // but don't persist gifs...
                if (info.bitmaps.length > 1)
                    return;
                FileCache cache = ..getFileCache();
                if (cache == null)
                    return;
                File tempFile = cache.getTempFile();
                try {
                    FileOutputStream out = new FileOutputStream(tempFile);
                    Bitmap.CompressFormat format = info.bitmaps[0].hasAlpha() ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG;
                    info.bitmaps[0].compress(format, 100, out);
                    out.close();
                    cache.commitTempFiles(tempFile);
                }
                catch (Exception ex) {
                }
                finally {
                    tempFile.delete();
                }
            }
        });
    }
New to GrepCode? Check out our FAQ X