Allow ToolbarActionBar to pass-through unhandled keyShortcuts

It was consuming all keyShortcuts which broke system hotkeys
like shift+tab.

In order to prevent the decor/phonewindow from creating menus,
this creates a dummy view in onCreatePanelView.

This also includes a change to Activity to not send KEYCODE_TAB
keystrokes to the defaulthandler. This was preventing keyboard
navigation from working on any activity that had a default
search fallback.

Bug: 32482282
Bug: 18021345
Test: Added a CTS test (ToolbarTest#testKeyShortcuts) for toolbar
      keyShortcuts. Verified Tab-navigation works in Play Store.
Change-Id: I5c732a2b21219157818bed49576debd20d5a8178
(cherry picked from commit b22faf524e)
This commit is contained in:
Evan Rosky
2017-02-17 13:11:53 -08:00
parent 84eecd2532
commit c46203785c
2 changed files with 17 additions and 5 deletions

View File

@@ -2740,6 +2740,10 @@ public class Activity extends ContextThemeWrapper
return true;
}
return false;
} else if (keyCode == KeyEvent.KEYCODE_TAB) {
// Don't consume TAB here since it's used for navigation. Arrow keys
// aren't considered "typing keys" so they already won't get consumed.
return false;
} else {
// Common code for DEFAULT_KEYS_DIALER & DEFAULT_KEYS_SEARCH_*
boolean clearSpannable = false;

View File

@@ -477,12 +477,9 @@ public class ToolbarActionBar extends ActionBar {
final KeyCharacterMap kmap = KeyCharacterMap.load(
event != null ? event.getDeviceId() : KeyCharacterMap.VIRTUAL_KEYBOARD);
menu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC);
menu.performShortcut(keyCode, event, 0);
return 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;
return false;
}
@Override
@@ -525,6 +522,17 @@ public class ToolbarActionBar extends ActionBar {
}
return result;
}
@Override
public View onCreatePanelView(int featureId) {
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
// This gets called by PhoneWindow.preparePanel. Since this already manages
// its own panel, we return a dummy view here to prevent PhoneWindow from
// preparing a default one.
return new View(mDecorToolbar.getContext());
}
return super.onCreatePanelView(featureId);
}
}
private final class ActionMenuPresenterCallback implements MenuPresenter.Callback {