Esempio n. 1
0
  /**
   * download image from url through the Internet
   *
   * @param url
   * @return Bitmap from http
   */
  private Bitmap getImageHttp(String url) {
    // try to get image from file cache
    //    	Logger.debug(this, "Load image from network " + url);
    Bitmap bitmap;
    int times = 0;
    while (times < IMAGE_RETRY_TIMES) {
      try {
        URL u = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) u.openConnection();
        conn.setDoInput(true);
        conn.connect();
        InputStream inputStream = conn.getInputStream();

        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
        opt.inPurgeable = true;
        opt.inInputShareable = true;

        InputStream is = new FlushedInputStream(inputStream);
        bitmap = BitmapFactory.decodeStream(is, null, opt);
        is.close();
        inputStream.close();
        return bitmap;
      } catch (Exception e) {
        Logger.w("getImageHttp=" + url + e);
        times++;
      }
      continue;
    }
    return null;
  } // end of downloadBitmap
Esempio n. 2
0
  /**
   * download image from url through the Internet
   *
   * @param fileName
   * @return Bitmap from http
   */
  private Bitmap getImageFromHttp(String fileName) {
    // try to get image from file cache
    //    	Logger.debug(this, "Load image from network " + fileName);
    Bitmap bitmap = null;
    int times = 0;
    String urlString = ApiService.getDownloadPictureUrl();
    InputStream in = null;

    String[] strArray = fileName.split("_");

    JSONObject request = ApiService.getDownloadPicJson(strArray[0], mContext);
    //		HttpClient client = new DefaultHttpClient();
    HttpClient client = AsyncHttpClient.getDefaultHttpClient(); // https request
    HttpPost req = new HttpPost(urlString);

    while (times < IMAGE_RETRY_TIMES) {
      try {

        req.setHeader("Content-Type", "application/json;charset=UTF8");
        req.setEntity(new StringEntity(request.toString()));
        HttpResponse response = client.execute(req);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
          in = new BufferedInputStream(response.getEntity().getContent());
          BitmapFactory.Options opt = new BitmapFactory.Options();
          opt.inPreferredConfig = Bitmap.Config.RGB_565;
          opt.inPurgeable = true;
          opt.inInputShareable = true;

          InputStream is = new FlushedInputStream(in);
          bitmap = BitmapFactory.decodeStream(is, null, opt);
          is.close();
          in.close();
        } else {
          Logger.d(LOG_TAG + "_" + "error: " + response.getStatusLine().getStatusCode());
        }

        return bitmap;
      } catch (Exception e) {
        Logger.w("getImageHttp=" + fileName + e);
        times++;
      }
      continue;
    }
    return null;
  } // end of downloadBitmap
  public static void refreshDataSet(List<App> appList) {
    if (appList != null) {

      appListDataSource.clear();
      appListDataSource.addAll(appList);
    }

    if (updateAppListAdapter != null) {
      updateAppListAdapter.notifyDataSetChanged();
    }
    Logger.d("refresh update software successfull!");
  }
Esempio n. 4
0
 /**
  * Download the specified image from the Internet and binds it to the provided ImageView. The
  * binding is immediate if the image is found in the cache and will be done asynchronously
  * otherwise. A null bitmap will be associated to the ImageView if an error occurs.
  *
  * @param url The URL of the image to download.
  * @param imageView The ImageView to bind the downloaded image to.
  */
 @Deprecated
 public void download(BindHolder holder, Callback callback) {
   String url = holder.getUrl();
   if (null == url || "".equals(url)) {
     return;
   }
   // TO DO :  sbh : don't store bitmap object in cache , use local files (compressed cache)
   // Bitmap bitmap = imageMemoryCache.getBitmapFromCache(url);
   Bitmap bitmap = mLruMemoryCache.get(url);
   if (bitmap == null) {
     executorService.submit(new ImageTask(new ImageTaskHandler(callback), url, holder));
   } else {
     Logger.d(" return image from the cache, " + bitmap + "  from url =" + url);
     holder.setResource(bitmap);
     callback.callback(holder);
   }
 }