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

Commit fc2ad4fa authored by Brian Attwell's avatar Brian Attwell Committed by Android (Google) Code Review
Browse files

Merge "Use larger photo in contact editor" into lmp-mr1-dev

parents fe7e2b3f c3005213
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@
    android:orientation="horizontal"
    >
    <FrameLayout
        android:layout_width="48dip"
        android:layout_height="48dip"
        android:layout_width="72dp"
        android:layout_height="72dp"
    >
        <ImageView
            android:id="@+id/photo"
+12 −14
Original line number Diff line number Diff line
@@ -19,9 +19,9 @@ package com.android.contacts.editor;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
@@ -46,7 +46,6 @@ import com.android.contacts.common.model.account.AccountType.EditType;
public abstract class BaseRawContactEditorView extends LinearLayout {

    private PhotoEditorView mPhoto;
    private boolean mHasPhotoEditor = false;

    private View mBody;
    private View mDivider;
@@ -77,23 +76,22 @@ public abstract class BaseRawContactEditorView extends LinearLayout {

    /**
     * Assign the given {@link Bitmap} to the internal {@link PhotoEditorView}
     * for the {@link RawContactDelta} currently being edited.
     * in order to update the {@link RawContactDelta} currently being edited.
     */
    public void setPhotoBitmap(Bitmap bitmap) {
        mPhoto.setPhotoBitmap(bitmap);
    }

    protected void setHasPhotoEditor(boolean hasPhotoEditor) {
        mHasPhotoEditor = hasPhotoEditor;
        mPhoto.setVisibility(hasPhotoEditor ? View.VISIBLE : View.GONE);
    public void setPhotoEntry(Bitmap bitmap) {
        mPhoto.setPhotoEntry(bitmap);
    }

    /**
     * Return true if the current {@link RawContacts} supports {@link Photo},
     * which means that {@link PhotoEditorView} is enabled.
     * Assign the given photo {@link Uri} to UI of the {@link PhotoEditorView}, so that it can
     * display a full sized photo.
     */
    public boolean hasPhotoEditor() {
        return mHasPhotoEditor;
    public void setFullSizedPhoto(Uri uri) {
        mPhoto.setFullSizedPhoto(uri);
    }

    protected void setHasPhotoEditor(boolean hasPhotoEditor) {
        mPhoto.setVisibility(hasPhotoEditor ? View.VISIBLE : View.GONE);
    }

    /**
+11 −14
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.media.RingtoneManager;
import android.net.Uri;
@@ -862,10 +861,10 @@ public class ContactEditorFragment extends Fragment implements
            // Set up the photo handler.
            bindPhotoHandler(editor, type, mState);

            // If a new photo was chosen but not yet saved, we need to
            // update the thumbnail to reflect this.
            Bitmap bitmap = updatedBitmapForRawContact(rawContactId);
            if (bitmap != null) editor.setPhotoBitmap(bitmap);
            // If a new photo was chosen but not yet saved, we need to update the UI to
            // reflect this.
            final Uri photoUri = updatedPhotoUriForRawContact(rawContactId);
            if (photoUri != null) editor.setFullSizedPhoto(photoUri);

            if (editor instanceof RawContactEditorView) {
                final Activity activity = getActivity();
@@ -922,14 +921,12 @@ public class ContactEditorFragment extends Fragment implements
    }

    /**
     * If we've stashed a temporary file containing a contact's new photo,
     * decode it and return the bitmap.
     * If we've stashed a temporary file containing a contact's new photo, return its URI.
     * @param rawContactId identifies the raw-contact whose Bitmap we'll try to return.
     * @return Bitmap of photo for specified raw-contact, or null
     * @return Uru of photo for specified raw-contact, or null
     */
    private Bitmap updatedBitmapForRawContact(long rawContactId) {
        String path = mUpdatedPhotos.getString(String.valueOf(rawContactId));
        return path == null ? null : BitmapFactory.decodeFile(path);
    private Uri updatedPhotoUriForRawContact(long rawContactId) {
        return (Uri) mUpdatedPhotos.get(String.valueOf(rawContactId));
    }

    private void bindPhotoHandler(BaseRawContactEditorView editor, AccountType type,
@@ -1861,7 +1858,7 @@ public class ContactEditorFragment extends Fragment implements
        }

        if (requestingEditor != null) {
            requestingEditor.setPhotoBitmap(photo);
            requestingEditor.setPhotoEntry(photo);
        } else {
            Log.w(TAG, "The contact that requested the photo is no longer present.");
        }
@@ -2065,7 +2062,7 @@ public class ContactEditorFragment extends Fragment implements
             */
            @Override
            public void onRemovePictureChosen() {
                mEditor.setPhotoBitmap(null);
                mEditor.setPhotoEntry(null);

                // Prevent bitmap from being restored if rotate the device.
                // (only if we first chose a new photo before removing it)
+49 −7
Original line number Diff line number Diff line
@@ -19,13 +19,17 @@ package com.android.contacts.editor;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.DisplayPhoto;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.android.contacts.R;
import com.android.contacts.common.ContactPhotoManager.DefaultImageProvider;
import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
import com.android.contacts.common.model.RawContactDelta;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.ContactsUtils;
@@ -44,6 +48,7 @@ public class PhotoEditorView extends LinearLayout implements Editor {
    private ValuesDelta mEntry;
    private EditorListener mListener;
    private View mTriangleAffordance;
    private ContactPhotoManager mContactPhotoManager;

    private boolean mHasSetPhoto = false;
    private boolean mReadOnly;
@@ -72,6 +77,7 @@ public class PhotoEditorView extends LinearLayout implements Editor {
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mContactPhotoManager = ContactPhotoManager.getInstance(mContext);
        mTriangleAffordance = findViewById(R.id.photo_triangle_affordance);
        mPhotoImageView = (ImageView) findViewById(R.id.photo);
        mFrameView = findViewById(R.id.frame);
@@ -111,6 +117,20 @@ public class PhotoEditorView extends LinearLayout implements Editor {
                mFrameView.setEnabled(isEnabled());
                mHasSetPhoto = true;
                mEntry.setFromTemplate(false);

                if (values.getAfter() == null || values.getAfter().get(Photo.PHOTO) == null) {
                    // If the user hasn't updated the PHOTO value, then PHOTO_FILE_ID may contain
                    // a reference to a larger version of PHOTO that we can bind to the UI.
                    // Otherwise, we need to wait for a call to #setFullSizedPhoto() to update
                    // our full sized image.
                    final Integer photoFileId = values.getAsInteger(Photo.PHOTO_FILE_ID);
                    if (photoFileId != null) {
                        final Uri photoUri = DisplayPhoto.CONTENT_URI.buildUpon()
                                .appendPath(photoFileId.toString()).build();
                        setFullSizedPhoto(photoUri);
                    }
                }

            } else {
                resetDefault();
            }
@@ -127,10 +147,10 @@ public class PhotoEditorView extends LinearLayout implements Editor {
    }

    /**
     * Assign the given {@link Bitmap} as the new value, updating UI and
     * readying for persisting through {@link ValuesDelta}.
     * Assign the given {@link Bitmap} as the new value for the sake of building
     * {@link ValuesDelta}. We may as well bind a thumbnail to the UI while we are at it.
     */
    public void setPhotoBitmap(Bitmap photo) {
    public void setPhotoEntry(Bitmap photo) {
        if (photo == null) {
            // Clear any existing photo and return
            mEntry.put(Photo.PHOTO, (byte[])null);
@@ -138,7 +158,10 @@ public class PhotoEditorView extends LinearLayout implements Editor {
            return;
        }

        mPhotoImageView.setImageBitmap(photo);
        final int size = ContactsUtils.getThumbnailSize(getContext());
        final Bitmap scaled = Bitmap.createScaledBitmap(photo, size, size, false);

        mPhotoImageView.setImageBitmap(scaled);
        mFrameView.setEnabled(isEnabled());
        mHasSetPhoto = true;
        mEntry.setFromTemplate(false);
@@ -152,10 +175,29 @@ public class PhotoEditorView extends LinearLayout implements Editor {
        // code all over the place, because we don't have to test whether
        // there is a change in EITHER the delta-list OR a changed photo...
        // this way, there is always a change in the delta-list.
        final int size = ContactsUtils.getThumbnailSize(getContext());
        final Bitmap scaled = Bitmap.createScaledBitmap(photo, size, size, false);
        final byte[] compressed = ContactPhotoUtils.compressBitmap(scaled);
        if (compressed != null) mEntry.setPhoto(compressed);
        if (compressed != null) {
            mEntry.setPhoto(compressed);
        }
    }

    /**
     * Bind the {@param photoUri}'s photo to editor's UI. This doesn't affect {@link ValuesDelta}.
     */
    public void setFullSizedPhoto(Uri photoUri) {
        if (photoUri != null) {
            final DefaultImageProvider fallbackToPreviousImage = new DefaultImageProvider() {
                @Override
                public void applyDefaultImage(ImageView view, int extent, boolean darkTheme,
                        DefaultImageRequest defaultImageRequest) {
                    // Before we finish setting the full sized image, don't change the current
                    // image that is set in any way.
                }
            };
            mContactPhotoManager.loadPhoto(mPhotoImageView, photoUri,
                    mPhotoImageView.getWidth(), /* darkTheme = */ false, /* isCircular = */ false,
                    /* defaultImageRequest = */ null, fallbackToPreviousImage);
        }
    }

    /**