Refactor Dialogs
Bug:2969342
Change-Id: Ic8d7d4bc6db0ab6b1368035210b2ca2008087d3d
diff --git a/src/com/android/contacts/views/detail/ContactDetailFragment.java b/src/com/android/contacts/views/detail/ContactDetailFragment.java
index c734f84..390a7b1 100644
--- a/src/com/android/contacts/views/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/views/detail/ContactDetailFragment.java
@@ -918,8 +918,8 @@
return; // Don't show a dialog.
}
- final SelectAccountDialogFragment dialog =
- new SelectAccountDialogFragment(getId(), true);
+ final SelectAccountDialogFragment dialog = new SelectAccountDialogFragment(true);
+ dialog.setTargetFragment(this, 0);
dialog.show(getFragmentManager(), SelectAccountDialogFragment.TAG);
break;
}
diff --git a/src/com/android/contacts/views/editor/ContactEditorFragment.java b/src/com/android/contacts/views/editor/ContactEditorFragment.java
index 6699a84..26f5375 100644
--- a/src/com/android/contacts/views/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/views/editor/ContactEditorFragment.java
@@ -19,7 +19,6 @@
import com.android.contacts.JoinContactActivity;
import com.android.contacts.R;
import com.android.contacts.model.ContactsSource;
-import com.android.contacts.model.ContactsSource.EditType;
import com.android.contacts.model.Editor;
import com.android.contacts.model.Editor.EditorListener;
import com.android.contacts.model.EntityDelta;
@@ -42,8 +41,6 @@
import android.accounts.Account;
import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
import android.app.Fragment;
import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
@@ -56,7 +53,6 @@
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Entity;
import android.content.Intent;
import android.content.Loader;
@@ -80,7 +76,6 @@
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
-import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -89,9 +84,7 @@
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewStub;
-import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
-import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;
@@ -106,7 +99,8 @@
public class ContactEditorFragment extends Fragment implements
SplitContactConfirmationDialogFragment.Listener, PickPhotoDialogFragment.Listener,
- SelectAccountDialogFragment.Listener, AggregationSuggestionEngine.Listener {
+ SelectAccountDialogFragment.Listener, ModifyPhotoDialogFragment.Listener,
+ AggregationSuggestionEngine.Listener {
private static final String TAG = "ContactEditorFragment";
@@ -263,8 +257,7 @@
Log.d(TAG, "onActivityCreated(" + savedInstanceState + ")");
// Handle initial actions only when existing state missing
- final boolean hasIncomingState = savedInstanceState != null &&
- savedInstanceState.containsKey(KEY_EDIT_STATE);
+ final boolean hasIncomingState = savedInstanceState != null;
if (!hasIncomingState) {
if (Intent.ACTION_EDIT.equals(mAction)) {
@@ -371,9 +364,9 @@
return; // Don't show a dialog.
}
- final SelectAccountDialogFragment dialog = new SelectAccountDialogFragment(getId(),
- isNewContact);
- dialog.show(getActivity(), SelectAccountDialogFragment.TAG);
+ final SelectAccountDialogFragment dialog = new SelectAccountDialogFragment(isNewContact);
+ dialog.setTargetFragment(this, 0);
+ dialog.show(getFragmentManager(), SelectAccountDialogFragment.TAG);
}
/**
@@ -446,8 +439,31 @@
R.layout.item_read_only_contact_editor, mContent, false);
}
final PhotoEditorView photoEditor = editor.getPhotoEditor();
- photoEditor.setEditorListener(new PhotoListener(rawContactId, source.readOnly,
- photoEditor));
+ final boolean sourceReadOnly = source.readOnly;
+ photoEditor.setEditorListener(new EditorListener() {
+ @Override
+ public void onRequest(int request) {
+ if (!hasValidState()) return;
+
+ if (request == EditorListener.REQUEST_PICK_PHOTO) {
+ if (editor.hasSetPhoto()) {
+ // There is an existing photo, offer to remove, replace, or promote to
+ // primary
+ final ModifyPhotoDialogFragment fragment =
+ new ModifyPhotoDialogFragment(sourceReadOnly, rawContactId);
+ fragment.setTargetFragment(ContactEditorFragment.this, 0);
+ fragment.show(getFragmentManager(), ModifyPhotoDialogFragment.TAG);
+ } else if (!sourceReadOnly) {
+ // No photo set and not read-only, try to set the photo
+ doPickPhotoAction(rawContactId);
+ }
+ }
+ }
+
+ @Override
+ public void onDeleted(Editor removedEditor) {
+ }
+ });
mContent.addView(editor);
editor.setState(entity, source, mViewIdGenerator);
@@ -463,7 +479,7 @@
}
@Override
- public void onDeleted(Editor editor) {
+ public void onDeleted(Editor removedEditor) {
}
});
@@ -545,8 +561,9 @@
if (!hasValidState()) return false;
mRawContactIdRequestingPhoto = rawContactId;
- final PickPhotoDialogFragment dialogFragment = new PickPhotoDialogFragment(getId());
- dialogFragment.show(getActivity(), PickPhotoDialogFragment.TAG);
+ final PickPhotoDialogFragment dialogFragment = new PickPhotoDialogFragment();
+ dialogFragment.setTargetFragment(this, 0);
+ dialogFragment.show(getFragmentManager(), PickPhotoDialogFragment.TAG);
return true;
}
@@ -555,8 +572,9 @@
if (!hasValidState()) return false;
final SplitContactConfirmationDialogFragment dialog =
- new SplitContactConfirmationDialogFragment(getId());
- dialog.show(getActivity(), SplitContactConfirmationDialogFragment.TAG);
+ new SplitContactConfirmationDialogFragment();
+ dialog.setTargetFragment(this, 0);
+ dialog.show(getFragmentManager(), SplitContactConfirmationDialogFragment.TAG);
return true;
}
@@ -894,6 +912,7 @@
/**
* Compare EntityDeltas for sorting the stack of editors.
*/
+ @Override
public int compare(EntityDelta one, EntityDelta two) {
// Check direct equality
if (one.equals(two)) {
@@ -964,105 +983,6 @@
}
/**
- * Class that listens to requests coming from photo editors
- */
- private class PhotoListener implements EditorListener, DialogInterface.OnClickListener {
- private long mRawContactId;
- private boolean mReadOnly;
- private PhotoEditorView mEditor;
-
- public PhotoListener(long rawContactId, boolean readOnly, PhotoEditorView editor) {
- mRawContactId = rawContactId;
- mReadOnly = readOnly;
- mEditor = editor;
- }
-
- public void onDeleted(Editor editor) {
- // Do nothing
- }
-
- public void onRequest(int request) {
- if (!hasValidState()) return;
-
- if (request == EditorListener.REQUEST_PICK_PHOTO) {
- if (mEditor.hasSetPhoto()) {
- // There is an existing photo, offer to remove, replace, or promoto to primary
- createPhotoDialog().show();
- } else if (!mReadOnly) {
- // No photo set and not read-only, try to set the photo
- doPickPhotoAction(mRawContactId);
- }
- }
- }
-
- /**
- * Prepare dialog for picking a new {@link EditType} or entering a
- * custom label. This dialog is limited to the valid types as determined
- * by {@link EntityModifier}.
- */
- public Dialog createPhotoDialog() {
- // Wrap our context to inflate list items using correct theme
- final Context dialogContext = new ContextThemeWrapper(mContext,
- android.R.style.Theme_Light);
-
- String[] choices;
- if (mReadOnly) {
- choices = new String[1];
- choices[0] = mContext.getString(R.string.use_photo_as_primary);
- } else {
- choices = new String[3];
- choices[0] = mContext.getString(R.string.use_photo_as_primary);
- choices[1] = mContext.getString(R.string.removePicture);
- choices[2] = mContext.getString(R.string.changePicture);
- }
- final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
- android.R.layout.simple_list_item_1, choices);
-
- final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
- builder.setTitle(R.string.attachToContact);
- builder.setSingleChoiceItems(adapter, -1, this);
- return builder.create();
- }
-
- /**
- * Called when something in the dialog is clicked
- */
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
-
- switch (which) {
- case 0:
- // Set the photo as super primary
- mEditor.setSuperPrimary(true);
-
- // And set all other photos as not super primary
- int count = mContent.getChildCount();
- for (int i = 0; i < count; i++) {
- View childView = mContent.getChildAt(i);
- if (childView instanceof BaseContactEditorView) {
- BaseContactEditorView editor = (BaseContactEditorView) childView;
- PhotoEditorView photoEditor = editor.getPhotoEditor();
- if (!photoEditor.equals(mEditor)) {
- photoEditor.setSuperPrimary(false);
- }
- }
- }
- break;
-
- case 1:
- // Remove the photo
- mEditor.setPhotoBitmap(null);
- break;
-
- case 2:
- // Pick a new photo for the contact
- doPickPhotoAction(mRawContactId);
- break;
- }
- }
- }
-
- /**
* Returns the contact ID for the currently edited contact or 0 if the contact is new.
*/
protected long getContactId() {
@@ -1492,8 +1412,8 @@
case REQUEST_CODE_PHOTO_PICKED_WITH_DATA: {
// As we are coming back to this view, the editor will be reloaded automatically,
// which will cause the photo that is set here to disappear. To prevent this,
- // we remember set a flag which is interpreted after loading.
- // This is set here anyway to reduce flickering
+ // we remember to set a flag which is interpreted after loading.
+ // This photo is set here already to reduce flickering.
mPhoto = data.getParcelableExtra("data");
setPhoto(mRawContactIdRequestingPhoto, mPhoto);
mRawContactIdRequestingPhotoAfterLoad = mRawContactIdRequestingPhoto;
@@ -1501,7 +1421,6 @@
break;
}
-
case REQUEST_CODE_CAMERA_WITH_DATA: {
doCropPhoto(mCurrentPhotoFile);
break;
@@ -1511,6 +1430,7 @@
final long contactId = ContentUris.parseId(data.getData());
joinAggregate(contactId);
}
+ break;
}
}
}
@@ -1629,9 +1549,54 @@
*/
@Override
public void onAccountSelectorCancelled() {
- // If nothing remains, close activity
- if (!hasValidState()) {
- if (mListener != null) mListener.onAccountSelectorAborted();
+ if (!hasValidState() && mListener != null) {
+ mListener.onAccountSelectorAborted();
}
}
+
+ /**
+ * User has chosen to set the selected photo as the (super) primary photo
+ */
+ @Override
+ public void onUseAsPrimaryChosen(long rawContactId) {
+ // Set the IsSuperPrimary for each editor
+ int count = mContent.getChildCount();
+ for (int i = 0; i < count; i++) {
+ final View childView = mContent.getChildAt(i);
+ if (childView instanceof BaseContactEditorView) {
+ final BaseContactEditorView editor = (BaseContactEditorView) childView;
+ final PhotoEditorView photoEditor = editor.getPhotoEditor();
+ photoEditor.setSuperPrimary(editor.getRawContactId() == rawContactId);
+ }
+ }
+ }
+
+ /**
+ * User has chosen to remove a picture
+ */
+ @Override
+ public void onRemovePictureChose(long rawContactId) {
+ // find the correct editor and remove it's photo
+ final int editorCount = mContent.getChildCount();
+ for (int i = 0; i < editorCount; i++) {
+ final View child = mContent.getChildAt(i);
+ if (child instanceof BaseContactEditorView) {
+ final BaseContactEditorView editor =
+ (BaseContactEditorView) child;
+ if (editor.getRawContactId() == rawContactId) {
+ editor.setPhotoBitmap(null);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * User has chosen to change a picture
+ */
+ @Override
+ public void onChangePictureChosen(long rawContactId) {
+ // Pick a new photo for the contact
+ doPickPhotoAction(rawContactId);
+ }
}
diff --git a/src/com/android/contacts/views/editor/ModifyPhotoDialogFragment.java b/src/com/android/contacts/views/editor/ModifyPhotoDialogFragment.java
new file mode 100644
index 0000000..a7b6efe
--- /dev/null
+++ b/src/com/android/contacts/views/editor/ModifyPhotoDialogFragment.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2010 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.views.editor;
+
+import com.android.contacts.R;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.Fragment;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.view.ContextThemeWrapper;
+import android.widget.ArrayAdapter;
+import android.widget.ListAdapter;
+
+/**
+ * Shows a dialog asking the user what to do with an existing photo.
+ * The result is passed back to the Fragment that is configured by
+ * {@link Fragment#setTargetFragment(Fragment, int)}, which
+ * has to implement {@link ModifyPhotoDialogFragment.Listener}.
+ * Does not perform any action by itself.
+ */
+public class ModifyPhotoDialogFragment extends DialogFragment {
+ public static final String TAG = "PhotoDialogFragment";
+ private static final String BUNDLE_IS_READ_ONLY = "IS_READ_ONLY";
+ private static final String BUNDLE_RAW_CONTACT_ID = "RAW_CONTACT_ID";
+
+ private boolean mIsReadOnly;
+ private long mRawContactId;
+
+ public ModifyPhotoDialogFragment() {
+ }
+
+ public ModifyPhotoDialogFragment(boolean isReadOnly, long rawContactId) {
+ mIsReadOnly = isReadOnly;
+ mRawContactId = rawContactId;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (savedInstanceState != null) {
+ mIsReadOnly = savedInstanceState.getBoolean(BUNDLE_IS_READ_ONLY);
+ mRawContactId = savedInstanceState.getLong(BUNDLE_RAW_CONTACT_ID);
+ }
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(BUNDLE_IS_READ_ONLY, mIsReadOnly);
+ outState.putLong(BUNDLE_RAW_CONTACT_ID, mRawContactId);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ // Wrap our context to inflate list items using correct theme
+ final Activity context = getActivity();
+ final Context dialogContext = new ContextThemeWrapper(context,
+ android.R.style.Theme_Light);
+
+ final String[] choices;
+ if (mIsReadOnly) {
+ choices = new String[1];
+ choices[0] = context.getString(R.string.use_photo_as_primary);
+ } else {
+ choices = new String[3];
+ choices[0] = context.getString(R.string.use_photo_as_primary);
+ choices[1] = context.getString(R.string.removePicture);
+ choices[2] = context.getString(R.string.changePicture);
+ }
+ final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
+ android.R.layout.simple_list_item_1, choices);
+
+ final DialogInterface.OnClickListener clickListener =
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+
+ final Listener target = (Listener) getTargetFragment();
+ switch (which) {
+ case 0:
+ target.onUseAsPrimaryChosen(mRawContactId);
+ break;
+ case 1:
+ target.onRemovePictureChose(mRawContactId);
+ break;
+ case 2:
+ target.onChangePictureChosen(mRawContactId);
+ break;
+ }
+ }
+ };
+
+ final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
+ builder.setTitle(R.string.attachToContact);
+ builder.setSingleChoiceItems(adapter, -1, clickListener);
+ return builder.create();
+ }
+
+ public interface Listener {
+ void onUseAsPrimaryChosen(long rawContactId);
+ void onRemovePictureChose(long rawContactId);
+ void onChangePictureChosen(long rawContactId);
+ }
+}
diff --git a/src/com/android/contacts/views/editor/PickPhotoDialogFragment.java b/src/com/android/contacts/views/editor/PickPhotoDialogFragment.java
index d93497d..44e2001 100644
--- a/src/com/android/contacts/views/editor/PickPhotoDialogFragment.java
+++ b/src/com/android/contacts/views/editor/PickPhotoDialogFragment.java
@@ -20,6 +20,8 @@
import android.app.AlertDialog;
import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
@@ -29,21 +31,18 @@
/**
* Shows a dialog asking the user whether to take a photo or pick a photo from the gallery.
- * The result is passed back to the Fragment with the Id that is passed in the constructor
- * (or the Activity if -1 is passed).
- * The target must implement {@link PickPhotoDialogFragment.Listener}.
+ * The result is passed back to the Fragment that is configured by
+ * {@link Fragment#setTargetFragment(Fragment, int)}, which
+ * has to implement {@link PickPhotoDialogFragment.Listener}.
* Does not perform any action by itself.
*/
-public class PickPhotoDialogFragment extends TargetedDialogFragment {
+public class PickPhotoDialogFragment extends DialogFragment {
public static final String TAG = "PickPhotoDialogFragment";
public PickPhotoDialogFragment() {
}
- public PickPhotoDialogFragment(int targetFragmentId) {
- super(targetFragmentId);
- }
-
+ @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Wrap our context to inflate list items using the light theme
final Context dialogContext = new ContextThemeWrapper(getActivity(),
@@ -58,9 +57,10 @@
final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
builder.setTitle(R.string.attachToContact);
builder.setSingleChoiceItems(adapter, -1, new DialogInterface.OnClickListener() {
+ @Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
- final Listener targetListener = (Listener) getTarget();
+ final Listener targetListener = (Listener) getTargetFragment();
switch(which) {
case 0:
targetListener.onTakePhotoChosen();
diff --git a/src/com/android/contacts/views/editor/SelectAccountDialogFragment.java b/src/com/android/contacts/views/editor/SelectAccountDialogFragment.java
index 3740fe3..4441a4d 100644
--- a/src/com/android/contacts/views/editor/SelectAccountDialogFragment.java
+++ b/src/com/android/contacts/views/editor/SelectAccountDialogFragment.java
@@ -23,6 +23,8 @@
import android.accounts.Account;
import android.app.AlertDialog;
import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
@@ -37,12 +39,12 @@
/**
* Shows a dialog asking the user which account to chose.
- * The result is passed back to the Fragment with the Id that is passed in the constructor
- * (or the Activity if -1 is passed).
- * The target must implement {@link SelectAccountDialogFragment.Listener}.
+ * The result is passed back to the Fragment that is configured by
+ * {@link Fragment#setTargetFragment(Fragment, int)}, which has to implement
+ * {@link SelectAccountDialogFragment.Listener}.
* Does not perform any action by itself.
*/
-public class SelectAccountDialogFragment extends TargetedDialogFragment {
+public class SelectAccountDialogFragment extends DialogFragment {
public static final String TAG = "SelectAccountDialogFragment";
private static final String IS_NEW_CONTACT = "IS_NEW_CONTACT";
@@ -51,8 +53,7 @@
public SelectAccountDialogFragment() {
}
- public SelectAccountDialogFragment(int targetFragmentId, boolean isNewContact) {
- super(targetFragmentId);
+ public SelectAccountDialogFragment(boolean isNewContact) {
mIsNewContact = isNewContact;
}
@@ -85,14 +86,17 @@
android.R.layout.simple_list_item_2, accounts) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
+ final View resultView;
if (convertView == null) {
- convertView = dialogInflater.inflate(android.R.layout.simple_list_item_2,
+ resultView = dialogInflater.inflate(android.R.layout.simple_list_item_2,
parent, false);
+ } else {
+ resultView = convertView;
}
// TODO: show icon along with title
- final TextView text1 = (TextView)convertView.findViewById(android.R.id.text1);
- final TextView text2 = (TextView)convertView.findViewById(android.R.id.text2);
+ final TextView text1 = (TextView)resultView.findViewById(android.R.id.text1);
+ final TextView text2 = (TextView)resultView.findViewById(android.R.id.text2);
final Account account = this.getItem(position);
final ContactsSource source = sources.getInflatedSource(account.type,
@@ -101,24 +105,27 @@
text1.setText(account.name);
text2.setText(source.getDisplayLabel(getContext()));
- return convertView;
+ return resultView;
}
};
- final Listener targetListener = (Listener) getTarget();
final DialogInterface.OnClickListener clickListener =
new DialogInterface.OnClickListener() {
+ @Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
- targetListener.onAccountChosen(accountAdapter.getItem(which), mIsNewContact);
+ final Listener target = (Listener) getTargetFragment();
+ target.onAccountChosen(accountAdapter.getItem(which), mIsNewContact);
}
};
final DialogInterface.OnCancelListener cancelListener =
new DialogInterface.OnCancelListener() {
+ @Override
public void onCancel(DialogInterface dialog) {
- targetListener.onAccountSelectorCancelled();
+ final Listener target = (Listener) getTargetFragment();
+ target.onAccountSelectorCancelled();
}
};
diff --git a/src/com/android/contacts/views/editor/SplitContactConfirmationDialogFragment.java b/src/com/android/contacts/views/editor/SplitContactConfirmationDialogFragment.java
index 4089abf..ee5dba3 100644
--- a/src/com/android/contacts/views/editor/SplitContactConfirmationDialogFragment.java
+++ b/src/com/android/contacts/views/editor/SplitContactConfirmationDialogFragment.java
@@ -20,25 +20,23 @@
import android.app.AlertDialog;
import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Bundle;
/**
* Shows a dialog asking the user whether to split the contact. The result is passed back
- * to the Fragment with the Id that is passed in the constructor (or the Activity if -1 is passed).
- * The target must implement {@link SplitContactConfirmationDialogFragment.Listener}
+ * to the Fragment that is configured by {@link Fragment#setTargetFragment(Fragment, int)}, which
+ * has to implement {@link SplitContactConfirmationDialogFragment.Listener}.
* Does not split the contact itself.
*/
-public class SplitContactConfirmationDialogFragment extends TargetedDialogFragment {
+public class SplitContactConfirmationDialogFragment extends DialogFragment {
public static final String TAG = "SplitContactConfirmationDialog";
public SplitContactConfirmationDialogFragment() {
}
- public SplitContactConfirmationDialogFragment(int targetFragmentId) {
- super(targetFragmentId);
- }
-
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
@@ -46,8 +44,9 @@
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setMessage(R.string.splitConfirmation);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
public void onClick(DialogInterface dialog, int which) {
- final Listener targetListener = (Listener) getTarget();
+ final Listener targetListener = (Listener) getTargetFragment();
targetListener.onSplitContactConfirmed();
}
});
diff --git a/src/com/android/contacts/views/editor/TargetedDialogFragment.java b/src/com/android/contacts/views/editor/TargetedDialogFragment.java
deleted file mode 100644
index ee0047d..0000000
--- a/src/com/android/contacts/views/editor/TargetedDialogFragment.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2010 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.views.editor;
-
-import android.app.DialogFragment;
-import android.os.Bundle;
-
-/**
- * A DialogFragment that can send its result to a target (which is either an Activity or a Fragment)
- * TODO: This should be removed once there is Framework support for handling of Targets.
- */
-public class TargetedDialogFragment extends DialogFragment {
- private static final String TARGET_FRAGMENT_ID = "TARGET_FRAGMENT_ID";
-
- private int mTargetFragmentId;
-
- public TargetedDialogFragment() {
- mTargetFragmentId = -1;
- }
-
- public TargetedDialogFragment(int targetFragmentId) {
- mTargetFragmentId = targetFragmentId;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (savedInstanceState != null) {
- mTargetFragmentId = savedInstanceState.getInt(TARGET_FRAGMENT_ID);
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putInt(TARGET_FRAGMENT_ID, mTargetFragmentId);
- }
-
- protected Object getTarget() {
- return mTargetFragmentId == -1 ? getActivity()
- : getActivity().getFragmentManager().findFragmentById(mTargetFragmentId);
- }
-}