Example #1
0
 /**
  * Detatches the bitmap container from the request and cancels the request if no one is left
  * listening.
  *
  * @param container The container to remove from the list
  * @return True if the request was canceled, false otherwise.
  */
 public boolean removeContainerAndCancelIfNecessary(ImageContainer container) {
   mContainers.remove(container);
   if (mContainers.size() == 0) {
     mRequest.cancel();
     return true;
   }
   return false;
 }
Example #2
0
  /**
   * Our comparator sorts from high to low priority, and secondarily by sequence number to provide
   * FIFO ordering.
   */
  @Override
  public int compareTo(Request<T> other) {
    Priority left = this.getPriority();
    Priority right = other.getPriority();

    // High-priority requests are "lesser" so they are sorted to the front.
    // Equal priorities are sorted by sequence number to provide FIFO ordering.
    return left == right ? this.mSequence - other.mSequence : right.ordinal() - left.ordinal();
  }
    @SuppressWarnings("unchecked")
    @Override
    public void run() {
      // If this request has canceled, finish it and don't deliver.
      if (mRequest.isCanceled()) {
        mRequest.finish("canceled-at-delivery");
        return;
      }

      // Deliver a normal response or error, depending.
      if (mResponse.isSuccess()) {
        mRequest.deliverResponse(mResponse.result);
      } else {
        mRequest.deliverError(mResponse.error);
      }

      // If this is an intermediate response, add a marker, otherwise we're done
      // and the request can be finished.
      if (mResponse.intermediate) {
        mRequest.addMarker("intermediate-response");
      } else {
        mRequest.finish("done");
      }

      // If we have been provided a post-delivery runnable, run it.
      if (mRunnable != null) {
        mRunnable.run();
      }
    }
 @Override
 public void postError(Request<?> request, ResponseError error) {
   request.addMarker("post-error");
   Response<?> response = Response.error(error);
   mResponsePoster.execute(new ResponseDeliveryRunnable(request, response, null));
 }
 @Override
 public void postResponse(Request<?> request, Response<?> response, Runnable runnable) {
   request.markDelivered();
   request.addMarker("post-response");
   mResponsePoster.execute(new ResponseDeliveryRunnable(request, response, runnable));
 }