diff options
| author | Romain Guy <romainguy@android.com> | 2010-03-08 17:44:40 -0800 |
|---|---|---|
| committer | Romain Guy <romainguy@android.com> | 2010-03-08 17:44:40 -0800 |
| commit | 3e141685003939a9addce21ba2492ea3a8aebee6 (patch) | |
| tree | 94272f31a5f8eec7d80c6c91657ba69a26ac6bfe /core/java/android/widget/PopupWindow.java | |
| parent | 31e78e07254d672797c5972beba39b0e6f154184 (diff) | |
Fix scrolling bug in AutoCompleteTextView.
Bug #2495033
This fixes various issues. ACTV would sometimes not update its popup to match
its size/location.
Change-Id: Ic662bddf40e49b09482b15ff91666be3709da1d5
Diffstat (limited to 'core/java/android/widget/PopupWindow.java')
| -rw-r--r-- | core/java/android/widget/PopupWindow.java | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index d20ab3beadf6..cf2ed86745dc 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -126,7 +126,7 @@ public class PopupWindow { WindowManager.LayoutParams p = (WindowManager.LayoutParams) mPopupView.getLayoutParams(); - mAboveAnchor = findDropDownPosition(anchor, p, mAnchorXoff, mAnchorYoff); + updateAboveAnchor(findDropDownPosition(anchor, p, mAnchorXoff, mAnchorYoff)); update(p.x, p.y, -1, -1, true); } } @@ -729,22 +729,8 @@ public class PopupWindow { WindowManager.LayoutParams p = createPopupLayout(anchor.getWindowToken()); preparePopup(p); - mAboveAnchor = findDropDownPosition(anchor, p, xoff, yoff); - if (mBackground != null) { - // If the background drawable provided was a StateListDrawable with above-anchor - // and below-anchor states, use those. Otherwise rely on refreshDrawableState to - // do the job. - if (mAboveAnchorBackgroundDrawable != null) { - if (mAboveAnchor) { - mPopupView.setBackgroundDrawable(mAboveAnchorBackgroundDrawable); - } else { - mPopupView.setBackgroundDrawable(mBelowAnchorBackgroundDrawable); - } - } else { - mPopupView.refreshDrawableState(); - } - } + updateAboveAnchor(findDropDownPosition(anchor, p, xoff, yoff)); if (mHeightMode < 0) p.height = mLastHeight = mHeightMode; if (mWidthMode < 0) p.width = mLastWidth = mWidthMode; @@ -754,6 +740,27 @@ public class PopupWindow { invokePopup(p); } + private void updateAboveAnchor(boolean aboveAnchor) { + if (aboveAnchor != mAboveAnchor) { + mAboveAnchor = aboveAnchor; + + if (mBackground != null) { + // If the background drawable provided was a StateListDrawable with above-anchor + // and below-anchor states, use those. Otherwise rely on refreshDrawableState to + // do the job. + if (mAboveAnchorBackgroundDrawable != null) { + if (mAboveAnchor) { + mPopupView.setBackgroundDrawable(mAboveAnchorBackgroundDrawable); + } else { + mPopupView.setBackgroundDrawable(mBelowAnchorBackgroundDrawable); + } + } else { + mPopupView.refreshDrawableState(); + } + } + } + } + /** * Indicates whether the popup is showing above (the y coordinate of the popup's bottom * is less than the y coordinate of the anchor) or below the anchor view (the y coordinate @@ -915,7 +922,7 @@ public class PopupWindow { anchor.getLocationInWindow(mDrawingLocation); p.x = mDrawingLocation[0] + xoff; - p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff; + p.y = mDrawingLocation[1] + anchor.getHeight() + yoff; boolean onTop = false; @@ -932,26 +939,26 @@ public class PopupWindow { // the edit box int scrollX = anchor.getScrollX(); int scrollY = anchor.getScrollY(); - Rect r = new Rect(scrollX, scrollY, scrollX + mPopupWidth, - scrollY + mPopupHeight + anchor.getMeasuredHeight()); + Rect r = new Rect(scrollX, scrollY, scrollX + mPopupWidth + xoff, + scrollY + mPopupHeight + anchor.getHeight() + yoff); anchor.requestRectangleOnScreen(r, true); - + // now we re-evaluate the space available, and decide from that // whether the pop-up will go above or below the anchor. anchor.getLocationInWindow(mDrawingLocation); p.x = mDrawingLocation[0] + xoff; - p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff; + p.y = mDrawingLocation[1] + anchor.getHeight() + yoff; // determine whether there is more space above or below the anchor anchor.getLocationOnScreen(mScreenLocation); - onTop = (displayFrame.bottom - mScreenLocation[1] - anchor.getMeasuredHeight() - yoff) < + onTop = (displayFrame.bottom - mScreenLocation[1] - anchor.getHeight() - yoff) < (mScreenLocation[1] - yoff - displayFrame.top); if (onTop) { p.gravity = Gravity.LEFT | Gravity.BOTTOM; p.y = root.getHeight() - mDrawingLocation[1] + yoff; } else { - p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff; + p.y = mDrawingLocation[1] + anchor.getHeight() + yoff; } } @@ -1257,13 +1264,16 @@ public class PopupWindow { } } + int x = p.x; + int y = p.y; + if (updateLocation) { - mAboveAnchor = findDropDownPosition(anchor, p, xoff, yoff); + updateAboveAnchor(findDropDownPosition(anchor, p, xoff, yoff)); } else { - mAboveAnchor = findDropDownPosition(anchor, p, mAnchorXoff, mAnchorYoff); + updateAboveAnchor(findDropDownPosition(anchor, p, mAnchorXoff, mAnchorYoff)); } - - update(p.x, p.y, width, height); + + update(p.x, p.y, width, height, x != p.x || y != p.y); } /** |
