Most visited

Recently visited

Added in API level 1

Window.Callback

public static interface Window.Callback

android.view.Window.Callback
Known Indirect Subclasses


API from a Window back to its caller. This allows the client to intercept key dispatching, panels and menus, etc.

Summary

Public methods

abstract boolean dispatchGenericMotionEvent(MotionEvent event)

Called to process generic motion events.

abstract boolean dispatchKeyEvent(KeyEvent event)

Called to process key events.

abstract boolean dispatchKeyShortcutEvent(KeyEvent event)

Called to process a key shortcut event.

abstract boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event)

Called to process population of AccessibilityEvents.

abstract boolean dispatchTouchEvent(MotionEvent event)

Called to process touch screen events.

abstract boolean dispatchTrackballEvent(MotionEvent event)

Called to process trackball events.

abstract void onActionModeFinished(ActionMode mode)

Called when an action mode has been finished.

abstract void onActionModeStarted(ActionMode mode)

Called when an action mode has been started.

abstract void onAttachedToWindow()

Called when the window has been attached to the window manager.

abstract void onContentChanged()

This hook is called whenever the content view of the screen changes (due to a call to Window.setContentView or Window.addContentView).

abstract boolean onCreatePanelMenu(int featureId, Menu menu)

Initialize the contents of the menu for panel 'featureId'.

abstract View onCreatePanelView(int featureId)

Instantiate the view to display in the panel for 'featureId'.

abstract void onDetachedFromWindow()

Called when the window has been attached to the window manager.

abstract boolean onMenuItemSelected(int featureId, MenuItem item)

Called when a panel's menu item has been selected by the user.

abstract boolean onMenuOpened(int featureId, Menu menu)

Called when a panel's menu is opened by the user.

abstract void onPanelClosed(int featureId, Menu menu)

Called when a panel is being closed.

abstract boolean onPreparePanel(int featureId, View view, Menu menu)

Prepare a panel to be displayed.

default void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu, int deviceId)

Called when Keyboard Shortcuts are requested for the current window.

abstract boolean onSearchRequested()

Called when the user signals the desire to start a search.

abstract boolean onSearchRequested(SearchEvent searchEvent)

Called when the user signals the desire to start a search.

abstract void onWindowAttributesChanged(WindowManager.LayoutParams attrs)

This is called whenever the current window attributes change.

abstract void onWindowFocusChanged(boolean hasFocus)

This hook is called whenever the window focus changes.

abstract ActionMode onWindowStartingActionMode(ActionMode.Callback callback)

Called when an action mode is being started for this window.

abstract ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type)

Called when an action mode is being started for this window.

Public methods

dispatchGenericMotionEvent

Added in API level 12
boolean dispatchGenericMotionEvent (MotionEvent event)

Called to process generic motion events. At the very least your implementation must call superDispatchGenericMotionEvent(MotionEvent) to do the standard processing.

Parameters
event MotionEvent: The generic motion event.
Returns
boolean boolean Return true if this event was consumed.

dispatchKeyEvent

Added in API level 1
boolean dispatchKeyEvent (KeyEvent event)

Called to process key events. At the very least your implementation must call superDispatchKeyEvent(KeyEvent) to do the standard key processing.

Parameters
event KeyEvent: The key event.
Returns
boolean boolean Return true if this event was consumed.

dispatchKeyShortcutEvent

Added in API level 11
boolean dispatchKeyShortcutEvent (KeyEvent event)

Called to process a key shortcut event. At the very least your implementation must call superDispatchKeyShortcutEvent(KeyEvent) to do the standard key shortcut processing.

Parameters
event KeyEvent: The key shortcut event.
Returns
boolean True if this event was consumed.

dispatchPopulateAccessibilityEvent

Added in API level 4
boolean dispatchPopulateAccessibilityEvent (AccessibilityEvent event)

Called to process population of AccessibilityEvents.

Parameters
event AccessibilityEvent: The event.
Returns
boolean boolean Return true if event population was completed.

dispatchTouchEvent

Added in API level 1
boolean dispatchTouchEvent (MotionEvent event)

Called to process touch screen events. At the very least your implementation must call superDispatchTouchEvent(MotionEvent) to do the standard touch screen processing.

Parameters
event MotionEvent: The touch screen event.
Returns
boolean boolean Return true if this event was consumed.

dispatchTrackballEvent

Added in API level 1
boolean dispatchTrackballEvent (MotionEvent event)

Called to process trackball events. At the very least your implementation must call superDispatchTrackballEvent(MotionEvent) to do the standard trackball processing.

Parameters
event MotionEvent: The trackball event.
Returns
boolean boolean Return true if this event was consumed.

onActionModeFinished

Added in API level 11
void onActionModeFinished (ActionMode mode)

Called when an action mode has been finished. The appropriate mode callback method will have already been invoked.

Parameters
mode ActionMode: The mode that was just finished.

onActionModeStarted

Added in API level 11
void onActionModeStarted (ActionMode mode)

Called when an action mode has been started. The appropriate mode callback method will have already been invoked.

Parameters
mode ActionMode: The new mode that has just been started.

onAttachedToWindow

Added in API level 5
void onAttachedToWindow ()

Called when the window has been attached to the window manager. See View.onAttachedToWindow() for more information.

onContentChanged

Added in API level 1
void onContentChanged ()

This hook is called whenever the content view of the screen changes (due to a call to Window.setContentView or Window.addContentView).

onCreatePanelMenu

Added in API level 1
boolean onCreatePanelMenu (int featureId, 
                Menu menu)

Initialize the contents of the menu for panel 'featureId'. This is called if onCreatePanelView() returns null, giving you a standard menu in which you can place your items. It is only called once for the panel, the first time it is shown.

You can safely hold on to menu (and any items created from it), making modifications to it as desired, until the next time onCreatePanelMenu() is called for this feature.

Parameters
featureId int: The panel being created.
menu Menu: The menu inside the panel.
Returns
boolean boolean You must return true for the panel to be displayed; if you return false it will not be shown.

onCreatePanelView

Added in API level 1
View onCreatePanelView (int featureId)

Instantiate the view to display in the panel for 'featureId'. You can return null, in which case the default content (typically a menu) will be created for you.

Parameters
featureId int: Which panel is being created.
Returns
View view The top-level view to place in the panel.

See also:

onDetachedFromWindow

Added in API level 5
void onDetachedFromWindow ()

Called when the window has been attached to the window manager. See View.onDetachedFromWindow() for more information.

onMenuItemSelected

Added in API level 1
boolean onMenuItemSelected (int featureId, 
                MenuItem item)

Called when a panel's menu item has been selected by the user.

Parameters
featureId int: The panel that the menu is in.
item MenuItem: The menu item that was selected.
Returns
boolean boolean Return true to finish processing of selection, or false to perform the normal menu handling (calling its Runnable or sending a Message to its target Handler).

onMenuOpened

Added in API level 1
boolean onMenuOpened (int featureId, 
                Menu menu)

Called when a panel's menu is opened by the user. This may also be called when the menu is changing from one type to another (for example, from the icon menu to the expanded menu).

Parameters
featureId int: The panel that the menu is in.
menu Menu: The menu that is opened.
Returns
boolean Return true to allow the menu to open, or false to prevent the menu from opening.

onPanelClosed

Added in API level 1
void onPanelClosed (int featureId, 
                Menu menu)

Called when a panel is being closed. If another logical subsequent panel is being opened (and this panel is being closed to make room for the subsequent panel), this method will NOT be called.

Parameters
featureId int: The panel that is being displayed.
menu Menu: If onCreatePanelView() returned null, this is the Menu being displayed in the panel.

onPreparePanel

Added in API level 1
boolean onPreparePanel (int featureId, 
                View view, 
                Menu menu)

Prepare a panel to be displayed. This is called right before the panel window is shown, every time it is shown.

Parameters
featureId int: The panel that is being displayed.
view View: The View that was returned by onCreatePanelView().
menu Menu: If onCreatePanelView() returned null, this is the Menu being displayed in the panel.
Returns
boolean boolean You must return true for the panel to be displayed; if you return false it will not be shown.

See also:

onProvideKeyboardShortcuts

Added in API level 24
void onProvideKeyboardShortcuts (List<KeyboardShortcutGroup> data, 
                Menu menu, 
                int deviceId)

Called when Keyboard Shortcuts are requested for the current window.

Parameters
data List: The data list to populate with shortcuts.
menu Menu: The current menu, which may be null.
deviceId int: The id for the connected device the shortcuts should be provided for.

onSearchRequested

Added in API level 1
boolean onSearchRequested ()

Called when the user signals the desire to start a search.

Returns
boolean true if search launched, false if activity refuses (blocks)

See also:

onSearchRequested

Added in API level 23
boolean onSearchRequested (SearchEvent searchEvent)

Called when the user signals the desire to start a search.

Parameters
searchEvent SearchEvent: A SearchEvent describing the signal to start a search.
Returns
boolean true if search launched, false if activity refuses (blocks)

onWindowAttributesChanged

Added in API level 1
void onWindowAttributesChanged (WindowManager.LayoutParams attrs)

This is called whenever the current window attributes change.

Parameters
attrs WindowManager.LayoutParams

onWindowFocusChanged

Added in API level 1
void onWindowFocusChanged (boolean hasFocus)

This hook is called whenever the window focus changes. See View.onWindowFocusChangedNotLocked(boolean) for more information.

Parameters
hasFocus boolean: Whether the window now has focus.

onWindowStartingActionMode

Added in API level 11
ActionMode onWindowStartingActionMode (ActionMode.Callback callback)

Called when an action mode is being started for this window. Gives the callback an opportunity to handle the action mode in its own unique and beautiful way. If this method returns null the system can choose a way to present the mode or choose not to start the mode at all. This is equivalent to onWindowStartingActionMode(android.view.ActionMode.Callback, int) with type TYPE_PRIMARY.

Parameters
callback ActionMode.Callback: Callback to control the lifecycle of this action mode
Returns
ActionMode The ActionMode that was started, or null if the system should present it

onWindowStartingActionMode

Added in API level 23
ActionMode onWindowStartingActionMode (ActionMode.Callback callback, 
                int type)

Called when an action mode is being started for this window. Gives the callback an opportunity to handle the action mode in its own unique and beautiful way. If this method returns null the system can choose a way to present the mode or choose not to start the mode at all.

Parameters
callback ActionMode.Callback: Callback to control the lifecycle of this action mode
type int: One of TYPE_PRIMARY or TYPE_FLOATING.
Returns
ActionMode The ActionMode that was started, or null if the system should present it

Hooray!