Merge "Fix "<N> contacts" label in tablet contact list" into ics-mr1
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ae2c680..0824358 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -136,7 +136,7 @@
     <!-- Menu item (in the action bar) that creates a new group [CHAR LIMIT=12] -->
     <string name="menu_new_group_action_bar">New</string>
 
-    <!-- Title of the confirmation dialog for separating contacts into multiple instances [CHAR LIMIT=20] -->
+    <!-- Title of the confirmation dialog for separating contacts into multiple instances [CHAR LIMIT=26] -->
     <string name="splitConfirmation_title">Separate contact?</string>
 
     <!-- Confirmation dialog for separating contacts into multiple instances [CHAR LIMIT=NONE] -->
@@ -163,7 +163,7 @@
     <!-- Toast shown after two contacts have been joined by a user action -->
     <string name="contactsJoinedMessage">Contacts joined</string>
 
-    <!-- Confirmation dialog title after users selects to delete a contact. [CHAR LIMIT=20]-->
+    <!-- Confirmation dialog title after users selects to delete a contact. [CHAR LIMIT=25]-->
     <string name="deleteConfirmation_title">Delete contact?</string>
 
     <!-- Menu item that opens the Options activity for a given contact [CHAR LIMIT=15] -->
@@ -414,7 +414,7 @@
     <!-- Text displayed when the call log is empty -->
     <string name="recentCalls_empty">Call log is empty.</string>
 
-    <!-- Title of the confirmation dialog for clearing the call log. [CHAR LIMIT=20]  -->
+    <!-- Title of the confirmation dialog for clearing the call log. [CHAR LIMIT=37]  -->
     <string name="clearCallLogConfirmation_title">Clear call log?</string>
 
     <!-- Confirmation dialog for clearing the call log. [CHAR LIMIT=NONE]  -->
@@ -823,7 +823,7 @@
     <!-- The failed reason which should not be shown but it may in some buggy condition. [CHAR LIMIT=40] -->
     <string name="fail_reason_unknown">Unknown error.</string>
 
-    <!-- Dialog title shown when a user is asked to select vCard file. [CHAR LIMIT=20] -->
+    <!-- Dialog title shown when a user is asked to select vCard file. [CHAR LIMIT=25] -->
     <string name="select_vcard_title">Choose vCard file</string>
 
     <!-- The title shown when vCard importer is caching files to be imported into local temporary
@@ -888,7 +888,7 @@
     <!-- The percentage, used for expressing the progress of vCard import/export. -->
     <string name="percentage">%s%%</string>
 
-    <!-- Dialog title shown when a user confirms whether he/she export Contact data. [CHAR LIMIT=20] -->
+    <!-- Dialog title shown when a user confirms whether he/she export Contact data. [CHAR LIMIT=32] -->
     <string name="confirm_export_title">Export contacts?</string>
 
     <!-- Dialog message shown when a user confirms whether he/she export Contact data [CHAR LIMIT=NONE] -->
@@ -1018,7 +1018,7 @@
     <!-- The menu item to bulk import or bulk export contacts from SIM card or SD card.  [CHAR LIMIT=30]-->
     <string name="menu_import_export">Import/export</string>
 
-    <!-- Dialog title when selecting the bulk operation to perform from a list. [CHAR LIMIT=25] -->
+    <!-- Dialog title when selecting the bulk operation to perform from a list. [CHAR LIMIT=36] -->
     <string name="dialog_import_export">Import/export contacts</string>
 
     <!-- The menu item to share the currently viewed contact [CHAR LIMIT=30] -->
diff --git a/src/com/android/contacts/detail/ContactDetailViewPagerAdapter.java b/src/com/android/contacts/detail/ContactDetailViewPagerAdapter.java
index e0ed5e9..edcfc39 100644
--- a/src/com/android/contacts/detail/ContactDetailViewPagerAdapter.java
+++ b/src/com/android/contacts/detail/ContactDetailViewPagerAdapter.java
@@ -19,10 +19,11 @@
 import android.support.v4.view.PagerAdapter;
 import android.support.v4.view.ViewPager;
 import android.view.View;
-import android.view.ViewGroup;
 
 /**
- * Adapter for the {@link ViewPager} for the contact detail page for a contact with social updates.
+ * Adapter for the {@link ViewPager} for the contact detail page for a contact in 2 cases:
+ * 1) without social updates, and 2) with social updates. The default initial case is for
+ * the contact with social updates which uses all possible pages.
  */
 public class ContactDetailViewPagerAdapter extends PagerAdapter {
 
@@ -34,6 +35,12 @@
 
     private static final int MAX_FRAGMENT_VIEW_COUNT = 2;
 
+    /**
+     * The initial value for the view count needs to be MAX_FRAGMENT_VIEW_COUNT,
+     * otherwise anything smaller would break screen rotation functionality for a user viewing
+     * a contact with social updates (i.e. the user was viewing the second page, rotates the
+     * device, the view pager requires the second page to exist immediately on launch).
+     */
     private int mFragmentViewCount = MAX_FRAGMENT_VIEW_COUNT;
 
     private View mAboutFragmentView;
@@ -67,12 +74,16 @@
     /** Gets called when the number of items changes. */
     @Override
     public int getItemPosition(Object object) {
+        // Always return a valid index for the about fragment view because it's always shown
+        // whether the contact has social updates or not.
         if (object == mAboutFragmentView) {
             return INDEX_ABOUT_FRAGMENT;
         }
-        if (object == mUpdatesFragmentView) {
+        // Only return a valid index for the updates fragment view if our view count > 1.
+        if (object == mUpdatesFragmentView && mFragmentViewCount > 1) {
             return INDEX_UPDATES_FRAGMENT;
         }
+        // Otherwise the view should have no position.
         return POSITION_NONE;
     }
 
@@ -84,8 +95,10 @@
     public Object instantiateItem(View container, int position) {
         switch (position) {
             case INDEX_ABOUT_FRAGMENT:
+                mAboutFragmentView.setVisibility(View.VISIBLE);
                 return mAboutFragmentView;
             case INDEX_UPDATES_FRAGMENT:
+                mUpdatesFragmentView.setVisibility(View.VISIBLE);
                 return mUpdatesFragmentView;
         }
         throw new IllegalArgumentException("Invalid position: " + position);
@@ -93,6 +106,7 @@
 
     @Override
     public void destroyItem(View container, int position, Object object) {
+        ((View) object).setVisibility(View.GONE);
     }
 
     @Override