Fix bug 3067895 - Popup menus clip to container windows
ListPopupWindows will now move to fit within the screen, but will not be constrained by their parent windows. Change-Id: I2a19ef474926f328466db32874db4191beebf626
This commit is contained in:
@@ -576,6 +576,7 @@ public class ListPopupWindow {
|
||||
|
||||
mPopup.setWindowLayoutMode(widthSpec, heightSpec);
|
||||
mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
|
||||
mPopup.setClipToScreenEnabled(true);
|
||||
|
||||
// use outside touchable to dismiss drop down when touching outside of it, so
|
||||
// only set this if the dropdown is not always visible
|
||||
|
||||
@@ -27,7 +27,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.StateListDrawable;
|
||||
import android.os.IBinder;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
@@ -89,6 +89,7 @@ public class PopupWindow {
|
||||
private boolean mClippingEnabled = true;
|
||||
private boolean mSplitTouchEnabled;
|
||||
private boolean mLayoutInScreen;
|
||||
private boolean mClipToScreen;
|
||||
|
||||
private OnTouchListener mTouchInterceptor;
|
||||
|
||||
@@ -101,7 +102,7 @@ public class PopupWindow {
|
||||
|
||||
private int mPopupWidth;
|
||||
private int mPopupHeight;
|
||||
|
||||
|
||||
private int[] mDrawingLocation = new int[2];
|
||||
private int[] mScreenLocation = new int[2];
|
||||
private Rect mTempRect = new Rect();
|
||||
@@ -581,6 +582,17 @@ public class PopupWindow {
|
||||
mClippingEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clip this popup window to the screen, but not to the containing window.
|
||||
*
|
||||
* @param enabled True to clip to the screen.
|
||||
* @hide
|
||||
*/
|
||||
public void setClipToScreenEnabled(boolean enabled) {
|
||||
mClipToScreen = enabled;
|
||||
setClippingEnabled(!enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Indicates whether the popup window supports splitting touches.</p>
|
||||
*
|
||||
@@ -1059,6 +1071,21 @@ public class PopupWindow {
|
||||
}
|
||||
}
|
||||
|
||||
if (mClipToScreen) {
|
||||
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);
|
||||
}
|
||||
|
||||
p.y = Math.max(p.y, displayFrame.top);
|
||||
}
|
||||
|
||||
p.gravity |= Gravity.DISPLAY_CLIP_VERTICAL;
|
||||
|
||||
return onTop;
|
||||
|
||||
Reference in New Issue
Block a user