Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cdf3fc32 authored by blong's avatar blong
Browse files

Add SIM photo for SIM contacts

- Add the account parameter to recognize SIM contacts photo

Change-Id: I26bbe3ba072b1823de618a22bedb92543ee7e06b
parent 7419add9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1296,7 +1296,7 @@ public class MultiPickContactActivity extends ListActivity implements
                if (photoId == 0) {
                    request = new DefaultImageRequest(cache.name, cache.lookupKey, true);
                }
                mContactPhotoManager.loadThumbnail(photo, photoId, false, true, request);
                mContactPhotoManager.loadThumbnail(photo, photoId, account, false, true, request);
            } else if (isPickPhone()) {
                cache.id = cursor.getLong(PHONE_COLUMN_ID);
                cache.name = cursor.getString(PHONE_COLUMN_DISPLAY_NAME);
+19 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.contacts.list;

import android.accounts.Account;
import android.content.ContentUris;
import android.content.Context;
import android.content.CursorLoader;
@@ -24,6 +25,7 @@ import android.net.Uri.Builder;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
@@ -47,6 +49,8 @@ public class EmailAddressListAdapter extends ContactEntryListAdapter {
            Email.PHOTO_ID,                  // 4
            Email.LOOKUP_KEY,                // 5
            Email.DISPLAY_NAME_PRIMARY,      // 6
            RawContacts.ACCOUNT_TYPE,        // 7
            RawContacts.ACCOUNT_NAME         // 8
        };

        private static final String[] PROJECTION_ALTERNATIVE = new String[] {
@@ -57,6 +61,8 @@ public class EmailAddressListAdapter extends ContactEntryListAdapter {
            Email.PHOTO_ID,                  // 4
            Email.LOOKUP_KEY,                // 5
            Email.DISPLAY_NAME_ALTERNATIVE,  // 6
            RawContacts.ACCOUNT_TYPE,        // 7
            RawContacts.ACCOUNT_NAME         // 8
        };

        public static final int EMAIL_ID           = 0;
@@ -66,6 +72,8 @@ public class EmailAddressListAdapter extends ContactEntryListAdapter {
        public static final int EMAIL_PHOTO_ID     = 4;
        public static final int EMAIL_LOOKUP_KEY   = 5;
        public static final int EMAIL_DISPLAY_NAME = 6;
        public static final int EMAIL_ACCOUNT_TYPE = 7;
        public static final int EMAIL_ACCOUNT_NAME = 8;
    }

    private final CharSequence mUnknownNameText;
@@ -173,13 +181,22 @@ public class EmailAddressListAdapter extends ContactEntryListAdapter {
        if (!cursor.isNull(EmailQuery.EMAIL_PHOTO_ID)) {
            photoId = cursor.getLong(EmailQuery.EMAIL_PHOTO_ID);
        }

        Account account = null;
        if (!cursor.isNull(EmailQuery.EMAIL_ACCOUNT_TYPE)
                && !cursor.isNull(EmailQuery.EMAIL_ACCOUNT_NAME)) {
            final String accountType = cursor.getString(EmailQuery.EMAIL_ACCOUNT_TYPE);
            final String accountName = cursor.getString(EmailQuery.EMAIL_ACCOUNT_NAME);
            account = new Account(accountName, accountType);
        }

        DefaultImageRequest request = null;
        if (photoId == 0) {
             request = getDefaultImageRequestFromCursor(cursor, EmailQuery.EMAIL_DISPLAY_NAME,
                    EmailQuery.EMAIL_LOOKUP_KEY);
        }
        getPhotoLoader().loadThumbnail(view.getPhotoView(), photoId, false, getCircularPhotos(),
                request);
        getPhotoLoader().loadThumbnail(view.getPhotoView(), photoId, account,
                false, getCircularPhotos(), request);
    }
//
//    protected void bindSearchSnippet(final ContactListItemView view, Cursor cursor) {
+18 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.contacts.list;

import android.accounts.Account;
import android.content.ContentUris;
import android.content.Context;
import android.content.CursorLoader;
@@ -24,6 +25,7 @@ import android.net.Uri.Builder;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.view.View;
import android.view.ViewGroup;

@@ -46,6 +48,8 @@ public class PostalAddressListAdapter extends ContactEntryListAdapter {
            StructuredPostal.PHOTO_ID,                  // 4
            StructuredPostal.LOOKUP_KEY,                // 5
            StructuredPostal.DISPLAY_NAME_PRIMARY,      // 6
            RawContacts.ACCOUNT_TYPE,                   // 7
            RawContacts.ACCOUNT_NAME                    // 8
        };

        private static final String[] PROJECTION_ALTERNATIVE = new String[] {
@@ -56,6 +60,8 @@ public class PostalAddressListAdapter extends ContactEntryListAdapter {
            StructuredPostal.PHOTO_ID,                  // 4
            StructuredPostal.LOOKUP_KEY,                // 5
            StructuredPostal.DISPLAY_NAME_ALTERNATIVE,  // 6
            RawContacts.ACCOUNT_TYPE,                   // 7
            RawContacts.ACCOUNT_NAME,                   // 8
        };

        public static final int POSTAL_ID           = 0;
@@ -65,6 +71,8 @@ public class PostalAddressListAdapter extends ContactEntryListAdapter {
        public static final int POSTAL_PHOTO_ID     = 4;
        public static final int POSTAL_LOOKUP_KEY   = 5;
        public static final int POSTAL_DISPLAY_NAME = 6;
        public static final int POSTAL_ACCOUNT_TYPE  = 7;
        public static final int POSTAL_ACCOUNT_NAME  = 8;
    }

    private final CharSequence mUnknownNameText;
@@ -165,14 +173,22 @@ public class PostalAddressListAdapter extends ContactEntryListAdapter {
            photoId = cursor.getLong(PostalQuery.POSTAL_PHOTO_ID);
        }

        Account account = null;
        if (!cursor.isNull(PostalQuery.POSTAL_ACCOUNT_TYPE)
                && !cursor.isNull(PostalQuery.POSTAL_ACCOUNT_NAME)) {
            final String accountType = cursor.getString(PostalQuery.POSTAL_ACCOUNT_TYPE);
            final String accountName = cursor.getString(PostalQuery.POSTAL_ACCOUNT_NAME);
            account = new Account(accountName, accountType);
        }

        DefaultImageRequest request = null;
        if (photoId == 0) {
            request = getDefaultImageRequestFromCursor(cursor, PostalQuery.POSTAL_DISPLAY_NAME,
                    PostalQuery.POSTAL_LOOKUP_KEY);
        }

        getPhotoLoader().loadThumbnail(view.getPhotoView(), photoId, false, getCircularPhotos(),
                request);
        getPhotoLoader().loadThumbnail(view.getPhotoView(), photoId, account,
                false, getCircularPhotos(), request);
    }
//
//    protected void bindSearchSnippet(final ContactListItemView view, Cursor cursor) {
+19 −8
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.contacts.util;

import android.accounts.Account;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -30,6 +32,7 @@ import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
import com.android.contacts.common.lettertiles.LetterTileDrawable;
import com.android.contacts.common.model.Contact;
import com.android.contacts.common.model.RawContact;

import java.util.Arrays;

@@ -53,9 +56,17 @@ public class ImageViewDrawableSetter {
    }

    public Bitmap setupContactPhoto(Contact contactData, ImageView photoView) {
        Account account = null;
        mContact = contactData;
        setTarget(photoView);
        return setCompressedImage(contactData.getPhotoBinaryData());
        RawContact rawContact = contactData.getRawContacts().get(0);
        final String accountType = rawContact.getAccountTypeString();
        final String accountName = rawContact.getAccountName();
        if (!TextUtils.isEmpty(accountType) && !TextUtils.isEmpty(accountName)) {
            account = new Account(accountName, accountType);
        }
        return setCompressedImage(contactData.getPhotoBinaryData(),
                photoView.getContext(), account);
    }

    public void setTransitionDuration(int durationInMillis) {
@@ -83,7 +94,7 @@ public class ImageViewDrawableSetter {
        return mCompressed;
    }

    protected Bitmap setCompressedImage(byte[] compressed) {
    protected Bitmap setCompressedImage(byte[] compressed, Context c, Account account) {
        if (mPreviousDrawable == null) {
            // If we don't already have a drawable, skip the exit-early test
            // below; otherwise we might not end up setting the default image.
@@ -97,10 +108,9 @@ public class ImageViewDrawableSetter {
            return previousBitmap();
        }

        Drawable newDrawable = decodedBitmapDrawable(compressed);
        if (newDrawable == null) {
            newDrawable = defaultDrawable();
        }
        final Drawable newDrawable = (compressed == null)
                ? defaultDrawable(c,account)
                : decodedBitmapDrawable(compressed);

        // Remember this for next time, so that we can check if it changed.
        mCompressed = compressed;
@@ -140,7 +150,7 @@ public class ImageViewDrawableSetter {
     * retrieve a default drawable for this contact. If not, then use the name as the contact
     * identifier instead.
     */
    private Drawable defaultDrawable() {
    private Drawable defaultDrawable(Context c, Account account) {
        Resources resources = mTarget.getResources();
        DefaultImageRequest request;
        int contactType = ContactPhotoManager.TYPE_DEFAULT;
@@ -156,7 +166,8 @@ public class ImageViewDrawableSetter {
            request = new DefaultImageRequest(mContact.getDisplayName(), mContact.getLookupKey(),
                    contactType, false /* isCircular */);
        }
        return ContactPhotoManager.getDefaultAvatarDrawableForContact(resources, true, request);
        return ContactPhotoManager.getDefaultAvatarDrawableForContact(
                c, resources, true, request, account);
    }

    private BitmapDrawable decodedBitmapDrawable(byte[] compressed) {