Beispiel #1
0
  private Bitmap getBitmap(String url) {
    File f = fileCache.getFile(url);

    // from SD cache
    Bitmap b = decodeFile(f);
    if (b != null) return b;

    // from web
    try {
      Bitmap bitmap = null;
      URL imageUrl = new URL(url);
      HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
      conn.setConnectTimeout(30000);
      conn.setReadTimeout(30000);
      conn.setInstanceFollowRedirects(true);
      InputStream is = conn.getInputStream();
      OutputStream os = new FileOutputStream(f);
      CopyStream(is, os);
      os.close();
      conn.disconnect();
      bitmap = decodeFile(f);
      return bitmap;
    } catch (Throwable ex) {
      ex.printStackTrace();
      if (ex instanceof OutOfMemoryError) memoryCache.clear();
      return null;
    }
  }
Beispiel #2
0
 public void DisplayImage(String url, ImageView imageView) {
   imageViews.put(imageView, url);
   Bitmap bitmap = memoryCache.get(url);
   if (bitmap != null) imageView.setImageBitmap(bitmap);
   else {
     queuePhoto(url, imageView);
     imageView.setImageResource(stub_id);
   }
 }
Beispiel #3
0
 public void clearCache() {
   memoryCache.clear();
   fileCache.clear();
 }