Skip to content

Instantly share code, notes, and snippets.

@brnhffmnn
Created June 11, 2013 09:34
Show Gist options
  • Save brnhffmnn/5755653 to your computer and use it in GitHub Desktop.
Save brnhffmnn/5755653 to your computer and use it in GitHub Desktop.
ActionBarSherlock: IcsListPopupWindow screen clipping method. Untested. Call in show(): mPopup.setWindowLayoutMode(widthSpec, heightSpec); applyClipToScreen(); //XXX mPopup.setClipToScreenEnabled(true);
protected void applyClipToScreen() {
final WindowManager.LayoutParams p = (LayoutParams) mPromptView.getLayoutParams();
mDropDownAnchorView.getLocationOnScreen(mScreenLocation);
final Rect displayFrame = new Rect();
mDropDownAnchorView.getWindowVisibleDisplayFrame(displayFrame);
final 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 = Math.min(p.width, displayFrameWidth);
}
if (mPromptPosition == POSITION_PROMPT_ABOVE) {
int popupTop = mScreenLocation[1] + mDropDownHorizontalOffset - mDropDownWidth;
if (popupTop < 0) {
p.y += popupTop;
}
} else {
p.y = Math.max(p.y, displayFrame.top);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment