From 9a426841c94bfbb6427e3313f1698cc42bc2eaaf Mon Sep 17 00:00:00 2001 From: Jenly Date: Tue, 14 Sep 2021 16:08:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E5=A4=96=E6=8F=90=E4=BE=9B=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E5=8F=AF=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 16 +- app-dialog/build.gradle | 10 +- .../java/com/king/app/dialog/AppDialog.java | 71 ++++- .../com/king/app/dialog/AppDialogConfig.java | 8 +- .../com/king/app/dialog/BaseDialogConfig.java | 251 ++++++++++++++++-- .../dialog/fragment/AppDialogFragment.java | 20 +- .../dialog/fragment/BaseDialogFragment.java | 34 ++- .../main/res/anim/app_dialog_bottom_in.xml | 9 + .../main/res/anim/app_dialog_bottom_out.xml | 9 + .../src/main/res/anim/app_dialog_left_in.xml | 9 + .../src/main/res/anim/app_dialog_left_out.xml | 9 + .../src/main/res/anim/app_dialog_right_in.xml | 9 + .../main/res/anim/app_dialog_right_out.xml | 9 + ..._dialog_in.xml => app_dialog_scale_in.xml} | 5 +- ...ialog_out.xml => app_dialog_scale_out.xml} | 5 +- .../src/main/res/anim/app_dialog_top_in.xml | 9 + .../src/main/res/anim/app_dialog_top_out.xml | 9 + ...ctor.xml => app_cancel_color_selector.xml} | 0 app-dialog/src/main/res/layout/app_dialog.xml | 20 +- app-dialog/src/main/res/values/colors.xml | 4 +- app-dialog/src/main/res/values/strings.xml | 2 + app-dialog/src/main/res/values/styles.xml | 31 ++- app-updater/build.gradle | 13 +- .../java/com/king/app/updater/AppUpdater.java | 11 + .../com/king/app/updater/UpdateConfig.java | 20 +- .../app/updater/service/DownloadService.java | 15 +- .../com/king/app/updater/util/AppUtils.java | 6 +- .../app/updater/util/NotificationUtils.java | 37 ++- app/build.gradle | 15 +- app/release/app-release.apk | Bin 2273024 -> 2606391 bytes app/release/output-metadata.json | 4 +- .../com/king/appupdater/MainActivity.java | 91 +++++-- .../res/color/btn_cancel_color_selector.xml | 5 + .../res/drawable/btn_confirm_selector.xml | 18 ++ app/src/main/res/layout/activity_main.xml | 13 +- app/src/main/res/layout/dialog.xml | 10 +- app/src/main/res/layout/dialog_custom.xml | 43 +-- app/src/main/res/layout/dialog_heads_up.xml | 25 ++ app/src/main/res/layout/dialog_progress.xml | 43 +++ app/src/main/res/values/colors.xml | 11 +- app/src/main/res/values/strings.xml | 2 + app/src/main/res/values/styles.xml | 11 + build.gradle | 25 +- gradle.properties | 6 +- versions.gradle | 47 +--- 45 files changed, 800 insertions(+), 220 deletions(-) create mode 100644 app-dialog/src/main/res/anim/app_dialog_bottom_in.xml create mode 100644 app-dialog/src/main/res/anim/app_dialog_bottom_out.xml create mode 100644 app-dialog/src/main/res/anim/app_dialog_left_in.xml create mode 100644 app-dialog/src/main/res/anim/app_dialog_left_out.xml create mode 100644 app-dialog/src/main/res/anim/app_dialog_right_in.xml create mode 100644 app-dialog/src/main/res/anim/app_dialog_right_out.xml rename app-dialog/src/main/res/anim/{app_dialog_in.xml => app_dialog_scale_in.xml} (67%) rename app-dialog/src/main/res/anim/{app_dialog_out.xml => app_dialog_scale_out.xml} (67%) create mode 100644 app-dialog/src/main/res/anim/app_dialog_top_in.xml create mode 100644 app-dialog/src/main/res/anim/app_dialog_top_out.xml rename app-dialog/src/main/res/color/{app_dialog_button_color_selector.xml => app_cancel_color_selector.xml} (100%) create mode 100644 app/src/main/res/color/btn_cancel_color_selector.xml create mode 100644 app/src/main/res/drawable/btn_confirm_selector.xml create mode 100644 app/src/main/res/layout/dialog_heads_up.xml create mode 100644 app/src/main/res/layout/dialog_progress.xml diff --git a/README.md b/README.md index e538d21..9dbdaf9 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,9 @@ allprojects { //----------AndroidX 版本 //app-updater - implementation 'com.github.jenly1314.AppUpdater:app-updater:1.1.0' + implementation 'com.github.jenly1314.AppUpdater:app-updater:1.1.1' //app-dialog - implementation 'com.github.jenly1314.AppUpdater:app-dialog:1.1.0' + implementation 'com.github.jenly1314.AppUpdater:app-dialog:1.1.1' ``` @@ -92,9 +92,9 @@ allprojects { //简单弹框升级 AppDialogConfig config = new AppDialogConfig(context); config.setTitle("简单弹框升级") - .setOk("升级") + .setConfirm("升级") //旧版本使用setOk .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") - .setOnClickOk(new View.OnClickListener() { + .setOnClickConfirm(new View.OnClickListener() { //旧版本使用setOnClickOk @Override public void onClick(View v) { new AppUpdater.Builder() @@ -110,9 +110,9 @@ allprojects { //简单DialogFragment升级 AppDialogConfig config = new AppDialogConfig(context); config.setTitle("简单DialogFragment升级") - .setOk("升级") + .setConfirm("升级") //旧版本使用setOk .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") - .setOnClickOk(new View.OnClickListener() { + .setOnClickConfirm(new View.OnClickListener() { //旧版本使用setOnClickOk @Override public void onClick(View v) { new AppUpdater.Builder() @@ -138,6 +138,10 @@ allprojects { ## 版本记录 +#### v1.1.1:2021-9-14 +* 对外提供更多可配置参数 +* 优化细节 + #### v1.1.0:2021-7-2 (从v1.1.0开始不再发布至JCenter) * 后续版本只支持androidx,版本名称不再带有androidx标识 * 优化细节 diff --git a/app-dialog/build.gradle b/app-dialog/build.gradle index a020802..59505ff 100644 --- a/app-dialog/build.gradle +++ b/app-dialog/build.gradle @@ -32,11 +32,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - testImplementation deps.test.junit - androidTestImplementation deps.test.runner - androidTestImplementation deps.test.espresso - //androidx - compileOnly deps.androidx.appcompat + testImplementation "junit:junit:$versions.junit" + androidTestImplementation "androidx.test.ext:junit:$versions.androidExtJunit" + androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espressoCore" + + compileOnly "androidx.appcompat:appcompat:$versions.appcompat" } diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java index b26937f..95c5fa4 100644 --- a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java +++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java @@ -3,7 +3,7 @@ package com.king.app.dialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; -import android.util.Log; +import android.view.Gravity; import android.view.KeyEvent; import android.view.View; import android.view.Window; @@ -22,7 +22,7 @@ public enum AppDialog { INSTANCE; - private final float DEFAULT_WIDTH_RATIO = 0.85f; + final float DEFAULT_WIDTH_RATIO = 0.85f; private Dialog mDialog; @@ -110,14 +110,13 @@ public enum AppDialog { showDialog(config,true); } - /** * 显示弹框 * @param config 弹框配置 {@link AppDialogConfig} * @param isCancel 是否可取消(默认为true,false则拦截back键) */ public void showDialog(AppDialogConfig config,boolean isCancel){ - showDialog(config.getContext(),config.buildAppDialogView(),config.getStyleId(),DEFAULT_WIDTH_RATIO,isCancel); + showDialog(config.getContext(),config, isCancel); } /** @@ -129,7 +128,6 @@ public enum AppDialog { showDialog(context,config,true); } - /** * 显示弹框 * @param context @@ -137,7 +135,7 @@ public enum AppDialog { * @param isCancel 是否可取消(默认为true,false则拦截back键) */ public void showDialog(Context context,AppDialogConfig config,boolean isCancel){ - showDialog(context,config.buildAppDialogView(),config.getStyleId(),DEFAULT_WIDTH_RATIO,isCancel); + showDialog(context,config.buildAppDialogView(),config.getStyleId(),config.getGravity(),config.getWidthRatio(),isCancel); } /** @@ -180,6 +178,7 @@ public enum AppDialog { showDialog(context,contentView,R.style.app_dialog,widthRatio,isCancel); } + /** * 显示弹框 * @param context @@ -191,6 +190,17 @@ public enum AppDialog { showDialog(context,contentView,styleId,widthRatio,true); } + /** + * 显示弹框 + * @param context + * @param contentView 弹框内容视图 + * @param styleId Dialog样式 + * @param widthRatio 宽度比例,根据屏幕宽度计算得来 + */ + public void showDialog(Context context, View contentView, @StyleRes int styleId, int gravity, float widthRatio){ + showDialog(context,contentView,styleId,gravity, widthRatio, true); + } + /** * 显示弹框 * @param context @@ -200,8 +210,21 @@ public enum AppDialog { * @param isCancel 是否可取消(默认为true,false则拦截back键) */ public void showDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio,final boolean isCancel){ + showDialog(context,contentView,styleId,Gravity.NO_GRAVITY,widthRatio,isCancel); + } + + /** + * 显示弹框 + * @param context + * @param contentView 弹框内容视图 + * @param styleId Dialog样式 + * @param gravity Dialog的对齐方式 + * @param widthRatio 宽度比例,根据屏幕宽度计算得来 + * @param isCancel 是否可取消(默认为true,false则拦截back键) + */ + public void showDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio,final boolean isCancel){ dismissDialog(); - mDialog = createDialog(context,contentView,styleId,widthRatio,isCancel); + mDialog = createDialog(context, contentView, styleId, gravity, widthRatio, isCancel); mDialog.show(); } @@ -209,12 +232,14 @@ public enum AppDialog { * 设置弹框窗口配置 * @param context * @param dialog + * @param gravity * @param widthRatio */ - private void setDialogWindow(Context context,Dialog dialog,float widthRatio){ + private void setDialogWindow(Context context,Dialog dialog,int gravity,float widthRatio){ Window window = dialog.getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.width = (int)(context.getResources().getDisplayMetrics().widthPixels * widthRatio); + lp.gravity = gravity; window.setAttributes(lp); } @@ -302,9 +327,22 @@ public enum AppDialog { * @param widthRatio 宽度比例,根据屏幕宽度计算得来 */ public Dialog createDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio){ - return createDialog(context,contentView,styleId,widthRatio,true); + return createDialog(context,contentView,styleId,Gravity.NO_GRAVITY,widthRatio,true); } + /** + * 创建弹框 + * @param context + * @param contentView 弹框内容视图 + * @param styleId Dialog样式 + * @param gravity Dialog的对齐方式 + * @param widthRatio 宽度比例,根据屏幕宽度计算得来 + */ + public Dialog createDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio){ + return createDialog(context,contentView,styleId,gravity,widthRatio,true); + } + + /** * 创建弹框 * @param context @@ -314,6 +352,19 @@ public enum AppDialog { * @param isCancel 是否可取消(默认为true,false则拦截back键) */ public Dialog createDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio,final boolean isCancel){ + return createDialog(context,contentView,styleId,Gravity.NO_GRAVITY,widthRatio,isCancel); + } + + /** + * 创建弹框 + * @param context + * @param contentView 弹框内容视图 + * @param styleId Dialog样式 + * @param gravity Dialog的对齐方式 + * @param widthRatio 宽度比例,根据屏幕宽度计算得来 + * @param isCancel 是否可取消(默认为true,false则拦截back键) + */ + public Dialog createDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio,final boolean isCancel){ Dialog dialog = new Dialog(context,styleId); dialog.setContentView(contentView); dialog.setCanceledOnTouchOutside(false); @@ -330,7 +381,7 @@ public enum AppDialog { } }); - setDialogWindow(context,dialog,widthRatio); + setDialogWindow(context, dialog, gravity, widthRatio); return dialog; } diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java index 20e9c0a..be5208e 100644 --- a/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java +++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java @@ -98,10 +98,10 @@ public class AppDialogConfig extends BaseDialogConfig{ line.setVisibility(isHideCancel ? View.GONE : View.VISIBLE); } - Button btnDialogOK = getView(okId); - if(btnDialogOK != null){ - setText(btnDialogOK,ok); - btnDialogOK.setOnClickListener(onClickOk != null ? onClickOk : AppDialog.INSTANCE.mOnClickDismissDialog); + Button btnDialogConfirm = getView(confirmId); + if(btnDialogConfirm != null){ + setText(btnDialogConfirm,confirm); + btnDialogConfirm.setOnClickListener(onClickConfirm != null ? onClickConfirm : AppDialog.INSTANCE.mOnClickDismissDialog); } diff --git a/app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java b/app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java index 9963052..dd9e58c 100644 --- a/app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java +++ b/app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java @@ -1,6 +1,7 @@ package com.king.app.dialog; import android.content.Context; +import android.view.Gravity; import android.view.View; import androidx.annotation.IdRes; @@ -17,13 +18,11 @@ public class BaseDialogConfig { /** * 布局ID */ - @LayoutRes - int layoutId; + @LayoutRes int layoutId; /** * 标题视图ID */ - @IdRes - int titleId = R.id.tvDialogTitle; + @IdRes int titleId = R.id.tvDialogTitle; /** * 内容视图ID */ @@ -35,7 +34,7 @@ public class BaseDialogConfig { /** * 确定视图ID(右边按钮) */ - @IdRes int okId = R.id.btnDialogOK; + @IdRes int confirmId = R.id.btnDialogConfirm; /** * 按钮中间分割线ID */ @@ -44,8 +43,12 @@ public class BaseDialogConfig { /** * 样式ID */ - @StyleRes - int styleId = R.style.app_dialog; + @StyleRes int styleId = R.style.app_dialog; + + /** + * 对话框动画样式ID + */ + @StyleRes int animationStyleId = R.style.app_dialog_scale_animation; /** * 标题文本 @@ -62,7 +65,7 @@ public class BaseDialogConfig { /** * 确定按钮文本 */ - CharSequence ok; + CharSequence confirm; /** * 是否隐藏取消按钮,如果隐藏取消则底部只显示一个按钮 */ @@ -72,14 +75,28 @@ public class BaseDialogConfig { */ boolean isHideTitle; + /** + * 宽度比例,根据屏幕宽度计算得来 + */ + float widthRatio = AppDialog.INSTANCE.DEFAULT_WIDTH_RATIO; + + /** + * Dialog对齐方式 + */ + int gravity = Gravity.NO_GRAVITY; + View.OnClickListener onClickCancel; - View.OnClickListener onClickOk; + View.OnClickListener onClickConfirm; public BaseDialogConfig(){ this(R.layout.app_dialog); } + /** + * 构造 + * @param layoutId 布局ID + */ public BaseDialogConfig(@LayoutRes int layoutId){ this.layoutId = layoutId; } @@ -105,6 +122,11 @@ public class BaseDialogConfig { return titleId; } + /** + * 设置标题布局ID + * @param titleId + * @return + */ public BaseDialogConfig setTitleId(@IdRes int titleId) { this.titleId = titleId; return this; @@ -114,15 +136,39 @@ public class BaseDialogConfig { return styleId; } - public BaseDialogConfig setStyleId(@IdRes int styleId) { + /** + * 设置Dialog样式ID(仅对Dialog有效,如果使用的是DialogFragment,请使用{@link #setAnimationStyleId(int)}) + * @param styleId + * @return + */ + public BaseDialogConfig setStyleId(@StyleRes int styleId) { this.styleId = styleId; return this; } + public int getAnimationStyleId(){ + return animationStyleId; + } + + /** + * 对话框动画样式ID (仅对DialogFragment有效,如果使用的是Dialog,请使用{@link #setStyleId(int)}) + * @param animationStyleId + * @return + */ + public BaseDialogConfig setAnimationStyleId(@StyleRes int animationStyleId) { + this.animationStyleId = animationStyleId; + return this; + } + public @IdRes int getContentId() { return contentId; } + /** + * 设置内容布局ID + * @param contentId + * @return + */ public BaseDialogConfig setContentId(@IdRes int contentId) { this.contentId = contentId; return this; @@ -132,17 +178,52 @@ public class BaseDialogConfig { return cancelId; } + /** + * 设置取消按钮布局ID + * @param cancelId + * @return + */ public BaseDialogConfig setCancelId(@IdRes int cancelId) { this.cancelId = cancelId; return this; } + /** + * 获取确定按钮布局ID + * @return + * @Deprecated 请使用 {@link #getConfirmId()}来代替,后续版本可能会移除此方法 + */ + @Deprecated public @IdRes int getOkId() { - return okId; + return getConfirmId(); } + /** + * 设置确定按钮布局ID + * @param okId + * @return + * @Deprecated 请使用 {@link #setConfirmId(int)}来代替,后续版本可能移除此方法 + */ + @Deprecated public BaseDialogConfig setOkId(@IdRes int okId) { - this.okId = okId; + return setConfirmId(okId); + } + + /** + * 获取确定按钮布局ID + * @return + */ + public @IdRes int getConfirmId() { + return confirmId; + } + + /** + * 设置确定按钮布局ID + * @param confirmId + * @return + */ + public BaseDialogConfig setConfirmId(@IdRes int confirmId) { + this.confirmId = confirmId; return this; } @@ -150,6 +231,11 @@ public class BaseDialogConfig { return lineId; } + /** + * 设置分割线布局ID + * @param lineId + * @return + */ public BaseDialogConfig setLineId(@IdRes int lineId) { this.lineId = lineId; return this; @@ -159,11 +245,22 @@ public class BaseDialogConfig { return title; } + /** + * 设置标题 + * @param title + * @return + */ public BaseDialogConfig setTitle(CharSequence title) { this.title = title; return this; } + /** + * 设置标题 + * @param context + * @param resId + * @return + */ public BaseDialogConfig setTitle(@NonNull Context context, @StringRes int resId) { this.title = context.getString(resId); return this; @@ -173,6 +270,11 @@ public class BaseDialogConfig { return content; } + /** + * 设置文本内容 + * @param content + * @return + */ public BaseDialogConfig setContent(CharSequence content) { this.content = content; return this; @@ -182,27 +284,80 @@ public class BaseDialogConfig { return cancel; } + /** + * 设置取消按钮文本内容 + * @param cancel + * @return + */ public BaseDialogConfig setCancel(CharSequence cancel) { this.cancel = cancel; return this; } + /** + * 设置取消按钮文本内容 + * @param context + * @param resId + * @return + */ public BaseDialogConfig setCancel(@NonNull Context context, @StringRes int resId) { this.cancel = context.getString(resId); return this; } + /** + * 获取确定按钮文本内容 + * @return + * @deprecated 请使用 {@link #getConfirm()} 来代替,后续版本可能会移除此方法 + */ public CharSequence getOk() { - return ok; + return getConfirm(); } + /** + * 设置确定按钮文本内容 + * @param ok + * @return + * @deprecated 请使用 {@link #setConfirm(CharSequence)} 来代替,后续版本可能会移除此方法 + */ public BaseDialogConfig setOk(CharSequence ok) { - this.ok = ok; - return this; + return setConfirm(ok); } + /** + * 设置确定按钮文本内容 + * @param context + * @param resId + * @return + * @deprecated 请使用 {@link #setConfirm(Context, int)}来代替,后续版本可能会移除此方法 + */ public BaseDialogConfig setOk(@NonNull Context context, @StringRes int resId) { - this.ok = context.getString(resId); + return setConfirm(context,resId); + } + + public CharSequence getConfirm() { + return confirm; + } + + /** + * 设置确定按钮文本内容 + * @param confirm + * @return + */ + public BaseDialogConfig setConfirm(CharSequence confirm) { + this.confirm = confirm; + return this; + } + + /** + * 设置确定按钮文本内容 + * @param context + * @param resId + * @return + * + */ + public BaseDialogConfig setConfirm(@NonNull Context context, @StringRes int resId) { + this.confirm = context.getString(resId); return this; } @@ -210,6 +365,11 @@ public class BaseDialogConfig { return isHideCancel; } + /** + * 设置是否隐藏取消按钮 + * @param hideCancel + * @return + */ public BaseDialogConfig setHideCancel(boolean hideCancel) { isHideCancel = hideCancel; return this; @@ -219,11 +379,44 @@ public class BaseDialogConfig { return isHideTitle; } + /** + * 设置是否隐藏标题 + * @param hideTitle + * @return + */ public BaseDialogConfig setHideTitle(boolean hideTitle){ isHideTitle = hideTitle; return this; } + public float getWidthRatio() { + return widthRatio; + } + + /** + * 设置Dialog的宽度比例,根据屏幕宽度计算得来 + * @param widthRatio + * @return + */ + public BaseDialogConfig setWidthRatio(float widthRatio){ + this.widthRatio = widthRatio; + return this; + } + + public int getGravity() { + return gravity; + } + + /** + * 设置Dialog的对齐方式 + * @param gravity + * @return + */ + public BaseDialogConfig setGravity(int gravity){ + this.gravity = gravity; + return this; + } + public View.OnClickListener getOnClickCancel() { return onClickCancel; } @@ -238,18 +431,38 @@ public class BaseDialogConfig { return this; } + public View.OnClickListener getOnClickConfirm() { + return onClickConfirm; + } + + /** + * 设置“确定”按钮点击监听,不设置默认点击关闭弹框 + * @param onClickConfirm + * @return + */ + public BaseDialogConfig setOnClickConfirm(View.OnClickListener onClickConfirm) { + this.onClickConfirm = onClickConfirm; + return this; + } + + + /** + * 获取“确定”按钮点击监听,不设置默认点击关闭弹框 + * @return + * @deprecated 请使用 {@link #getOnClickConfirm()}来代替,后续版本可能会移除此方法 + */ public View.OnClickListener getOnClickOk() { - return onClickOk; + return getOnClickConfirm(); } /** * 设置“确定”按钮点击监听,不设置默认点击关闭弹框 * @param onClickOk * @return + * @deprecated 请使用 {@link #setOnClickConfirm(View.OnClickListener)}来代替,后续版本可能会移除此方法 */ public BaseDialogConfig setOnClickOk(View.OnClickListener onClickOk) { - this.onClickOk = onClickOk; - return this; + return setOnClickConfirm(onClickOk); } diff --git a/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java b/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java index 3c738ee..54be9dd 100644 --- a/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java +++ b/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java @@ -1,5 +1,7 @@ package com.king.app.dialog.fragment; +import android.app.Dialog; +import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.Button; @@ -57,12 +59,22 @@ public class AppDialogFragment extends BaseDialogFragment { line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); } - Button btnDialogOK = rootView.findViewById(config.getOkId()); - if(btnDialogOK != null){ - setText(btnDialogOK,config.getOk()); - btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : getOnClickDismiss()); + Button btnDialogConfirm = rootView.findViewById(config.getConfirmId()); + if(btnDialogConfirm != null){ + setText(btnDialogConfirm,config.getConfirm()); + btnDialogConfirm.setOnClickListener(config.getOnClickConfirm() != null ? config.getOnClickConfirm() : getOnClickDismiss()); } } } + + + @Override + protected void initDialogWindow(Context context, Dialog dialog, int gravity, float widthRatio, int animationStyleId) { + if(config != null){ + super.initDialogWindow(context,dialog,config.getGravity(), config.getWidthRatio(), config.getAnimationStyleId()); + }else{ + super.initDialogWindow(context, dialog, gravity, widthRatio, animationStyleId); + } + } } \ No newline at end of file diff --git a/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java b/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java index 869fadf..43d4391 100644 --- a/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java +++ b/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java @@ -5,6 +5,7 @@ import android.content.Context; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -27,29 +28,44 @@ public abstract class BaseDialogFragment extends DialogFragment { private View mRootView; + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - super.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); - super.getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); - mRootView = inflater.inflate(getRootLayoutId(), container, false); init(mRootView); return mRootView; } + + @NonNull @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - super.getDialog().getWindow().getAttributes().windowAnimations = R.style.app_dialog_animation; - getDialog().setCanceledOnTouchOutside(false); - setDialogWindow(getContext(),getDialog(),DEFAULT_WIDTH_RATIO); + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + Dialog dialog = super.onCreateDialog(savedInstanceState); + dialog.setCanceledOnTouchOutside(false); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + initDialogWindow(getContext(),dialog,Gravity.NO_GRAVITY,DEFAULT_WIDTH_RATIO,R.style.app_dialog_scale_animation); + return dialog; + } + + protected void initDialogWindow(Context context,Dialog dialog,int gravity,float widthRatio,int animationStyleId){ + setDialogWindow(context, dialog, gravity, widthRatio, animationStyleId); } - private void setDialogWindow(Context context, Dialog dialog, float widthRatio){ + /** + * 设置弹框窗口配置 + * @param context + * @param dialog + * @param gravity + * @param widthRatio + */ + private void setDialogWindow(Context context,Dialog dialog,int gravity,float widthRatio,int animationStyleId){ Window window = dialog.getWindow(); + window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); WindowManager.LayoutParams lp = window.getAttributes(); + lp.windowAnimations = animationStyleId; lp.width = (int)(context.getResources().getDisplayMetrics().widthPixels * widthRatio); + lp.gravity = gravity; window.setAttributes(lp); } diff --git a/app-dialog/src/main/res/anim/app_dialog_bottom_in.xml b/app-dialog/src/main/res/anim/app_dialog_bottom_in.xml new file mode 100644 index 0000000..eb805d5 --- /dev/null +++ b/app-dialog/src/main/res/anim/app_dialog_bottom_in.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/anim/app_dialog_bottom_out.xml b/app-dialog/src/main/res/anim/app_dialog_bottom_out.xml new file mode 100644 index 0000000..8d764ff --- /dev/null +++ b/app-dialog/src/main/res/anim/app_dialog_bottom_out.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/anim/app_dialog_left_in.xml b/app-dialog/src/main/res/anim/app_dialog_left_in.xml new file mode 100644 index 0000000..fcf2204 --- /dev/null +++ b/app-dialog/src/main/res/anim/app_dialog_left_in.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/anim/app_dialog_left_out.xml b/app-dialog/src/main/res/anim/app_dialog_left_out.xml new file mode 100644 index 0000000..18dad1d --- /dev/null +++ b/app-dialog/src/main/res/anim/app_dialog_left_out.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/anim/app_dialog_right_in.xml b/app-dialog/src/main/res/anim/app_dialog_right_in.xml new file mode 100644 index 0000000..b6c84dc --- /dev/null +++ b/app-dialog/src/main/res/anim/app_dialog_right_in.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/anim/app_dialog_right_out.xml b/app-dialog/src/main/res/anim/app_dialog_right_out.xml new file mode 100644 index 0000000..c3a87f7 --- /dev/null +++ b/app-dialog/src/main/res/anim/app_dialog_right_out.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/anim/app_dialog_in.xml b/app-dialog/src/main/res/anim/app_dialog_scale_in.xml similarity index 67% rename from app-dialog/src/main/res/anim/app_dialog_in.xml rename to app-dialog/src/main/res/anim/app_dialog_scale_in.xml index 847f7a0..9d060fa 100644 --- a/app-dialog/src/main/res/anim/app_dialog_in.xml +++ b/app-dialog/src/main/res/anim/app_dialog_scale_in.xml @@ -1,6 +1,7 @@ - - + - - + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/anim/app_dialog_top_out.xml b/app-dialog/src/main/res/anim/app_dialog_top_out.xml new file mode 100644 index 0000000..9fcc37c --- /dev/null +++ b/app-dialog/src/main/res/anim/app_dialog_top_out.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/color/app_dialog_button_color_selector.xml b/app-dialog/src/main/res/color/app_cancel_color_selector.xml similarity index 100% rename from app-dialog/src/main/res/color/app_dialog_button_color_selector.xml rename to app-dialog/src/main/res/color/app_cancel_color_selector.xml diff --git a/app-dialog/src/main/res/layout/app_dialog.xml b/app-dialog/src/main/res/layout/app_dialog.xml index fbb9c61..aba0186 100644 --- a/app-dialog/src/main/res/layout/app_dialog.xml +++ b/app-dialog/src/main/res/layout/app_dialog.xml @@ -11,7 +11,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" - android:padding="10dp" + android:paddingTop="10dp" + android:paddingBottom="10dp" + android:paddingLeft="16dp" + android:paddingRight="16dp" android:lines="1" android:textSize="@dimen/app_dialog_title_text_size" android:textColor="@color/app_dialog_title_color" @@ -20,10 +23,13 @@ android:id="@+id/tvDialogContent" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="10dp" + android:paddingTop="10dp" + android:paddingBottom="10dp" + android:paddingLeft="16dp" + android:paddingRight="16dp" android:textSize="@dimen/app_dialog_content_text_size" - android:textColor="@color/app_dialog_content_color" android:layout_marginBottom="16dp" + android:textColor="@color/app_dialog_content_color" android:lineSpacingMultiplier="1.2" />