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

Commit 3b60d022 authored by Emilie Roberts's avatar Emilie Roberts Committed by Android (Google) Code Review
Browse files

Merge "Close Dialog when ESC Pressed"

parents 1ab70f3b c1c572ef
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -609,18 +609,19 @@ public class Dialog implements DialogInterface, Window.Callback,

    /**
     * A key was pressed down.
     * 
     * <p>If the focused view didn't want this event, this method is called.
     *
     * <p>The default implementation consumed the KEYCODE_BACK to later
     * handle it in {@link #onKeyUp}.
     * <p>
     * If the focused view didn't want this event, this method is called.
     * <p>
     * Default implementation consumes {@link KeyEvent#KEYCODE_BACK KEYCODE_BACK}
     * and, as of {@link android.os.Build.VERSION_CODES#P P}, {@link KeyEvent#KEYCODE_ESCAPE
     * KEYCODE_ESCAPE} to later handle them in {@link #onKeyUp}.
     * 
     * @see #onKeyUp
     * @see android.view.KeyEvent
     */
    @Override
    public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE) {
            event.startTracking();
            return true;
        }
@@ -640,16 +641,18 @@ public class Dialog implements DialogInterface, Window.Callback,

    /**
     * A key was released.
     * 
     * <p>The default implementation handles KEYCODE_BACK to close the
     * dialog.
     * <p>
     * Default implementation consumes {@link KeyEvent#KEYCODE_BACK KEYCODE_BACK}
     * and, as of {@link android.os.Build.VERSION_CODES#P P}, {@link KeyEvent#KEYCODE_ESCAPE
     * KEYCODE_ESCAPE} to close the dialog.
     *
     * @see #onKeyDown
     * @see KeyEvent
     * @see android.view.KeyEvent
     */
    @Override
    public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking()
        if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE)
                && event.isTracking()
                && !event.isCanceled()) {
            onBackPressed();
            return true;