diff --git a/README.md b/README.md index 80b0919..f0794ec 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ allprojects { ``` dependencies { ... - implementation 'com.github.xuexiangjys:XUpdate:1.1.2' + implementation 'com.github.xuexiangjys:XUpdate:1.1.3' } ``` @@ -300,7 +300,7 @@ XUpdate.newBuild(getActivity()) * promptThemeColor: 设置主题颜色(升级/安装按钮的背景色) * promptTopResId: 弹窗的标题背景的资源图片 -* promptWidthRatio: 弹窗宽度占屏幕宽度的比例,默认是0.8 +* promptWidthRatio: 弹窗宽度占屏幕宽度的比例,默认是-1,不做约束 * promptHeightRatio: 弹窗高度占屏幕高度的比例,默认是-1,不做约束 ``` diff --git a/app/build.gradle b/app/build.gradle index f1fa26b..9c4abc0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,7 +60,7 @@ dependencies { androidTestImplementation deps.espresso.core implementation project(':xupdate-lib') -// implementation 'com.github.xuexiangjys:XUpdate:1.1.1' +// implementation 'com.github.xuexiangjys:XUpdate:1.1.2' implementation 'com.github.xuexiangjys.XUtil:xutil-core:1.1.6' implementation 'com.github.xuexiangjys.XUtil:xutil-sub:1.1.6' diff --git a/xupdate-lib/src/main/java/com/xuexiang/xupdate/UpdateManager.java b/xupdate-lib/src/main/java/com/xuexiang/xupdate/UpdateManager.java index 7a823d6..53a9e1d 100644 --- a/xupdate-lib/src/main/java/com/xuexiang/xupdate/UpdateManager.java +++ b/xupdate-lib/src/main/java/com/xuexiang/xupdate/UpdateManager.java @@ -653,12 +653,12 @@ public Builder supportBackgroundUpdate(boolean supportBackgroundUpdate) { } /** - * 设置版本更新提示器宽度占屏幕的比例,默认是0.8 + * 设置版本更新提示器宽度占屏幕的比例,默认是-1,不做约束 * * @param widthRatio * @return */ - public Builder promptWidthRatio(@FloatRange(from = 0.5F, to = 1F) float widthRatio) { + public Builder promptWidthRatio(float widthRatio) { promptEntity.setWidthRatio(widthRatio); return this; } diff --git a/xupdate-lib/src/main/java/com/xuexiang/xupdate/entity/PromptEntity.java b/xupdate-lib/src/main/java/com/xuexiang/xupdate/entity/PromptEntity.java index f87cb16..8be15ed 100644 --- a/xupdate-lib/src/main/java/com/xuexiang/xupdate/entity/PromptEntity.java +++ b/xupdate-lib/src/main/java/com/xuexiang/xupdate/entity/PromptEntity.java @@ -41,7 +41,7 @@ public PromptEntity() { mThemeColor = -1; mTopResId = -1; mSupportBackgroundUpdate = false; - mWidthRatio = 0.8F; + mWidthRatio = -1; mHeightRatio = -1; } @@ -92,7 +92,7 @@ public PromptEntity setSupportBackgroundUpdate(boolean supportBackgroundUpdate) return this; } - public PromptEntity setWidthRatio(@FloatRange(from = 0.5F, to = 1F) float widthRatio) { + public PromptEntity setWidthRatio(float widthRatio) { mWidthRatio = widthRatio; return this; } diff --git a/xupdate-lib/src/main/java/com/xuexiang/xupdate/widget/UpdateDialog.java b/xupdate-lib/src/main/java/com/xuexiang/xupdate/widget/UpdateDialog.java index 9b97bff..36d9bdd 100644 --- a/xupdate-lib/src/main/java/com/xuexiang/xupdate/widget/UpdateDialog.java +++ b/xupdate-lib/src/main/java/com/xuexiang/xupdate/widget/UpdateDialog.java @@ -250,8 +250,10 @@ private void setDialogTheme(int themeColor, int topResId, float widthRatio, floa if (window != null) { WindowManager.LayoutParams lp = window.getAttributes(); DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); - lp.width = (int) (displayMetrics.widthPixels * widthRatio); - if (heightRatio > 0) { + if (widthRatio > 0 && widthRatio < 1) { + lp.width = (int) (displayMetrics.widthPixels * widthRatio); + } + if (heightRatio > 0 && heightRatio < 1) { lp.height = (int) (displayMetrics.heightPixels * heightRatio); } window.setAttributes(lp); diff --git a/xupdate-lib/src/main/java/com/xuexiang/xupdate/widget/UpdateDialogFragment.java b/xupdate-lib/src/main/java/com/xuexiang/xupdate/widget/UpdateDialogFragment.java index 451e009..a4541ef 100644 --- a/xupdate-lib/src/main/java/com/xuexiang/xupdate/widget/UpdateDialogFragment.java +++ b/xupdate-lib/src/main/java/com/xuexiang/xupdate/widget/UpdateDialogFragment.java @@ -181,8 +181,10 @@ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { window.setGravity(Gravity.CENTER); WindowManager.LayoutParams lp = window.getAttributes(); DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); - lp.width = (int) (displayMetrics.widthPixels * mPromptEntity.getWidthRatio()); - if (mPromptEntity.getHeightRatio() > 0) { + if (mPromptEntity.getWidthRatio() > 0 && mPromptEntity.getWidthRatio() < 1) { + lp.width = (int) (displayMetrics.widthPixels * mPromptEntity.getWidthRatio()); + } + if (mPromptEntity.getHeightRatio() > 0 && mPromptEntity.getHeightRatio() < 1) { lp.height = (int) (displayMetrics.heightPixels * mPromptEntity.getHeightRatio()); } window.setAttributes(lp);