public static void prioritizeRequest(ImageRequest request) { RequestKey key = new RequestKey(request.getImageUri(), request.getCallerTag()); synchronized (pendingRequests) { DownloaderContext downloaderContext = pendingRequests.get(key); if (downloaderContext != null) { downloaderContext.workItem.moveToFront(); } } }
public static boolean cancelRequest(ImageRequest request) { boolean cancelled = false; RequestKey key = new RequestKey(request.getImageUri(), request.getCallerTag()); synchronized (pendingRequests) { DownloaderContext downloaderContext = pendingRequests.get(key); if (downloaderContext != null) { // If we were able to find the request in our list of pending requests, then we will // definitely be able to prevent an ImageResponse from being issued. This is // regardless of whether a cache-read or network-download is underway for this // request. cancelled = true; if (downloaderContext.workItem.cancel()) { pendingRequests.remove(key); } else { // May be attempting a cache-read right now. So keep track of the cancellation // to prevent network calls etc downloaderContext.isCancelled = true; } } } return cancelled; }
private void processImageResponse(ImageResponse response, String graphObjectId, ImageView imageView) { pendingRequests.remove(graphObjectId); if (response.getError() != null) { callOnErrorListener(response.getError()); } if (imageView == null) { // This was a pre-fetch request. if (response.getBitmap() != null) { // Is the cache too big? if (prefetchedPictureCache.size() >= MAX_PREFETCHED_PICTURES) { // Find the oldest one and remove it. String oldestId = prefetchedProfilePictureIds.remove(0); prefetchedPictureCache.remove(oldestId); } prefetchedPictureCache.put(graphObjectId, response); } } else if (graphObjectId.equals(imageView.getTag())) { Exception error = response.getError(); Bitmap bitmap = response.getBitmap(); if (error == null && bitmap != null) { imageView.setImageBitmap(bitmap); imageView.setTag(response.getRequest().getImageUri()); } } }
ImageResponse response = prefetchedPictureCache.get(id); profilePic.setImageBitmap(response.getBitmap()); profilePic.setTag(response.getRequest().getImageUri()); } else { downloadProfilePicture(id, pictureURI, profilePic);
private void processImageResponse(String id, ImageResponse response) { if (response != null) { Bitmap bitmap = response.getBitmap(); if (bitmap != null) { BitmapDrawable drawable = new BitmapDrawable( UserSettingsFragment.this.getResources(), bitmap); drawable.setBounds(0, 0, getResources().getDimensionPixelSize( R.dimen.usersettings_fragment_profile_picture_width), getResources().getDimensionPixelSize( R.dimen.usersettings_fragment_profile_picture_height)); userProfilePic = drawable; userProfilePicID = id; connectedStateLabel.setCompoundDrawables(null, drawable, null, null); connectedStateLabel.setTag(response.getRequest().getImageUri()); } } } }
private void processImageResponse(String id, ImageResponse response) { if (response != null) { Bitmap bitmap = response.getBitmap(); if (bitmap != null) { BitmapDrawable drawable = new BitmapDrawable( UserSettingsFragment.this.getResources(), bitmap); drawable.setBounds(0, 0, getResources().getDimensionPixelSize( R.dimen.usersettings_fragment_profile_picture_width), getResources().getDimensionPixelSize( R.dimen.usersettings_fragment_profile_picture_height)); userProfilePic = drawable; userProfilePicID = id; connectedStateLabel.setCompoundDrawables(null, drawable, null, null); connectedStateLabel.setTag(response.getRequest().getImageUri()); } } } }
/** * Downloads the image specified in the passed in request. * If a callback is specified, it is guaranteed to be invoked on the calling thread. * @param request Request to process */ public static void downloadAsync(ImageRequest request) { if (request == null) { return; } // NOTE: This is the ONLY place where the original request's Url is read. From here on, // we will keep track of the Url separately. This is because we might be dealing with a // redirect response and the Url might change. We can't create our own new ImageRequests // for these changed Urls since the caller might be doing some book-keeping with the // requests object reference. So we keep the old references and just map them to new urls in // the downloader. RequestKey key = new RequestKey(request.getImageUri(), request.getCallerTag()); synchronized (pendingRequests) { DownloaderContext downloaderContext = pendingRequests.get(key); if (downloaderContext != null) { downloaderContext.request = request; downloaderContext.isCancelled = false; downloaderContext.workItem.moveToFront(); } else { enqueueCacheRead(request, key, request.isCachedRedirectAllowed()); } } }
ImageRequest request = getImageRequest(); if (request != null) { Uri requestUri = request.getImageUri();
ImageRequest request = getImageRequest(); if (request != null) { Uri requestUri = request.getImageUri();
public static void prioritizeRequest(ImageRequest request) { RequestKey key = new RequestKey(request.getImageUri(), request.getCallerTag()); synchronized (pendingRequests) { DownloaderContext downloaderContext = pendingRequests.get(key); if (downloaderContext != null) { downloaderContext.workItem.moveToFront(); } } }
public static boolean cancelRequest(ImageRequest request) { boolean cancelled = false; RequestKey key = new RequestKey(request.getImageUri(), request.getCallerTag()); synchronized (pendingRequests) { DownloaderContext downloaderContext = pendingRequests.get(key); if (downloaderContext != null) { // If we were able to find the request in our list of pending requests, then we will // definitely be able to prevent an ImageResponse from being issued. This is regardless // of whether a cache-read or network-download is underway for this request. cancelled = true; if (downloaderContext.workItem.cancel()) { pendingRequests.remove(key); } else { // May be attempting a cache-read right now. So keep track of the cancellation // to prevent network calls etc downloaderContext.isCancelled = true; } } } return cancelled; }
private void processImageResponse(ImageResponse response, String graphObjectId, ImageView imageView) { pendingRequests.remove(graphObjectId); if (response.getError() != null) { callOnErrorListener(response.getError()); } if (imageView == null) { // This was a pre-fetch request. if (response.getBitmap() != null) { // Is the cache too big? if (prefetchedPictureCache.size() >= MAX_PREFETCHED_PICTURES) { // Find the oldest one and remove it. String oldestId = prefetchedProfilePictureIds.remove(0); prefetchedPictureCache.remove(oldestId); } prefetchedPictureCache.put(graphObjectId, response); } } else if (graphObjectId.equals(imageView.getTag())) { Exception error = response.getError(); Bitmap bitmap = response.getBitmap(); if (error == null && bitmap != null) { imageView.setImageBitmap(bitmap); imageView.setTag(response.getRequest().getImageUri()); } } }
private void processImageResponse(String id, ImageResponse response) { if (response != null) { Bitmap bitmap = response.getBitmap(); if (bitmap != null) { BitmapDrawable drawable = new BitmapDrawable(UserSettingsFragment.this.getResources(), bitmap); drawable.setBounds(0, 0, getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_width), getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_height)); userProfilePic = drawable; userProfilePicID = id; connectedStateLabel.setCompoundDrawables(null, drawable, null, null); connectedStateLabel.setTag(response.getRequest().getImageUri()); } } } }
ImageResponse response = prefetchedPictureCache.get(id); profilePic.setImageBitmap(response.getBitmap()); profilePic.setTag(response.getRequest().getImageUri()); } else { downloadProfilePicture(id, pictureURI, profilePic);
/** * Downloads the image specified in the passed in request. * If a callback is specified, it is guaranteed to be invoked on the calling thread. * @param request Request to process */ public static void downloadAsync(ImageRequest request) { if (request == null) { return; } // NOTE: This is the ONLY place where the original request's Url is read. From here on, // we will keep track of the Url separately. This is because we might be dealing with a // redirect response and the Url might change. We can't create our own new ImageRequests // for these changed Urls since the caller might be doing some book-keeping with the request's // object reference. So we keep the old references and just map them to new urls in the downloader RequestKey key = new RequestKey(request.getImageUri(), request.getCallerTag()); synchronized (pendingRequests) { DownloaderContext downloaderContext = pendingRequests.get(key); if (downloaderContext != null) { downloaderContext.request = request; downloaderContext.isCancelled = false; downloaderContext.workItem.moveToFront(); } else { enqueueCacheRead(request, key, request.isCachedRedirectAllowed()); } } }
ImageRequest request = getImageRequest(); if (request != null) { URI requestUrl = request.getImageUri();