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" />
diff --git a/app-dialog/src/main/res/values/colors.xml b/app-dialog/src/main/res/values/colors.xml
index e794281..bb89e6a 100644
--- a/app-dialog/src/main/res/values/colors.xml
+++ b/app-dialog/src/main/res/values/colors.xml
@@ -1,13 +1,13 @@
- #FF4081
+ #5588FF
#333333
#333333
#333333
@color/colorAccent
- #f2f2f2
+ #F2F2F2
diff --git a/app-dialog/src/main/res/values/strings.xml b/app-dialog/src/main/res/values/strings.xml
index fe748b8..8fec0c9 100644
--- a/app-dialog/src/main/res/values/strings.xml
+++ b/app-dialog/src/main/res/values/strings.xml
@@ -3,5 +3,7 @@
提示
取消
+ 确定
+
确定
diff --git a/app-dialog/src/main/res/values/styles.xml b/app-dialog/src/main/res/values/styles.xml
index 2e84b0f..d810f96 100644
--- a/app-dialog/src/main/res/values/styles.xml
+++ b/app-dialog/src/main/res/values/styles.xml
@@ -2,9 +2,32 @@
-
+
+
+
+
+
+
+
+
+
+
@@ -15,7 +38,7 @@
- true
- @android:color/transparent
- true
- - @style/app_dialog_animation
+ - @style/app_dialog_scale_animation
diff --git a/app-updater/build.gradle b/app-updater/build.gradle
index 2cfaaf7..d420e3b 100644
--- a/app-updater/build.gradle
+++ b/app-updater/build.gradle
@@ -31,12 +31,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
- compileOnly deps.okhttp
+ 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"
+ compileOnly "com.squareup.okhttp3:okhttp:$versions.okhttp"
}
diff --git a/app-updater/src/main/java/com/king/app/updater/AppUpdater.java b/app-updater/src/main/java/com/king/app/updater/AppUpdater.java
index 380e6c4..f3503bf 100644
--- a/app-updater/src/main/java/com/king/app/updater/AppUpdater.java
+++ b/app-updater/src/main/java/com/king/app/updater/AppUpdater.java
@@ -361,6 +361,17 @@ public class AppUpdater {
return this;
}
+ /**
+ * 是否支持通过删除通知栏来取消下载(默认为:false)
+ * @param cancelDownload
+ * @return
+ */
+ public Builder setCancelDownload(boolean cancelDownload){
+ mConfig.setCancelDownload(cancelDownload);
+ return this;
+ }
+
+
public AppUpdater build(@NonNull Context context){
AppUpdater appUpdater = new AppUpdater(context,mConfig);
return appUpdater;
diff --git a/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java b/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
index ae6a1b7..9612aee 100644
--- a/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
+++ b/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
@@ -97,6 +97,11 @@ public class UpdateConfig implements Parcelable {
*/
private boolean isDeleteCancelFile = true;
+ /**
+ * 是否支持通过删除通知栏来取消下载
+ */
+ private boolean isCancelDownload = false;
+
/**
* APK文件的MD5
*/
@@ -354,12 +359,23 @@ public class UpdateConfig implements Parcelable {
/**
* 设置是否自动删除取消下载的文件
- * @param deleteCancelFile 是否删除取消下载的文件(默认为true)
+ * @param deleteCancelFile 是否删除取消下载的文件(默认为:true)
*/
public void setDeleteCancelFile(boolean deleteCancelFile) {
isDeleteCancelFile = deleteCancelFile;
}
+ public boolean isCancelDownload(){
+ return isCancelDownload;
+ }
+
+ /**
+ * 是否支持通过删除通知栏来取消下载(默认为:false)
+ * @param cancelDownload
+ */
+ public void setCancelDownload(boolean cancelDownload) {
+ isCancelDownload = cancelDownload;
+ }
@Override
public int describeContents() {
@@ -395,6 +411,7 @@ public class UpdateConfig implements Parcelable {
}
dest.writeByte(this.isDeleteCancelFile ? (byte) 1 : (byte) 0);
+ dest.writeByte(this.isCancelDownload ? (byte) 1 : (byte) 0);
dest.writeString(this.apkMD5);
}
@@ -423,6 +440,7 @@ public class UpdateConfig implements Parcelable {
this.mRequestProperty.put(key, value);
}
this.isDeleteCancelFile = in.readByte() != 0;
+ this.isCancelDownload = in.readByte() != 0;
this.apkMD5 = in.readString();
}
diff --git a/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java b/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
index 1f4137c..3b65d4d 100644
--- a/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
+++ b/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
@@ -164,11 +164,7 @@ public class DownloadService extends Service {
}
Log.d(Constants.TAG,"File:" + mFile);
- if(httpManager != null){
- mHttpManager = httpManager;
- }else{
- mHttpManager = HttpManager.getInstance();
- }
+ mHttpManager = httpManager != null ? httpManager : HttpManager.getInstance();
mHttpManager.download(url,path,filename,config.getRequestProperty(),new AppDownloadCallback(config,callback));
}
@@ -177,7 +173,7 @@ public class DownloadService extends Service {
* 停止下载
*/
public void stopDownload(){
- if(mHttpManager!=null){
+ if(mHttpManager != null){
mHttpManager.cancel();
}
}
@@ -231,6 +227,8 @@ public class DownloadService extends Service {
private boolean isDeleteCancelFile;
+ private boolean isCancelDownload;
+
private UpdateCallback callback;
private int reDownloads;
@@ -263,6 +261,7 @@ public class DownloadService extends Service {
this.isShowPercentage = config.isShowPercentage();
this.isReDownload = config.isReDownload();
this.isDeleteCancelFile = config.isDeleteCancelFile();
+ this.isCancelDownload = config.isCancelDownload();
}
@@ -272,7 +271,7 @@ public class DownloadService extends Service {
isDownloading = true;
mLastProgress = 0;
if(isShowNotification){
- NotificationUtils.showStartNotification(getContext(),notifyId,channelId,channelName,notificationIcon,getString(R.string.app_updater_start_notification_title),getString(R.string.app_updater_start_notification_content),config.isVibrate(),config.isSound());
+ NotificationUtils.showStartNotification(getContext(),notifyId,channelId,channelName,notificationIcon,getString(R.string.app_updater_start_notification_title),getString(R.string.app_updater_start_notification_content),config.isVibrate(),config.isSound(),isCancelDownload);
}
if(callback!=null){
@@ -299,7 +298,7 @@ public class DownloadService extends Service {
content += percentage;
}
- NotificationUtils.showProgressNotification(getContext(),notifyId, channelId, notificationIcon, getString(R.string.app_updater_progress_notification_title), content, currProgress, 100);
+ NotificationUtils.showProgressNotification(getContext(),notifyId, channelId, notificationIcon, getString(R.string.app_updater_progress_notification_title), content, currProgress, 100,isCancelDownload);
}
}
diff --git a/app-updater/src/main/java/com/king/app/updater/util/AppUtils.java b/app-updater/src/main/java/com/king/app/updater/util/AppUtils.java
index f61c746..9280677 100644
--- a/app-updater/src/main/java/com/king/app/updater/util/AppUtils.java
+++ b/app-updater/src/main/java/com/king/app/updater/util/AppUtils.java
@@ -40,7 +40,10 @@ public final class AppUtils {
*/
public static String getAppFullName(Context context,String url,String defaultName){
if(url.endsWith(".apk")){
- return url.substring(url.lastIndexOf("/") + 1);
+ String apkName = url.substring(url.lastIndexOf("/") + 1);
+ if(apkName.length() <= 64){
+ return apkName;
+ }
}
String filename = getAppName(context);
@@ -84,7 +87,6 @@ public final class AppUtils {
*/
public static String getAppName(Context context) {
try{
-
int labelRes = getPackageInfo(context).applicationInfo.labelRes;
return context.getResources().getString(labelRes);
} catch (Exception e) {
diff --git a/app-updater/src/main/java/com/king/app/updater/util/NotificationUtils.java b/app-updater/src/main/java/com/king/app/updater/util/NotificationUtils.java
index 9b8308d..89a5c53 100644
--- a/app-updater/src/main/java/com/king/app/updater/util/NotificationUtils.java
+++ b/app-updater/src/main/java/com/king/app/updater/util/NotificationUtils.java
@@ -28,7 +28,7 @@ public class NotificationUtils {
}
/**
- * 显示开始下载是的通知
+ * 显示开始下载时的通知
* @param notifyId
* @param channelId
* @param channelName
@@ -36,12 +36,12 @@ public class NotificationUtils {
* @param title
* @param content
*/
- public static void showStartNotification(Context context, int notifyId,String channelId, String channelName,@DrawableRes int icon,CharSequence title,CharSequence content,boolean isVibrate,boolean isSound){
+ public static void showStartNotification(Context context, int notifyId,String channelId, String channelName,@DrawableRes int icon,CharSequence title,CharSequence content,boolean isVibrate,boolean isSound, boolean isCancelDownload){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
createNotificationChannel(context,channelId,channelName,isVibrate,isSound);
}
NotificationCompat.Builder builder = buildNotification(context,channelId,icon,title,content);
- builder.setPriority(NotificationManager.IMPORTANCE_HIGH);
+ builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
if(isVibrate && isSound){
builder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);
}else if(isVibrate){
@@ -50,8 +50,20 @@ public class NotificationUtils {
builder.setDefaults(Notification.DEFAULT_SOUND);
}
+ if(isCancelDownload){
+ Intent intent = new Intent(context, DownloadService.class);
+ intent.putExtra(Constants.KEY_STOP_DOWNLOAD_SERVICE,true);
+ PendingIntent deleteIntent = PendingIntent.getService(context, notifyId,intent, PendingIntent.FLAG_CANCEL_CURRENT);
+ builder.setDeleteIntent(deleteIntent);
+ }
+
Notification notification = builder.build();
- notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE;
+ if(isCancelDownload){
+ notification.flags = Notification.FLAG_ONLY_ALERT_ONCE;
+ }else{
+ notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE;
+ }
+
notifyNotification(context,notifyId,notification);
}
@@ -65,11 +77,24 @@ public class NotificationUtils {
* @param progress
* @param size
*/
- public static void showProgressNotification(Context context, int notifyId,String channelId,@DrawableRes int icon,CharSequence title,CharSequence content,int progress,int size){
+ public static void showProgressNotification(Context context, int notifyId,String channelId,@DrawableRes int icon,CharSequence title,CharSequence content,int progress,int size, boolean isCancelDownload){
NotificationCompat.Builder builder = buildNotification(context,channelId,icon,title,content,progress,size);
+ if(isCancelDownload){
+ Intent intent = new Intent(context, DownloadService.class);
+ intent.putExtra(Constants.KEY_STOP_DOWNLOAD_SERVICE,true);
+ PendingIntent deleteIntent = PendingIntent.getService(context, notifyId,intent, PendingIntent.FLAG_CANCEL_CURRENT);
+ builder.setDeleteIntent(deleteIntent);
+ }
+
Notification notification = builder.build();
- notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE;
+
+ if(isCancelDownload){
+ notification.flags = Notification.FLAG_ONLY_ALERT_ONCE;
+ }else{
+ notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE;
+ }
+
notifyNotification(context,notifyId,notification);
}
diff --git a/app/build.gradle b/app/build.gradle
index f43b2ae..66bf61b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -24,13 +24,14 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
- testImplementation deps.test.junit
- androidTestImplementation deps.test.runner
- androidTestImplementation deps.test.espresso
- //androidx
- implementation deps.androidx.appcompat
- implementation deps.androidx.constraintlayout
- implementation deps.okhttp
+ testImplementation "junit:junit:$versions.junit"
+ androidTestImplementation "androidx.test.ext:junit:$versions.androidExtJunit"
+ androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espressoCore"
+
+ implementation "androidx.appcompat:appcompat:$versions.appcompat"
+ implementation "androidx.constraintlayout:constraintlayout:$versions.constraintLayout"
+
+ implementation "com.squareup.okhttp3:okhttp:$versions.okhttp"
implementation project(':app-updater')
implementation project(':app-dialog')
diff --git a/app/release/app-release.apk b/app/release/app-release.apk
index 2ce9bed..9ba6029 100644
Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ
diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json
index 5c5bea5..e745fee 100644
--- a/app/release/output-metadata.json
+++ b/app/release/output-metadata.json
@@ -10,8 +10,8 @@
{
"type": "SINGLE",
"filters": [],
- "versionCode": 19,
- "versionName": "1.1.0",
+ "versionCode": 20,
+ "versionName": "1.1.1",
"outputFile": "app-release.apk"
}
]
diff --git a/app/src/main/java/com/king/appupdater/MainActivity.java b/app/src/main/java/com/king/appupdater/MainActivity.java
index 76f261a..b874c4d 100644
--- a/app/src/main/java/com/king/appupdater/MainActivity.java
+++ b/app/src/main/java/com/king/appupdater/MainActivity.java
@@ -3,10 +3,11 @@ package com.king.appupdater;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
+import android.os.CountDownTimer;
import android.util.Log;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
@@ -39,6 +40,7 @@ public class MainActivity extends AppCompatActivity {
// private String mUrl = "https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk";
private String mUrl = "https://gitlab.com/jenly1314/AppUpdater/-/raw/master/app/release/app-release.apk";
+ private TextView tvProgress;
private ProgressBar progressBar;
private Toast toast;
@@ -49,9 +51,9 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- progressBar = findViewById(R.id.progressBar);
- progressBar.setVisibility(View.INVISIBLE);
- progressBar.setMax(100);
+// progressBar = findViewById(R.id.progressBar);
+// progressBar.setVisibility(View.INVISIBLE);
+// progressBar.setMax(100);
PermissionUtils.verifyReadAndWritePermissions(this,Constants.RE_CODE_STORAGE_PERMISSION);
}
@@ -96,43 +98,62 @@ public class MainActivity extends AppCompatActivity {
if(isDownloading){
showToast("已经在下载中,请勿重复下载。");
}else{
- showToast("开始下载…");
+// showToast("开始下载…");
+ View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_progress,null);
+ tvProgress = view.findViewById(R.id.tvProgress);
+ progressBar = view.findViewById(R.id.progressBar);
+ AppDialog.INSTANCE.showDialog(getContext(),view,false);
}
}
@Override
public void onStart(String url) {
- progressBar.setProgress(0);
- progressBar.setVisibility(View.VISIBLE);
+ updateProgress(0,100);
}
@Override
public void onProgress(long progress, long total, boolean isChange) {
- int currProgress = (int)(progress * 1.0f / total * 100.0f);
if(isChange){
- progressBar.setProgress(currProgress);
+ updateProgress(progress,total);
}
- Log.d(TAG,String.format("onProgress:%d/%d | %d%%",progress,total,currProgress));
}
@Override
public void onFinish(File file) {
- progressBar.setVisibility(View.INVISIBLE);
+ AppDialog.INSTANCE.dismissDialog();
+ showToast("下载完成");
}
@Override
public void onError(Exception e) {
- progressBar.setVisibility(View.INVISIBLE);
+ AppDialog.INSTANCE.dismissDialog();
+ showToast("下载失败");
}
@Override
public void onCancel() {
- progressBar.setVisibility(View.INVISIBLE);
+ AppDialog.INSTANCE.dismissDialog();
+ showToast("取消下载");
}
});
mAppUpdater.start();
}
+ private void updateProgress(long progress, long total){
+ if(tvProgress == null || progressBar == null){
+ return;
+ }
+ if(progress > 0){
+ int currProgress = (int)(progress * 1.0f / total * 100.0f);
+ tvProgress.setText(getString(R.string.app_updater_progress_notification_content) + currProgress + "%");
+ progressBar.setProgress(currProgress);
+ Log.d(TAG,String.format("onProgress:%d/%d | %d%%",progress,total,currProgress));
+ }else{
+ tvProgress.setText(getString(R.string.app_updater_start_notification_content));
+ }
+
+ }
+
/**
* 系统弹框升级
*/
@@ -147,6 +168,29 @@ public class MainActivity extends AppCompatActivity {
.setUrl(mUrl)
.build(getContext())
.setUpdateCallback(new AppUpdateCallback() {
+ @Override
+ public void onStart(String url) {
+ super.onStart(url);
+ //模仿系统自带的横幅通知效果
+ AppDialogConfig config = new AppDialogConfig(getContext(),R.layout.dialog_heads_up);
+ config.setStyleId(R.style.app_dialog_heads_up)
+ .setWidthRatio(.95f)
+ .setGravity(Gravity.TOP);
+ AppDialog.INSTANCE.showDialog(getContext(),config);
+ new CountDownTimer(1500,500){
+
+ @Override
+ public void onTick(long millisUntilFinished) {
+
+ }
+
+ @Override
+ public void onFinish() {
+ AppDialog.INSTANCE.dismissDialog();
+ }
+ }.start();
+ }
+
@Override
public void onProgress(long progress, long total, boolean isChange) {
Log.d(TAG,String.format("onProgress:%d/%d",progress,total));
@@ -168,9 +212,9 @@ public class MainActivity extends AppCompatActivity {
private void clickBtn4(){
AppDialogConfig config = new AppDialogConfig(getContext());
config.setTitle("简单弹框升级")
- .setOk("升级")
+ .setConfirm("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
- .setOnClickOk(new View.OnClickListener() {
+ .setOnClickConfirm(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAppUpdater = new AppUpdater(getContext(),mUrl);
@@ -186,11 +230,11 @@ public class MainActivity extends AppCompatActivity {
*/
private void clickBtn5(){
AppDialogConfig config = new AppDialogConfig(getContext(),R.layout.dialog);
- config.setOk("升级")
+ config.setConfirm("升级")
.setHideCancel(true)
.setTitle("简单自定义弹框升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
- .setOnClickOk(new View.OnClickListener() {
+ .setOnClickConfirm(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAppUpdater = new AppUpdater.Builder()
@@ -200,8 +244,7 @@ public class MainActivity extends AppCompatActivity {
AppDialog.INSTANCE.dismissDialog();
}
});
- //强制升级,拦截返回
- AppDialog.INSTANCE.showDialog(config,false);
+ AppDialog.INSTANCE.showDialog(config);
}
/**
@@ -215,15 +258,15 @@ public class MainActivity extends AppCompatActivity {
TextView tvContent = view.findViewById(R.id.tvContent);
tvContent.setText("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、");
- Button btnCancel = view.findViewById(R.id.btnCancel);
+ View btnCancel = view.findViewById(R.id.btnCancel);
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AppDialog.INSTANCE.dismissDialog();
}
});
- Button btnOK = view.findViewById(R.id.btnOK);
- btnOK.setOnClickListener(new View.OnClickListener() {
+ View btnConfirm = view.findViewById(R.id.btnConfirm);
+ btnConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAppUpdater = new AppUpdater.Builder()
@@ -247,9 +290,9 @@ public class MainActivity extends AppCompatActivity {
private void clickBtn7(){
AppDialogConfig config = new AppDialogConfig(getContext());
config.setTitle("简单DialogFragment升级")
- .setOk("升级")
+ .setConfirm("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
- .setOnClickOk(new View.OnClickListener() {
+ .setOnClickConfirm(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAppUpdater = new AppUpdater.Builder()
diff --git a/app/src/main/res/color/btn_cancel_color_selector.xml b/app/src/main/res/color/btn_cancel_color_selector.xml
new file mode 100644
index 0000000..a43e1d1
--- /dev/null
+++ b/app/src/main/res/color/btn_cancel_color_selector.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/btn_confirm_selector.xml b/app/src/main/res/drawable/btn_confirm_selector.xml
new file mode 100644
index 0000000..8708b6a
--- /dev/null
+++ b/app/src/main/res/drawable/btn_confirm_selector.xml
@@ -0,0 +1,18 @@
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index ada176c..b558b10 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -6,16 +6,6 @@
android:layout_height="match_parent"
tools:context=".MainActivity">
-
diff --git a/app/src/main/res/layout/dialog_custom.xml b/app/src/main/res/layout/dialog_custom.xml
index e72c947..479b12b 100644
--- a/app/src/main/res/layout/dialog_custom.xml
+++ b/app/src/main/res/layout/dialog_custom.xml
@@ -4,7 +4,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="30dp"
- android:background="@android:color/white"
+ android:background="@drawable/app_dialog_bg"
android:orientation="vertical">
+ android:textSize="16sp" />
-
-
-
+
+ android:textColor="@color/btn_cancel_color_selector" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_heads_up.xml b/app/src/main/res/layout/dialog_heads_up.xml
new file mode 100644
index 0000000..68ffcf4
--- /dev/null
+++ b/app/src/main/res/layout/dialog_heads_up.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_progress.xml b/app/src/main/res/layout/dialog_progress.xml
new file mode 100644
index 0000000..966485e
--- /dev/null
+++ b/app/src/main/res/layout/dialog_progress.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index d312cf6..39b7c43 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,10 +1,15 @@
- #3F51B5
- #303F9F
- #FF4081
+ #5588FF
+ #4B7CFD
+ #5588FF
#FFFFFF
+ #FFFFFF
+
+ #666666
+ #999999
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 32437f1..ae72d33 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,4 +1,6 @@
AppUpdater
+ 忽略
+
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 85bc450..04af31e 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -9,6 +9,17 @@
- false
+
+
+