Supress "saved" Toasts when expanding the compact editor

Bug 19124091

Change-Id: I38a329be3f997ae93ec90810d24473f5ef800488
diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
index f25d01a..22396a6 100644
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -134,6 +134,7 @@
     private long mPhotoRawContactId;
     private Bundle mUpdatedPhotos = new Bundle();
     private MaterialColorMapUtils.MaterialPalette mMaterialPalette;
+    private boolean mShowToastAfterSave = true;
 
     @Override
     public void onCreate(Bundle savedState) {
@@ -289,6 +290,11 @@
     }
 
     @Override
+    protected boolean showToastAfterSave() {
+        return mShowToastAfterSave;
+    }
+
+    @Override
     protected boolean doSaveAction(int saveMode) {
         // Save contact
         final Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState,
@@ -353,7 +359,8 @@
             // Pass on all the data that has been entered so far
             ArrayList<ContentValues> contentValues = mState.get(0).getContentValues();
             if (contentValues != null && contentValues.size() != 0) {
-                intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, contentValues);
+                intent.putParcelableArrayListExtra(
+                        ContactsContract.Intents.Insert.DATA, contentValues);
             }
             // Name must be passed separately since it is skipped in RawContactModifier.parseValues
             final StructuredNameEditorView structuredNameEditorView =
@@ -366,7 +373,10 @@
             }
             getActivity().finish();
         } else {
-            // Whatever is in the form will be saved when the hosting activity is finished
+            // Prevent a Toast from being displayed as we transition to the full editor
+            mShowToastAfterSave = false;
+
+            // Save whatever is in the form
             save(SaveMode.RELOAD);
         }
 
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index 57905d1..ecba02b 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -1273,7 +1273,7 @@
             Uri contactLookupUri) {
         if (hadChanges) {
             if (saveSucceeded) {
-                if (saveMode != SaveMode.JOIN) {
+                if (saveMode != SaveMode.JOIN && showToastAfterSave()) {
                     Toast.makeText(mContext, R.string.contactSavedToast, Toast.LENGTH_SHORT).show();
                 }
             } else {
@@ -1327,6 +1327,14 @@
     }
 
     /**
+     * Whether to show a Toast message after saves have completed.
+     * Does not affect successful toasts shown after joins, which are never displayed.
+     */
+    protected boolean showToastAfterSave() {
+        return true;
+    }
+
+    /**
      * Shows a list of aggregates that can be joined into the currently viewed aggregate.
      *
      * @param contactLookupUri the fresh URI for the currently edited contact (after saving it)