Methods Summary |
---|
public void | addContentView(android.view.View view, ViewGroup.LayoutParams params)Add an additional content view to the screen. Added after any existing
ones in the screen -- existing views are NOT removed.
mWindow.addContentView(view, params);
|
public void | cancel()Cancel the dialog. This is essentially the same as calling {@link #dismiss()}, but it will
also call your {@link DialogInterface.OnCancelListener} (if registered).
if (mCancelMessage != null) {
// Obtain a new message so this dialog can be re-used
Message.obtain(mCancelMessage).sendToTarget();
}
dismiss();
|
public void | closeOptionsMenu()
mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL);
|
public void | dismiss()Dismiss this dialog, removing it from the screen. This method can be
invoked safely from any thread. Note that you should not override this
method to do cleanup when the dialog is dismissed, instead implement
that in {@link #onStop}.
if (Thread.currentThread() != mUiThread) {
mHandler.post(mDismissAction);
} else {
mDismissAction.run();
}
|
private void | dismissDialog()
if (mDecor == null) {
if (Config.LOGV) Log.v(LOG_TAG,
"[Dialog] dismiss: already dismissed, ignore");
return;
}
if (!mShowing) {
if (Config.LOGV) Log.v(LOG_TAG,
"[Dialog] dismiss: not showing, ignore");
return;
}
mWindowManager.removeView(mDecor);
mDecor = null;
mWindow.closeAllPanels();
onStop();
mShowing = false;
sendDismissMessage();
|
public boolean | dispatchKeyEvent(android.view.KeyEvent event)Called to process key events. You can override this to intercept all
key events before they are dispatched to the window. Be sure to call
this implementation for key events that should be handled normally.
if ((mOnKeyListener != null) && (mOnKeyListener.onKey(this, event.getKeyCode(), event))) {
return true;
}
if (mWindow.superDispatchKeyEvent(event)) {
return true;
}
return event.dispatch(this);
|
void | dispatchOnCreate(android.os.Bundle savedInstanceState)
onCreate(savedInstanceState);
mCreated = true;
|
public boolean | dispatchTouchEvent(android.view.MotionEvent ev)Called to process touch screen events. You can override this to
intercept all touch screen events before they are dispatched to the
window. Be sure to call this implementation for touch screen events
that should be handled normally.
if (mWindow.superDispatchTouchEvent(ev)) {
return true;
}
return onTouchEvent(ev);
|
public boolean | dispatchTrackballEvent(android.view.MotionEvent ev)Called to process trackball events. You can override this to
intercept all trackball events before they are dispatched to the
window. Be sure to call this implementation for trackball events
that should be handled normally.
if (mWindow.superDispatchTrackballEvent(ev)) {
return true;
}
return onTrackballEvent(ev);
|
public android.view.View | findViewById(int id)Finds a view that was identified by the id attribute from the XML that
was processed in {@link #onStart}.
return mWindow.findViewById(id);
|
public final android.content.Context | getContext()Retrieve the Context this Dialog is running in.
return mContext;
|
public android.view.View | getCurrentFocus()Call {@link android.view.Window#getCurrentFocus} on the
Window if this Activity to return the currently focused view.
return mWindow != null ? mWindow.getCurrentFocus() : null;
|
public android.view.LayoutInflater | getLayoutInflater()
return getWindow().getLayoutInflater();
|
public final Activity | getOwnerActivity()Returns the Activity that owns this Dialog. For example, if
{@link Activity#showDialog(int)} is used to show this Dialog, that
Activity will be the owner (by default). Depending on how this dialog was
created, this may return null.
return mOwnerActivity;
|
public final int | getVolumeControlStream()
return getWindow().getVolumeControlStream();
|
public android.view.Window | getWindow()Retrieve the current Window for the activity. This can be used to
directly access parts of the Window API that are not available
through Activity/Screen.
return mWindow;
|
public void | hide()Hide the dialog, but do not dismiss it.
if (mDecor != null) mDecor.setVisibility(View.GONE);
|
private boolean | isOutOfBounds(android.view.MotionEvent event)
final int x = (int) event.getX();
final int y = (int) event.getY();
final int slop = ViewConfiguration.get(mContext).getScaledWindowTouchSlop();
final View decorView = getWindow().getDecorView();
return (x < -slop) || (y < -slop)
|| (x > (decorView.getWidth()+slop))
|| (y > (decorView.getHeight()+slop));
|
public boolean | isShowing()
return mShowing;
|
public void | onContentChanged()
|
public boolean | onContextItemSelected(android.view.MenuItem item)
return false;
|
public void | onContextMenuClosed(android.view.Menu menu)
|
protected void | onCreate(android.os.Bundle savedInstanceState)Similar to {@link Activity#onCreate}, you should initialized your dialog
in this method, including calling {@link #setContentView}.
|
public void | onCreateContextMenu(android.view.ContextMenu menu, android.view.View v, android.view.ContextMenu.ContextMenuInfo menuInfo)
|
public boolean | onCreateOptionsMenu(android.view.Menu menu)It is usually safe to proxy this call to the owner activity's
{@link Activity#onCreateOptionsMenu(Menu)} if the client desires the same
menu for this Dialog.
return true;
|
public boolean | onCreatePanelMenu(int featureId, android.view.Menu menu)
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
return onCreateOptionsMenu(menu);
}
return false;
|
public android.view.View | onCreatePanelView(int featureId)
return null;
|
public boolean | onKeyDown(int keyCode, android.view.KeyEvent event)A key was pressed down.
If the focused view didn't want this event, this method is called.
The default implementation handles KEYCODE_BACK to close the
dialog.
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (mCancelable) {
cancel();
}
return true;
}
return false;
|
public boolean | onKeyMultiple(int keyCode, int repeatCount, android.view.KeyEvent event)Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent)
KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle
the event).
return false;
|
public boolean | onKeyUp(int keyCode, android.view.KeyEvent event)A key was released.
return false;
|
public boolean | onMenuItemSelected(int featureId, android.view.MenuItem item)
return false;
|
public boolean | onMenuOpened(int featureId, android.view.Menu menu)
return true;
|
public boolean | onOptionsItemSelected(android.view.MenuItem item)
return false;
|
public void | onOptionsMenuClosed(android.view.Menu menu)
|
public void | onPanelClosed(int featureId, android.view.Menu menu)
|
public boolean | onPrepareOptionsMenu(android.view.Menu menu)It is usually safe to proxy this call to the owner activity's
{@link Activity#onPrepareOptionsMenu(Menu)} if the client desires the
same menu for this Dialog.
return true;
|
public boolean | onPreparePanel(int featureId, android.view.View view, android.view.Menu menu)
if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) {
boolean goforit = onPrepareOptionsMenu(menu);
return goforit && menu.hasVisibleItems();
}
return true;
|
public void | onRestoreInstanceState(android.os.Bundle savedInstanceState)Restore the state of the dialog from a previously saved bundle.
The default implementation restores the state of the dialog's view
hierarchy that was saved in the default implementation of {@link #onSaveInstanceState()},
so be sure to call through to super when overriding unless you want to
do all restoring of state yourself.
final Bundle dialogHierarchyState = savedInstanceState.getBundle(DIALOG_HIERARCHY_TAG);
if (dialogHierarchyState == null) {
// dialog has never been shown, or onCreated, nothing to restore.
return;
}
dispatchOnCreate(savedInstanceState);
mWindow.restoreHierarchyState(dialogHierarchyState);
if (savedInstanceState.getBoolean(DIALOG_SHOWING_TAG)) {
show();
}
|
public android.os.Bundle | onSaveInstanceState()Saves the state of the dialog into a bundle.
The default implementation saves the state of its view hierarchy, so you'll
likely want to call through to super if you override this to save additional
state.
Bundle bundle = new Bundle();
bundle.putBoolean(DIALOG_SHOWING_TAG, mShowing);
if (mCreated) {
bundle.putBundle(DIALOG_HIERARCHY_TAG, mWindow.saveHierarchyState());
}
return bundle;
|
public boolean | onSearchRequested()This hook is called when the user signals the desire to start a search.
// not during dialogs, no.
return false;
|
protected void | onStart()Called when the dialog is starting.
|
protected void | onStop()Called to tell you that you're stopping.
|
public boolean | onTouchEvent(android.view.MotionEvent event)Called when a touch screen event was not handled by any of the views
under it. This is most useful to process touch events that happen outside
of your window bounds, where there is no view to receive it.
if (mCancelable && mCanceledOnTouchOutside && event.getAction() == MotionEvent.ACTION_DOWN
&& isOutOfBounds(event)) {
cancel();
return true;
}
return false;
|
public boolean | onTrackballEvent(android.view.MotionEvent event)Called when the trackball was moved and not handled by any of the
views inside of the activity. So, for example, if the trackball moves
while focus is on a button, you will receive a call here because
buttons do not normally do anything with trackball events. The call
here happens before trackball movements are converted to
DPAD key events, which then get sent back to the view hierarchy, and
will be processed at the point for things like focus navigation.
return false;
|
public void | onWindowAttributesChanged(WindowManager.LayoutParams params)
if (mDecor != null) {
mWindowManager.updateViewLayout(mDecor, params);
}
|
public void | onWindowFocusChanged(boolean hasFocus)
|
public void | openContextMenu(android.view.View view)
view.showContextMenu();
|
public void | openOptionsMenu()
mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null);
|
public void | registerForContextMenu(android.view.View view)
view.setOnCreateContextMenuListener(this);
|
public final boolean | requestWindowFeature(int featureId)Enable extended window features. This is a convenience for calling
{@link android.view.Window#requestFeature getWindow().requestFeature()}.
return getWindow().requestFeature(featureId);
|
private void | sendDismissMessage()
if (mDismissMessage != null) {
// Obtain a new message so this dialog can be re-used
Message.obtain(mDismissMessage).sendToTarget();
}
|
public void | setCancelMessage(android.os.Message msg)Set a message to be sent when the dialog is canceled.
mCancelMessage = msg;
|
public void | setCancelable(boolean flag)Sets whether this dialog is cancelable with the
{@link KeyEvent#KEYCODE_BACK BACK} key.
mCancelable = flag;
|
public void | setCanceledOnTouchOutside(boolean cancel)Sets whether this dialog is canceled when touched outside the window's
bounds. If setting to true, the dialog is set to be cancelable if not
already set.
if (cancel && !mCancelable) {
mCancelable = true;
}
mCanceledOnTouchOutside = cancel;
|
public void | setContentView(int layoutResID)Set the screen content from a layout resource. The resource will be
inflated, adding all top-level views to the screen.
mWindow.setContentView(layoutResID);
|
public void | setContentView(android.view.View view)Set the screen content to an explicit view. This view is placed
directly into the screen's view hierarchy. It can itself be a complex
view hierarhcy.
mWindow.setContentView(view);
|
public void | setContentView(android.view.View view, ViewGroup.LayoutParams params)Set the screen content to an explicit view. This view is placed
directly into the screen's view hierarchy. It can itself be a complex
view hierarhcy.
mWindow.setContentView(view, params);
|
public void | setDismissMessage(android.os.Message msg)Set a message to be sent when the dialog is dismissed.
mDismissMessage = msg;
|
public final void | setFeatureDrawable(int featureId, android.graphics.drawable.Drawable drawable)Convenience for calling
{@link android.view.Window#setFeatureDrawable(int, Drawable)}.
getWindow().setFeatureDrawable(featureId, drawable);
|
public final void | setFeatureDrawableAlpha(int featureId, int alpha)Convenience for calling
{@link android.view.Window#setFeatureDrawableAlpha}.
getWindow().setFeatureDrawableAlpha(featureId, alpha);
|
public final void | setFeatureDrawableResource(int featureId, int resId)Convenience for calling
{@link android.view.Window#setFeatureDrawableResource}.
getWindow().setFeatureDrawableResource(featureId, resId);
|
public final void | setFeatureDrawableUri(int featureId, android.net.Uri uri)Convenience for calling
{@link android.view.Window#setFeatureDrawableUri}.
getWindow().setFeatureDrawableUri(featureId, uri);
|
public void | setOnCancelListener(OnCancelListener listener)Set a listener to be invoked when the dialog is canceled.
This will only be invoked when the dialog is canceled, if the creator
needs to know when it is dismissed in general, use
{@link #setOnDismissListener}.
if (listener != null) {
mCancelMessage = mDismissCancelHandler.obtainMessage(CANCEL, listener);
} else {
mCancelMessage = null;
}
|
public void | setOnDismissListener(OnDismissListener listener)Set a listener to be invoked when the dialog is dismissed.
if (listener != null) {
mDismissMessage = mDismissCancelHandler.obtainMessage(DISMISS, listener);
} else {
mDismissMessage = null;
}
|
public void | setOnKeyListener(OnKeyListener onKeyListener)Sets the callback that will be called if a key is dispatched to the dialog.
mOnKeyListener = onKeyListener;
|
public final void | setOwnerActivity(Activity activity)Sets the Activity that owns this dialog. An example use: This Dialog will
use the suggested volume control stream of the Activity.
mOwnerActivity = activity;
getWindow().setVolumeControlStream(mOwnerActivity.getVolumeControlStream());
|
public void | setTitle(java.lang.CharSequence title)Set the title text for this dialog's window.
mWindow.setTitle(title);
mWindow.getAttributes().setTitle(title);
|
public void | setTitle(int titleId)Set the title text for this dialog's window. The text is retrieved
from the resources with the supplied identifier.
setTitle(mContext.getText(titleId));
|
public final void | setVolumeControlStream(int streamType)By default, this will use the owner Activity's suggested stream type.
getWindow().setVolumeControlStream(streamType);
|
public void | show()Start the dialog and display it on screen. The window is placed in the
application layer and opaque. Note that you should not override this
method to do initialization when the dialog is shown, instead implement
that in {@link #onStart}.
if (mShowing) {
if (Config.LOGV) Log.v(LOG_TAG,
"[Dialog] start: already showing, ignore");
if (mDecor != null) mDecor.setVisibility(View.VISIBLE);
return;
}
if (!mCreated) {
dispatchOnCreate(null);
}
onStart();
mDecor = mWindow.getDecorView();
WindowManager.LayoutParams l = mWindow.getAttributes();
if ((l.softInputMode
& WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) == 0) {
WindowManager.LayoutParams nl = new WindowManager.LayoutParams();
nl.copyFrom(l);
nl.softInputMode |=
WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
l = nl;
}
mWindowManager.addView(mDecor, l);
mShowing = true;
|
public void | takeKeyEvents(boolean get)Request that key events come to this dialog. Use this if your
dialog has no views with focus, but the dialog still wants
a chance to process key events.
mWindow.takeKeyEvents(get);
|
public void | unregisterForContextMenu(android.view.View view)
view.setOnCreateContextMenuListener(null);
|