Revert "Load the raw contact's photo in picker dialog"
This reverts commit 21bdf08ac2f7e53a1fd9ee69317302b1d035169c.
Bug: 32096517
Bug: 32384257
Change-Id: I5f5f2790a394c9bf27da60b0630474eb92701e12
diff --git a/src/com/android/contacts/common/ContactPhotoManager.java b/src/com/android/contacts/common/ContactPhotoManager.java
index 2a8ad15..5ec1eea 100644
--- a/src/com/android/contacts/common/ContactPhotoManager.java
+++ b/src/com/android/contacts/common/ContactPhotoManager.java
@@ -467,7 +467,7 @@
/**
* Calls {@link #loadThumbnail(ImageView, long, boolean, DefaultImageRequest,
* DefaultImageProvider)} using the {@link DefaultImageProvider} {@link #DEFAULT_AVATAR}.
- */
+ */
public final void loadThumbnail(ImageView view, long photoId, boolean darkTheme,
boolean isCircular, DefaultImageRequest defaultImageRequest) {
loadThumbnail(view, photoId, darkTheme, isCircular, defaultImageRequest, DEFAULT_AVATAR);
@@ -830,7 +830,7 @@
} else {
if (DEBUG) Log.d(TAG, "loadPhoto request: " + photoId);
loadPhotoByIdOrUri(view, Request.createFromThumbnailId(photoId, darkTheme, isCircular,
- defaultProvider, defaultImageRequest));
+ defaultProvider));
}
}
@@ -1178,8 +1178,6 @@
/**
* Stores the supplied bitmap in cache.
- * bytes should be null to indicate a failure to load the photo. An empty byte[] signifies
- * a successful load but no photo was available.
*/
private void cacheBitmap(Object key, byte[] bytes, boolean preloading, int requestedExtent) {
if (DEBUG) {
@@ -1205,11 +1203,10 @@
}
if (bytes != null) {
+ mBitmapHolderCache.put(key, holder);
if (mBitmapHolderCache.get(key) != holder) {
Log.w(TAG, "Bitmap too big to fit in cache.");
mBitmapHolderCache.put(key, BITMAP_UNAVAILABLE);
- } else {
- mBitmapHolderCache.put(key, holder);
}
} else {
mBitmapHolderCache.put(key, BITMAP_UNAVAILABLE);
@@ -1510,9 +1507,6 @@
while (cursor.moveToNext()) {
Long id = cursor.getLong(0);
byte[] bytes = cursor.getBlob(1);
- if (bytes == null) {
- bytes = new byte[0];
- }
cacheBitmap(id, bytes, preloading, -1);
mPhotoIds.remove(id);
}
@@ -1532,11 +1526,8 @@
ContentUris.withAppendedId(Data.CONTENT_URI, id),
COLUMNS, null, null, null);
if (profileCursor != null && profileCursor.moveToFirst()) {
- byte[] bytes = profileCursor.getBlob(1);
- if (bytes == null) {
- bytes = new byte[0];
- }
- cacheBitmap(profileCursor.getLong(0), bytes, preloading, -1);
+ cacheBitmap(profileCursor.getLong(0), profileCursor.getBlob(1),
+ preloading, -1);
} else {
// Couldn't load a photo this way either.
cacheBitmap(id, null, preloading, -1);
@@ -1650,9 +1641,9 @@
}
public static Request createFromThumbnailId(long id, boolean darkTheme, boolean isCircular,
- DefaultImageProvider defaultProvider, DefaultImageRequest defaultRequest) {
+ DefaultImageProvider defaultProvider) {
return new Request(id, null /* no URI */, -1, darkTheme, isCircular, defaultProvider,
- defaultRequest);
+ /* defaultRequest */ null);
}
public static Request createFromUri(Uri uri, int requestedExtent, boolean darkTheme,
diff --git a/src/com/android/contacts/editor/PickRawContactDialogFragment.java b/src/com/android/contacts/editor/PickRawContactDialogFragment.java
index dd4eb30..aa3e015 100644
--- a/src/com/android/contacts/editor/PickRawContactDialogFragment.java
+++ b/src/com/android/contacts/editor/PickRawContactDialogFragment.java
@@ -3,9 +3,12 @@
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
+import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
+import android.net.Uri;
import android.os.Bundle;
+import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
@@ -97,7 +100,7 @@
String displayName =
mPreferences.getDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY
- ? rawContact.displayName : rawContact.displayNameAlt;
+ ? rawContact.displayName : rawContact.displayNameAlt;
if (TextUtils.isEmpty(displayName)) {
displayName = mContext.getString(R.string.missing_name);
@@ -127,12 +130,16 @@
final ContactPhotoManager.DefaultImageRequest
request = new ContactPhotoManager.DefaultImageRequest(
displayName, String.valueOf(rawContact.id), /* isCircular = */ true);
+ final Uri photoUri = Uri.withAppendedPath(
+ ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContact.id),
+ RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
- ContactPhotoManager.getInstance(mContext).loadThumbnail(holder.photo,
- rawContact.photoId,
+ ContactPhotoManager.getInstance(mContext).loadDirectoryPhoto(holder.photo,
+ photoUri,
/* darkTheme = */ false,
/* isCircular = */ true,
request);
+
return view;
}
diff --git a/src/com/android/contacts/editor/PickRawContactLoader.java b/src/com/android/contacts/editor/PickRawContactLoader.java
index b3df4a6..1939666 100644
--- a/src/com/android/contacts/editor/PickRawContactLoader.java
+++ b/src/com/android/contacts/editor/PickRawContactLoader.java
@@ -9,16 +9,12 @@
import android.os.Parcelable;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
-import android.provider.ContactsContract.Data;
-import android.provider.ContactsContract.Profile;
import android.provider.ContactsContract.RawContacts;
import com.android.contacts.common.model.AccountTypeManager;
import com.android.contacts.common.model.account.AccountType;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
/**
* Loader for the pick a raw contact to edit activity. Loads all raw contact metadata for the
@@ -47,11 +43,6 @@
private static final int DISPLAY_NAME_PRIMARY = 4;
private static final int DISPLAY_NAME_ALTERNATIVE = 5;
- private static final String PHOTO_SELECTION_PREFIX =
- ContactsContract.Data.RAW_CONTACT_ID + " IN (";
- private static final String PHOTO_SELECTION_SUFFIX = ") AND " + ContactsContract.Data.MIMETYPE
- + "=" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE;
-
public PickRawContactLoader(Context context, Uri contactUri) {
super(context);
mContactUri = ensureIsContactUri(contactUri);
@@ -62,7 +53,7 @@
final ContentResolver resolver = getContext().getContentResolver();
// Get the id of the contact we're looking at.
final Cursor contactCursor = resolver.query(
- mContactUri, new String[] {Contacts._ID, Contacts.IS_USER_PROFILE}, null,
+ mContactUri, new String[]{Contacts._ID, Contacts.IS_USER_PROFILE}, null,
null, null);
if (contactCursor == null) {
@@ -101,51 +92,20 @@
}
rawContactCursor.moveToPosition(-1);
- final StringBuilder photoSelection = new StringBuilder(PHOTO_SELECTION_PREFIX);
- final Map<Long, RawContact> rawContactMap = new HashMap<>();
try {
while (rawContactCursor.moveToNext()) {
RawContact rawContact = new RawContact();
rawContact.id = rawContactCursor.getLong(RAW_CONTACT_ID);
- photoSelection.append(rawContact.id).append(',');
rawContact.displayName = rawContactCursor.getString(DISPLAY_NAME_PRIMARY);
rawContact.displayNameAlt = rawContactCursor.getString(DISPLAY_NAME_ALTERNATIVE);
rawContact.accountName = rawContactCursor.getString(ACCOUNT_NAME);
rawContact.accountType = rawContactCursor.getString(ACCOUNT_TYPE);
rawContact.accountDataSet = rawContactCursor.getString(DATA_SET);
result.rawContacts.add(rawContact);
- rawContactMap.put(rawContact.id, rawContact);
}
} finally {
rawContactCursor.close();
}
-
- // Remove the last ','
- if (photoSelection.length() > 0) {
- photoSelection.deleteCharAt(photoSelection.length() - 1);
- }
- photoSelection.append(PHOTO_SELECTION_SUFFIX);
-
- final Uri dataUri = result.isUserProfile
- ? Uri.withAppendedPath(Profile.CONTENT_URI, Data.CONTENT_URI.getPath())
- : Data.CONTENT_URI;
- final Cursor photoCursor = resolver.query(
- dataUri,
- new String[] {Data.RAW_CONTACT_ID, Contacts.Photo._ID},
- photoSelection.toString(), null, null);
-
- if (photoCursor != null) {
- try {
- photoCursor.moveToPosition(-1);
- while (photoCursor.moveToNext()) {
- final long rawContactId = photoCursor.getLong(/* Data.RAW_CONTACT_ID */ 0);
- rawContactMap.get(rawContactId).photoId =
- photoCursor.getLong(/* PHOTO._ID */ 1);
- }
- } finally {
- photoCursor.close();
- }
- }
return result;
}
@@ -265,7 +225,6 @@
};
public long id;
- public long photoId;
public String displayName;
public String displayNameAlt;
public String accountName;
@@ -276,7 +235,6 @@
private RawContact(Parcel in) {
id = in.readLong();
- photoId = in.readLong();
displayName = in.readString();
displayNameAlt = in.readString();
accountName = in.readString();
@@ -292,7 +250,6 @@
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
- dest.writeLong(photoId);
dest.writeString(displayName);
dest.writeString(displayNameAlt);
dest.writeString(accountName);