Exemplo n.º 1
0
		/// <summary>
		/// Returns the maximum height that is available for the popup to be
		/// completely shown, optionally ignoring any bottom decorations such as
		/// the input method.
		/// </summary>
		/// <remarks>
		/// Returns the maximum height that is available for the popup to be
		/// completely shown, optionally ignoring any bottom decorations such as
		/// the input method. It is recommended that this height be the maximum for
		/// the popup's height, otherwise it is possible that the popup will be
		/// clipped.
		/// </remarks>
		/// <param name="anchor">The view on which the popup window must be anchored.</param>
		/// <param name="yOffset">y offset from the view's bottom edge</param>
		/// <param name="ignoreBottomDecorations">
		/// if true, the height returned will be
		/// all the way to the bottom of the display, ignoring any
		/// bottom decorations
		/// </param>
		/// <returns>
		/// The maximum available height for the popup to be completely
		/// shown.
		/// </returns>
		/// <hide>Pending API council approval.</hide>
		public virtual int getMaxAvailableHeight(android.view.View anchor, int yOffset, bool
			 ignoreBottomDecorations)
		{
			android.graphics.Rect displayFrame = new android.graphics.Rect();
			anchor.getWindowVisibleDisplayFrame(displayFrame);
			int[] anchorPos = mDrawingLocation;
			anchor.getLocationOnScreen(anchorPos);
			int bottomEdge = displayFrame.bottom;
			if (ignoreBottomDecorations)
			{
				android.content.res.Resources res = anchor.getContext().getResources();
				bottomEdge = res.getDisplayMetrics().heightPixels;
			}
			int distanceToBottom = bottomEdge - (anchorPos[1] + anchor.getHeight()) - yOffset;
			int distanceToTop = anchorPos[1] - displayFrame.top + yOffset;
			// anchorPos[1] is distance from anchor to top of screen
			int returnedHeight = System.Math.Max(distanceToBottom, distanceToTop);
			if (mBackground != null)
			{
				mBackground.getPadding(mTempRect);
				returnedHeight -= mTempRect.top + mTempRect.bottom;
			}
			return returnedHeight;
		}
Exemplo n.º 2
0
		/// <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;
		}