// Dialog.java
/**
* Sets whether this dialog is canceled when touched outside the window's
* bounds. If setting to true, the dialog is set to be cancelable if not
* already set.
*
* @param cancel Whether the dialog should be canceled when touched outside
* the window.
*/publicvoidsetCanceledOnTouchOutside(booleancancel){if(cancel&&!mCancelable){mCancelable=true;}mWindow.setCloseOnTouchOutside(cancel);}// Window.java
/** @hide */@UnsupportedAppUsagepublicvoidsetCloseOnTouchOutside(booleanclose){mCloseOnTouchOutside=close;mSetCloseOnTouchOutside=true;}
/**
* Called when the dialog has detected the user's press of the back
* key. The default implementation simply cancels the dialog (only if
* it is cancelable), but you can override this to do whatever you want.
*
* <p>
* If you target version {@link android.os.Build.VERSION_CODES#TIRAMISU} or later, you
* should not use this method but register an {@link OnBackInvokedCallback} on an
* {@link OnBackInvokedDispatcher} that you can retrieve using
* {@link #getOnBackInvokedDispatcher()}. You should also set
* {@code android:enableOnBackInvokedCallback="true"} in the application manifest.
*
* <p>Alternatively, you
* can use {@code androidx.activity.ComponentDialog#getOnBackPressedDispatcher()}
* for backward compatibility.
*
* @deprecated Use {@link OnBackInvokedCallback} or
* {@code androidx.activity.OnBackPressedCallback} to handle back navigation instead.
* <p>
* Starting from Android 13 (API level 33), back event handling is
* moving to an ahead-of-time model and {@link #onBackPressed()} and
* {@link KeyEvent#KEYCODE_BACK} should not be used to handle back events (back gesture or
* back button click). Instead, an {@link OnBackInvokedCallback} should be registered using
* {@link Dialog#getOnBackInvokedDispatcher()}
* {@link OnBackInvokedDispatcher#registerOnBackInvokedCallback(int, OnBackInvokedCallback)
* .registerOnBackInvokedCallback(priority, callback)}.
*/@DeprecatedpublicvoidonBackPressed(){if(mCancelable){cancel();}}
/**
* Called when a touch screen event was not handled by any of the views
* under it. This is most useful to process touch events that happen outside
* of your window bounds, where there is no view to receive it.
*
* @param event The touch screen event being processed.
* @return Return true if you have consumed the event, false if you haven't.
* The default implementation will cancel the dialog when a touch
* happens outside of the window bounds.
*/publicbooleanonTouchEvent(@NonNullMotionEventevent){if(mCancelable&&mShowing&&mWindow.shouldCloseOnTouch(mContext,event)){cancel();returntrue;}returnfalse;}