Skip to content

Commit 3fa3e3c

Browse files
committed
// 2.2.0-alpha2
1 parent bfb6644 commit 3fa3e3c

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ QuickPopupBuilder支持链式调用生成一个基于QuickPopup的PopupWindow,
319319
### 更新日志 ([历史更新](https://github.com/razerdp/BasePopup/blob/master/UpdateLog.md))
320320

321321
* **Candy2.2.0**
322+
* **Candy2.2.0-alpha2**(2019/03/21)
323+
* 增加`setMaxWidth()`和`setMaxHeight()`方法,想最大半屏显示?走起~
322324
* **Candy2.2.0-alpha**(2019/03/21)
323325
* 增加`setBackgroundView(View)`方法,现在BasePopup的背景控件可以随意由你定制啦~当然PopupWindow的背景动画控制方法依旧生效
324326

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def moduleName = 'BasePopup_Candy'
3535

3636

3737
group = "com.github.razerdp"
38-
version = "2.2.0-alpha"
38+
version = "2.2.0-alpha2"
3939

4040
install {
4141
repositories.mavenInstaller {

lib/src/main/java/razerdp/basepopup/BasePopupHelper.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ final class BasePopupHelper implements PopupTouchController, PopupWindowActionLi
108108
private boolean isCustomMeasureWidth;
109109
private boolean isCustomMeasureHeight;
110110

111+
private int maxWidth, maxHeight;
111112

112113
BasePopupHelper(PopupTouchController controller) {
113114
mAnchorViewLocation = new int[2];
@@ -617,6 +618,24 @@ BasePopupHelper setBackgroundView(View backgroundView) {
617618
return this;
618619
}
619620

621+
int getMaxWidth() {
622+
return maxWidth;
623+
}
624+
625+
BasePopupHelper setMaxWidth(int maxWidth) {
626+
this.maxWidth = maxWidth;
627+
return this;
628+
}
629+
630+
int getMaxHeight() {
631+
return maxHeight;
632+
}
633+
634+
BasePopupHelper setMaxHeight(int maxHeight) {
635+
this.maxHeight = maxHeight;
636+
return this;
637+
}
638+
620639
//-----------------------------------------controller-----------------------------------------
621640
void handleShow() {
622641
//针对官方的坑(两个popup切换页面后重叠)

lib/src/main/java/razerdp/basepopup/BasePopupWindow.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,15 @@ public BasePopupWindow setHeight(int height) {
17611761
return this;
17621762
}
17631763

1764+
public BasePopupWindow setMaxWidth(int maxWidth) {
1765+
mHelper.setMaxWidth(maxWidth);
1766+
return this;
1767+
}
1768+
1769+
public BasePopupWindow setMaxHeight(int maxHeight) {
1770+
mHelper.setMaxHeight(maxHeight);
1771+
return this;
1772+
}
17641773
//------------------------------------------状态控制-----------------------------------------------
17651774

17661775

lib/src/main/java/razerdp/basepopup/PopupDecorViewProxy.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,31 @@ private void measureWithIntercept(int widthMeasureSpec, int heightMeasureSpec) {
217217
measureChild(child, MeasureSpec.makeMeasureSpec(getScreenWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(getScreenHeight(), MeasureSpec.EXACTLY));
218218
} else {
219219
final LayoutParams lp = child.getLayoutParams();
220+
221+
int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
222+
if (mHelper.getMaxWidth() > 0) {
223+
int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
224+
if (sizeWidth > mHelper.getMaxWidth()) {
225+
widthMeasureSpec = MeasureSpec.makeMeasureSpec(mHelper.getMaxWidth(), MeasureSpec.EXACTLY);
226+
}
227+
}
228+
220229
final int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
221230
childLeftMargin + childRightMargin, lp.width);
222231
int fixedHeightMeasureSpec = heightMeasureSpec;
223232
//针对match_parent
224233
if (mHelper.isClipToScreen() && mHelper.isShowAsDropDown() && lp.height == LayoutParams.MATCH_PARENT) {
225-
int mode = MeasureSpec.getMode(heightMeasureSpec);
226234
int restContentHeight = getScreenHeight() - (mHelper.getAnchorY() + mHelper.getAnchorHeight()) - childTopMargin - childBottomMargin;
227235
if (restContentHeight == 0) {
228236
restContentHeight = MeasureSpec.getSize(heightMeasureSpec);
229237
}
230-
fixedHeightMeasureSpec = MeasureSpec.makeMeasureSpec(restContentHeight, mode);
238+
fixedHeightMeasureSpec = MeasureSpec.makeMeasureSpec(restContentHeight, modeHeight);
239+
}
240+
if (mHelper.getMaxHeight() > 0) {
241+
int sizeHeight = MeasureSpec.getSize(fixedHeightMeasureSpec);
242+
if (sizeHeight > mHelper.getMaxHeight()) {
243+
fixedHeightMeasureSpec = MeasureSpec.makeMeasureSpec(mHelper.getMaxHeight(), MeasureSpec.EXACTLY);
244+
}
231245
}
232246
final int childHeightMeasureSpec = getChildMeasureSpec(fixedHeightMeasureSpec,
233247
childTopMargin + childBottomMargin, lp.height);
@@ -249,6 +263,14 @@ private void measureWithOutIntercept(int widthMeasureSpec, int heightMeasureSpec
249263
if (child.getVisibility() != GONE) {
250264
if (child == mTarget) {
251265
final LayoutParams lp = child.getLayoutParams();
266+
267+
if (mHelper.getMaxWidth() > 0) {
268+
int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
269+
if (sizeWidth > mHelper.getMaxWidth()) {
270+
widthMeasureSpec = MeasureSpec.makeMeasureSpec(mHelper.getMaxWidth(), MeasureSpec.EXACTLY);
271+
}
272+
}
273+
252274
int fixedHeightMeasureSpec = heightMeasureSpec;
253275
if (mHelper.isClipToScreen() && mHelper.isShowAsDropDown() && lp.height == LayoutParams.MATCH_PARENT) {
254276
int mode = MeasureSpec.getMode(heightMeasureSpec);
@@ -258,6 +280,14 @@ private void measureWithOutIntercept(int widthMeasureSpec, int heightMeasureSpec
258280
}
259281
fixedHeightMeasureSpec = MeasureSpec.makeMeasureSpec(restContentHeight, mode);
260282
}
283+
284+
if (mHelper.getMaxHeight() > 0) {
285+
int sizeHeight = MeasureSpec.getSize(fixedHeightMeasureSpec);
286+
if (sizeHeight > mHelper.getMaxHeight()) {
287+
fixedHeightMeasureSpec = MeasureSpec.makeMeasureSpec(mHelper.getMaxHeight(), MeasureSpec.EXACTLY);
288+
}
289+
}
290+
261291
final int childHeightMeasureSpec = getChildMeasureSpec(fixedHeightMeasureSpec,
262292
childTopMargin + childBottomMargin, lp.height);
263293

0 commit comments

Comments
 (0)