Merge "Fixed group editing popup from contact editor" into jb-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 56c7b9f..a9c781a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -551,11 +551,16 @@
             </intent-filter>
         </activity>
 
-        <!-- Internal photo selection activity -->
+        <!--
+            Internal photo selection activity.  This activity handles all configuration changes by
+            itself.
+        -->
         <activity android:name=".activities.PhotoSelectionActivity"
             android:theme="@style/Theme.PhotoSelector"
             android:launchMode="singleTop"
-            android:windowSoftInputMode="stateUnchanged">
+            android:windowSoftInputMode="stateUnchanged"
+            android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize"
+            >
         </activity>
 
         <!-- Interstitial activity that shows a phone disambig dialog -->
diff --git a/res/values-cs/strings.xml b/res/values-cs/strings.xml
index 91cdf43..84d8627 100644
--- a/res/values-cs/strings.xml
+++ b/res/values-cs/strings.xml
@@ -72,7 +72,7 @@
     <string name="deleteConfirmation" msgid="811706994761610640">"Tento kontakt bude smazán."</string>
     <string name="menu_done" msgid="796017761764190697">"Hotovo"</string>
     <string name="menu_doNotSave" msgid="58593876893538465">"Zrušit"</string>
-    <string name="menu_discard" msgid="6456087569315685632">"Zrušit"</string>
+    <string name="menu_discard" msgid="6456087569315685632">"Zahodit"</string>
     <string name="label_notes" msgid="8337354953278341042">"Poznámky"</string>
     <string name="label_sip_address" msgid="124073911714324974">"Internetový hovor"</string>
     <string name="ghostData_company" msgid="5414421120553765775">"Společnost"</string>
@@ -494,7 +494,7 @@
     <string name="set_default" msgid="4417505153468300351">"Výchozí nastavení"</string>
     <string name="clear_default" msgid="7193185801596678067">"Vymazat výchozí nastavení"</string>
     <string name="toast_text_copied" msgid="5143776250008541719">"Text zkopírován"</string>
-    <string name="cancel_confirmation_dialog_message" msgid="5885724679874403115">"Zrušit změny?"</string>
+    <string name="cancel_confirmation_dialog_message" msgid="5885724679874403115">"Zahodit změny?"</string>
     <string name="call_type_and_date" msgid="747163730039311423">"<xliff:g id="CALL_TYPE">%1$s</xliff:g> <xliff:g id="CALL_SHORT_DATE">%2$s</xliff:g>"</string>
     <string name="profile_display_name" msgid="4127389543625918771">"Nastavit profil"</string>
     <string name="enter_contact_name" msgid="1738391320566349924">"Zadejte jméno osoby"</string>
diff --git a/res/values-el/strings.xml b/res/values-el/strings.xml
index dc88270..309c810 100644
--- a/res/values-el/strings.xml
+++ b/res/values-el/strings.xml
@@ -278,11 +278,9 @@
     <string name="search_settings_description" msgid="2675223022992445813">"Ονόματα ων επαφών σας"</string>
     <string name="add_2sec_pause" msgid="9214012315201040129">"Προσθήκη παύσης 2 δευτερολέπτων"</string>
     <string name="add_wait" msgid="3360818652790319634">"Προσθήκη αναμονής"</string>
-    <!-- no translation found for call_disambig_title (4392886850104795739) -->
-    <skip />
+    <string name="call_disambig_title" msgid="4392886850104795739">"Επιλέξτε αριθμό"</string>
     <string name="call_settings" msgid="7666474782093693667">"Ρυθμίσεις"</string>
-    <!-- no translation found for sms_disambig_title (5846266399240630846) -->
-    <skip />
+    <string name="sms_disambig_title" msgid="5846266399240630846">"Επιλέξτε αριθμό"</string>
     <string name="make_primary" msgid="5829291915305113983">"Διατήρηση αυτής της ρύθμισης"</string>
     <string name="quickcontact_missing_app" msgid="358168575340921552">"Δεν βρέθηκε εφαρμογή για τη διαχείριση αυτής της ενέργειας."</string>
     <string name="missing_name" msgid="8745511583852904385">"(Χωρίς όνομα)"</string>
diff --git a/res/values-en-rGB/strings.xml b/res/values-en-rGB/strings.xml
index 2e1cf2b..e2fadc0 100644
--- a/res/values-en-rGB/strings.xml
+++ b/res/values-en-rGB/strings.xml
@@ -278,11 +278,9 @@
     <string name="search_settings_description" msgid="2675223022992445813">"Names of your contacts"</string>
     <string name="add_2sec_pause" msgid="9214012315201040129">"Add 2-sec pause"</string>
     <string name="add_wait" msgid="3360818652790319634">"Add wait"</string>
-    <!-- no translation found for call_disambig_title (4392886850104795739) -->
-    <skip />
+    <string name="call_disambig_title" msgid="4392886850104795739">"Choose number"</string>
     <string name="call_settings" msgid="7666474782093693667">"Settings"</string>
-    <!-- no translation found for sms_disambig_title (5846266399240630846) -->
-    <skip />
+    <string name="sms_disambig_title" msgid="5846266399240630846">"Choose number"</string>
     <string name="make_primary" msgid="5829291915305113983">"Remember this choice"</string>
     <string name="quickcontact_missing_app" msgid="358168575340921552">"No app was found to handle this action."</string>
     <string name="missing_name" msgid="8745511583852904385">"(No name)"</string>
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index 412e26d..b806404 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -278,11 +278,9 @@
     <string name="search_settings_description" msgid="2675223022992445813">"Noms de vos contacts"</string>
     <string name="add_2sec_pause" msgid="9214012315201040129">"Ajouter une pause de 2 s"</string>
     <string name="add_wait" msgid="3360818652790319634">"Ajouter Attendre"</string>
-    <!-- no translation found for call_disambig_title (4392886850104795739) -->
-    <skip />
+    <string name="call_disambig_title" msgid="4392886850104795739">"Sélectionner un numéro"</string>
     <string name="call_settings" msgid="7666474782093693667">"Paramètres"</string>
-    <!-- no translation found for sms_disambig_title (5846266399240630846) -->
-    <skip />
+    <string name="sms_disambig_title" msgid="5846266399240630846">"Sélectionner un numéro"</string>
     <string name="make_primary" msgid="5829291915305113983">"Mémoriser ce choix"</string>
     <string name="quickcontact_missing_app" msgid="358168575340921552">"Aucune application pouvant gérer cette action n\'a été trouvée."</string>
     <string name="missing_name" msgid="8745511583852904385">"(Sans nom)"</string>
diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml
index 492d5f9..e2d429c 100644
--- a/res/values-it/strings.xml
+++ b/res/values-it/strings.xml
@@ -278,11 +278,9 @@
     <string name="search_settings_description" msgid="2675223022992445813">"I nomi dei tuoi contatti"</string>
     <string name="add_2sec_pause" msgid="9214012315201040129">"Aggiungi pausa 2 sec"</string>
     <string name="add_wait" msgid="3360818652790319634">"Aggiungi attesa"</string>
-    <!-- no translation found for call_disambig_title (4392886850104795739) -->
-    <skip />
+    <string name="call_disambig_title" msgid="4392886850104795739">"Scegli numero"</string>
     <string name="call_settings" msgid="7666474782093693667">"Impostazioni"</string>
-    <!-- no translation found for sms_disambig_title (5846266399240630846) -->
-    <skip />
+    <string name="sms_disambig_title" msgid="5846266399240630846">"Scegli numero"</string>
     <string name="make_primary" msgid="5829291915305113983">"Memorizza questa scelta"</string>
     <string name="quickcontact_missing_app" msgid="358168575340921552">"Nessuna applicazione trovata per gestire questa azione."</string>
     <string name="missing_name" msgid="8745511583852904385">"(Nessun nome)"</string>
diff --git a/res/values-sw580dp/styles.xml b/res/values-sw580dp/styles.xml
index 9a54c6f..c387435 100644
--- a/res/values-sw580dp/styles.xml
+++ b/res/values-sw580dp/styles.xml
@@ -40,7 +40,7 @@
         <item name="list_item_header_text_indent">8dip</item>
         <item name="list_item_header_text_size">14sp</item>
         <item name="list_item_header_text_color">@color/people_app_theme_color</item>
-        <item name="list_item_header_height">26dip</item>
+        <item name="list_item_header_height">32dip</item>
         <item name="list_item_header_underline_height">1dip</item>
         <item name="list_item_header_underline_color">@color/people_app_theme_color</item>
         <item name="list_item_data_width_weight">5</item>
diff --git a/res/values-sw680dp/styles.xml b/res/values-sw680dp/styles.xml
index dce3b7d..31de81b 100644
--- a/res/values-sw680dp/styles.xml
+++ b/res/values-sw680dp/styles.xml
@@ -39,7 +39,7 @@
         <item name="list_item_prefix_highlight_color">@color/people_app_theme_color</item>
         <item name="list_item_header_text_indent">8dip</item>
         <item name="list_item_header_text_color">@color/people_app_theme_color</item>
-        <item name="list_item_header_height">24dip</item>
+        <item name="list_item_header_height">32dip</item>
         <item name="list_item_header_text_size">14sp</item>
         <item name="list_item_header_underline_color">@color/people_app_theme_color</item>
         <item name="list_item_header_underline_height">1dip</item>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 7404335..3be1222 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -152,7 +152,7 @@
         <item name="list_item_prefix_highlight_color">@color/people_app_theme_color</item>
         <item name="list_item_header_text_color">@color/people_app_theme_color</item>
         <item name="list_item_header_text_size">14sp</item>
-        <item name="list_item_header_height">26dip</item>
+        <item name="list_item_header_height">32dip</item>
         <item name="list_item_header_underline_height">1dip</item>
         <item name="list_item_header_underline_color">@color/people_app_theme_color</item>
         <item name="list_item_data_width_weight">5</item>
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 464075a..1194a5e 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -343,7 +343,7 @@
         final FragmentTransaction transaction = fragmentManager.beginTransaction();
 
         // Prepare the fragments which are used both on 1-pane and on 2-pane.
-        boolean isUsingTwoPanes = PhoneCapabilityTester.isUsingTwoPanes(this);
+        final boolean isUsingTwoPanes = PhoneCapabilityTester.isUsingTwoPanes(this);
         if (isUsingTwoPanes) {
             mFavoritesFragment = getFragment(R.id.favorites_fragment);
             mAllFragment = getFragment(R.id.all_fragment);
@@ -437,6 +437,9 @@
             mFavoritesFragment.enableQuickContact(true);
             mFavoritesFragment.setDisplayType(DisplayType.STARRED_ONLY);
         } else {
+            // For 2-pane in All and Groups but not in Favorites fragment, show the chevron
+            // for quick contact popup
+            mFavoritesFragment.enableQuickContact(isUsingTwoPanes);
             mFavoritesFragment.setDisplayType(DisplayType.STREQUENT);
         }
 
@@ -851,9 +854,13 @@
 
         private Fragment getFragment(int position) {
             if (mTabPagerAdapterSearchMode) {
-                if (position == 0) {
-                    return mAllFragment;
+                if (position != 0) {
+                    // This has only been observed in monkey tests.
+                    // Let's log this issue, but not crash
+                    Log.w(TAG, "Request fragment at position=" + position + ", eventhough we " +
+                            "are in search mode");
                 }
+                return mAllFragment;
             } else {
                 if (position == TabState.FAVORITES) {
                     return mFavoritesFragment;
diff --git a/src/com/android/contacts/activities/PhotoSelectionActivity.java b/src/com/android/contacts/activities/PhotoSelectionActivity.java
index d443782..509bd48 100644
--- a/src/com/android/contacts/activities/PhotoSelectionActivity.java
+++ b/src/com/android/contacts/activities/PhotoSelectionActivity.java
@@ -30,6 +30,7 @@
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.content.res.Configuration;
 import android.graphics.Bitmap;
 import android.graphics.Rect;
 import android.net.Uri;
@@ -59,10 +60,6 @@
     /** Number of ms for the animation to hide the backdrop on finish. */
     private static final int BACKDROP_FADEOUT_DURATION = 100;
 
-    private static final String KEY_CURRENT_PHOTO_FILE = "currentphotofile";
-
-    private static final String KEY_SUB_ACTIVITY_IN_PROGRESS = "subinprogress";
-
     /** Intent extra to get the photo URI. */
     public static final String PHOTO_URI = "photo_uri";
 
@@ -132,10 +129,7 @@
     /** Whether a sub-activity is currently in progress. */
     private boolean mSubActivityInProgress;
 
-    /**
-     * A photo result received by the activity, persisted across activity lifecycle.
-     */
-    private PendingPhotoResult mPendingPhotoResult;
+    private boolean mCloseActivityWhenCameBackFromSubActivity;
 
     /**
      * The photo file being interacted with, if any.  Saved/restored between activity instances.
@@ -146,13 +140,6 @@
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.photoselection_activity);
-        if (savedInstanceState != null) {
-            String fileName = savedInstanceState.getString(KEY_CURRENT_PHOTO_FILE);
-            if (fileName != null) {
-                mCurrentPhotoFile = new File(fileName);
-            }
-            mSubActivityInProgress = savedInstanceState.getBoolean(KEY_SUB_ACTIVITY_IN_PROGRESS);
-        }
 
         // Pull data out of the intent.
         final Intent intent = getIntent();
@@ -187,11 +174,26 @@
     }
 
     @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+
+        // The current look may not seem right on the new configuration, so let's just close self.
+
+        if (!mSubActivityInProgress) {
+            finishImmediatelyWithNoAnimation();
+        } else {
+            // A sub-activity is in progress, so don't close it yet, but close it when we come back
+            // to this activity.
+            mCloseActivityWhenCameBackFromSubActivity = true;
+        }
+    }
+
+    @Override
     public void finish() {
         if (!mSubActivityInProgress) {
             closePhotoAndFinish();
         } else {
-            activityFinish();
+            finishImmediatelyWithNoAnimation();
         }
     }
 
@@ -227,7 +229,7 @@
         return intent;
     }
 
-    private void activityFinish() {
+    private void finishImmediatelyWithNoAnimation() {
         super.finish();
     }
 
@@ -360,15 +362,13 @@
                 anim.addListener(new AnimatorListenerAdapter() {
                     @Override
                     public void onAnimationEnd(Animator animation) {
-                        activityFinish();
+                        finishImmediatelyWithNoAnimation();
                     }
                 });
                 anim.start();
             }
         };
 
-        // TODO: This won't animate in the right way if the rotation has changed since the activity
-        // was first started.
         animatePhoto(mPhotoStartParams);
         animateAwayBackground();
     }
@@ -395,28 +395,23 @@
     }
 
     @Override
-    protected void onSaveInstanceState(Bundle outState) {
-        super.onSaveInstanceState(outState);
-        if (mCurrentPhotoFile != null) {
-            outState.putString(KEY_CURRENT_PHOTO_FILE, mCurrentPhotoFile.toString());
-        }
-        outState.putBoolean(KEY_SUB_ACTIVITY_IN_PROGRESS, mSubActivityInProgress);
-    }
-
-    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         if (mPhotoHandler != null) {
             mSubActivityInProgress = false;
             if (mPhotoHandler.handlePhotoActivityResult(requestCode, resultCode, data)) {
-                // Clear out any pending photo result.
-                mPendingPhotoResult = null;
+                // Result was handled.  We'll get a callback later.
             } else {
-                // User returning to the photo selection activity.  Re-display options.
-                mPhotoHandler.onClick(mPhotoView);
+                // User cancelled the sub-activity and returning to the photo selection activity.
+                if (mCloseActivityWhenCameBackFromSubActivity) {
+                    finishImmediatelyWithNoAnimation();
+                } else {
+                    // Re-display options.
+                    mPhotoHandler.onClick(mPhotoView);
+                }
             }
         } else {
-            // Create a pending photo result to be handled when the photo handler is created.
-            mPendingPhotoResult = new PendingPhotoResult(requestCode, resultCode, data);
+            // The result comes back before we prepare the handler?  This activity won't get
+            // re-created for orientation changes, so this shouldn't happen.
         }
     }
 
@@ -432,24 +427,19 @@
         mode &= ~PhotoActionPopup.Flags.REMOVE_PHOTO;
 
         mPhotoHandler = new PhotoHandler(this, mPhotoView, mode, mState);
-        if (mPendingPhotoResult != null) {
-            mPhotoHandler.handlePhotoActivityResult(mPendingPhotoResult.mRequestCode,
-                    mPendingPhotoResult.mResultCode, mPendingPhotoResult.mData);
-            mPendingPhotoResult = null;
-        } else {
-            // Setting the photo in displayPhoto() resulted in a relayout
-            // request... to avoid jank, wait until this layout has happened.
-            SchedulingUtils.doAfterLayout(mBackdrop, new Runnable() {
-                @Override
-                public void run() {
-                    animatePhotoOpen();
-                }
-            });
-        }
+
+        // Setting the photo in displayPhoto() resulted in a relayout
+        // request... to avoid jank, wait until this layout has happened.
+        SchedulingUtils.doAfterLayout(mBackdrop, new Runnable() {
+            @Override
+            public void run() {
+                animatePhotoOpen();
+            }
+        });
     }
 
     private final class PhotoHandler extends PhotoSelectionHandler {
-        private PhotoActionListener mListener;
+        private final PhotoActionListener mListener;
 
         private PhotoHandler(
                 Context context, View photoView, int photoMode, EntityDeltaList state) {
@@ -496,15 +486,4 @@
             }
         }
     }
-
-    private static class PendingPhotoResult {
-        private int mRequestCode;
-        private int mResultCode;
-        private Intent mData;
-        private PendingPhotoResult(int requestCode, int resultCode, Intent data) {
-            mRequestCode = requestCode;
-            mResultCode = resultCode;
-            mData = data;
-        }
-    }
 }
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 5a6a3b6..7d9f510 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -1027,8 +1027,11 @@
         Intent intent = ContactSaveService.createSaveContactIntent(getActivity(), mState,
                 SAVE_MODE_EXTRA_KEY, saveMode, isEditingUserProfile(), getActivity().getClass(),
                 ContactEditorActivity.ACTION_SAVE_COMPLETED, mUpdatedPhotos);
-
         getActivity().startService(intent);
+
+        // Don't try to save the same photos twice.
+        mUpdatedPhotos = new Bundle();
+
         return true;
     }
 
diff --git a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
index 5c79c45..e358f6f 100644
--- a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
@@ -56,8 +56,6 @@
     private View mSearchProgress;
     private TextView mSearchProgressText;
 
-    private View mPaddingView;
-
     private class FilterHeaderClickListener implements OnClickListener {
         @Override
         public void onClick(View view) {
@@ -258,8 +256,6 @@
         mProfileTitle.setVisibility(show ? View.VISIBLE : View.GONE);
         mMessageContainer.setVisibility(show ? View.VISIBLE : View.GONE);
         mProfileMessage.setVisibility(show ? View.VISIBLE : View.GONE);
-
-        mPaddingView.setVisibility(show ? View.GONE : View.VISIBLE);
     }
 
     /**
@@ -295,11 +291,5 @@
                 startActivity(intent);
             }
         });
-
-        View paddingViewContainer =
-                inflater.inflate(R.layout.contact_detail_list_padding, null, false);
-        mPaddingView = paddingViewContainer.findViewById(R.id.contact_detail_list_padding);
-        mPaddingView.setVisibility(View.GONE);
-        getListView().addHeaderView(paddingViewContainer);
     }
 }