Program: 42322
Project: 42322
Buggy source:
/** 
 * <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>
 * @param anchor the view on which the popup window must be anchored
 * @param p the layout parameters used to display the drop down
 * @return true if the popup is translated upwards to fit on screen
 */
private boolean findDropDownPosition(View anchor,WindowManager.LayoutParams p,int xoff,int yoff){
  anchor.getLocationInWindow(mDrawingLocation);
  p.x=mDrawingLocation[0] + xoff;
  p.y=mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff;
  boolean onTop=false;
  p.gravity=Gravity.LEFT | Gravity.TOP;
  anchor.getLocationOnScreen(mScreenLocation);
  final Rect displayFrame=new Rect();
  anchor.getWindowVisibleDisplayFrame(displayFrame);
  final View root=anchor.getRootView();
  if (p.y + mPopupHeight > displayFrame.bottom || p.x + mPopupWidth - root.getWidth() > 0) {
    int scrollX=anchor.getScrollX();
    int scrollY=anchor.getScrollY();
    Rect r=new Rect(scrollX,scrollY,scrollX + mPopupWidth,scrollY + mPopupHeight + anchor.getMeasuredHeight());
    anchor.requestRectangleOnScreen(r,true);
    anchor.getLocationInWindow(mDrawingLocation);
    p.x=mDrawingLocation[0] + xoff;
    p.y=mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff;
    anchor.getLocationOnScreen(mScreenLocation);
    onTop=(displayFrame.bottom - mScreenLocation[1] - anchor.getMeasuredHeight()- 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.gravity|=Gravity.DISPLAY_CLIP_VERTICAL;
  return onTop;
}

Fixed version (ground truth):
/** 
 * <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>
 * @param anchor the view on which the popup window must be anchored
 * @param p the layout parameters used to display the drop down
 * @return true if the popup is translated upwards to fit on screen
 */
private boolean findDropDownPosition(View anchor,WindowManager.LayoutParams p,int xoff,int yoff){
  anchor.getLocationInWindow(mDrawingLocation);
  p.x=mDrawingLocation[0] + xoff;
  p.y=mDrawingLocation[1] + anchor.getHeight() + yoff;
  boolean onTop=false;
  p.gravity=Gravity.LEFT | Gravity.TOP;
  anchor.getLocationOnScreen(mScreenLocation);
  final Rect displayFrame=new Rect();
  anchor.getWindowVisibleDisplayFrame(displayFrame);
  final View root=anchor.getRootView();
  if (p.y + mPopupHeight > displayFrame.bottom || p.x + mPopupWidth - root.getWidth() > 0) {
    int scrollX=anchor.getScrollX();
    int scrollY=anchor.getScrollY();
    Rect r=new Rect(scrollX,scrollY,scrollX + mPopupWidth + xoff,scrollY + mPopupHeight + anchor.getHeight()+ yoff);
    anchor.requestRectangleOnScreen(r,true);
    anchor.getLocationInWindow(mDrawingLocation);
    p.x=mDrawingLocation[0] + xoff;
    p.y=mDrawingLocation[1] + anchor.getHeight() + yoff;
    anchor.getLocationOnScreen(mScreenLocation);
    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.getHeight() + yoff;
    }
  }
  p.gravity|=Gravity.DISPLAY_CLIP_VERTICAL;
  return onTop;
}