Exemple #1
0
  @Override
  public Void call() {
    if (imagesManager.debug) {
      Log.d(TAG, "Start image task");
    }
    try {

      if (!imagesManager.waitForPause()) {
        // interrupted
        cancel();
        return null;
      }

      final ImageResult result = request.readImage();
      if (result == null) {
        throw new IllegalStateException("Image is not returned!");
      }
      safeImageSet(result);

      finish();

    } catch (final MalformedURLException e) {

      Log.e(TAG, "Bad URL: " + request.url + ". Loading canceled.", e);
      error(e);

    } catch (final IOException e) {

      if (imagesManager.debug) {
        Log.e(TAG, "IO error for " + request.url + ": " + e.getMessage());
      }
      error(e);

    } catch (final Exception e) {

      Log.e(TAG, "Cannot load image " + request.url, e);
      error(e);

    } finally {

      final boolean removed = imagesManager.currentLoads.remove(request.getKey(), this);
      if (imagesManager.debug) {
        Log.d(TAG, "Current loaders count: " + imagesManager.currentLoads.size());
        if (!removed) {
          Log.w(TAG, "Incorrect loader in currents for " + request.getKey());
        }
      }
    }
    return null;
  }