コード例 #1
0
  private void sendImageRequest(boolean allowCachedResponse) {
    try {
      ImageRequest.Builder requestBuilder =
          new ImageRequest.Builder(
              getContext(), ImageRequest.getProfilePictureUri(profileId, queryWidth, queryHeight));

      ImageRequest request =
          requestBuilder
              .setAllowCachedRedirects(allowCachedResponse)
              .setCallerTag(this)
              .setCallback(
                  new ImageRequest.Callback() {
                    @Override
                    public void onCompleted(ImageResponse response) {
                      processResponse(response);
                    }
                  })
              .build();

      // Make sure to cancel the old request before sending the new one to prevent
      // accidental cancellation of the new request. This could happen if the URL and
      // caller tag stayed the same.
      if (lastRequest != null) {
        ImageDownloader.cancelRequest(lastRequest);
      }
      lastRequest = request;

      ImageDownloader.downloadAsync(request);
    } catch (Exception e) {
      Logger.log(LoggingBehavior.REQUESTS, Log.ERROR, TAG, e.toString());
    }
  }
コード例 #2
0
  private ImageRequest getImageRequest() {
    ImageRequest request = null;
    try {
      ImageRequest.Builder requestBuilder =
          new ImageRequest.Builder(
              getActivity(),
              ImageRequest.getProfilePictureUrl(
                  user.getId(),
                  getResources()
                      .getDimensionPixelSize(
                          R.dimen.com_facebook_usersettingsfragment_profile_picture_width),
                  getResources()
                      .getDimensionPixelSize(
                          R.dimen.com_facebook_usersettingsfragment_profile_picture_height)));

      request =
          requestBuilder
              .setCallerTag(this)
              .setCallback(
                  new ImageRequest.Callback() {
                    @Override
                    public void onCompleted(ImageResponse response) {
                      processImageResponse(user.getId(), response);
                    }
                  })
              .build();
    } catch (URISyntaxException e) {
    }
    return request;
  }
コード例 #3
0
  private void downloadProfilePicture(
      final String profileId, URI pictureURI, final ImageView imageView) {
    if (pictureURI == null) {
      return;
    }

    // If we don't have an imageView, we are pre-fetching this image to store in-memory because we
    // think the user might scroll to its corresponding list row. If we do have an imageView, we
    // only want to queue a download if the view's tag isn't already set to the URL (which would
    // mean
    // it's already got the correct picture).
    boolean prefetching = imageView == null;
    if (prefetching || !pictureURI.equals(imageView.getTag())) {
      if (!prefetching) {
        // Setting the tag to the profile ID indicates that we're currently downloading the
        // picture for this profile; we'll set it to the actual picture URL when complete.
        imageView.setTag(profileId);
        imageView.setImageResource(getDefaultPicture());
      }

      ImageRequest.Builder builder =
          new ImageRequest.Builder(context.getApplicationContext(), pictureURI)
              .setCallerTag(this)
              .setCallback(
                  new ImageRequest.Callback() {
                    @Override
                    public void onCompleted(ImageResponse response) {
                      processImageResponse(response, profileId, imageView);
                    }
                  });

      ImageRequest newRequest = builder.build();
      pendingRequests.put(profileId, newRequest);

      ImageDownloader.downloadAsync(newRequest);
    }
  }