Skip to content

Commit fb8dbdd

Browse files
committed
update BaseDialog
1 parent db9ba4d commit fb8dbdd

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

AndroidCore/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ version = "1.0.2"
99

1010
android {
1111
compileSdkVersion 29
12-
buildToolsVersion "29.0.2"
12+
buildToolsVersion "29.0.3"
1313

1414
defaultConfig {
1515
minSdkVersion 15

AndroidCore/src/main/java/cn/beingyi/androidcore/base/BaseDialog.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
**/
2020
public abstract class BaseDialog {
2121

22-
2322
public Context context;
2423
Dialog dialog;
2524

@@ -29,7 +28,7 @@ public BaseDialog(Context context) {
2928

3029
Config config=config();
3130

32-
dialog.setCancelable(true);
31+
dialog.setCancelable(config.isCanCancelable());
3332
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
3433
if(!config.isHasBgShadow()) {
3534
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
@@ -54,6 +53,33 @@ public BaseDialog(Context context) {
5453

5554
}
5655

56+
public void setHeight(int height){
57+
DisplayMetrics outMetrics = new DisplayMetrics();
58+
((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
59+
int widthPixels = outMetrics.widthPixels;
60+
int heightPixels = outMetrics.heightPixels;
61+
62+
WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
63+
p.gravity = Gravity.TOP;
64+
p.height= height;
65+
p.width= widthPixels;
66+
dialog.getWindow().setAttributes(p);
67+
}
68+
69+
70+
public void setHeightX(int split){
71+
DisplayMetrics outMetrics = new DisplayMetrics();
72+
((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
73+
int widthPixels = outMetrics.widthPixels;
74+
int heightPixels = outMetrics.heightPixels;
75+
76+
WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
77+
p.gravity = Gravity.TOP;
78+
p.height= heightPixels/split;
79+
p.width= widthPixels;
80+
dialog.getWindow().setAttributes(p);
81+
}
82+
5783

5884
public abstract int getContentView();
5985

@@ -77,8 +103,9 @@ protected <T extends View> T find(int viewId) {
77103

78104

79105
public class Config{
80-
boolean hasBgShadow;
81-
int gravity;
106+
private boolean hasBgShadow;
107+
private int gravity;
108+
private boolean canCancelable;
82109

83110
public boolean isHasBgShadow() {
84111
return hasBgShadow;
@@ -95,6 +122,14 @@ public int getGravity() {
95122
public void setGravity(int gravity) {
96123
this.gravity = gravity;
97124
}
125+
126+
public boolean isCanCancelable() {
127+
return canCancelable;
128+
}
129+
130+
public void setCanCancelable(boolean canCancelable) {
131+
this.canCancelable = canCancelable;
132+
}
98133
}
99134

100135
}

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 29
5-
buildToolsVersion "29.0.2"
5+
buildToolsVersion "29.0.3"
66
defaultConfig {
77
applicationId "cn.beingyi.sample"
88
minSdkVersion 15

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-all.zip

0 commit comments

Comments
 (0)