Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.koushikdutta.ion.loader;
 
 import  android.content.Context;
 import  android.net.Uri;
 
Created by koush on 5/22/13.
public class ContentLoader extends StreamLoader {
    @Override
    public Future<BitmapInfoloadBitmap(final Context contextfinal Ion ionfinal String keyfinal String urifinal int resizeWidthfinal int resizeHeightfinal boolean animateGif) {
        if (!uri.startsWith("content:/"))
            return null;
        return super.loadBitmap(contextionkeyuriresizeWidthresizeHeightanimateGif);
    }
    @Override
    protected InputStream getInputStream(Context contextString urithrows Exception {
        return context.getContentResolver().openInputStream(Uri.parse(uri));
    }
    @Override
    public Future<DataEmitterload(final Ion ionfinal AsyncHttpRequest requestfinal FutureCallback<LoaderEmittercallback) {
        if (!request.getUri().getScheme().startsWith("content"))
            return null;
        final InputStreamDataEmitterFuture ret = new InputStreamDataEmitterFuture();
        ion.getHttpClient().getServer().post(new Runnable() {
            @Override
            public void run() {
                try {
                    InputStream stream = ion.getContext().getContentResolver().openInputStream(Uri.parse(request.getUri().toString()));
                    if (stream == null)
                        throw new Exception("Unable to load content stream");
                    int available = stream.available();
                    InputStreamDataEmitter emitter = new InputStreamDataEmitter(ion.getHttpClient().getServer(), stream);
                    ret.setComplete(emitter);
                    callback.onCompleted(null,
                        new LoaderEmitter(emitteravailable.nullnull));
                }
                catch (Exception e) {
                    ret.setComplete(e);
                    callback.onCompleted(enull);
                }
            }
        });
        return ret;
    }
New to GrepCode? Check out our FAQ X