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

Commit 77150c5f authored by Svet Ganov's avatar Svet Ganov
Browse files

Hide autofill popup if anchor removed

Test: Manual
Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases

bug:64601372

Change-Id: Ic55dabb99cd5015d318ab3be1231b6aa5c67294e
parent a120e6b6
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -47,6 +47,19 @@ public class AutofillPopupWindow extends PopupWindow {
    private final WindowPresenter mWindowPresenter;
    private WindowManager.LayoutParams mWindowLayoutParams;

    private final View.OnAttachStateChangeListener mOnAttachStateChangeListener =
            new View.OnAttachStateChangeListener() {
        @Override
        public void onViewAttachedToWindow(View v) {
            /* ignore - handled by the super class */
        }

        @Override
        public void onViewDetachedFromWindow(View v) {
            dismiss();
        }
    };

    /**
     * Creates a popup window with a presenter owning the window and responsible for
     * showing/hiding/updating the backing window. This can be useful of the window is
@@ -208,7 +221,21 @@ public class AutofillPopupWindow extends PopupWindow {
        p.packageName = anchor.getContext().getPackageName();
        mWindowPresenter.show(p, getTransitionEpicenter(), isLayoutInsetDecor(),
                anchor.getLayoutDirection());
        return;
    }

    @Override
    protected void attachToAnchor(View anchor, int xoff, int yoff, int gravity) {
        super.attachToAnchor(anchor, xoff, yoff, gravity);
        anchor.addOnAttachStateChangeListener(mOnAttachStateChangeListener);
    }

    @Override
    protected void detachFromAnchor() {
        final View anchor = getAnchor();
        if (anchor != null) {
            anchor.removeOnAttachStateChangeListener(mOnAttachStateChangeListener);
        }
        super.detachFromAnchor();
    }

    @Override
+8 −3
Original line number Diff line number Diff line
@@ -2296,8 +2296,8 @@ public class PopupWindow {
    }

    /** @hide */
    protected final void detachFromAnchor() {
        final View anchor = mAnchor != null ? mAnchor.get() : null;
    protected void detachFromAnchor() {
        final View anchor = getAnchor();
        if (anchor != null) {
            final ViewTreeObserver vto = anchor.getViewTreeObserver();
            vto.removeOnScrollChangedListener(mOnScrollChangedListener);
@@ -2316,7 +2316,7 @@ public class PopupWindow {
    }

    /** @hide */
    protected final void attachToAnchor(View anchor, int xoff, int yoff, int gravity) {
    protected void attachToAnchor(View anchor, int xoff, int yoff, int gravity) {
        detachFromAnchor();

        final ViewTreeObserver vto = anchor.getViewTreeObserver();
@@ -2339,6 +2339,11 @@ public class PopupWindow {
        mAnchoredGravity = gravity;
    }

    /** @hide */
    protected @Nullable View getAnchor() {
        return mAnchor != null ? mAnchor.get() : null;
    }

    private void alignToAnchor() {
        final View anchor = mAnchor != null ? mAnchor.get() : null;
        if (anchor != null && anchor.isAttachedToWindow() && hasDecorView()) {