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

Commit da2311c8 authored by Josep del Rio's avatar Josep del Rio Committed by Josep del Río
Browse files

Finish certain activities when using Escape

Some activities are styled to look and behave like dialogs while
not being one. Our intention is to have Escape close dialogs, and
this change will apply the same logic to activities that use
`closeOnTouchOutside`.

Bug: 281809692
Test: Use voice input in Google Play search; confirmed that Escape
will close the activity that looks like a dialog

Change-Id: I2e3c75e44de750b248e8c78071fcf639bd78a152
parent 306a7509
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -3882,7 +3882,9 @@ public class Activity extends ContextThemeWrapper
     * it will set up the dispatch to call {@link #onKeyUp} where the action
     * will be performed; for earlier applications, it will perform the
     * action immediately in on-down, as those versions of the platform
     * behaved.
     * behaved. This implementation will also take care of {@link KeyEvent#KEYCODE_ESCAPE}
     * by finishing the activity if it would be closed by touching outside
     * of it.
     *
     * <p>Other additional default key handling may be performed
     * if configured with {@link #setDefaultKeyMode}.
@@ -3904,6 +3906,11 @@ public class Activity extends ContextThemeWrapper
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_ESCAPE && mWindow.shouldCloseOnTouchOutside()) {
            event.startTracking();
            return true;
        }

        if (mDefaultKeyMode == DEFAULT_KEYS_DISABLE) {
            return false;
        } else if (mDefaultKeyMode == DEFAULT_KEYS_SHORTCUT) {
@@ -3999,6 +4006,15 @@ public class Activity extends ContextThemeWrapper
                return true;
            }
        }

        if (keyCode == KeyEvent.KEYCODE_ESCAPE
                && mWindow.shouldCloseOnTouchOutside()
                && event.isTracking()
                && !event.isCanceled()) {
            finish();
            return true;
        }

        return false;
    }

+5 −0
Original line number Diff line number Diff line
@@ -1481,6 +1481,11 @@ public abstract class Window {
        }
    }

    /** @hide */
    public boolean shouldCloseOnTouchOutside() {
        return mCloseOnTouchOutside;
    }

    /** @hide */
    @SuppressWarnings("HiddenAbstractMethod")
    @UnsupportedAppUsage