Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.koushikdutta.ion.loader;
 
 
 import  android.content.Context;
 import  android.content.pm.PackageManager;
 import  android.graphics.Bitmap;
 import  android.graphics.Point;
 import  android.graphics.drawable.BitmapDrawable;
 
Created by koush on 11/3/13.
public class PackageIconLoader extends SimpleLoader {
    @Override
    public Future<BitmapInfoloadBitmap(Context contextfinal Ion ionfinal String keyfinal String uriint resizeWidthint resizeHeightboolean animateGif) {
        if (uri == null || !uri.startsWith("package:"))
            return null;
        final SimpleFuture<BitmapInforet = new SimpleFuture<BitmapInfo>();
        Ion.getBitmapLoadExecutorService().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    final URI request = URI.create(uri);
                    String pkg = request.getHost();
                    PackageManager pm = ion.getContext().getPackageManager();
                    Bitmap bmp = ((BitmapDrawable)pm.getPackageInfo(pkg, 0).applicationInfo.loadIcon(pm)).getBitmap();
                    if (bmp == null)
                        throw new Exception("package icon failed to load");
                    BitmapInfo info = new BitmapInfo(keynullbmpnew Point(bmp.getWidth(), bmp.getHeight()));
                    info.loadedFrom =  ..;
                    ret.setComplete(info);
                }
                catch (Exception e) {
                    ret.setComplete(e);
                }
            }
        });
        return ret;
    }
New to GrepCode? Check out our FAQ X