am f95bd0fe: Merge "Argh forget to include my final part of the change." into honeycomb

* commit 'f95bd0feb57f1503be7c08083c0a4d22286256e8':
  Argh forget to include my final part of the change.
This commit is contained in:
Dianne Hackborn
2011-01-25 15:25:39 -08:00
committed by Android Git Automerger
2 changed files with 37 additions and 2 deletions

View File

@@ -85,6 +85,7 @@ public class Dialog implements DialogInterface, Window.Callback,
*/
protected boolean mCancelable = true;
private String mCancelAndDismissTaken;
private Message mCancelMessage;
private Message mDismissMessage;
private Message mShowMessage;
@@ -1029,6 +1030,11 @@ public class Dialog implements DialogInterface, Window.Callback,
* @param listener The {@link DialogInterface.OnCancelListener} to use.
*/
public void setOnCancelListener(final OnCancelListener listener) {
if (mCancelAndDismissTaken != null) {
throw new IllegalStateException(
"OnCancelListener is already taken by "
+ mCancelAndDismissTaken + " and can not be replaced.");
}
if (listener != null) {
mCancelMessage = mListenersHandler.obtainMessage(CANCEL, listener);
} else {
@@ -1050,6 +1056,11 @@ public class Dialog implements DialogInterface, Window.Callback,
* @param listener The {@link DialogInterface.OnDismissListener} to use.
*/
public void setOnDismissListener(final OnDismissListener listener) {
if (mCancelAndDismissTaken != null) {
throw new IllegalStateException(
"OnDismissListener is already taken by "
+ mCancelAndDismissTaken + " and can not be replaced.");
}
if (listener != null) {
mDismissMessage = mListenersHandler.obtainMessage(DISMISS, listener);
} else {
@@ -1077,6 +1088,22 @@ public class Dialog implements DialogInterface, Window.Callback,
mDismissMessage = msg;
}
/** @hide */
public boolean takeCancelAndDismissListeners(String msg, final OnCancelListener cancel,
final OnDismissListener dismiss) {
if (mCancelAndDismissTaken != null) {
mCancelAndDismissTaken = null;
} else if (mCancelMessage != null || mDismissMessage != null) {
return false;
}
setOnCancelListener(cancel);
setOnDismissListener(dismiss);
mCancelAndDismissTaken = msg;
return true;
}
/**
* By default, this will use the owner Activity's suggested stream type.
*

View File

@@ -378,6 +378,12 @@ public class DialogFragment extends Fragment
* default implementation simply instantiates and returns a {@link Dialog}
* class.
*
* <p><em>Note: DialogFragment own the {@link Dialog#setOnCancelListener
* Dialog.setOnCancelListener} and {@link Dialog#setOnDismissListener
* Dialog.setOnDismissListener} callbacks. You must not set them yourself.</em>
* To find out about these events, override {@link #onCancel(DialogInterface)}
* and {@link #onDismiss(DialogInterface)}.</p>
*
* @param savedInstanceState The last saved instance state of the Fragment,
* or null if this is a freshly created Fragment.
*
@@ -417,8 +423,10 @@ public class DialogFragment extends Fragment
}
mDialog.setOwnerActivity(getActivity());
mDialog.setCancelable(mCancelable);
mDialog.setOnCancelListener(this);
mDialog.setOnDismissListener(this);
if (!mDialog.takeCancelAndDismissListeners("DialogFragment", this, this)) {
throw new IllegalStateException(
"You can not set Dialog's OnCancelListener or OnDismissListener");
}
if (savedInstanceState != null) {
Bundle dialogState = savedInstanceState.getBundle(SAVED_DIALOG_STATE_TAG);
if (dialogState != null) {