diff options
author | Jeff Brown <jeffbrown@google.com> | 2011-01-04 19:57:47 -0800 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2011-01-05 14:51:24 -0800 |
commit | 64da12ab1f472e01325b6c6d094153ac110eaf7b (patch) | |
tree | 29b0e44f574a489ea8a5ce5062f244113538382d /core/java/android/app/Dialog.java | |
parent | f31161a0e71c0446283610e9bf7a11e0be12bd5e (diff) | |
download | frameworks_base-64da12ab1f472e01325b6c6d094153ac110eaf7b.zip frameworks_base-64da12ab1f472e01325b6c6d094153ac110eaf7b.tar.gz frameworks_base-64da12ab1f472e01325b6c6d094153ac110eaf7b.tar.bz2 |
Add dispatch key shortcut window callback.
Enables Activities and Dialogs to implement key shortcut behavior.
Useful for global key shortcuts that are not bound to the focused
view or to a menu.
Change-Id: If377d20b227ee1c5cac84c47c9630b2d77f67e2c
Diffstat (limited to 'core/java/android/app/Dialog.java')
-rw-r--r-- | core/java/android/app/Dialog.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java index e69e664..6791400 100644 --- a/core/java/android/app/Dialog.java +++ b/core/java/android/app/Dialog.java @@ -571,7 +571,21 @@ public class Dialog implements DialogInterface, Window.Callback, cancel(); } } - + + /** + * Called when an key shortcut event is not handled by any of the views in the Dialog. + * Override this method to implement global key shortcuts for the Dialog. + * Key shortcuts can also be implemented by setting the + * {@link MenuItem#setShortcut(char, char) shortcut} property of menu items. + * + * @param keyCode The value in event.getKeyCode(). + * @param event Description of the key event. + * @return True if the key shortcut was handled. + */ + public boolean onKeyShortcut(int keyCode, KeyEvent event) { + return false; + } + /** * 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 @@ -659,6 +673,22 @@ public class Dialog implements DialogInterface, Window.Callback, } /** + * Called to process a key shortcut event. + * You can override this to intercept all key shortcut events before they are + * dispatched to the window. Be sure to call this implementation for key shortcut + * events that should be handled normally. + * + * @param event The key shortcut event. + * @return True if this event was consumed. + */ + public boolean dispatchKeyShortcutEvent(KeyEvent event) { + if (mWindow.superDispatchKeyShortcutEvent(event)) { + return true; + } + return onKeyShortcut(event.getKeyCode(), event); + } + + /** * 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 |