diff options
| -rw-r--r-- | core/java/android/widget/PopupWindow.java | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index 9b89491ce408..883fc2308e12 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -1834,7 +1834,8 @@ public class PopupWindow { // can expect the OnAttachStateChangeListener to have been called prior // to executing this method, so we can rely on that instead. final Transition exitTransition = mExitTransition; - if (mIsAnchorRootAttached && exitTransition != null && decorView.isLaidOut()) { + if (exitTransition != null && decorView.isLaidOut() + && (mIsAnchorRootAttached || mAnchorRoot == null)) { // The decor view is non-interactive and non-IME-focusable during exit transitions. final LayoutParams p = (LayoutParams) decorView.getLayoutParams(); p.flags |= LayoutParams.FLAG_NOT_TOUCHABLE; @@ -1842,18 +1843,13 @@ public class PopupWindow { p.flags &= ~LayoutParams.FLAG_ALT_FOCUSABLE_IM; mWindowManager.updateViewLayout(decorView, p); + final View anchorRoot = mAnchorRoot != null ? mAnchorRoot.get() : null; + final Rect epicenter = getTransitionEpicenter(); + // Once we start dismissing the decor view, all state (including // the anchor root) needs to be moved to the decor view since we // may open another popup while it's busy exiting. - final View anchorRoot = mAnchorRoot != null ? mAnchorRoot.get() : null; - final Rect epicenter = getTransitionEpicenter(); - exitTransition.setEpicenterCallback(new EpicenterCallback() { - @Override - public Rect onGetEpicenter(Transition transition) { - return epicenter; - } - }); - decorView.startExitTransition(exitTransition, anchorRoot, + decorView.startExitTransition(exitTransition, anchorRoot, epicenter, new TransitionListenerAdapter() { @Override public void onTransitionEnd(Transition transition) { @@ -2348,8 +2344,9 @@ public class PopupWindow { * its {@code onTransitionEnd} method called even if the transition * never starts; however, it may be called with a {@code null} argument. */ - public void startExitTransition(Transition transition, final View anchorRoot, - final TransitionListener listener) { + public void startExitTransition(@NonNull Transition transition, + @Nullable final View anchorRoot, @Nullable final Rect epicenter, + @NonNull final TransitionListener listener) { if (transition == null) { return; } @@ -2357,23 +2354,35 @@ public class PopupWindow { // The anchor view's window may go away while we're executing our // transition, in which case we need to end the transition // immediately and execute the listener to remove the popup. - anchorRoot.addOnAttachStateChangeListener(mOnAnchorRootDetachedListener); + if (anchorRoot != null) { + anchorRoot.addOnAttachStateChangeListener(mOnAnchorRootDetachedListener); + } // The exit listener MUST be called for cleanup, even if the // transition never starts or ends. Stash it for later. mPendingExitListener = new TransitionListenerAdapter() { @Override - public void onTransitionEnd(Transition transition) { - anchorRoot.removeOnAttachStateChangeListener(mOnAnchorRootDetachedListener); - listener.onTransitionEnd(transition); + public void onTransitionEnd(Transition t) { + if (anchorRoot != null) { + anchorRoot.removeOnAttachStateChangeListener(mOnAnchorRootDetachedListener); + } + + listener.onTransitionEnd(t); // The listener was called. Our job here is done. mPendingExitListener = null; + t.removeListener(this); } }; final Transition exitTransition = transition.clone(); exitTransition.addListener(mPendingExitListener); + exitTransition.setEpicenterCallback(new EpicenterCallback() { + @Override + public Rect onGetEpicenter(Transition transition) { + return epicenter; + } + }); final int count = getChildCount(); for (int i = 0; i < count; i++) { |