Android APIs
Added in API level 1
public static interface

Window.Callback

android.view.Window.Callback
Known Indirect Subclasses

Class Overview

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.
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

public abstract boolean dispatchGenericMotionEvent (MotionEvent event)

Added in API level 12

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.

public abstract boolean dispatchKeyEvent (KeyEvent event)

Added in API level 1

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.

public abstract boolean dispatchKeyShortcutEvent (KeyEvent event)

Added in API level 11

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.

public abstract boolean dispatchPopulateAccessibilityEvent (AccessibilityEvent event)

Added in API level 4

Called to process population of AccessibilityEvents.

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

public abstract boolean dispatchTouchEvent (MotionEvent event)

Added in API level 1

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.

public abstract boolean dispatchTrackballEvent (MotionEvent event)

Added in API level 1

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.

public abstract void onActionModeFinished (ActionMode mode)

Added in API level 11

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.

public abstract void onActionModeStarted (ActionMode mode)

Added in API level 11

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.

public abstract void onAttachedToWindow ()

Added in API level 5

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

public abstract void onContentChanged ()

Added in API level 1

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

public abstract boolean onCreatePanelMenu (int featureId, Menu menu)

Added in API level 1

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.

public abstract View onCreatePanelView (int featureId)

Added in API level 1

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.

public abstract void onDetachedFromWindow ()

Added in API level 5

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

public abstract boolean onMenuItemSelected (int featureId, MenuItem item)

Added in API level 1

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).

public abstract boolean onMenuOpened (int featureId, Menu menu)

Added in API level 1

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.

public abstract void onPanelClosed (int featureId, Menu menu)

Added in API level 1

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.

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

Added in API level 1

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.

public abstract boolean onSearchRequested ()

Added in API level 1

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

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

public abstract boolean onSearchRequested (SearchEvent searchEvent)

Added in API level 23

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)

public abstract void onWindowAttributesChanged (WindowManager.LayoutParams attrs)

Added in API level 1

This is called whenever the current window attributes change.

Parameters
attrs WindowManager.LayoutParams

public abstract void onWindowFocusChanged (boolean hasFocus)

Added in API level 1

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.

public abstract ActionMode onWindowStartingActionMode (ActionMode.Callback callback)

Added in API level 11

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

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

Added in API level 23

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