Example #1
1
  public Bitmap getBitmap(String fileId, String size, boolean fromUrl) {
    File file = fileCache.getFile(fileId + size);

    // from SD cache
    Bitmap bitmap = decodeFile(file, size);

    if (bitmap != null) {
      return bitmap;
    }

    // from web
    try {
      bitmap = null;

      if (fromUrl) {
        InputStream is =
            ConnectionHandler.httpGetRequest(fileId, UsersManagement.getLoginUser().getId());
        OutputStream os = new FileOutputStream(file);
        Utils.copyStream(is, os);
        os.close();
        is.close();
      } else {
        CouchDB.downloadFile(fileId, file);
      }

      bitmap = decodeFile(file, size);

      return bitmap;
      // return ConnectionHandler.getBitmapObject(url);
    } catch (Throwable ex) {
      ex.printStackTrace();
      if (ex instanceof OutOfMemoryError) memoryCache.clear();
      return null;
    }
  }
Example #2
0
  public Bitmap getBitmap(String url) {
    File f = fileCache.getFile(url);

    // from SD cache
    Bitmap bitmap = decodeFile(f);

    if (bitmap != null) {
      Logger.error("ImageLoader", "fileCache.returnBitmap : " + url);
      return bitmap;
    }

    // from web
    try {

      bitmap = null;
      InputStream is =
          ConnectionHandler.httpGetRequest(url, UsersManagement.getLoginUser().getId());
      OutputStream os = new FileOutputStream(f);
      Utils.copyStream(is, os);
      os.close();
      is.close();
      // conn.disconnect();
      bitmap = decodeFile(f);

      return bitmap;
      // return ConnectionHandler.getBitmapObject(url);
    } catch (Throwable ex) {
      ex.printStackTrace();
      if (ex instanceof OutOfMemoryError) memoryCache.clear();
      return null;
    }
  }