am b2777867: am 6a401410: Merge "Let the ActionBar handle keyboard shortcuts." into mnc-dev

* commit 'b277786736e41525a232ad7ecb61de706311b295':
  Let the ActionBar handle keyboard shortcuts.
This commit is contained in:
Abodunrinwa Toki
2015-07-15 23:03:45 +00:00
committed by Android Git Automerger
3 changed files with 20 additions and 1 deletions

View File

@@ -1056,6 +1056,11 @@ public abstract class ActionBar {
return false;
}
/** @hide */
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
return false;
}
/** @hide */
public boolean collapseActionView() {
return false;

View File

@@ -2469,7 +2469,9 @@ public class Activity extends ContextThemeWrapper
* @return True if the key shortcut was handled.
*/
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
return false;
// Let the Action Bar have a chance at handling the shortcut.
ActionBar actionBar = getActionBar();
return (actionBar != null && actionBar.onKeyShortcut(keyCode, event));
}
/**

View File

@@ -463,6 +463,18 @@ public class ToolbarActionBar extends ActionBar {
return true;
}
@Override
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
Menu menu = mDecorToolbar.getMenu();
if (menu != null) {
menu.performShortcut(keyCode, event, 0);
}
// This action bar always returns true for handling keyboard shortcuts.
// This will block the window from preparing a temporary panel to handle
// keyboard shortcuts.
return true;
}
public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
mMenuVisibilityListeners.add(listener);
}