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

Commit 306a7509 authored by Josep del Río's avatar Josep del Río Committed by Android (Google) Code Review
Browse files

Merge "Dismiss dialogs with the Escape key" into udc-qpr-dev

parents ddc735f1 22031ddf
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -694,13 +694,23 @@ public class Dialog implements DialogInterface, Window.Callback,
     */
    @Override
    public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE)
                && event.isTracking()
                && !event.isCanceled()
                && !WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
        if (event.isTracking() && !event.isCanceled()) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
                        onBackPressed();
                        return true;
                    }
                    break;
                case KeyEvent.KEYCODE_ESCAPE:
                    if (mCancelable) {
                        cancel();
                    } else {
                        dismiss();
                    }
                    return true;
            }
        }
        return false;
    }