Merge change 7135 into donut

* changes:
  Fixes lock on Home. Adds a new API on Dialog to get a callback when the dialog shows.
This commit is contained in:
Android (Google) Code Review
2009-07-14 14:51:06 -07:00
2 changed files with 48 additions and 6 deletions

View File

@@ -86,6 +86,7 @@ public class Dialog implements DialogInterface, Window.Callback,
private Message mCancelMessage; private Message mCancelMessage;
private Message mDismissMessage; private Message mDismissMessage;
private Message mShowMessage;
/** /**
* Whether to cancel the dialog when a touch is received outside of the * Whether to cancel the dialog when a touch is received outside of the
@@ -140,7 +141,7 @@ public class Dialog implements DialogInterface, Window.Callback,
w.setWindowManager(mWindowManager, null, null); w.setWindowManager(mWindowManager, null, null);
w.setGravity(Gravity.CENTER); w.setGravity(Gravity.CENTER);
mUiThread = Thread.currentThread(); mUiThread = Thread.currentThread();
mDismissCancelHandler = new DismissCancelHandler(this); mListenersHandler = new ListenersHandler(this);
} }
/** /**
@@ -235,6 +236,8 @@ public class Dialog implements DialogInterface, Window.Callback,
} }
mWindowManager.addView(mDecor, l); mWindowManager.addView(mDecor, l);
mShowing = true; mShowing = true;
sendShowMessage();
} }
/** /**
@@ -289,6 +292,13 @@ public class Dialog implements DialogInterface, Window.Callback,
} }
} }
private void sendShowMessage() {
if (mShowMessage != null) {
// Obtain a new message so this dialog can be re-used
Message.obtain(mShowMessage).sendToTarget();
}
}
// internal method to make sure mcreated is set properly without requiring // internal method to make sure mcreated is set properly without requiring
// users to call through to super in onCreate // users to call through to super in onCreate
void dispatchOnCreate(Bundle savedInstanceState) { void dispatchOnCreate(Bundle savedInstanceState) {
@@ -890,7 +900,7 @@ public class Dialog implements DialogInterface, Window.Callback,
*/ */
public void setOnCancelListener(final OnCancelListener listener) { public void setOnCancelListener(final OnCancelListener listener) {
if (listener != null) { if (listener != null) {
mCancelMessage = mDismissCancelHandler.obtainMessage(CANCEL, listener); mCancelMessage = mListenersHandler.obtainMessage(CANCEL, listener);
} else { } else {
mCancelMessage = null; mCancelMessage = null;
} }
@@ -911,12 +921,25 @@ public class Dialog implements DialogInterface, Window.Callback,
*/ */
public void setOnDismissListener(final OnDismissListener listener) { public void setOnDismissListener(final OnDismissListener listener) {
if (listener != null) { if (listener != null) {
mDismissMessage = mDismissCancelHandler.obtainMessage(DISMISS, listener); mDismissMessage = mListenersHandler.obtainMessage(DISMISS, listener);
} else { } else {
mDismissMessage = null; mDismissMessage = null;
} }
} }
/**
* Sets a listener to be invoked when the dialog is shown.
*
* @hide Pending API council approval
*/
public void setOnShowListener(OnShowListener listener) {
if (listener != null) {
mShowMessage = mListenersHandler.obtainMessage(SHOW, listener);
} else {
mShowMessage = null;
}
}
/** /**
* Set a message to be sent when the dialog is dismissed. * Set a message to be sent when the dialog is dismissed.
* @param msg The msg to send when the dialog is dismissed. * @param msg The msg to send when the dialog is dismissed.
@@ -951,13 +974,14 @@ public class Dialog implements DialogInterface, Window.Callback,
private static final int DISMISS = 0x43; private static final int DISMISS = 0x43;
private static final int CANCEL = 0x44; private static final int CANCEL = 0x44;
private static final int SHOW = 0x45;
private Handler mDismissCancelHandler; private Handler mListenersHandler;
private static final class DismissCancelHandler extends Handler { private static final class ListenersHandler extends Handler {
private WeakReference<DialogInterface> mDialog; private WeakReference<DialogInterface> mDialog;
public DismissCancelHandler(Dialog dialog) { public ListenersHandler(Dialog dialog) {
mDialog = new WeakReference<DialogInterface>(dialog); mDialog = new WeakReference<DialogInterface>(dialog);
} }
@@ -970,6 +994,9 @@ public class Dialog implements DialogInterface, Window.Callback,
case CANCEL: case CANCEL:
((OnCancelListener) msg.obj).onCancel(mDialog.get()); ((OnCancelListener) msg.obj).onCancel(mDialog.get());
break; break;
case SHOW:
((OnShowListener) msg.obj).onShow(mDialog.get());
break;
} }
} }
} }

View File

@@ -91,6 +91,21 @@ public interface DialogInterface {
public void onDismiss(DialogInterface dialog); public void onDismiss(DialogInterface dialog);
} }
/**
* Interface used to allow the creator of a dialog to run some code when the
* dialog is shown.
* @hide Pending API council approval
*/
interface OnShowListener {
/**
* This method will be invoked when the dialog is shown.
*
* @param dialog The dialog that was shown will be passed into the
* method.
*/
public void onShow(DialogInterface dialog);
}
/** /**
* Interface used to allow the creator of a dialog to run some code when an * Interface used to allow the creator of a dialog to run some code when an
* item on the dialog is clicked.. * item on the dialog is clicked..