Пример #1
0
  public Bitmap retrieveBitmap(URL photoUrl) {
    Bitmap bitmap = null;

    if (BitmapCache.isInCache(photoUrl.toString())) {
      bitmap = BitmapCache.get(photoUrl.toString());
    } else {
      int retries = 0;
      do {
        if (retries > 0) {
          Log.e(TAG, "Couldn't retrieve Image. Retrying for " + retries + " time");
        }
        try {
          HttpResponse response = netMgr.getHTTPResponse(photoUrl);
          Object input = response.getEntity().getContent();
          InputStream inputStream = (InputStream) input;
          bitmap = BitmapFactory.decodeStream(inputStream);
          BitmapCache.put(photoUrl.toString(), bitmap);
        } catch (IllegalArgumentException e) {
          Log.e(TAG, "Could not retireve bitmap wth null URL", e);
        } catch (IOException e) {
          Log.e(TAG, "Could not retrieve bitmap from resulting httpResponse", e);
        }
        retries++;
      } while (bitmap == null && retries < 3);
    }

    return bitmap;
  }
Пример #2
0
  private List<Track> retrieveTracks(URL url) {
    List<Track> tracks = null;

    String responseAsString = null;
    int retries = 0;
    do {
      if (retries > 0) {
        Log.e(TAG, "Couldn't retrieve Tracks. Retrying: " + retries);
      }
      try {
        HttpResponse response = netMgr.getHTTPResponse(url);
        InputStream input = response.getEntity().getContent();
        responseAsString = convertStreamToString(input);
        tracks = convertJsonToTracks(responseAsString);
      } catch (IllegalArgumentException e) {
        Log.e(TAG, "Could not retrieve tracks with null URL", e);
      } catch (IOException e) {
        Log.e(TAG, "Could not retrieve tracks from resulting httpResponse", e);
      }
      retries++;
    } while (responseAsString == null && retries < 3);

    return tracks;
  }