Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.koushikdutta.ion.loader;
 
 import  android.content.Context;
 import  android.graphics.Bitmap;
 import  android.graphics.BitmapFactory;
 import  android.graphics.Point;
 import  android.net.Uri;
 import  android.text.TextUtils;
 
Created by koush on 6/27/14.
public class StreamLoader extends SimpleLoader {
    protected BitmapInfo loadGif(String key, Point sizeInputStream in, BitmapFactory.Options optionsthrows Exception {
        GifDecoder decoder = new GifDecoder(innew GifAction() {
            @Override
            public boolean parseOk(boolean parseStatusint frameIndex) {
                return true;
            }
        });
        decoder.run();
        StreamUtility.closeQuietly(in);
        if (decoder.getFrameCount() == 0)
            throw new Exception("failed to load gif");
        Bitmap[] bitmaps = new Bitmap[decoder.getFrameCount()];
        int[] delays = decoder.getDelays();
        for (int i = 0; i < decoder.getFrameCount(); i++) {
            Bitmap bitmap = decoder.getFrameImage(i);
            if (bitmap == null)
                throw new Exception("failed to load gif frame");
            bitmaps[i] = bitmap;
        }
        BitmapInfo info = new BitmapInfo(keyoptions.outMimeTypebitmapssize);
        info.delays = delays;
        return info;
    }
    protected InputStream getInputStream(Context contextString urithrows Exception {
        return null;
    }
    @Override
    public Future<BitmapInfoloadBitmap(final Context contextfinal Ion ionfinal String keyfinal String urifinal int resizeWidthfinal int resizeHeightfinal boolean animateGif) {
        final SimpleFuture<BitmapInforet = new SimpleFuture<BitmapInfo>();
//        Log.d("FileLoader", "Loading file bitmap " + uri + " " + resizeWidth + "," + resizeHeight);
        Ion.getBitmapLoadExecutorService().execute(new Runnable() {
            @Override
            public void run() {
                InputStream in = null;
                try {
                    in = getInputStream(contexturi);
                    BitmapFactory.Options options = ion.getBitmapCache().prepareBitmapOptions(inresizeWidthresizeHeight);
                    if (options == null)
                        throw new Exception("BitmapFactory.Options failed to load");
                    StreamUtility.closeQuietly(in);
                    Point size = new Point(options.outWidthoptions.outHeight);
                    BitmapInfo info;
                    in = getInputStream(contexturi);
                    if (animateGif && TextUtils.equals("image/gif"options.outMimeType)) {
                        info = loadGif(keysizeinoptions);
                    }
                    else {
                        Bitmap bitmap = IonBitmapCache.loadBitmap(inoptions);
                        if (bitmap == null)
                            throw new Exception("Bitmap failed to load");
                        info = new BitmapInfo(keyoptions.outMimeTypenew Bitmap[] { bitmap }, size);
                    }
                    info.loadedFrom =  ..;
                    ret.setComplete(info);
                }
                catch (OutOfMemoryError e) {
                    ret.setComplete(new Exception(e), null);
                }
                catch (Exception e) {
                    ret.setComplete(e);
                }
                finally {
                    StreamUtility.closeQuietly(in);
                }
            }
        });
        return ret;
    }
New to GrepCode? Check out our FAQ X