Search in sources :

Example 16 with ImageRequest

use of com.facebook.internal.ImageRequest in project facebook-android-sdk by facebook.

the class UserSettingsFragment method getImageRequest.

private ImageRequest getImageRequest() {
    ImageRequest request = null;
    ImageRequest.Builder requestBuilder = new ImageRequest.Builder(getActivity(), ImageRequest.getProfilePictureUri(user.optString("id"), getResources().getDimensionPixelSize(R.dimen.usersettings_fragment_profile_picture_width), getResources().getDimensionPixelSize(R.dimen.usersettings_fragment_profile_picture_height)));
    request = requestBuilder.setCallerTag(this).setCallback(new ImageRequest.Callback() {

        @Override
        public void onCompleted(ImageResponse response) {
            processImageResponse(user.optString("id"), response);
        }
    }).build();
    return request;
}
Also used : ImageRequest(com.facebook.internal.ImageRequest) ImageResponse(com.facebook.internal.ImageResponse)

Example 17 with ImageRequest

use of com.facebook.internal.ImageRequest in project facebook-android-sdk by facebook.

the class UserSettingsFragment method updateUI.

private void updateUI() {
    if (!isAdded()) {
        return;
    }
    if (AccessToken.getCurrentAccessToken() != null) {
        connectedStateLabel.setTextColor(getResources().getColor(R.color.usersettings_fragment_connected_text_color));
        connectedStateLabel.setShadowLayer(1f, 0f, -1f, getResources().getColor(R.color.usersettings_fragment_connected_shadow_color));
        if (user != null) {
            ImageRequest request = getImageRequest();
            if (request != null) {
                Uri requestUri = request.getImageUri();
                // Do we already have the right picture? If so, leave it alone.
                if (!requestUri.equals(connectedStateLabel.getTag())) {
                    if (user.optString("id").equals(userProfilePicID)) {
                        connectedStateLabel.setCompoundDrawables(null, userProfilePic, null, null);
                        connectedStateLabel.setTag(requestUri);
                    } else {
                        ImageDownloader.downloadAsync(request);
                    }
                }
            }
            connectedStateLabel.setText(user.optString("name"));
        } else {
            connectedStateLabel.setText(getResources().getString(R.string.usersettings_fragment_logged_in));
            Drawable noProfilePic = getResources().getDrawable(R.drawable.profile_default_icon);
            noProfilePic.setBounds(0, 0, getResources().getDimensionPixelSize(R.dimen.usersettings_fragment_profile_picture_width), getResources().getDimensionPixelSize(R.dimen.usersettings_fragment_profile_picture_height));
            connectedStateLabel.setCompoundDrawables(null, noProfilePic, null, null);
        }
    } else {
        int textColor = getResources().getColor(R.color.usersettings_fragment_not_connected_text_color);
        connectedStateLabel.setTextColor(textColor);
        connectedStateLabel.setShadowLayer(0f, 0f, 0f, textColor);
        connectedStateLabel.setText(getResources().getString(R.string.usersettings_fragment_not_logged_in));
        connectedStateLabel.setCompoundDrawables(null, null, null, null);
        connectedStateLabel.setTag(null);
    }
}
Also used : ImageRequest(com.facebook.internal.ImageRequest) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) Uri(android.net.Uri)

Example 18 with ImageRequest

use of com.facebook.internal.ImageRequest in project facebook-android-sdk by facebook.

the class GraphObjectAdapter method prioritizeViewRange.

public void prioritizeViewRange(int firstVisibleItem, int lastVisibleItem, int prefetchBuffer) {
    if ((lastVisibleItem < firstVisibleItem) || (sectionKeys.size() == 0)) {
        return;
    }
    // the top down.
    for (int i = lastVisibleItem; i >= 0; i--) {
        SectionAndItem sectionAndItem = getSectionAndItem(i);
        if (sectionAndItem.graphObject != null) {
            String id = getIdOfGraphObject(sectionAndItem.graphObject);
            ImageRequest request = pendingRequests.get(id);
            if (request != null) {
                ImageDownloader.prioritizeRequest(request);
            }
        }
    }
    // For items which are not visible, but within the buffer on either side, we want to
    // fetch those items and store them in a small in-memory cache of bitmaps.
    int start = Math.max(0, firstVisibleItem - prefetchBuffer);
    int end = Math.min(lastVisibleItem + prefetchBuffer, getCount() - 1);
    ArrayList<JSONObject> graphObjectsToPrefetchPicturesFor = new ArrayList<JSONObject>();
    // Add the IDs before and after the visible range.
    for (int i = start; i < firstVisibleItem; ++i) {
        SectionAndItem sectionAndItem = getSectionAndItem(i);
        if (sectionAndItem.graphObject != null) {
            graphObjectsToPrefetchPicturesFor.add(sectionAndItem.graphObject);
        }
    }
    for (int i = lastVisibleItem + 1; i <= end; ++i) {
        SectionAndItem sectionAndItem = getSectionAndItem(i);
        if (sectionAndItem.graphObject != null) {
            graphObjectsToPrefetchPicturesFor.add(sectionAndItem.graphObject);
        }
    }
    for (JSONObject graphObject : graphObjectsToPrefetchPicturesFor) {
        Uri uri = getPictureUriOfGraphObject(graphObject);
        final String id = getIdOfGraphObject(graphObject);
        // This URL already have been requested for pre-fetching, but we want to act in an LRU manner, so move
        // it to the end of the list regardless.
        boolean alreadyPrefetching = prefetchedProfilePictureIds.remove(id);
        prefetchedProfilePictureIds.add(id);
        // If we've already requested it for pre-fetching, no need to do so again.
        if (!alreadyPrefetching) {
            downloadProfilePicture(id, uri, null);
        }
    }
}
Also used : JSONObject(org.json.JSONObject) ImageRequest(com.facebook.internal.ImageRequest) Uri(android.net.Uri)

Example 19 with ImageRequest

use of com.facebook.internal.ImageRequest in project facebook-android-sdk by facebook.

the class GraphObjectAdapter method downloadProfilePicture.

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);
    }
}
Also used : ImageRequest(com.facebook.internal.ImageRequest) ImageResponse(com.facebook.internal.ImageResponse)

Example 20 with ImageRequest

use of com.facebook.internal.ImageRequest in project phonegap-facebook-plugin by Wizcorp.

the class UserSettingsFragment method getImageRequest.

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;
}
Also used : ImageRequest(com.facebook.internal.ImageRequest) ImageResponse(com.facebook.internal.ImageResponse) URISyntaxException(java.net.URISyntaxException)

Aggregations

ImageRequest (com.facebook.internal.ImageRequest)22 ImageResponse (com.facebook.internal.ImageResponse)11 URI (java.net.URI)8 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 Drawable (android.graphics.drawable.Drawable)6 URISyntaxException (java.net.URISyntaxException)4 Uri (android.net.Uri)3 JSONObject (org.json.JSONObject)1