Loading core/java/android/widget/PopupWindow.java +40 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,9 @@ import android.view.WindowManager; import android.view.WindowManager.LayoutParams; import android.view.WindowManager.LayoutParams.SoftInputModeFlags; import android.view.WindowManagerGlobal; import android.window.OnBackInvokedCallback; import android.window.OnBackInvokedDispatcher; import android.window.WindowOnBackInvokedDispatcher; import com.android.internal.R; Loading Loading @@ -277,6 +280,8 @@ public class PopupWindow { private boolean mPopupViewInitialLayoutDirectionInherited; private OnBackInvokedCallback mBackCallback; /** * <p>Create a new empty, non focusable popup window of dimension (0,0).</p> * Loading Loading @@ -2028,6 +2033,8 @@ public class PopupWindow { final PopupDecorView decorView = mDecorView; final View contentView = mContentView; unregisterBackCallback(decorView.findOnBackInvokedDispatcher()); final ViewGroup contentHolder; final ViewParent contentParent = contentView.getParent(); if (contentParent instanceof ViewGroup) { Loading Loading @@ -2082,6 +2089,15 @@ public class PopupWindow { } } private void unregisterBackCallback(@Nullable OnBackInvokedDispatcher onBackInvokedDispatcher) { OnBackInvokedCallback backCallback = mBackCallback; mBackCallback = null; if (onBackInvokedDispatcher != null && backCallback != null) { onBackInvokedDispatcher.unregisterOnBackInvokedCallback( backCallback); } } /** * Returns the window-relative epicenter bounds to be used by enter and * exit transitions. Loading Loading @@ -2725,6 +2741,30 @@ public class PopupWindow { } } } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) { return; } OnBackInvokedDispatcher dispatcher = findOnBackInvokedDispatcher(); if (dispatcher == null) { return; } mBackCallback = PopupWindow.this::dismiss; dispatcher.registerOnBackInvokedCallback(OnBackInvokedDispatcher.PRIORITY_DEFAULT, mBackCallback); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); unregisterBackCallback(findOnBackInvokedDispatcher()); } } private class PopupBackgroundView extends FrameLayout { Loading Loading
core/java/android/widget/PopupWindow.java +40 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,9 @@ import android.view.WindowManager; import android.view.WindowManager.LayoutParams; import android.view.WindowManager.LayoutParams.SoftInputModeFlags; import android.view.WindowManagerGlobal; import android.window.OnBackInvokedCallback; import android.window.OnBackInvokedDispatcher; import android.window.WindowOnBackInvokedDispatcher; import com.android.internal.R; Loading Loading @@ -277,6 +280,8 @@ public class PopupWindow { private boolean mPopupViewInitialLayoutDirectionInherited; private OnBackInvokedCallback mBackCallback; /** * <p>Create a new empty, non focusable popup window of dimension (0,0).</p> * Loading Loading @@ -2028,6 +2033,8 @@ public class PopupWindow { final PopupDecorView decorView = mDecorView; final View contentView = mContentView; unregisterBackCallback(decorView.findOnBackInvokedDispatcher()); final ViewGroup contentHolder; final ViewParent contentParent = contentView.getParent(); if (contentParent instanceof ViewGroup) { Loading Loading @@ -2082,6 +2089,15 @@ public class PopupWindow { } } private void unregisterBackCallback(@Nullable OnBackInvokedDispatcher onBackInvokedDispatcher) { OnBackInvokedCallback backCallback = mBackCallback; mBackCallback = null; if (onBackInvokedDispatcher != null && backCallback != null) { onBackInvokedDispatcher.unregisterOnBackInvokedCallback( backCallback); } } /** * Returns the window-relative epicenter bounds to be used by enter and * exit transitions. Loading Loading @@ -2725,6 +2741,30 @@ public class PopupWindow { } } } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) { return; } OnBackInvokedDispatcher dispatcher = findOnBackInvokedDispatcher(); if (dispatcher == null) { return; } mBackCallback = PopupWindow.this::dismiss; dispatcher.registerOnBackInvokedCallback(OnBackInvokedDispatcher.PRIORITY_DEFAULT, mBackCallback); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); unregisterBackCallback(findOnBackInvokedDispatcher()); } } private class PopupBackgroundView extends FrameLayout { Loading