Wrap show dialog fragment in isSafeToCommitTransactions check

The dialog fragment is shown from an onClick handler which can be
run after onSaveInstanceState is called which results in the
IllegalStateException. Our base activity classes already have a
method to check for this, so call it before attempting to show the
dialog fragment.

Also delete an unused class.

Test: N/A

Bug: 33341841
Change-Id: I1e27bd473666025251c95f8d497c71a248a5a2c8
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5674fc5..053d0e3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -439,11 +439,6 @@
 
     <!-- The message in a confirmation dialog shown when the user selects a
         contact aggregation suggestion in Contact editor. [CHAR LIMIT=512]-->
-    <string name="aggregation_suggestion_join_dialog_message">Link
-        the current contact with the selected contact?</string>
-
-    <!-- The message in a confirmation dialog shown when the user selects a
-        contact aggregation suggestion in Contact editor. [CHAR LIMIT=512]-->
     <string name="aggregation_suggestion_edit_dialog_message">Switch to editing
         the selected contact? Information you entered so far will be copied.</string>
 
diff --git a/src/com/android/contacts/activities/ContactEditorActivity.java b/src/com/android/contacts/activities/ContactEditorActivity.java
index abb8463..326ff93 100644
--- a/src/com/android/contacts/activities/ContactEditorActivity.java
+++ b/src/com/android/contacts/activities/ContactEditorActivity.java
@@ -468,7 +468,12 @@
      */
     public void changePhoto(int photoMode) {
         mPhotoMode = photoMode;
-        PhotoSourceDialogFragment.show(this, mPhotoMode);
+        // This method is called from an onClick handler in the PhotoEditorView. It's possible for
+        // onClick methods to run after onSaveInstanceState is called for the activity, so check
+        // if it's safe to commit transactions before trying.
+        if (isSafeToCommitTransactions()) {
+            PhotoSourceDialogFragment.show(this, mPhotoMode);
+        }
     }
 
     public Toolbar getToolbar() {
diff --git a/src/com/android/contacts/editor/JoinSuggestedContactDialogFragment.java b/src/com/android/contacts/editor/JoinSuggestedContactDialogFragment.java
deleted file mode 100644
index be3313b..0000000
--- a/src/com/android/contacts/editor/JoinSuggestedContactDialogFragment.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.contacts.editor;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.content.DialogInterface;
-import android.os.Bundle;
-
-import com.android.contacts.R;
-
-public class JoinSuggestedContactDialogFragment extends DialogFragment {
-
-    private static final String ARG_RAW_CONTACT_IDS = "rawContactIds";
-
-    public static void show(ContactEditorFragment fragment, long[] rawContactIds) {
-        final Bundle args = new Bundle();
-        args.putLongArray(ARG_RAW_CONTACT_IDS, rawContactIds);
-
-        final JoinSuggestedContactDialogFragment dialog = new JoinSuggestedContactDialogFragment();
-        dialog.setArguments(args);
-        dialog.setTargetFragment(fragment, 0);
-        dialog.show(fragment.getFragmentManager(), "join");
-    }
-
-    @Override
-    public Dialog onCreateDialog(Bundle savedInstanceState) {
-        return new AlertDialog.Builder(getActivity())
-                .setIconAttribute(android.R.attr.alertDialogIcon)
-                .setMessage(R.string.aggregation_suggestion_join_dialog_message)
-                .setPositiveButton(android.R.string.yes,
-                        new DialogInterface.OnClickListener() {
-                            @Override
-                            public void onClick(DialogInterface dialog, int whichButton) {
-                                ContactEditorFragment targetFragment =
-                                        (ContactEditorFragment) getTargetFragment();
-                                long rawContactIds[] =
-                                        getArguments().getLongArray(ARG_RAW_CONTACT_IDS);
-                                targetFragment.doJoinSuggestedContact(rawContactIds);
-                            }
-                        }
-                )
-                .setNegativeButton(android.R.string.no, null)
-                .create();
-    }
-}