Show check mark when none is primary in photo picker
am: bb601f2d4a

* commit 'bb601f2d4a7ed4db46dd87a4d451d42c666f1591':
  Show check mark when none is primary in photo picker
diff --git a/src/com/android/contacts/activities/CompactContactEditorActivity.java b/src/com/android/contacts/activities/CompactContactEditorActivity.java
index dc16049..d10684b 100644
--- a/src/com/android/contacts/activities/CompactContactEditorActivity.java
+++ b/src/com/android/contacts/activities/CompactContactEditorActivity.java
@@ -22,6 +22,7 @@
 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 @@
             // 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 @@
                     .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);
diff --git a/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java b/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
index bc9435b..f6d5f8d 100644
--- a/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
+++ b/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
@@ -50,6 +50,8 @@
 
     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 @@
             }
 
             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 @@
 
             // 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 @@
     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 @@
         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 @@
         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 @@
         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 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);
     }
 
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index 181bc44..9e2efed 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -191,6 +191,11 @@
     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.
      */
diff --git a/src/com/android/contacts/editor/EditorIntents.java b/src/com/android/contacts/editor/EditorIntents.java
index d87a726..c135d06 100644
--- a/src/com/android/contacts/editor/EditorIntents.java
+++ b/src/com/android/contacts/editor/EditorIntents.java
@@ -46,10 +46,11 @@
      * 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 @@
         }
     }
 
+    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
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 734eb73..d4f961b 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -2638,7 +2638,8 @@
                 mContactData.getLookupUri(),
                 mHasComputedThemeColor
                         ? new MaterialPalette(mColorFilterColor, mStatusBarColor) : null,
-                mContactData.getPhotoId());
+                mContactData.getPhotoId(),
+                mContactData.getPhotoUri());
     }
 
     private void editContact() {