Example usage for android.graphics.drawable Drawable createFromStream

List of usage examples for android.graphics.drawable Drawable createFromStream

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable createFromStream.

Prototype

public static Drawable createFromStream(InputStream is, String srcName) 

Source Link

Document

Create a drawable from an inputstream

Usage

From source file:Main.java

public static Drawable byteToDrawable(byte[] byteArray) {
    ByteArrayInputStream ins = new ByteArrayInputStream(byteArray);
    return Drawable.createFromStream(ins, null);
}

From source file:org.npr.android.news.DownloadDrawable.java

public static Drawable createFromUrl(String url) {
    InputStream data = null;/*www. j av a 2 s  . co m*/
    Log.d(LOG_TAG, "Starting download");
    HttpClient http = new DefaultHttpClient();
    HttpGet method = new HttpGet(url);

    HttpResponse response = null;
    try {
        response = http.execute(method);
        data = response.getEntity().getContent();
    } catch (ClientProtocolException e) {
        Log.e(LOG_TAG, "error downloading", e);
    } catch (IOException e) {
        Log.e(LOG_TAG, "error downloading", e);
    } catch (IllegalStateException e) {
        Log.e(LOG_TAG, "error downloading", e);
    }
    Log.d(LOG_TAG, "Download complete");
    return Drawable.createFromStream(data, url);
}

From source file:mc.lib.assets.AssetsHelper.java

public static Drawable readImage(Context context, String path) {
    InputStream is = null;/*from  w  ww . j a  v  a 2 s . c  om*/
    try {
        is = context.getAssets().open(path);
        return Drawable.createFromStream(is, null);
    } catch (IOException e) {
        Log.e(LOGTAG, "Can not read asset " + path, e);
    } finally {
        StreamHelper.close(is);
    }
    return null;
}

From source file:com.social.services.managers.DrawableManager.java

private Drawable fetchDrawable(String urlString) {

    try {/*from   w  ww. ja v  a2 s  . c  o m*/
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(new FlushedInputStream(is), "src");
        if (null != drawable) {
            drawableMap.put(urlString, drawable);
        }
        return drawable;
    } catch (MalformedURLException e) {
        Log.e(this.getClass().getSimpleName(),
                "*************   fetchDrawable() -> " + urlString + " fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e(this.getClass().getSimpleName(),
                "*************   fetchDrawable() -> " + urlString + " fetchDrawable failed", e);
        return null;
    }
}

From source file:com.vti.managers.DrawableManager.java

private Drawable fetchDrawable(String urlString) {
    try {/*from  ww w. jav a2 s. co m*/
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(new FlushedInputStream(is), "src");
        if (null != drawable) {
            drawableMap.put(urlString, drawable);
        }
        return drawable;
    } catch (Exception e) {
        Log.e(TAG, "*************   fetchDrawable() -> " + urlString + " fetchDrawable failed");
        return null;
    }
}

From source file:com.login.android.cardapio.garcom.util.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }/* w  w w. java2s . c  om*/
    try {

        InputStream is = fetch(urlString);

        Drawable drawable = Drawable.createFromStream(is, "src");

        if (drawable != null) {
            drawableMap.put(urlString, drawable);
        } else {
            Log.w(this.getClass().getSimpleName(), "could not get thumbnail");
        }

        return drawable;
    } catch (MalformedURLException e) {
        Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
        return null;
    } catch (OutOfMemoryError Err) {
        Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", Err);
        System.gc();
        return null;
    }
}

From source file:co.uk.rehope.androidapp.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return (Drawable) drawableMap.get(urlString);
    }/* ww  w  .ja  va  2  s.  c  o m*/

    try {
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");
        drawableMap.put(urlString, drawable);
        return drawable;
    } catch (MalformedURLException e) {
        return null;
    } catch (IOException e) {
        return null;
    }
}

From source file:it.cdpaf.helper.DrawableManager.java

public static Drawable fetchDrawable(String urlString, Context ctx) {
    if (drawableMap.containsKey(urlString)) {
        Log.d(ctx.getClass().getSimpleName(),
                "DRAWABLE MANAGER FD:" + "RIUSO: " + urlString + " Size:" + drawableMap.size());
        return drawableMap.get(urlString);

    }//from w w  w.j  a v a2 s  . c  o m

    Log.d(ctx.getClass().getSimpleName(), "image url:" + urlString);
    try {

        InputStream is = fetch(urlString, ctx);

        Drawable drawable = Drawable.createFromStream(is, "src");

        if (drawable != null) {
            drawableMap.put(urlString, drawable);
            Log.d(ctx.getClass().getSimpleName(),
                    "got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight()
                            + "," + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + ","
                            + drawable.getMinimumWidth());
        } else {
            Log.w(ctx.getClass().getSimpleName(), "could not get thumbnail");
        }

        return drawable;
    } catch (MalformedURLException e) {
        Log.e(ctx.getClass().getSimpleName(), "MALFORMEDURL EXC fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e(ctx.getClass().getSimpleName(), "IO EXCP fetchDrawable failed", e);
        return null;
    }
}

From source file:it.fdev.utils.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }//from w ww. j  a va2  s  .  co m
    try {
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");
        if (drawable != null) {
            drawableMap.put(urlString, drawable);
        } else {
            Log.w(Utils.TAG, "could not get thumbnail");
        }
        return drawable;
    } catch (MalformedURLException e) {
        Log.e(Utils.TAG, "fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e(Utils.TAG, "fetchDrawable failed", e);
        return null;
    }
}

From source file:net.cs76.projects.student10792819.DrawableManager.java

/**
 * Fetch drawable. This fetches a drawable from the url and returns it. Returns null on errors.
 *
 * @param urlString the url string/* www .  java 2  s .c o  m*/
 * @return the drawable
 */
public static Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        Drawable o = drawableMap.get(urlString).get();

        if (o != null)
            return o;
    }

    try {
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");

        if (drawable != null) {
            drawableMap.put(urlString, new SoftReference<Drawable>(drawable));
        } else {
            Log.w("DrawableManager", "could not get thumbnail");
        }

        return drawable;
    } catch (MalformedURLException e) {
        Log.e("DrawableManager", "fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e("DrawableManager", "fetchDrawable failed", e);
        return null;
    }
}