List of usage examples for android.graphics.drawable Drawable createFromStream
public static Drawable createFromStream(InputStream is, String srcName)
From source file:com.swavdev.tc.DrawableManager.java
protected Drawable fetchDrawable(String urlString) { if (drawableMap.containsKey(urlString)) { Log.i(TAG, "key found:" + urlString); return drawableMap.get(urlString); }//from w w w . j a v a 2s . c o m Log.d(this.getClass().getSimpleName(), "image url:" + urlString); try { InputStream is = fetch(urlString); Drawable drawable = Drawable.createFromStream(is, "src"); if (drawable != null && !drawableMap.containsKey(urlString)) { 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; } }
From source file:com.tnc.android.graphite.utils.GraphiteConnection.java
public static DrawableGraph getGraph(String serverUrl, String ps) throws Exception { URL url = new URL(serverUrl + GRAPH_PARAM_STRING + ps); HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.setConnectTimeout(45000);/* w w w . j ava 2s . c o m*/ http.setReadTimeout(45000); Drawable image = Drawable.createFromStream(http.getInputStream(), null); DrawableGraph dg = new DrawableGraph(); dg.setImage(image); return dg; }
From source file:com.unitedcoders.android.gpodroid.tools.Tools.java
public static Drawable LoadImageFromWebOperations(String url) { try {//from www.j a v a 2s . c o m InputStream is = (InputStream) new URL(url).getContent(); Drawable d = Drawable.createFromStream(is, "src name"); return d; } catch (Exception e) { System.out.println("Exc=" + e); return null; } }
From source file:com.azcltd.android.test.kolesov.DrawableManager.java
public Drawable fetchDrawable(String urlString, boolean isForceUpdate) { if (drawableMap.containsKey(urlString) && (!isForceUpdate)) { return drawableMap.get(urlString); }//from w w w . j av a2 s .c om //Log.d(this.getClass().getSimpleName(), "image url:" + urlString); Drawable drawable = null; try { InputStream is = fetch(urlString); drawable = Drawable.createFromStream(is, "src"); is.close(); if (drawable != null) { drawableMap.put(urlString, drawable); // Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", " // + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", " // + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth()); } else { drawable = getAsBitmap(urlString); // else // Log.w(urlString, "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 (Exception e) { drawable = getAsBitmap(urlString); } return drawable; }
From source file:net.sarangnamu.android.DrawableManager.java
public Drawable fetchDrawable(String urlString) { if (drawableMap.containsKey(urlString)) { return drawableMap.get(urlString); }// ww w .j a v a2 s.com Log.d(this.getClass().getSimpleName(), "image url:" + urlString); try { InputStream is = fetch(urlString); Drawable drawable = null; drawable = Drawable.createFromStream(is, "src"); if (drawable != null) { drawableMap.put(urlString, drawable); Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth()); } 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; } }
From source file:com.labs.okey.commonride.utils.DrawableManager.java
public Drawable fetchDrawable(String urlString) { if (drawableMap.containsKey(urlString)) { return drawableMap.get(urlString); }/* ww w . j a va2 s . c o m*/ Log.d(this.getClass().getSimpleName(), "image url:" + urlString); try { InputStream is = fetch(urlString); Drawable drawable = Drawable.createFromStream(is, "src"); if (isRounded) { drawable = RoundedDrawable.fromDrawable(drawable); if (drawable instanceof RoundedDrawable) { ((RoundedDrawable) drawable).setCornerRadius(cornerRadius).setBorderColor(borderColor) .setBorderWidth(4).setOval(true); } } if (drawable != null) { drawableMap.put(urlString, drawable); Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth()); } 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 (Exception e) { Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e); return null; } }
From source file:com.neudesic.mobile.pulse.ui.drawable.DrawableManager.java
public synchronized Drawable fetchDrawable(String urlString) { if (drawableMap.containsKey(urlString)) { Log.d(getClass().getSimpleName(), "loading image from localcache"); return drawableMap.get(urlString); }// w ww . j a va 2 s .c o m Log.d(this.getClass().getSimpleName(), "image url:" + urlString); try { InputStream is = fetch(urlString); Drawable drawable = Drawable.createFromStream(is, "src"); if (drawableMap.size() > MAX_CACHE_SIZE) { drawableMap.clear(); } drawableMap.put(urlString, drawable); Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth()); 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; } }
From source file:fr.cph.chicago.connection.GStreetViewConnect.java
/** * Connect to the API and get the MAP/* w w w . j a v a 2s. co m*/ * * @param address the address to connect to * @return a drawable map */ @NonNull private Optional<Drawable> connectUrl(@NonNull final String address) { Log.v(TAG, "Address: " + address); InputStream is = null; try { is = (InputStream) new URL(address).getContent(); return Optional.of(Drawable.createFromStream(is, "src name")); } catch (final Exception e) { Log.e(TAG, e.getMessage(), e); // TODO add a temporary image here return Optional.empty(); } finally { IOUtils.closeQuietly(is); } }
From source file:es.vicfran.bookdrop.fragments.BookDetailFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { titleTextView = (TextView) view.findViewById(R.id.lbl_title); authorTextView = (TextView) view.findViewById(R.id.lbl_author); coverImageView = (ImageView) view.findViewById(R.id.img_book_cover); if (dbxBook != null) { titleTextView.setText(dbxBook.getBook().getMetadata().getFirstTitle()); authorTextView.setText(parseAuthors(dbxBook.getBook().getMetadata().getAuthors())); Drawable thumbDrawable = null;//from www . j a v a 2 s. co m try { Resource coverImage = dbxBook.getBook().getCoverImage(); if (coverImage != null) { thumbDrawable = Drawable.createFromStream(coverImage.getInputStream(), ""); } } catch (IOException e) { thumbDrawable = null; } coverImageView.setImageDrawable((thumbDrawable != null) ? thumbDrawable : getActivity().getResources().getDrawable(R.drawable.ic_launcher)); } }
From source file:org.opensourcetlapp.tl.CustomImageGetter.java
@Override public Drawable getDrawable(String url) { try {//ww w.ja va 2 s . co m // get name of image String name = url.substring(url.lastIndexOf("/") + 1); InputStream is; try { try { is = assetManager.open("images/" + name); } catch (IOException e) { is = context.openFileInput(name); } } catch (FileNotFoundException e) { is = getImageInputStream(url); if (!name.contains("draw.php?poll_id")) { FileOutputStream out = context.openFileOutput(name, Context.MODE_PRIVATE); byte[] buffer = new byte[1024]; int totalLength = 0; int length; while ((length = is.read(buffer)) >= 0) { totalLength += length; out.write(buffer, 0, length); } is.close(); out.close(); is = context.openFileInput(name); } } // cache dir + name of image + the image save format Drawable d = Drawable.createFromStream(is, name); //Drawable d = Drawable.createFromPath(f.getAbsolutePath()); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());// make it the size of the image return d; } catch (Exception e) { e.printStackTrace(); } return null; }