Merge "Don't use file ID of the removed photo" into nyc-dev
diff --git a/res/layout/all_photos_button.xml b/res/layout/all_photos_button.xml
index 6ccdca5..83578c3 100644
--- a/res/layout/all_photos_button.xml
+++ b/res/layout/all_photos_button.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="135dp"
-    android:layout_height="135dp"
+    android:layout_width="@dimen/photo_picker_item_ideal_width"
+    android:layout_height="@dimen/photo_picker_item_ideal_width"
     android:background="@color/google_grey_600"
     android:orientation="vertical">
 
diff --git a/res/layout/compact_photo_selection_fragment.xml b/res/layout/compact_photo_selection_fragment.xml
index b35dae5..42f5b96 100644
--- a/res/layout/compact_photo_selection_fragment.xml
+++ b/res/layout/compact_photo_selection_fragment.xml
@@ -22,7 +22,7 @@
       android:numColumns="auto_fit"
       android:verticalSpacing="3dp"
       android:horizontalSpacing="3dp"
-      android:stretchMode="none"
+      android:stretchMode="columnWidth"
       android:gravity="center"
       android:paddingTop="3dp"
       android:drawSelectorOnTop="true"/>
diff --git a/res/layout/compact_photo_selection_item.xml b/res/layout/compact_photo_selection_item.xml
index c625765..aea8ff6 100644
--- a/res/layout/compact_photo_selection_item.xml
+++ b/res/layout/compact_photo_selection_item.xml
@@ -21,8 +21,8 @@
 
     <ImageView
             android:id="@+id/image"
-            android:layout_width="135dp"
-            android:layout_height="135dp"
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/photo_picker_item_ideal_width"
             android:adjustViewBounds="true"
             android:layout_centerInParent="true"
             android:scaleType="centerCrop" />
diff --git a/res/layout/take_a_photo_button.xml b/res/layout/take_a_photo_button.xml
index 28ec60b..b837e85 100644
--- a/res/layout/take_a_photo_button.xml
+++ b/res/layout/take_a_photo_button.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="135dp"
-    android:layout_height="135dp"
+    android:layout_width="@dimen/photo_picker_item_ideal_width"
+    android:layout_height="@dimen/photo_picker_item_ideal_width"
     android:background="@color/google_grey_600"
     android:orientation="vertical">
 
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 8fe5c72..7b4cd12 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -280,8 +280,8 @@
       of ListView's will not match the padding inside list items -->
     <dimen name="contact_browser_list_item_padding_top_or_bottom">12dp</dimen>
 
-    <!-- Width of padding between columns of photos in photo picker -->
-    <dimen name="photo_picker_column_padding_width">1dp</dimen>
+    <!-- Ideal item width in photo picker -->
+    <dimen name="photo_picker_item_ideal_width">135dp</dimen>
 
     <!-- Margin between name field and whatever fields are above it. -->
     <dimen name="compact_editor_name_top_margin">8dp</dimen>
diff --git a/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java b/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
index bc9435b..3f157a4 100644
--- a/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
+++ b/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
@@ -28,7 +28,6 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.provider.ContactsContract;
-import android.text.TextUtils;
 import android.util.DisplayMetrics;
 import android.view.Display;
 import android.view.LayoutInflater;
@@ -53,9 +52,6 @@
     private final int VIEW_TYPE_TAKE_PHOTO = 0;
     private final int VIEW_TYPE_ALL_PHOTOS = 1;
     private final int VIEW_TYPE_IMAGE = 2;
-    private final int NUMBER_OF_COLUMNS_PORTRAIT = 3;
-    private final int NUMBER_OF_COLUMNS_LANDSCAPE = 5;
-    private int mNumberOfColumns;
 
     /**
      * Callbacks hosts this Fragment.
@@ -295,7 +291,7 @@
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 final PhotoSourceDialogFragment.Listener listener =
                         (PhotoSourceDialogFragment.Listener) getActivity();
-                if (position == 0){
+                if (position == 0) {
                     listener.onTakePhotoChosen();
                 } else if (position == 1) {
                     listener.onPickFromGalleryChosen();
@@ -312,17 +308,11 @@
 
         final Display display = getActivity().getWindowManager().getDefaultDisplay();
         final DisplayMetrics outMetrics = new DisplayMetrics ();
-        display.getMetrics(outMetrics);
+        display.getRealMetrics(outMetrics); // real metrics include the navigation Bar
 
-        // portrait -- 3 columns; landscape -- 5 columns.
-        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;
-        float dpColumnWidth  = (outMetrics.widthPixels - paddingWidth * (mNumberOfColumns - 1) *
-                density) / mNumberOfColumns;
-        mGridView.setColumnWidth((int) dpColumnWidth);
+        final float numColumns = outMetrics.widthPixels /
+                getResources().getDimension(R.dimen.photo_picker_item_ideal_width);
+        mGridView.setNumColumns(Math.round(numColumns));
 
         return view;
     }
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 90cd350..8ebbb25 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -1147,18 +1147,13 @@
                     LOADER_CONTACT_ID, null, mLoaderContactCallbacks);
         } else if (oldLookupUri != mLookupUri) {
             // After copying a directory contact, the contact URI changes. Therefore,
-            // we need to restart the loader and reload the new contact.
+            // we need to reload the new contact.
             destroyInteractionLoaders();
-            mContactLoader = (ContactLoader) getLoaderManager().restartLoader(
-                    LOADER_CONTACT_ID, null, mLoaderContactCallbacks);
-            // mContactLoader may not be in the state of "started". If not, onContentChanged() will
-            // not call forceLoad(), so QuickContact will not get the newly updated hi-res
-            // photo. If this is the case, we call forceLoad explicitly. See b/25204200.
-            if (!mContactLoader.isStarted()) {
-                mContactLoader.forceLoad();
-            }
+            mContactLoader = (ContactLoader) (Loader<?>) getLoaderManager().getLoader(
+                    LOADER_CONTACT_ID);
             mCachedCp2DataCardModel = null;
         }
+        mContactLoader.forceLoad();
 
         NfcHandler.register(this, mLookupUri);
     }