summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohit Yengisetty <rohit@cyngn.com>2015-04-13 18:19:21 -0700
committerMichael Bestas <mikeioannina@gmail.com>2015-04-21 19:39:25 +0000
commitf23375743411d20f76ee5b2a772838f3f230644a (patch)
treeb90bd925cdac05e789153743374525ea1e583c2d
parent5dd21a4467ffa6fae7bd5cca12164553a51a9dd7 (diff)
downloadandroid_packages_apps_ContactsCommon-f23375743411d20f76ee5b2a772838f3f230644a.tar.gz
android_packages_apps_ContactsCommon-f23375743411d20f76ee5b2a772838f3f230644a.tar.bz2
android_packages_apps_ContactsCommon-f23375743411d20f76ee5b2a772838f3f230644a.zip
ContactsCommon : Modify ContactPhotoManager to fetch contacts' bitmaps
Change-Id: If7279a5a77c9d036c5ffdf0633c7577df30973b4 (cherry picked from commit ad0dff5a4331a1625c51c8b9cbcdbfbe5364dae2)
-rw-r--r--TestCommon/src/com/android/contacts/common/test/mocks/MockContactPhotoManager.java5
-rw-r--r--src/com/android/contacts/common/ContactPhotoManager.java121
2 files changed, 119 insertions, 7 deletions
diff --git a/TestCommon/src/com/android/contacts/common/test/mocks/MockContactPhotoManager.java b/TestCommon/src/com/android/contacts/common/test/mocks/MockContactPhotoManager.java
index 3b143deb..fce5cee9 100644
--- a/TestCommon/src/com/android/contacts/common/test/mocks/MockContactPhotoManager.java
+++ b/TestCommon/src/com/android/contacts/common/test/mocks/MockContactPhotoManager.java
@@ -46,6 +46,11 @@ public class MockContactPhotoManager extends ContactPhotoManager {
}
@Override
+ public void getBitmapForContact(Uri photoUri, ImageView imgView, int widthHint,
+ PhotoFetcherCallback cb) {
+ }
+
+ @Override
public void removePhoto(ImageView view) {
view.setImageDrawable(null);
}
diff --git a/src/com/android/contacts/common/ContactPhotoManager.java b/src/com/android/contacts/common/ContactPhotoManager.java
index f700fd8a..c7bee4a9 100644
--- a/src/com/android/contacts/common/ContactPhotoManager.java
+++ b/src/com/android/contacts/common/ContactPhotoManager.java
@@ -532,6 +532,18 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
}
/**
+ * Used to request bitmap of a Contact photo
+ *
+ * @param photoUri Uri of the contact's photo
+ * @param imgView Sentinel used to triage this request through the existing contact bitmap
+ * loading pipeline. The contact Bitmap won't be loaded into this imageview.
+ * @param widthHint suggest bitmap dimensions
+ * @param cb Callback via which a contact's bitmap is made available to the requester
+ */
+ public abstract void getBitmapForContact(Uri photoUri, ImageView imgView, int widthHint,
+ PhotoFetcherCallback cb);
+
+ /**
* Calls {@link #loadPhoto(ImageView, Uri, boolean, boolean, DefaultImageRequest,
* DefaultImageProvider)} with {@link #DEFAULT_AVATAR} and with the assumption, that
* the image is a thumbnail.
@@ -608,6 +620,13 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
@Override
public void onTrimMemory(int level) {
}
+
+ /**
+ * callbacks associated with contact image requests
+ */
+ public interface PhotoFetcherCallback {
+ public void onFetchComplete(Bitmap bitmap);
+ }
}
class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
@@ -885,6 +904,65 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
}
}
+ /**
+ * Checks the cache to satisfy the bitmap request. If not found, requests the loader for
+ * the contact's image.
+ */
+ @Override
+ public void getBitmapForContact(Uri photoUri, ImageView imgView, int widthHint,
+ PhotoFetcherCallback cb) {
+ // ensure request is for a valid contact uri before checking for bitmap
+ // or posting a load request
+ if (photoUri == null || isDefaultImageUri(photoUri)) return;
+
+ // formulate the contact bitmap request
+ Request request = Request.createBitmapOnly(photoUri, widthHint, cb);
+ // check bitmap cache
+ boolean done = decodeContactBitmapFromCache(request);
+
+ // if not in cache, put request in loading queue
+ if (!done) {
+ Request loadRequest = Request.createBitmapOnly(photoUri, widthHint, cb);
+ mPendingRequests.put(imgView, loadRequest);
+ if (!mPaused) {
+ requestLoading();
+ }
+ }
+ }
+
+ /**
+ * Checks the cache for the contact bitmap's bytes, decodes those bytes, and sends the
+ * decoded bitmap to the requester
+ *
+ * @return true if the bitmap is present and the cache and has been sent to the requester
+ */
+ private boolean decodeContactBitmapFromCache(Request request) {
+ Uri photoUri = request.getUri();
+ PhotoFetcherCallback cb = request.getCallback();
+
+ // check cache for the bitmap bytes
+ BitmapHolder holder = mBitmapHolderCache.get(request.getKey());
+ if (holder != null && holder.bytes != null && holder.bytes.length != 0) {
+ // inflate bitmap from cache bytes
+ int sampleSize =
+ BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent,
+ request.getRequestedExtent());
+ if (holder.decodedSampleSize == sampleSize && holder.bitmapRef != null &&
+ holder.bitmapRef.get() != null) {
+ // already has a decoded bitmap at the requested size
+ cb.onFetchComplete(holder.bitmapRef.get());
+ } else {
+ Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(holder.bytes, sampleSize);
+ // the decoded bitmap won't be stored in the BitmapHolder cache
+ cb.onFetchComplete(bitmap);
+ }
+ return true;
+ }
+
+ // cache doesn't contain the requested bitmap
+ return false;
+ }
+
@Override
public void removePhoto(ImageView view) {
view.setImageDrawable(null);
@@ -1159,10 +1237,15 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
Iterator<ImageView> iterator = mPendingRequests.keySet().iterator();
while (iterator.hasNext()) {
ImageView view = iterator.next();
- Request key = mPendingRequests.get(view);
- // TODO: Temporarily disable contact photo fading in, until issues with
- // RoundedBitmapDrawables overlapping the default image drawables are resolved.
- boolean loaded = loadCachedPhoto(view, key, false);
+ Request request = mPendingRequests.get(view);
+ boolean loaded = false;
+ if (request.isBitmapOnly()) {
+ decodeContactBitmapFromCache(request);
+ } else {
+ // TODO: Temporarily disable contact photo fading in, until issues with
+ // RoundedBitmapDrawables overlapping the default image drawables are resolved.
+ loaded = loadCachedPhoto(view, request, false);
+ }
if (loaded) {
iterator.remove();
}
@@ -1601,11 +1684,14 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
private final boolean mDarkTheme;
private final int mRequestedExtent;
private final DefaultImageProvider mDefaultProvider;
- /**
- * Whether or not the contact photo is to be displayed as a circle
- */
+ // Whether or not the contact photo is to be displayed as a circle
private final boolean mIsCircular;
+ // params for bitmap requests
+ private boolean mIsBitmapOnly;
+ private PhotoFetcherCallback mCallback;
+
+
private Request(long id, Uri uri, int requestedExtent, boolean darkTheme,
boolean isCircular, DefaultImageProvider defaultProvider) {
mId = id;
@@ -1627,6 +1713,23 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
defaultProvider);
}
+ public static Request createBitmapOnly(Uri uri, int requestedExtent,
+ PhotoFetcherCallback cb) {
+ Request request = new Request(0, uri, requestedExtent, false, false, null);
+ request.setBitmapOnly();
+ request.mCallback = cb;
+
+ return request;
+ }
+
+ public boolean isBitmapOnly() {
+ return mIsBitmapOnly;
+ }
+
+ public PhotoFetcherCallback getCallback() {
+ return mCallback;
+ }
+
public boolean isUriRequest() {
return mUri != null;
}
@@ -1643,6 +1746,10 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
return mRequestedExtent;
}
+ public void setBitmapOnly() {
+ mIsBitmapOnly = true;
+ }
+
@Override
public int hashCode() {
final int prime = 31;