summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alan Viverette <alanv@google.com> 2015-02-03 15:49:18 -0800
committer Alan Viverette <alanv@google.com> 2015-02-03 15:49:18 -0800
commit7878edfa1dacf20c6120dbf18327905d6bf117d0 (patch)
tree935862c6073200ed7db437bfc1811b1c9a1c0613
parentad575295918dba197dcf61bfb81d56348ed1f073 (diff)
PopupWindow animation fixes
Calls the dismiss listener immediately, which fixes compatibility with ListPopupWindow's global layout listener. Adjusts anchor bounds to better match up with the laid out window position. Caches the content view to avoid issues with setContentView(null) being called immediately after dismiss(). Change-Id: I897caeba26ffb2e689f8face199d2ab70718a86c
-rw-r--r--core/java/android/widget/PopupWindow.java48
1 files changed, 31 insertions, 17 deletions
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java
index 24380716127a..a929f3dfd5a0 100644
--- a/core/java/android/widget/PopupWindow.java
+++ b/core/java/android/widget/PopupWindow.java
@@ -160,7 +160,22 @@ public class PopupWindow {
private final EpicenterCallback mEpicenterCallback = new EpicenterCallback() {
@Override
public Rect onGetEpicenter(Transition transition) {
- return mAnchorBounds;
+ final View anchor = mAnchor.get();
+ final View decor = mDecorView;
+ if (anchor == null || decor == null) {
+ return null;
+ }
+
+ final Rect anchorBounds = mAnchorBounds;
+ final int[] anchorLocation = mAnchor.get().getLocationOnScreen();
+ final int[] popupLocation = mDecorView.getLocationOnScreen();
+
+ // Compute the position of the anchor relative to the popup.
+ anchorBounds.set(0, 0, anchor.getWidth(), anchor.getHeight());
+ anchorBounds.offset(anchorLocation[0] - popupLocation[0],
+ anchorLocation[1] - popupLocation[1]);
+
+ return anchorBounds;
}
};
@@ -1494,10 +1509,6 @@ public class PopupWindow {
p.gravity |= Gravity.DISPLAY_CLIP_VERTICAL;
- // Compute the position of the anchor relative to the popup.
- mAnchorBounds.set(0, 0, anchorWidth, anchorHeight);
- mAnchorBounds.offset(mDrawingLocation[0] - p.x, mDrawingLocation[1] - p.y);
-
return onTop;
}
@@ -1573,9 +1584,9 @@ public class PopupWindow {
}
/**
- * <p>Dispose of the popup window. This method can be invoked only after
- * {@link #showAsDropDown(android.view.View)} has been executed. Failing that, calling
- * this method will have no effect.</p>
+ * Disposes of the popup window. This method can be invoked only after
+ * {@link #showAsDropDown(android.view.View)} has been executed. Failing
+ * that, calling this method will have no effect.
*
* @see #showAsDropDown(android.view.View)
*/
@@ -1589,6 +1600,9 @@ public class PopupWindow {
mIsShowing = false;
if (mExitTransition != null) {
+ // Cache the content view, since it may change without notice.
+ final View contentView = mContentView;
+
mExitTransition.addTarget(mBackgroundView);
mExitTransition.addListener(new Transition.TransitionListenerAdapter() {
@Override
@@ -1596,7 +1610,7 @@ public class PopupWindow {
transition.removeListener(this);
transition.removeTarget(mBackgroundView);
- dismissImmediate();
+ dismissImmediate(contentView);
}
});
@@ -1605,7 +1619,11 @@ public class PopupWindow {
// Transition to invisible.
mBackgroundView.setVisibility(View.INVISIBLE);
} else {
- dismissImmediate();
+ dismissImmediate(mContentView);
+ }
+
+ if (mOnDismissListener != null) {
+ mOnDismissListener.onDismiss();
}
}
@@ -1613,21 +1631,17 @@ public class PopupWindow {
* Removes the popup from the window manager and tears down the supporting
* view hierarchy, if necessary.
*/
- private void dismissImmediate() {
+ private void dismissImmediate(View contentView) {
try {
mWindowManager.removeViewImmediate(mDecorView);
} finally {
mDecorView.removeView(mBackgroundView);
mDecorView = null;
- if (mBackgroundView != mContentView) {
- ((ViewGroup) mBackgroundView).removeView(mContentView);
+ if (mBackgroundView != contentView) {
+ ((ViewGroup) mBackgroundView).removeView(contentView);
}
mBackgroundView = null;
-
- if (mOnDismissListener != null) {
- mOnDismissListener.onDismiss();
- }
}
}