コード例 #1
0
  private void sendImageRequest(boolean allowCachedResponse) {
    try {
      ImageRequest.Builder requestBuilder =
          new ImageRequest.Builder(
              getContext(), ImageRequest.getProfilePictureUrl(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 (MalformedURLException e) {
      Logger.log(LoggingBehavior.REQUESTS, Log.ERROR, TAG, e.toString());
    }
  }
コード例 #2
0
  private void updateUI() {
    if (!isAdded()) {
      return;
    }
    if (isSessionOpen()) {
      connectedStateLabel.setTextColor(
          getResources()
              .getColor(
                  AirFacebookExtension.context.getResourceId(
                      "color.com_facebook_usersettingsfragment_connected_text_color")));
      connectedStateLabel.setShadowLayer(
          1f,
          0f,
          -1f,
          getResources()
              .getColor(
                  AirFacebookExtension.context.getResourceId(
                      "color.com_facebook_usersettingsfragment_connected_shadow_color")));

      if (user != null) {
        ImageRequest request = getImageRequest();
        if (request != null) {
          URL requestUrl = request.getImageUrl();
          // Do we already have the right picture? If so, leave it alone.
          if (!requestUrl.equals(connectedStateLabel.getTag())) {
            if (user.getId().equals(userProfilePicID)) {
              connectedStateLabel.setCompoundDrawables(null, userProfilePic, null, null);
              connectedStateLabel.setTag(requestUrl);
            } else {
              ImageDownloader.downloadAsync(request);
            }
          }
        }
        connectedStateLabel.setText(user.getName());
      } else {
        connectedStateLabel.setText(
            getResources()
                .getString(
                    AirFacebookExtension.context.getResourceId(
                        "string.com_facebook_usersettingsfragment_logged_in")));
        Drawable noProfilePic =
            getResources()
                .getDrawable(
                    AirFacebookExtension.context.getResourceId(
                        "drawable.com_facebook_profile_default_icon"));
        noProfilePic.setBounds(
            0,
            0,
            getResources()
                .getDimensionPixelSize(
                    AirFacebookExtension.context.getResourceId(
                        "dimen.com_facebook_usersettingsfragment_profile_picture_width")),
            getResources()
                .getDimensionPixelSize(
                    AirFacebookExtension.context.getResourceId(
                        "dimen.com_facebook_usersettingsfragment_profile_picture_height")));
        connectedStateLabel.setCompoundDrawables(null, noProfilePic, null, null);
      }
    } else {
      int textColor =
          getResources()
              .getColor(
                  AirFacebookExtension.context.getResourceId(
                      "color.com_facebook_usersettingsfragment_not_connected_text_color"));
      connectedStateLabel.setTextColor(textColor);
      connectedStateLabel.setShadowLayer(0f, 0f, 0f, textColor);
      connectedStateLabel.setText(
          getResources()
              .getString(
                  AirFacebookExtension.context.getResourceId(
                      "string.com_facebook_usersettingsfragment_not_logged_in")));
      connectedStateLabel.setCompoundDrawables(null, null, null, null);
      connectedStateLabel.setTag(null);
    }
  }