Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d32eb61 authored by Matthew Duggan's avatar Matthew Duggan
Browse files

Clear popups on KEYCODE_ESCAPE as well as KEYCODE_BACK

On desktop devices, users expect that the Escape key will clear various
popup windows in the same way as the Back button will on mobile devices.
This adds support for Escape to places the Back button currently clears
ListPopupWindow, AutoCompleteTextView, PopupWindow, and ScrollView.

Bug: 174164194
Test: Open popups of each type on a device with a physical keyboard and
  press escape.
Change-Id: I32e65ce4317db7de043c8a050d87126b0f38acce
parent ab682f31
Loading
Loading
Loading
Loading
+29 −28
Original line number Original line Diff line number Diff line
@@ -5948,6 +5948,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                okToSend = false;
                okToSend = false;
                break;
                break;
            case KeyEvent.KEYCODE_BACK:
            case KeyEvent.KEYCODE_BACK:
            case KeyEvent.KEYCODE_ESCAPE:
                if (mFiltered && mPopup != null && mPopup.isShowing()) {
                if (mFiltered && mPopup != null && mPopup.isShowing()) {
                    if (event.getAction() == KeyEvent.ACTION_DOWN
                    if (event.getAction() == KeyEvent.ACTION_DOWN
                            && event.getRepeatCount() == 0) {
                            && event.getRepeatCount() == 0) {
+2 −2
Original line number Original line Diff line number Diff line
@@ -788,8 +788,8 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe


    @Override
    @Override
    public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    public boolean onKeyPreIme(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && isPopupShowing()
        if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE)
                && !mPopup.isDropDownAlwaysVisible()) {
                && isPopupShowing() && !mPopup.isDropDownAlwaysVisible()) {
            // special case for the back key, we do not even try to send it
            // special case for the back key, we do not even try to send it
            // to the drop down list but instead, consume it immediately
            // to the drop down list but instead, consume it immediately
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
+2 −1
Original line number Original line Diff line number Diff line
@@ -1071,7 +1071,8 @@ public class ListPopupWindow implements ShowableListMenu {
     * @see #setModal(boolean)
     * @see #setModal(boolean)
     */
     */
    public boolean onKeyPreIme(int keyCode, @NonNull KeyEvent event) {
    public boolean onKeyPreIme(int keyCode, @NonNull KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && isShowing()) {
        if ((keyCode == KeyEvent.KEYCODE_BACK
                || keyCode == KeyEvent.KEYCODE_ESCAPE) && isShowing()) {
            // special case for the back key, we do not even try to send it
            // special case for the back key, we do not even try to send it
            // to the drop down list but instead, consume it immediately
            // to the drop down list but instead, consume it immediately
            final View anchorView = mDropDownAnchorView;
            final View anchorView = mDropDownAnchorView;
+2 −1
Original line number Original line Diff line number Diff line
@@ -2521,7 +2521,8 @@ public class PopupWindow {


        @Override
        @Override
        public boolean dispatchKeyEvent(KeyEvent event) {
        public boolean dispatchKeyEvent(KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
                      || event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE) {
                if (getKeyDispatcherState() == null) {
                if (getKeyDispatcherState() == null) {
                    return super.dispatchKeyEvent(event);
                    return super.dispatchKeyEvent(event);
                }
                }
+2 −1
Original line number Original line Diff line number Diff line
@@ -509,7 +509,8 @@ public class ScrollView extends FrameLayout {
        mTempRect.setEmpty();
        mTempRect.setEmpty();


        if (!canScroll()) {
        if (!canScroll()) {
            if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
            if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK
                    && event.getKeyCode() != KeyEvent.KEYCODE_ESCAPE) {
                View currentFocused = findFocus();
                View currentFocused = findFocus();
                if (currentFocused == this) currentFocused = null;
                if (currentFocused == this) currentFocused = null;
                View nextFocused = FocusFinder.getInstance().findNextFocus(this,
                View nextFocused = FocusFinder.getInstance().findNextFocus(this,