Merge change 1708 into donut
* changes: Fixes #1853550. Prevent NPE when calling the PopupWindow() and PopupWindow(int, int) constructors. Instead, throw an IllegalStateException when trying to show a popup with no content view.
This commit is contained in:
@@ -73,8 +73,8 @@ public class PopupWindow {
|
|||||||
*/
|
*/
|
||||||
public static final int INPUT_METHOD_NOT_NEEDED = 2;
|
public static final int INPUT_METHOD_NOT_NEEDED = 2;
|
||||||
|
|
||||||
private final Context mContext;
|
private Context mContext;
|
||||||
private final WindowManager mWindowManager;
|
private WindowManager mWindowManager;
|
||||||
|
|
||||||
private boolean mIsShowing;
|
private boolean mIsShowing;
|
||||||
private boolean mIsDropdown;
|
private boolean mIsDropdown;
|
||||||
@@ -159,8 +159,7 @@ public class PopupWindow {
|
|||||||
*/
|
*/
|
||||||
public PopupWindow(Context context, AttributeSet attrs, int defStyle) {
|
public PopupWindow(Context context, AttributeSet attrs, int defStyle) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mWindowManager = (WindowManager)context.getSystemService(
|
mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
|
||||||
Context.WINDOW_SERVICE);
|
|
||||||
|
|
||||||
TypedArray a =
|
TypedArray a =
|
||||||
context.obtainStyledAttributes(
|
context.obtainStyledAttributes(
|
||||||
@@ -273,11 +272,11 @@ public class PopupWindow {
|
|||||||
* @param height the popup's height
|
* @param height the popup's height
|
||||||
* @param focusable true if the popup can be focused, false otherwise
|
* @param focusable true if the popup can be focused, false otherwise
|
||||||
*/
|
*/
|
||||||
public PopupWindow(View contentView, int width, int height,
|
public PopupWindow(View contentView, int width, int height, boolean focusable) {
|
||||||
boolean focusable) {
|
if (contentView != null) {
|
||||||
mContext = contentView.getContext();
|
mContext = contentView.getContext();
|
||||||
mWindowManager = (WindowManager)mContext.getSystemService(
|
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
|
||||||
Context.WINDOW_SERVICE);
|
}
|
||||||
setContentView(contentView);
|
setContentView(contentView);
|
||||||
setWidth(width);
|
setWidth(width);
|
||||||
setHeight(height);
|
setHeight(height);
|
||||||
@@ -374,6 +373,14 @@ public class PopupWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mContentView = contentView;
|
mContentView = contentView;
|
||||||
|
|
||||||
|
if (mContext == null) {
|
||||||
|
mContext = mContentView.getContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mWindowManager == null) {
|
||||||
|
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -748,6 +755,11 @@ public class PopupWindow {
|
|||||||
* @param p the layout parameters of the popup's content view
|
* @param p the layout parameters of the popup's content view
|
||||||
*/
|
*/
|
||||||
private void preparePopup(WindowManager.LayoutParams p) {
|
private void preparePopup(WindowManager.LayoutParams p) {
|
||||||
|
if (mContentView == null || mContext == null || mWindowManager == null) {
|
||||||
|
throw new IllegalStateException("You must specify a valid content view by "
|
||||||
|
+ "calling setContentView() before attempting to show the popup.");
|
||||||
|
}
|
||||||
|
|
||||||
if (mBackground != null) {
|
if (mBackground != null) {
|
||||||
final ViewGroup.LayoutParams layoutParams = mContentView.getLayoutParams();
|
final ViewGroup.LayoutParams layoutParams = mContentView.getLayoutParams();
|
||||||
int height = ViewGroup.LayoutParams.FILL_PARENT;
|
int height = ViewGroup.LayoutParams.FILL_PARENT;
|
||||||
|
|||||||
Reference in New Issue
Block a user