ContactLoader always stores thumbnail blob
Bugle always uses Contact.PHOTO for color extraction. Therefore, in
order for Contacts' color extraction to match Bugles' color extraction
ContactLoader needs to include Contact.PHOTO regardless of whether a large
contact photo is available.
Previously, Contacts was downscaling the full sized image returned from
ContactsLoader. The resulting thumbnail was different enough from the thumbnails
synced by ContactSyncAdapter that about 20% of contact photos had different
extracted colors in Bugle and Contacts.
Bug: 17258486
Change-Id: Ib274da7bd6b6159a91beee0b2e35e0ffdfaab74a
diff --git a/src/com/android/contacts/common/model/Contact.java b/src/com/android/contacts/common/model/Contact.java
index 74b5596..9b96f86 100644
--- a/src/com/android/contacts/common/model/Contact.java
+++ b/src/com/android/contacts/common/model/Contact.java
@@ -85,6 +85,11 @@
private ImmutableList<GroupMetaData> mGroups;
private byte[] mPhotoBinaryData;
+ /**
+ * Small version of the contact photo loaded from a blob instead of from a file. If a large
+ * contact photo is not available yet, then this has the same value as mPhotoBinaryData.
+ */
+ private byte[] mThumbnailPhotoBinaryData;
private final boolean mSendToVoicemail;
private final String mCustomRingtone;
private final boolean mIsUserProfile;
@@ -218,6 +223,10 @@
mPhotoBinaryData = photoBinaryData;
}
+ /* package */ void setThumbnailPhotoBinaryData(byte[] photoBinaryData) {
+ mThumbnailPhotoBinaryData = photoBinaryData;
+ }
+
/**
* Returns the URI for the contact that contains both the lookup key and the ID. This is
* the best URI to reference a contact.
@@ -417,6 +426,10 @@
return mPhotoBinaryData;
}
+ public byte[] getThumbnailPhotoBinaryData() {
+ return mThumbnailPhotoBinaryData;
+ }
+
public ArrayList<ContentValues> getContentValues() {
if (mRawContacts.size() != 1) {
throw new IllegalStateException(
diff --git a/src/com/android/contacts/common/model/ContactLoader.java b/src/com/android/contacts/common/model/ContactLoader.java
index 81c10f8..6f3ee7f 100644
--- a/src/com/android/contacts/common/model/ContactLoader.java
+++ b/src/com/android/contacts/common/model/ContactLoader.java
@@ -40,7 +40,6 @@
import com.android.contacts.common.GeoUtil;
import com.android.contacts.common.GroupMetaData;
-import com.android.contacts.common.model.AccountTypeManager;
import com.android.contacts.common.model.account.AccountType;
import com.android.contacts.common.model.account.AccountTypeWithDataSet;
import com.android.contacts.common.util.Constants;
@@ -503,11 +502,13 @@
}
/**
- * Looks for the photo data item in entities. If found, creates a new Bitmap instance. If
- * not found, returns null
+ * Looks for the photo data item in entities. If found, a thumbnail will be stored. A larger
+ * photo will also be stored if available.
*/
private void loadPhotoBinaryData(Contact contactData) {
- // If we have a photo URI, try loading that first.
+ loadThumbnailBinaryData(contactData);
+
+ // Try to load the large photo from a file using the photo URI.
String photoUri = contactData.getPhotoUri();
if (photoUri != null) {
try {
@@ -544,6 +545,10 @@
}
// If we couldn't load from a file, fall back to the data blob.
+ contactData.setPhotoBinaryData(contactData.getThumbnailPhotoBinaryData());
+ }
+
+ private void loadThumbnailBinaryData(Contact contactData) {
final long photoId = contactData.getPhotoId();
if (photoId <= 0) {
// No photo ID
@@ -558,7 +563,7 @@
}
final PhotoDataItem photo = (PhotoDataItem) dataItem;
- contactData.setPhotoBinaryData(photo.getPhoto());
+ contactData.setThumbnailPhotoBinaryData(photo.getPhoto());
break;
}
}