/// <summary><p>Positions the popup window on screen.</summary> /// <remarks> /// <p>Positions the popup window on screen. When the popup window is too /// tall to fit under the anchor, a parent scroll view is seeked and scrolled /// up to reclaim space. If scrolling is not possible or not enough, the /// popup window gets moved on top of the anchor.</p> /// <p>The height must have been set on the layout parameters prior to /// calling this method.</p> /// </remarks> /// <param name="anchor">the view on which the popup window must be anchored</param> /// <param name="p">the layout parameters used to display the drop down</param> /// <returns>true if the popup is translated upwards to fit on screen</returns> private bool findDropDownPosition(android.view.View anchor, android.view.WindowManagerClass .LayoutParams p, int xoff, int yoff) { int anchorHeight = anchor.getHeight(); anchor.getLocationInWindow(mDrawingLocation); p.x = mDrawingLocation[0] + xoff; p.y = mDrawingLocation[1] + anchorHeight + yoff; bool onTop = false; p.gravity = android.view.Gravity.LEFT | android.view.Gravity.TOP; anchor.getLocationOnScreen(mScreenLocation); android.graphics.Rect displayFrame = new android.graphics.Rect(); anchor.getWindowVisibleDisplayFrame(displayFrame); int screenY = mScreenLocation[1] + anchorHeight + yoff; android.view.View root = anchor.getRootView(); if (screenY + mPopupHeight > displayFrame.bottom || p.x + mPopupWidth - root.getWidth () > 0) { // if the drop down disappears at the bottom of the screen. we try to // scroll a parent scrollview or move the drop down back up on top of // the edit box if (mAllowScrollingAnchorParent) { int scrollX = anchor.getScrollX(); int scrollY = anchor.getScrollY(); android.graphics.Rect r = new android.graphics.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.getHeight() + yoff; // determine whether there is more space above or below the anchor anchor.getLocationOnScreen(mScreenLocation); onTop = (displayFrame.bottom - mScreenLocation[1] - anchor.getHeight() - yoff) < (mScreenLocation[1] - yoff - displayFrame.top); if (onTop) { p.gravity = android.view.Gravity.LEFT | android.view.Gravity.BOTTOM; p.y = root.getHeight() - mDrawingLocation[1] + yoff; } else { p.y = mDrawingLocation[1] + anchor.getHeight() + yoff; } } if (mClipToScreen) { int displayFrameWidth = displayFrame.right - displayFrame.left; int right = p.x + p.width; if (right > displayFrameWidth) { p.x -= right - displayFrameWidth; } if (p.x < displayFrame.left) { p.x = displayFrame.left; p.width = System.Math.Min(p.width, displayFrameWidth); } if (onTop) { int popupTop = mScreenLocation[1] + yoff - mPopupHeight; if (popupTop < 0) { p.y += popupTop; } } else { p.y = System.Math.Max(p.y, displayFrame.top); } } p.gravity |= android.view.Gravity.DISPLAY_CLIP_VERTICAL; return onTop; }
private void setTouchTargetView(android.view.View view) { mTouchTargetView = view; if (view != null) { view.getLocationInWindow(mTouchTargetWindowLocation); } }