Add failure callback for loading avatar async
b/15431889
Change-Id: I554745b0aa3d754343076105bb1dbb11258b28c3
diff --git a/src/com/android/ex/chips/BaseRecipientAdapter.java b/src/com/android/ex/chips/BaseRecipientAdapter.java
index 02b4cdd..4ec0bb0 100644
--- a/src/com/android/ex/chips/BaseRecipientAdapter.java
+++ b/src/com/android/ex/chips/BaseRecipientAdapter.java
@@ -919,4 +919,9 @@
public void onPhotoBytesAsynchronouslyPopulated() {
notifyDataSetChanged();
}
+
+ @Override
+ public void onPhotoBytesAsyncLoadFailed() {
+ // Don't care
+ }
}
diff --git a/src/com/android/ex/chips/DefaultPhotoManager.java b/src/com/android/ex/chips/DefaultPhotoManager.java
index 265c410..3fd9db1 100644
--- a/src/com/android/ex/chips/DefaultPhotoManager.java
+++ b/src/com/android/ex/chips/DefaultPhotoManager.java
@@ -18,8 +18,6 @@
import android.content.ContentResolver;
import android.database.Cursor;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.ContactsContract;
@@ -27,7 +25,6 @@
import android.util.Log;
import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -70,7 +67,9 @@
final byte[] photoBytes = mPhotoCacheMap.get(photoThumbnailUri);
if (photoBytes != null) {
entry.setPhotoBytes(photoBytes);
- // notifyDataSetChanged() should be called by a caller.
+ if (callback != null) {
+ callback.onPhotoBytesAsynchronouslyPopulated();
+ }
} else {
if (DEBUG) {
Log.d(TAG, "No photo cache for " + entry.getDisplayName()
@@ -78,6 +77,8 @@
}
fetchPhotoAsync(entry, photoThumbnailUri, callback);
}
+ } else if (callback != null) {
+ callback.onPhotoBytesAsyncLoadFailed();
}
}
@@ -134,6 +135,8 @@
if (callback != null) {
callback.onPhotoBytesAsynchronouslyPopulated();
}
+ } else if (callback != null) {
+ callback.onPhotoBytesAsyncLoadFailed();
}
}
};
diff --git a/src/com/android/ex/chips/PhotoManager.java b/src/com/android/ex/chips/PhotoManager.java
index 51a5f79..fcc8c1c 100644
--- a/src/com/android/ex/chips/PhotoManager.java
+++ b/src/com/android/ex/chips/PhotoManager.java
@@ -39,5 +39,6 @@
interface PhotoManagerCallback {
void onPhotoBytesAsynchronouslyPopulated();
+ void onPhotoBytesAsyncLoadFailed();
}
}
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index af263a0..3269bdb 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -759,19 +759,21 @@
@Override
public void onPhotoBytesAsynchronouslyPopulated() {
final byte[] loadedPhotoBytes = contact.getPhotoBytes();
- final Bitmap icon;
- if (loadedPhotoBytes != null) {
- icon = BitmapFactory.decodeByteArray(loadedPhotoBytes, 0,
+ final Bitmap icon = BitmapFactory.decodeByteArray(loadedPhotoBytes, 0,
loadedPhotoBytes.length);
- } else {
- // TODO: can the scaled down default photo be cached?
- icon = mDefaultContactPhoto;
- }
// This is called on the main thread so we can draw the icon here
drawIcon(bitmapContainer, icon, paint);
// The view might not redraw itself since it's loaded in the background
invalidate();
}
+
+ @Override
+ public void onPhotoBytesAsyncLoadFailed() {
+ // TODO: can the scaled down default photo be cached?
+ drawIcon(bitmapContainer, mDefaultContactPhoto, paint);
+ // The view might not redraw itself since it's loaded in the background
+ invalidate();
+ }
});
} else {
final Bitmap icon = BitmapFactory.decodeByteArray(origPhotoBytes, 0,