Base class for Dialogs.
Note: Activities provide a facility to manage the creation, saving and
restoring of dialogs. See Activity.onCreateDialog(int),
Activity.onPrepareDialog(int,android.app.Dialog),
Activity.showDialog(int), and Activity.dismissDialog(int). If
these methods are used, getOwnerActivity() will return the Activity
that managed this dialog.
Often you will want to have a Dialog display on top of the current
input method, because there is no reason for it to accept text. You can
do this by setting the WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM window flag (assuming
your Dialog takes input focus, as it the default) with the following code:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
This field should be made private, so it is hidden from the SDK.
Whether to cancel the dialog when a touch is received outside of the
window's bounds.
private static final int DISMISS = 0x43;
private static final int CANCEL = 0x44;
private static final int SHOW = 0x45;
Create a Dialog window that uses the default dialog frame style.
- Parameters:
context The Context the Dialog is to run it. In particular, it
uses the window manager and theme in this context to
present its UI.
Create a Dialog window that uses a custom dialog style.
- Parameters:
context The Context in which the Dialog should run. In particular, it
uses the window manager and theme from this context to
present its UI.theme A style resource describing the theme to use for the
window. See Style
and Theme Resources for more information about defining and using
styles. This theme is applied on top of the current theme in
context. If 0, the default dialog theme will be used.
Retrieve the Context this Dialog is running in.
- Returns:
- Context The Context that was supplied to the constructor.
Sets the Activity that owns this dialog. An example use: This Dialog will
use the suggested volume control stream of the Activity.
- Parameters:
activity The Activity that owns this dialog.
Returns the Activity that owns this Dialog. For example, if
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.
- Returns:
- The Activity that owns this Dialog.
- Returns:
- Whether the dialog is currently showing.
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
onStart().
Hide the dialog, but do not dismiss it.
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
onStop().
Called when the dialog is starting.
Called to tell you that you're stopping.
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.
- Returns:
- A bundle with the state of the dialog.
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
onSaveInstanceState(),
so be sure to call through to super when overriding unless you want to
do all restoring of state yourself.
if (dialogHierarchyState == null) { 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.
- Returns:
- Window The current window, or null if the activity is not
visual.
Finds a view that was identified by the id attribute from the XML that
was processed in
onStart().
- Parameters:
id the identifier of the view to find- Returns:
- The view if found or null otherwise.
Set the screen content from a layout resource. The resource will be
inflated, adding all top-level views to the screen.
- Parameters:
layoutResID Resource ID to be inflated.
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.
- Parameters:
view The desired content to display.
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.
- Parameters:
view The desired content to display.params Layout parameters for the view.
Add an additional content view to the screen. Added after any existing
ones in the screen -- existing views are NOT removed.
- Parameters:
view The desired content to display.params Layout parameters for the view.
Set the title text for this dialog's window.
- Parameters:
title The new text to display in the title.
Set the title text for this dialog's window. The text is retrieved
from the resources with the supplied identifier.
- Parameters:
titleId the title's text resource identifier
A key was pressed down.
If the focused view didn't want this event, this method is called.
The default implementation consumed the KEYCODE_BACK to later
handle it in onKeyUp(int,android.view.KeyEvent).
Default implementation of
KeyEvent.Callback.onKeyLongPress(): always returns false (doesn't handle
the event).
A key was released.
The default implementation handles KEYCODE_BACK to close the
dialog.
Default implementation of
KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle
the event).
Called when the dialog has detected the user's press of the back
key. The default implementation simply cancels the dialog (only if
it is cancelable), but you can override this to do whatever you want.
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.
- Parameters:
event The touch screen event being processed.- Returns:
- Return true if you have consumed the event, false if you haven't.
The default implementation will cancel the dialog when a touch
happens outside of the window bounds.
final int x = (int) event.getX();
final int y = (int) event.getY();
return (x < -slop) || (y < -slop)
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.
- Parameters:
event The trackball event being processed.- Returns:
- Return true if you have consumed the event, false if you haven't.
The default implementation always returns false.
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.
- Parameters:
event The key event.- Returns:
- boolean Return true if this event was consumed.
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.
- Parameters:
ev The touch screen event.- Returns:
- boolean Return true if this event was consumed.
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.
- Parameters:
ev The trackball event.- Returns:
- boolean Return true if this event was consumed.
This hook is called when the user signals the desire to start a search.
searchManager.startSearch(null, false, appName, null, false);
- Returns:
- The activity associated with this dialog, or null if there is no assocaited activity.
while (activity == null && context != null) { 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.
Enable extended window features. This is a convenience for calling
getWindow().requestFeature().
Sets whether this dialog is cancelable with the
BACK key.
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.
- Parameters:
cancel Whether the dialog should be canceled when touched outside
the window.
Set a message to be sent when the dialog is canceled.
Set a listener to be invoked when the dialog is dismissed.
Sets a listener to be invoked when the dialog is shown.
Set a message to be sent when the dialog is dismissed.
- Parameters:
msg The msg to send when the dialog is dismissed.
By default, this will use the owner Activity's suggested stream type.
Sets the callback that will be called if a key is dispatched to the dialog.