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

Commit bb601f2d authored by Wenyi Wang's avatar Wenyi Wang
Browse files

Show check mark when none is primary in photo picker

If there is a photo in photo picker that is marked as primary,
we will use check that photo in photo picker.

Otherwise, with this CL, we compare the photo URI passed from
QuickContact to editor with the photo URIs in photo picker to
decide where to add a check mark.

Bug: 25092609
Change-Id: I0ae77f9874a60f45dcfb305d058ade9de4fef4a4
parent 5c502763
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.contacts.common.model.RawContactDeltaList;
import com.android.contacts.detail.PhotoSelectionHandler;
import com.android.contacts.editor.CompactContactEditorFragment;
import com.android.contacts.editor.CompactPhotoSelectionFragment;
import com.android.contacts.editor.ContactEditorBaseFragment;
import com.android.contacts.editor.PhotoSourceDialogFragment;

import android.app.FragmentTransaction;
@@ -138,6 +139,7 @@ public class CompactContactEditorActivity extends ContactEditorBaseActivity impl
            // Create the editor and photo selection fragments
            mFragment = new CompactContactEditorFragment();
            mPhotoSelectionFragment = new CompactPhotoSelectionFragment();
            mPhotoSelectionFragment.setArguments(getIntent().getExtras());
            getFragmentManager().beginTransaction()
                    .add(R.id.fragment_container, getEditorFragment(), TAG_COMPACT_EDITOR)
                    .add(R.id.fragment_container, mPhotoSelectionFragment, TAG_PHOTO_SELECTION)
@@ -155,6 +157,10 @@ public class CompactContactEditorActivity extends ContactEditorBaseActivity impl
                    .findFragmentByTag(TAG_COMPACT_EDITOR);
            mPhotoSelectionFragment = (CompactPhotoSelectionFragment) getFragmentManager()
                    .findFragmentByTag(TAG_PHOTO_SELECTION);
            final Bundle bundle = mPhotoSelectionFragment.getArguments();
            bundle.putString(ContactEditorBaseFragment.INTENT_EXTRA_PHOTO_URI,
                    getIntent().getExtras().getString(
                            ContactEditorBaseFragment.INTENT_EXTRA_PHOTO_URI));
            final FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            if (mIsPhotoSelection) {
                fragmentTransaction.hide(getEditorFragment()).show(mPhotoSelectionFragment);
+28 −5
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ public class CompactPhotoSelectionFragment extends Fragment {

    private static final String STATE_PHOTOS = "photos";
    private static final String STATE_PHOTO_MODE = "photoMode";
    private static final String STATE_HAS_PRIMARY = "hasPrimary";
    private static final String STATE_PHOTO_URI = "photoUri";
    private final int VIEW_TYPE_TAKE_PHOTO = 0;
    private final int VIEW_TYPE_ALL_PHOTOS = 1;
    private final int VIEW_TYPE_IMAGE = 2;
@@ -223,16 +225,18 @@ public class CompactPhotoSelectionFragment extends Fragment {
            }

            final Photo photo = mPhotos.get(position);
            Uri photoUri = Uri.EMPTY;

            // Bind the photo
            final ImageView imageView = (ImageView) photoItemView.findViewById(R.id.image);
            if (photo.updatedPhotoUri != null) {
                photoUri = photo.updatedPhotoUri;
                EditorUiUtils.loadPhoto(ContactPhotoManager.getInstance(mContext),
                        imageView, photo.updatedPhotoUri);
                        imageView, photoUri);
            } else {
                final Long photoFileId = EditorUiUtils.getPhotoFileId(photo.valuesDelta);
                if (photoFileId != null) {
                    final Uri photoUri = ContactsContract.DisplayPhoto.CONTENT_URI.buildUpon()
                    photoUri = ContactsContract.DisplayPhoto.CONTENT_URI.buildUpon()
                            .appendPath(photoFileId.toString()).build();
                    EditorUiUtils.loadPhoto(ContactPhotoManager.getInstance(mContext),
                            imageView, photoUri);
@@ -249,7 +253,9 @@ public class CompactPhotoSelectionFragment extends Fragment {

            // Display a check icon over the primary photo
            final ImageView checkImageView = (ImageView) photoItemView.findViewById(R.id.check);
            checkImageView.setVisibility(photo.primary ? View.VISIBLE : View.GONE);
            checkImageView.setVisibility(
                    photo.primary || photoUri.toString().equals(mEditorPhotoUri)
                            ? View.VISIBLE : View.GONE);

            photoItemView.setContentDescription(photo.contentDescription);

@@ -261,6 +267,8 @@ public class CompactPhotoSelectionFragment extends Fragment {
    private int mPhotoMode;
    private Listener mListener;
    private GridView mGridView;
    private String mEditorPhotoUri;
    private boolean mHasPrimary;

    public void setListener(Listener listener) {
        mListener = listener;
@@ -270,6 +278,13 @@ public class CompactPhotoSelectionFragment extends Fragment {
        mPhotos = photos;
        mPhotoMode = photoMode;
        mGridView.setAccessibilityDelegate(new View.AccessibilityDelegate() {});
        mHasPrimary = false;
        for (Photo photo : mPhotos) {
            if (photo.primary) {
                mHasPrimary = true;
                break;
            }
        }
    }

    @Override
@@ -278,6 +293,12 @@ public class CompactPhotoSelectionFragment extends Fragment {
        if (savedInstanceState != null) {
            mPhotos = savedInstanceState.getParcelableArrayList(STATE_PHOTOS);
            mPhotoMode = savedInstanceState.getInt(STATE_PHOTO_MODE, 0);
            mEditorPhotoUri = savedInstanceState.getString(STATE_PHOTO_URI);
            mHasPrimary = savedInstanceState.getBoolean(STATE_HAS_PRIMARY);
        }
        if (TextUtils.isEmpty(mEditorPhotoUri)) {
            mEditorPhotoUri = getArguments().getString(
                    ContactEditorBaseFragment.INTENT_EXTRA_PHOTO_URI);
        }
    }

@@ -315,8 +336,8 @@ public class CompactPhotoSelectionFragment extends Fragment {
        display.getMetrics(outMetrics);

        // portrait -- 3 columns; landscape -- 5 columns.
        mNumberOfColumns = outMetrics.heightPixels > outMetrics.widthPixels ?
                NUMBER_OF_COLUMNS_PORTRAIT : NUMBER_OF_COLUMNS_LANDSCAPE;
        mNumberOfColumns = outMetrics.heightPixels > outMetrics.widthPixels
                ? NUMBER_OF_COLUMNS_PORTRAIT : NUMBER_OF_COLUMNS_LANDSCAPE;
        final int paddingWidth = (int) getResources().getDimension(R.dimen
                .photo_picker_column_padding_width);
        float density  = getResources().getDisplayMetrics().density;
@@ -347,6 +368,8 @@ public class CompactPhotoSelectionFragment extends Fragment {
    public void onSaveInstanceState(Bundle outState) {
        outState.putParcelableArrayList(STATE_PHOTOS, mPhotos);
        outState.putInt(STATE_PHOTO_MODE, mPhotoMode);
        outState.putString(STATE_PHOTO_URI, mEditorPhotoUri);
        outState.putBoolean(STATE_HAS_PRIMARY, mHasPrimary);
        super.onSaveInstanceState(outState);
    }

+5 −0
Original line number Diff line number Diff line
@@ -190,6 +190,11 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
     */
    public static final String INTENT_EXTRA_PHOTO_ID = "photo_id";

    /**
     * Intent key to pass the URI of the photo to display on the editor.
     */
    public static final String INTENT_EXTRA_PHOTO_URI = "photo_uri";

    /**
     * Intent key to pass the ID of the raw contact id that should be displayed in the full editor
     * by itself.
+8 −1
Original line number Diff line number Diff line
@@ -46,10 +46,11 @@ public class EditorIntents {
     * existing contact.
     */
    public static Intent createCompactEditContactIntent(Uri contactLookupUri,
            MaterialPalette materialPalette, long photoId) {
            MaterialPalette materialPalette, long photoId, String photoUri) {
        final Intent intent = new Intent(Intent.ACTION_EDIT, contactLookupUri);
        putMaterialPalette(intent, materialPalette);
        putPhotoId(intent, photoId);
        putPhotoUri(intent, photoUri);
        return intent;
    }

@@ -159,6 +160,12 @@ public class EditorIntents {
        }
    }

    private static void putPhotoUri(Intent intent, String photoUri) {
        if (!Uri.EMPTY.toString().equals(photoUri)) {
            intent.putExtra(ContactEditorBaseFragment.INTENT_EXTRA_PHOTO_URI, photoUri);
        }
    }

    private static void putRawContactDeltaValues(Intent intent,
            RawContactDeltaList rawContactDeltaList, String displayName, String phoneticName) {
        // Pass on all the data that has been entered so far
+2 −1
Original line number Diff line number Diff line
@@ -2638,7 +2638,8 @@ public class QuickContactActivity extends ContactsActivity
                mContactData.getLookupUri(),
                mHasComputedThemeColor
                        ? new MaterialPalette(mColorFilterColor, mStatusBarColor) : null,
                mContactData.getPhotoId());
                mContactData.getPhotoId(),
                mContactData.getPhotoUri());
    }

    private void editContact() {