Пример #1
0
  private Bitmap getBitmap(String productid) {
    String hashedimagename = "";
    try {
      hashedimagename = MungPass("Image" + productid) + ".jpg";
    } catch (NoSuchAlgorithmException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    String url = Constants.DOWNLOAD_PATH + "media/k2/items/src/" + hashedimagename;
    Log.d("in ImageLoader, getBitmap, url: ", 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);
      InputStream is = conn.getInputStream();
      OutputStream os = new FileOutputStream(f);
      Utils.CopyStream(is, os);
      os.close();
      bitmap = decodeFile(f);
      return bitmap;
    } catch (Exception ex) {
      ex.printStackTrace();
      return null;
    }
  }
Пример #2
0
 public void clearCache() {
   memoryCache.clear();
   fileCache.clear();
 }