From 49ff098b926834a59280737c0a912ef54a260419 Mon Sep 17 00:00:00 2001 From: Rohit Yengisetty Date: Tue, 7 Jul 2015 15:37:27 -0700 Subject: ContactPhotoManager - Add ability to fetch contact bitmap based on photo id Change-Id: Ie9f4ec17ec7f598c8d0005e27107f300af829fc3 --- .../contacts/common/ContactPhotoManager.java | 36 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/com/android/contacts/common/ContactPhotoManager.java b/src/com/android/contacts/common/ContactPhotoManager.java index 547b5623..6fa20f69 100644 --- a/src/com/android/contacts/common/ContactPhotoManager.java +++ b/src/com/android/contacts/common/ContactPhotoManager.java @@ -543,6 +543,8 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 { public abstract void getBitmapForContact(Uri photoUri, ImageView imgView, int widthHint, PhotoFetcherCallback cb); + public abstract void getBitmapForContact(long photoId, ImageView imgView, int widthHint, + PhotoFetcherCallback cb); /** * Calls {@link #loadPhoto(ImageView, Uri, boolean, boolean, DefaultImageRequest, * DefaultImageProvider)} with {@link #DEFAULT_AVATAR} and with the assumption, that @@ -917,13 +919,22 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback { // formulate the contact bitmap request Request request = Request.createBitmapOnly(photoUri, widthHint, cb); - // check bitmap cache - boolean done = decodeContactBitmapFromCache(request); + getBitmapForContact(imgView, request); + } - // if not in cache, put request in loading queue + @Override + public void getBitmapForContact(long photoId, ImageView imgView, int widthHint, + PhotoFetcherCallback cb) { + if (photoId <= 0) return; + Request request = Request.createBitmapOnly(photoId, widthHint, cb); + getBitmapForContact(imgView, request); + } + + private void getBitmapForContact(ImageView imgView, Request request) { + boolean done = decodeContactBitmapFromCache(request); + // if not in cache, put request into loading queue if (!done) { - Request loadRequest = Request.createBitmapOnly(photoUri, widthHint, cb); - mPendingRequests.put(imgView, loadRequest); + mPendingRequests.put(imgView, request); if (!mPaused) { requestLoading(); } @@ -1737,6 +1748,21 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback { return request; } + public static Request createBitmapOnly(long photoId, int requestedExtent, + PhotoFetcherCallback cb) { + return createBitmapOnly(photoId, requestedExtent, cb, null); + } + + public static Request createBitmapOnly(long photoId, int requestedExtent, + PhotoFetcherCallback cb, DefaultImageRequest defaultImageRequest) { + Request request = new Request(photoId, null, requestedExtent, false, false, null, + defaultImageRequest); + request.setBitmapOnly(); + request.mCallback = cb; + + return request; + } + public boolean isBitmapOnly() { return mIsBitmapOnly; } -- cgit v1.2.3