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

Commit 651c6f7f authored by Vadim Caen's avatar Vadim Caen Committed by Automerger Merge Worker
Browse files

Merge "Migrate PopupWindow to use OnBackInvokedDispatcher" into tm-dev am:...

Merge "Migrate PopupWindow to use OnBackInvokedDispatcher" into tm-dev am: 0ba48fea am: 43204674

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17105464



Change-Id: Iddcef0df5d7cdd5895631077b24164b518a513e1
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 72827d03 43204674
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -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;

@@ -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>
     *
@@ -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) {
@@ -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.
@@ -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 {