对外提供更多可配置参数

pull/27/head 1.1.1
Jenly 3 years ago
parent 09972ded00
commit 9a426841c9
  1. 16
      README.md
  2. 10
      app-dialog/build.gradle
  3. 71
      app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
  4. 8
      app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
  5. 251
      app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java
  6. 20
      app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java
  7. 34
      app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java
  8. 9
      app-dialog/src/main/res/anim/app_dialog_bottom_in.xml
  9. 9
      app-dialog/src/main/res/anim/app_dialog_bottom_out.xml
  10. 9
      app-dialog/src/main/res/anim/app_dialog_left_in.xml
  11. 9
      app-dialog/src/main/res/anim/app_dialog_left_out.xml
  12. 9
      app-dialog/src/main/res/anim/app_dialog_right_in.xml
  13. 9
      app-dialog/src/main/res/anim/app_dialog_right_out.xml
  14. 5
      app-dialog/src/main/res/anim/app_dialog_scale_in.xml
  15. 5
      app-dialog/src/main/res/anim/app_dialog_scale_out.xml
  16. 9
      app-dialog/src/main/res/anim/app_dialog_top_in.xml
  17. 9
      app-dialog/src/main/res/anim/app_dialog_top_out.xml
  18. 0
      app-dialog/src/main/res/color/app_cancel_color_selector.xml
  19. 20
      app-dialog/src/main/res/layout/app_dialog.xml
  20. 4
      app-dialog/src/main/res/values/colors.xml
  21. 2
      app-dialog/src/main/res/values/strings.xml
  22. 31
      app-dialog/src/main/res/values/styles.xml
  23. 13
      app-updater/build.gradle
  24. 11
      app-updater/src/main/java/com/king/app/updater/AppUpdater.java
  25. 20
      app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
  26. 15
      app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
  27. 6
      app-updater/src/main/java/com/king/app/updater/util/AppUtils.java
  28. 33
      app-updater/src/main/java/com/king/app/updater/util/NotificationUtils.java
  29. 15
      app/build.gradle
  30. BIN
      app/release/app-release.apk
  31. 4
      app/release/output-metadata.json
  32. 91
      app/src/main/java/com/king/appupdater/MainActivity.java
  33. 5
      app/src/main/res/color/btn_cancel_color_selector.xml
  34. 18
      app/src/main/res/drawable/btn_confirm_selector.xml
  35. 13
      app/src/main/res/layout/activity_main.xml
  36. 10
      app/src/main/res/layout/dialog.xml
  37. 43
      app/src/main/res/layout/dialog_custom.xml
  38. 25
      app/src/main/res/layout/dialog_heads_up.xml
  39. 43
      app/src/main/res/layout/dialog_progress.xml
  40. 11
      app/src/main/res/values/colors.xml
  41. 2
      app/src/main/res/values/strings.xml
  42. 11
      app/src/main/res/values/styles.xml
  43. 23
      build.gradle
  44. 6
      gradle.properties
  45. 47
      versions.gradle

@ -58,9 +58,9 @@ allprojects {
//----------AndroidX 版本 //----------AndroidX 版本
//app-updater //app-updater
implementation 'com.github.jenly1314.AppUpdater:app-updater:1.1.0' implementation 'com.github.jenly1314.AppUpdater:app-updater:1.1.1'
//app-dialog //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); AppDialogConfig config = new AppDialogConfig(context);
config.setTitle("简单弹框升级") config.setTitle("简单弹框升级")
.setOk("升级") .setConfirm("升级") //旧版本使用setOk
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
.setOnClickOk(new View.OnClickListener() { .setOnClickConfirm(new View.OnClickListener() { //旧版本使用setOnClickOk
@Override @Override
public void onClick(View v) { public void onClick(View v) {
new AppUpdater.Builder() new AppUpdater.Builder()
@ -110,9 +110,9 @@ allprojects {
//简单DialogFragment升级 //简单DialogFragment升级
AppDialogConfig config = new AppDialogConfig(context); AppDialogConfig config = new AppDialogConfig(context);
config.setTitle("简单DialogFragment升级") config.setTitle("简单DialogFragment升级")
.setOk("升级") .setConfirm("升级") //旧版本使用setOk
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
.setOnClickOk(new View.OnClickListener() { .setOnClickConfirm(new View.OnClickListener() { //旧版本使用setOnClickOk
@Override @Override
public void onClick(View v) { public void onClick(View v) {
new AppUpdater.Builder() new AppUpdater.Builder()
@ -138,6 +138,10 @@ allprojects {
## 版本记录 ## 版本记录
#### v1.1.1:2021-9-14
* 对外提供更多可配置参数
* 优化细节
#### v1.1.0:2021-7-2 (从v1.1.0开始不再发布至JCenter) #### v1.1.0:2021-7-2 (从v1.1.0开始不再发布至JCenter)
* 后续版本只支持androidx,版本名称不再带有androidx标识 * 后续版本只支持androidx,版本名称不再带有androidx标识
* 优化细节 * 优化细节

@ -32,11 +32,11 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation deps.test.junit testImplementation "junit:junit:$versions.junit"
androidTestImplementation deps.test.runner androidTestImplementation "androidx.test.ext:junit:$versions.androidExtJunit"
androidTestImplementation deps.test.espresso androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espressoCore"
//androidx
compileOnly deps.androidx.appcompat compileOnly "androidx.appcompat:appcompat:$versions.appcompat"
} }

@ -3,7 +3,7 @@ package com.king.app.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.util.Log; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
@ -22,7 +22,7 @@ public enum AppDialog {
INSTANCE; INSTANCE;
private final float DEFAULT_WIDTH_RATIO = 0.85f; final float DEFAULT_WIDTH_RATIO = 0.85f;
private Dialog mDialog; private Dialog mDialog;
@ -110,14 +110,13 @@ public enum AppDialog {
showDialog(config,true); showDialog(config,true);
} }
/** /**
* 显示弹框 * 显示弹框
* @param config 弹框配置 {@link AppDialogConfig} * @param config 弹框配置 {@link AppDialogConfig}
* @param isCancel 是否可取消默认为truefalse则拦截back键 * @param isCancel 是否可取消默认为truefalse则拦截back键
*/ */
public void showDialog(AppDialogConfig config,boolean isCancel){ 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); showDialog(context,config,true);
} }
/** /**
* 显示弹框 * 显示弹框
* @param context * @param context
@ -137,7 +135,7 @@ public enum AppDialog {
* @param isCancel 是否可取消默认为truefalse则拦截back键 * @param isCancel 是否可取消默认为truefalse则拦截back键
*/ */
public void showDialog(Context context,AppDialogConfig config,boolean isCancel){ 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); showDialog(context,contentView,R.style.app_dialog,widthRatio,isCancel);
} }
/** /**
* 显示弹框 * 显示弹框
* @param context * @param context
@ -191,6 +190,17 @@ public enum AppDialog {
showDialog(context,contentView,styleId,widthRatio,true); 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 * @param context
@ -200,8 +210,21 @@ public enum AppDialog {
* @param isCancel 是否可取消默认为truefalse则拦截back键 * @param isCancel 是否可取消默认为truefalse则拦截back键
*/ */
public void showDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio,final boolean isCancel){ 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 是否可取消默认为truefalse则拦截back键
*/
public void showDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio,final boolean isCancel){
dismissDialog(); dismissDialog();
mDialog = createDialog(context,contentView,styleId,widthRatio,isCancel); mDialog = createDialog(context, contentView, styleId, gravity, widthRatio, isCancel);
mDialog.show(); mDialog.show();
} }
@ -209,12 +232,14 @@ public enum AppDialog {
* 设置弹框窗口配置 * 设置弹框窗口配置
* @param context * @param context
* @param dialog * @param dialog
* @param gravity
* @param widthRatio * @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(); Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes(); WindowManager.LayoutParams lp = window.getAttributes();
lp.width = (int)(context.getResources().getDisplayMetrics().widthPixels * widthRatio); lp.width = (int)(context.getResources().getDisplayMetrics().widthPixels * widthRatio);
lp.gravity = gravity;
window.setAttributes(lp); window.setAttributes(lp);
} }
@ -302,9 +327,22 @@ public enum AppDialog {
* @param widthRatio 宽度比例根据屏幕宽度计算得来 * @param widthRatio 宽度比例根据屏幕宽度计算得来
*/ */
public Dialog createDialog(Context context, View contentView, @StyleRes int styleId, float 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 * @param context
@ -314,6 +352,19 @@ public enum AppDialog {
* @param isCancel 是否可取消默认为truefalse则拦截back键 * @param isCancel 是否可取消默认为truefalse则拦截back键
*/ */
public Dialog createDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio,final boolean isCancel){ 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 是否可取消默认为truefalse则拦截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 dialog = new Dialog(context,styleId);
dialog.setContentView(contentView); dialog.setContentView(contentView);
dialog.setCanceledOnTouchOutside(false); dialog.setCanceledOnTouchOutside(false);
@ -330,7 +381,7 @@ public enum AppDialog {
} }
}); });
setDialogWindow(context,dialog,widthRatio); setDialogWindow(context, dialog, gravity, widthRatio);
return dialog; return dialog;
} }

@ -98,10 +98,10 @@ public class AppDialogConfig extends BaseDialogConfig{
line.setVisibility(isHideCancel ? View.GONE : View.VISIBLE); line.setVisibility(isHideCancel ? View.GONE : View.VISIBLE);
} }
Button btnDialogOK = getView(okId); Button btnDialogConfirm = getView(confirmId);
if(btnDialogOK != null){ if(btnDialogConfirm != null){
setText(btnDialogOK,ok); setText(btnDialogConfirm,confirm);
btnDialogOK.setOnClickListener(onClickOk != null ? onClickOk : AppDialog.INSTANCE.mOnClickDismissDialog); btnDialogConfirm.setOnClickListener(onClickConfirm != null ? onClickConfirm : AppDialog.INSTANCE.mOnClickDismissDialog);
} }

@ -1,6 +1,7 @@
package com.king.app.dialog; package com.king.app.dialog;
import android.content.Context; import android.content.Context;
import android.view.Gravity;
import android.view.View; import android.view.View;
import androidx.annotation.IdRes; import androidx.annotation.IdRes;
@ -17,13 +18,11 @@ public class BaseDialogConfig {
/** /**
* 布局ID * 布局ID
*/ */
@LayoutRes @LayoutRes int layoutId;
int layoutId;
/** /**
* 标题视图ID * 标题视图ID
*/ */
@IdRes @IdRes int titleId = R.id.tvDialogTitle;
int titleId = R.id.tvDialogTitle;
/** /**
* 内容视图ID * 内容视图ID
*/ */
@ -35,7 +34,7 @@ public class BaseDialogConfig {
/** /**
* 确定视图ID右边按钮 * 确定视图ID右边按钮
*/ */
@IdRes int okId = R.id.btnDialogOK; @IdRes int confirmId = R.id.btnDialogConfirm;
/** /**
* 按钮中间分割线ID * 按钮中间分割线ID
*/ */
@ -44,8 +43,12 @@ public class BaseDialogConfig {
/** /**
* 样式ID * 样式ID
*/ */
@StyleRes @StyleRes int styleId = R.style.app_dialog;
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; boolean isHideTitle;
/**
* 宽度比例根据屏幕宽度计算得来
*/
float widthRatio = AppDialog.INSTANCE.DEFAULT_WIDTH_RATIO;
/**
* Dialog对齐方式
*/
int gravity = Gravity.NO_GRAVITY;
View.OnClickListener onClickCancel; View.OnClickListener onClickCancel;
View.OnClickListener onClickOk; View.OnClickListener onClickConfirm;
public BaseDialogConfig(){ public BaseDialogConfig(){
this(R.layout.app_dialog); this(R.layout.app_dialog);
} }
/**
* 构造
* @param layoutId 布局ID
*/
public BaseDialogConfig(@LayoutRes int layoutId){ public BaseDialogConfig(@LayoutRes int layoutId){
this.layoutId = layoutId; this.layoutId = layoutId;
} }
@ -105,6 +122,11 @@ public class BaseDialogConfig {
return titleId; return titleId;
} }
/**
* 设置标题布局ID
* @param titleId
* @return
*/
public BaseDialogConfig setTitleId(@IdRes int titleId) { public BaseDialogConfig setTitleId(@IdRes int titleId) {
this.titleId = titleId; this.titleId = titleId;
return this; return this;
@ -114,15 +136,39 @@ public class BaseDialogConfig {
return styleId; 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; this.styleId = styleId;
return this; 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() { public @IdRes int getContentId() {
return contentId; return contentId;
} }
/**
* 设置内容布局ID
* @param contentId
* @return
*/
public BaseDialogConfig setContentId(@IdRes int contentId) { public BaseDialogConfig setContentId(@IdRes int contentId) {
this.contentId = contentId; this.contentId = contentId;
return this; return this;
@ -132,17 +178,52 @@ public class BaseDialogConfig {
return cancelId; return cancelId;
} }
/**
* 设置取消按钮布局ID
* @param cancelId
* @return
*/
public BaseDialogConfig setCancelId(@IdRes int cancelId) { public BaseDialogConfig setCancelId(@IdRes int cancelId) {
this.cancelId = cancelId; this.cancelId = cancelId;
return this; return this;
} }
/**
* 获取确定按钮布局ID
* @return
* @Deprecated 请使用 {@link #getConfirmId()}来代替后续版本可能会移除此方法
*/
@Deprecated
public @IdRes int getOkId() { public @IdRes int getOkId() {
return okId; return getConfirmId();
} }
/**
* 设置确定按钮布局ID
* @param okId
* @return
* @Deprecated 请使用 {@link #setConfirmId(int)}来代替后续版本可能移除此方法
*/
@Deprecated
public BaseDialogConfig setOkId(@IdRes int okId) { 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; return this;
} }
@ -150,6 +231,11 @@ public class BaseDialogConfig {
return lineId; return lineId;
} }
/**
* 设置分割线布局ID
* @param lineId
* @return
*/
public BaseDialogConfig setLineId(@IdRes int lineId) { public BaseDialogConfig setLineId(@IdRes int lineId) {
this.lineId = lineId; this.lineId = lineId;
return this; return this;
@ -159,11 +245,22 @@ public class BaseDialogConfig {
return title; return title;
} }
/**
* 设置标题
* @param title
* @return
*/
public BaseDialogConfig setTitle(CharSequence title) { public BaseDialogConfig setTitle(CharSequence title) {
this.title = title; this.title = title;
return this; return this;
} }
/**
* 设置标题
* @param context
* @param resId
* @return
*/
public BaseDialogConfig setTitle(@NonNull Context context, @StringRes int resId) { public BaseDialogConfig setTitle(@NonNull Context context, @StringRes int resId) {
this.title = context.getString(resId); this.title = context.getString(resId);
return this; return this;
@ -173,6 +270,11 @@ public class BaseDialogConfig {
return content; return content;
} }
/**
* 设置文本内容
* @param content
* @return
*/
public BaseDialogConfig setContent(CharSequence content) { public BaseDialogConfig setContent(CharSequence content) {
this.content = content; this.content = content;
return this; return this;
@ -182,27 +284,80 @@ public class BaseDialogConfig {
return cancel; return cancel;
} }
/**
* 设置取消按钮文本内容
* @param cancel
* @return
*/
public BaseDialogConfig setCancel(CharSequence cancel) { public BaseDialogConfig setCancel(CharSequence cancel) {
this.cancel = cancel; this.cancel = cancel;
return this; return this;
} }
/**
* 设置取消按钮文本内容
* @param context
* @param resId
* @return
*/
public BaseDialogConfig setCancel(@NonNull Context context, @StringRes int resId) { public BaseDialogConfig setCancel(@NonNull Context context, @StringRes int resId) {
this.cancel = context.getString(resId); this.cancel = context.getString(resId);
return this; return this;
} }
/**
* 获取确定按钮文本内容
* @return
* @deprecated 请使用 {@link #getConfirm()} 来代替后续版本可能会移除此方法
*/
public CharSequence getOk() { public CharSequence getOk() {
return ok; return getConfirm();
} }
/**
* 设置确定按钮文本内容
* @param ok
* @return
* @deprecated 请使用 {@link #setConfirm(CharSequence)} 来代替后续版本可能会移除此方法
*/
public BaseDialogConfig setOk(CharSequence ok) { public BaseDialogConfig setOk(CharSequence ok) {
this.ok = ok; return setConfirm(ok);
return this;
} }
/**
* 设置确定按钮文本内容
* @param context
* @param resId
* @return
* @deprecated 请使用 {@link #setConfirm(Context, int)}来代替后续版本可能会移除此方法
*/
public BaseDialogConfig setOk(@NonNull Context context, @StringRes int resId) { 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; return this;
} }
@ -210,6 +365,11 @@ public class BaseDialogConfig {
return isHideCancel; return isHideCancel;
} }
/**
* 设置是否隐藏取消按钮
* @param hideCancel
* @return
*/
public BaseDialogConfig setHideCancel(boolean hideCancel) { public BaseDialogConfig setHideCancel(boolean hideCancel) {
isHideCancel = hideCancel; isHideCancel = hideCancel;
return this; return this;
@ -219,11 +379,44 @@ public class BaseDialogConfig {
return isHideTitle; return isHideTitle;
} }
/**
* 设置是否隐藏标题
* @param hideTitle
* @return
*/
public BaseDialogConfig setHideTitle(boolean hideTitle){ public BaseDialogConfig setHideTitle(boolean hideTitle){
isHideTitle = hideTitle; isHideTitle = hideTitle;
return this; 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() { public View.OnClickListener getOnClickCancel() {
return onClickCancel; return onClickCancel;
} }
@ -238,18 +431,38 @@ public class BaseDialogConfig {
return this; 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() { public View.OnClickListener getOnClickOk() {
return onClickOk; return getOnClickConfirm();
} }
/** /**
* 设置确定按钮点击监听不设置默认点击关闭弹框 * 设置确定按钮点击监听不设置默认点击关闭弹框
* @param onClickOk * @param onClickOk
* @return * @return
* @deprecated 请使用 {@link #setOnClickConfirm(View.OnClickListener)}来代替后续版本可能会移除此方法
*/ */
public BaseDialogConfig setOnClickOk(View.OnClickListener onClickOk) { public BaseDialogConfig setOnClickOk(View.OnClickListener onClickOk) {
this.onClickOk = onClickOk; return setOnClickConfirm(onClickOk);
return this;
} }

@ -1,5 +1,7 @@
package com.king.app.dialog.fragment; package com.king.app.dialog.fragment;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@ -57,12 +59,22 @@ public class AppDialogFragment extends BaseDialogFragment {
line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
} }
Button btnDialogOK = rootView.findViewById(config.getOkId()); Button btnDialogConfirm = rootView.findViewById(config.getConfirmId());
if(btnDialogOK != null){ if(btnDialogConfirm != null){
setText(btnDialogOK,config.getOk()); setText(btnDialogConfirm,config.getConfirm());
btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : getOnClickDismiss()); 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);
}
}
} }

@ -5,6 +5,7 @@ import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -27,29 +28,44 @@ public abstract class BaseDialogFragment extends DialogFragment {
private View mRootView; private View mRootView;
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 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); mRootView = inflater.inflate(getRootLayoutId(), container, false);
init(mRootView); init(mRootView);
return mRootView; return mRootView;
} }
@NonNull
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); Dialog dialog = super.onCreateDialog(savedInstanceState);
super.getDialog().getWindow().getAttributes().windowAnimations = R.style.app_dialog_animation; dialog.setCanceledOnTouchOutside(false);
getDialog().setCanceledOnTouchOutside(false); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
setDialogWindow(getContext(),getDialog(),DEFAULT_WIDTH_RATIO); initDialogWindow(getContext(),dialog,Gravity.NO_GRAVITY,DEFAULT_WIDTH_RATIO,R.style.app_dialog_scale_animation);
return dialog;
} }
private void setDialogWindow(Context context, Dialog dialog, float widthRatio){ protected void initDialogWindow(Context context,Dialog dialog,int gravity,float widthRatio,int animationStyleId){
setDialogWindow(context, dialog, gravity, widthRatio, animationStyleId);
}
/**
* 设置弹框窗口配置
* @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 window = dialog.getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
WindowManager.LayoutParams lp = window.getAttributes(); WindowManager.LayoutParams lp = window.getAttributes();
lp.windowAnimations = animationStyleId;
lp.width = (int)(context.getResources().getDisplayMetrics().widthPixels * widthRatio); lp.width = (int)(context.getResources().getDisplayMetrics().widthPixels * widthRatio);
lp.gravity = gravity;
window.setAttributes(lp); window.setAttributes(lp);
} }

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="100%"
android:toYDelta="0%" />
</set>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0%"
android:toYDelta="100%" />
</set>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:fromYDelta="0"
android:toYDelta="0" />
</set>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<translate
android:fromXDelta="0%"
android:toXDelta="-100%"
android:fromYDelta="0"
android:toYDelta="0" />
</set>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<translate
android:fromXDelta="100%"
android:toXDelta="0%"
android:fromYDelta="0"
android:toYDelta="0" />
</set>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0"
android:toYDelta="0" />
</set>

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"> <set xmlns:android="http://schemas.android.com/apk/res/android"
<scale android:duration="200" android:duration="200">
<scale
android:pivotX="50%" android:pivotX="50%"
android:pivotY="50%" android:pivotY="50%"
android:fromXScale="0.0" android:fromXScale="0.0"

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"> <set xmlns:android="http://schemas.android.com/apk/res/android"
<scale android:duration="200" android:duration="200">
<scale
android:pivotX="50%" android:pivotX="50%"
android:pivotY="50%" android:pivotY="50%"
android:fromXScale="1.0" android:fromXScale="1.0"

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="-100%"
android:toYDelta="0%" />
</set>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0%"
android:toYDelta="-100%" />
</set>

@ -11,7 +11,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:padding="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:lines="1" android:lines="1"
android:textSize="@dimen/app_dialog_title_text_size" android:textSize="@dimen/app_dialog_title_text_size"
android:textColor="@color/app_dialog_title_color" android:textColor="@color/app_dialog_title_color"
@ -20,10 +23,13 @@
android:id="@+id/tvDialogContent" android:id="@+id/tvDialogContent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" 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:textSize="@dimen/app_dialog_content_text_size"
android:textColor="@color/app_dialog_content_color"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:textColor="@color/app_dialog_content_color"
android:lineSpacingMultiplier="1.2" /> android:lineSpacingMultiplier="1.2" />
<include layout="@layout/app_dialog_line_h"/> <include layout="@layout/app_dialog_line_h"/>
<LinearLayout <LinearLayout
@ -40,21 +46,21 @@
android:layout_weight="1" android:layout_weight="1"
android:text="@string/app_dialog_cancel" android:text="@string/app_dialog_cancel"
android:textSize="@dimen/app_dialog_button_text_size" android:textSize="@dimen/app_dialog_button_text_size"
android:textColor="@color/app_dialog_button_color_selector" android:textColor="@color/app_cancel_color_selector"
android:background="?android:attr/selectableItemBackground"/> android:background="?android:attr/selectableItemBackground"/>
<include <include
android:id="@+id/line" android:id="@+id/line"
layout="@layout/app_dialog_line_v"/> layout="@layout/app_dialog_line_v"/>
<Button <Button
android:id="@+id/btnDialogOK" android:id="@+id/btnDialogConfirm"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp" android:paddingBottom="10dp"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/app_dialog_ok" android:text="@string/app_dialog_confirm"
android:textSize="@dimen/app_dialog_button_text_size" android:textSize="@dimen/app_dialog_button_text_size"
android:textColor="@color/app_dialog_button_color_selector" android:textColor="@color/app_cancel_color_selector"
android:background="?android:attr/selectableItemBackground"/> android:background="?android:attr/selectableItemBackground"/>
</LinearLayout> </LinearLayout>

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorAccent">#FF4081</color> <color name="colorAccent">#5588FF</color>
<color name="app_dialog_title_color">#333333</color> <color name="app_dialog_title_color">#333333</color>
<color name="app_dialog_content_color">#333333</color> <color name="app_dialog_content_color">#333333</color>
<color name="app_dialog_button_normal_color">#333333</color> <color name="app_dialog_button_normal_color">#333333</color>
<color name="app_dialog_button_pressed_color">@color/colorAccent</color> <color name="app_dialog_button_pressed_color">@color/colorAccent</color>
<color name="app_dialog_line_color">#f2f2f2</color> <color name="app_dialog_line_color">#F2F2F2</color>
</resources> </resources>

@ -3,5 +3,7 @@
<string name="app_dialog_title">提示</string> <string name="app_dialog_title">提示</string>
<string name="app_dialog_cancel">取消</string> <string name="app_dialog_cancel">取消</string>
<string name="app_dialog_confirm">确定</string>
<string name="app_dialog_ok">确定</string> <string name="app_dialog_ok">确定</string>
</resources> </resources>

@ -2,9 +2,32 @@
<resources> <resources>
<!-- dialog animation --> <!-- dialog animation -->
<style name="app_dialog_animation" parent="android:style/Animation.Dialog"> <style name="app_dialog_scale_animation" parent="android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/app_dialog_in</item> <item name="android:windowEnterAnimation">@anim/app_dialog_scale_in</item>
<item name="android:windowExitAnimation">@anim/app_dialog_out</item> <item name="android:windowExitAnimation">@anim/app_dialog_scale_out</item>
</style>
<style name="app_dialog_animation" parent="app_dialog_scale_animation">
</style>
<style name="app_dialog_left_animation" parent="android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/app_dialog_left_in</item>
<item name="android:windowExitAnimation">@anim/app_dialog_left_out</item>
</style>
<style name="app_dialog_top_animation" parent="android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/app_dialog_top_in</item>
<item name="android:windowExitAnimation">@anim/app_dialog_top_out</item>
</style>
<style name="app_dialog_right_animation" parent="android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/app_dialog_right_in</item>
<item name="android:windowExitAnimation">@anim/app_dialog_right_out</item>
</style>
<style name="app_dialog_bottom_animation" parent="android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/app_dialog_bottom_in</item>
<item name="android:windowExitAnimation">@anim/app_dialog_bottom_out</item>
</style> </style>
<!-- dialog style --> <!-- dialog style -->
@ -15,7 +38,7 @@
<item name="android:windowNoTitle">true</item> <item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item> <item name="android:backgroundDimEnabled">true</item>
<item name="android:windowAnimationStyle">@style/app_dialog_animation</item> <item name="android:windowAnimationStyle">@style/app_dialog_scale_animation</item>
</style> </style>
</resources> </resources>

@ -31,12 +31,11 @@ android {
} }
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) testImplementation "junit:junit:$versions.junit"
testImplementation deps.test.junit androidTestImplementation "androidx.test.ext:junit:$versions.androidExtJunit"
androidTestImplementation deps.test.runner androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espressoCore"
androidTestImplementation deps.test.espresso
//androidx compileOnly "androidx.appcompat:appcompat:$versions.appcompat"
compileOnly deps.androidx.appcompat compileOnly "com.squareup.okhttp3:okhttp:$versions.okhttp"
compileOnly deps.okhttp
} }

@ -361,6 +361,17 @@ public class AppUpdater {
return this; return this;
} }
/**
* 是否支持通过删除通知栏来取消下载默认为false
* @param cancelDownload
* @return
*/
public Builder setCancelDownload(boolean cancelDownload){
mConfig.setCancelDownload(cancelDownload);
return this;
}
public AppUpdater build(@NonNull Context context){ public AppUpdater build(@NonNull Context context){
AppUpdater appUpdater = new AppUpdater(context,mConfig); AppUpdater appUpdater = new AppUpdater(context,mConfig);
return appUpdater; return appUpdater;

@ -97,6 +97,11 @@ public class UpdateConfig implements Parcelable {
*/ */
private boolean isDeleteCancelFile = true; private boolean isDeleteCancelFile = true;
/**
* 是否支持通过删除通知栏来取消下载
*/
private boolean isCancelDownload = false;
/** /**
* APK文件的MD5 * APK文件的MD5
*/ */
@ -354,12 +359,23 @@ public class UpdateConfig implements Parcelable {
/** /**
* 设置是否自动删除取消下载的文件 * 设置是否自动删除取消下载的文件
* @param deleteCancelFile 是否删除取消下载的文件默认为true * @param deleteCancelFile 是否删除取消下载的文件默认为true
*/ */
public void setDeleteCancelFile(boolean deleteCancelFile) { public void setDeleteCancelFile(boolean deleteCancelFile) {
isDeleteCancelFile = deleteCancelFile; isDeleteCancelFile = deleteCancelFile;
} }
public boolean isCancelDownload(){
return isCancelDownload;
}
/**
* 是否支持通过删除通知栏来取消下载默认为false
* @param cancelDownload
*/
public void setCancelDownload(boolean cancelDownload) {
isCancelDownload = cancelDownload;
}
@Override @Override
public int describeContents() { public int describeContents() {
@ -395,6 +411,7 @@ public class UpdateConfig implements Parcelable {
} }
dest.writeByte(this.isDeleteCancelFile ? (byte) 1 : (byte) 0); dest.writeByte(this.isDeleteCancelFile ? (byte) 1 : (byte) 0);
dest.writeByte(this.isCancelDownload ? (byte) 1 : (byte) 0);
dest.writeString(this.apkMD5); dest.writeString(this.apkMD5);
} }
@ -423,6 +440,7 @@ public class UpdateConfig implements Parcelable {
this.mRequestProperty.put(key, value); this.mRequestProperty.put(key, value);
} }
this.isDeleteCancelFile = in.readByte() != 0; this.isDeleteCancelFile = in.readByte() != 0;
this.isCancelDownload = in.readByte() != 0;
this.apkMD5 = in.readString(); this.apkMD5 = in.readString();
} }

@ -164,11 +164,7 @@ public class DownloadService extends Service {
} }
Log.d(Constants.TAG,"File:" + mFile); Log.d(Constants.TAG,"File:" + mFile);
if(httpManager != null){ mHttpManager = httpManager != null ? httpManager : HttpManager.getInstance();
mHttpManager = httpManager;
}else{
mHttpManager = HttpManager.getInstance();
}
mHttpManager.download(url,path,filename,config.getRequestProperty(),new AppDownloadCallback(config,callback)); mHttpManager.download(url,path,filename,config.getRequestProperty(),new AppDownloadCallback(config,callback));
} }
@ -177,7 +173,7 @@ public class DownloadService extends Service {
* 停止下载 * 停止下载
*/ */
public void stopDownload(){ public void stopDownload(){
if(mHttpManager!=null){ if(mHttpManager != null){
mHttpManager.cancel(); mHttpManager.cancel();
} }
} }
@ -231,6 +227,8 @@ public class DownloadService extends Service {
private boolean isDeleteCancelFile; private boolean isDeleteCancelFile;
private boolean isCancelDownload;
private UpdateCallback callback; private UpdateCallback callback;
private int reDownloads; private int reDownloads;
@ -263,6 +261,7 @@ public class DownloadService extends Service {
this.isShowPercentage = config.isShowPercentage(); this.isShowPercentage = config.isShowPercentage();
this.isReDownload = config.isReDownload(); this.isReDownload = config.isReDownload();
this.isDeleteCancelFile = config.isDeleteCancelFile(); this.isDeleteCancelFile = config.isDeleteCancelFile();
this.isCancelDownload = config.isCancelDownload();
} }
@ -272,7 +271,7 @@ public class DownloadService extends Service {
isDownloading = true; isDownloading = true;
mLastProgress = 0; mLastProgress = 0;
if(isShowNotification){ 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){ if(callback!=null){
@ -299,7 +298,7 @@ public class DownloadService extends Service {
content += percentage; 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);
} }
} }

@ -40,7 +40,10 @@ public final class AppUtils {
*/ */
public static String getAppFullName(Context context,String url,String defaultName){ public static String getAppFullName(Context context,String url,String defaultName){
if(url.endsWith(".apk")){ 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); String filename = getAppName(context);
@ -84,7 +87,6 @@ public final class AppUtils {
*/ */
public static String getAppName(Context context) { public static String getAppName(Context context) {
try{ try{
int labelRes = getPackageInfo(context).applicationInfo.labelRes; int labelRes = getPackageInfo(context).applicationInfo.labelRes;
return context.getResources().getString(labelRes); return context.getResources().getString(labelRes);
} catch (Exception e) { } catch (Exception e) {

@ -28,7 +28,7 @@ public class NotificationUtils {
} }
/** /**
* 显示开始下载的通知 * 显示开始下载的通知
* @param notifyId * @param notifyId
* @param channelId * @param channelId
* @param channelName * @param channelName
@ -36,12 +36,12 @@ public class NotificationUtils {
* @param title * @param title
* @param content * @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){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
createNotificationChannel(context,channelId,channelName,isVibrate,isSound); createNotificationChannel(context,channelId,channelName,isVibrate,isSound);
} }
NotificationCompat.Builder builder = buildNotification(context,channelId,icon,title,content); NotificationCompat.Builder builder = buildNotification(context,channelId,icon,title,content);
builder.setPriority(NotificationManager.IMPORTANCE_HIGH); builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
if(isVibrate && isSound){ if(isVibrate && isSound){
builder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND); builder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);
}else if(isVibrate){ }else if(isVibrate){
@ -50,8 +50,20 @@ public class NotificationUtils {
builder.setDefaults(Notification.DEFAULT_SOUND); 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 notification = builder.build();
if(isCancelDownload){
notification.flags = Notification.FLAG_ONLY_ALERT_ONCE;
}else{
notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE; notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE;
}
notifyNotification(context,notifyId,notification); notifyNotification(context,notifyId,notification);
} }
@ -65,11 +77,24 @@ public class NotificationUtils {
* @param progress * @param progress
* @param size * @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); 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 notification = builder.build();
if(isCancelDownload){
notification.flags = Notification.FLAG_ONLY_ALERT_ONCE;
}else{
notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE; notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE;
}
notifyNotification(context,notifyId,notification); notifyNotification(context,notifyId,notification);
} }

@ -24,13 +24,14 @@ android {
dependencies { dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation deps.test.junit testImplementation "junit:junit:$versions.junit"
androidTestImplementation deps.test.runner androidTestImplementation "androidx.test.ext:junit:$versions.androidExtJunit"
androidTestImplementation deps.test.espresso androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espressoCore"
//androidx
implementation deps.androidx.appcompat implementation "androidx.appcompat:appcompat:$versions.appcompat"
implementation deps.androidx.constraintlayout implementation "androidx.constraintlayout:constraintlayout:$versions.constraintLayout"
implementation deps.okhttp
implementation "com.squareup.okhttp3:okhttp:$versions.okhttp"
implementation project(':app-updater') implementation project(':app-updater')
implementation project(':app-dialog') implementation project(':app-dialog')

Binary file not shown.

@ -10,8 +10,8 @@
{ {
"type": "SINGLE", "type": "SINGLE",
"filters": [], "filters": [],
"versionCode": 19, "versionCode": 20,
"versionName": "1.1.0", "versionName": "1.1.1",
"outputFile": "app-release.apk" "outputFile": "app-release.apk"
} }
] ]

@ -3,10 +3,11 @@ package com.king.appupdater;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; 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://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 String mUrl = "https://gitlab.com/jenly1314/AppUpdater/-/raw/master/app/release/app-release.apk";
private TextView tvProgress;
private ProgressBar progressBar; private ProgressBar progressBar;
private Toast toast; private Toast toast;
@ -49,9 +51,9 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
progressBar = findViewById(R.id.progressBar); // progressBar = findViewById(R.id.progressBar);
progressBar.setVisibility(View.INVISIBLE); // progressBar.setVisibility(View.INVISIBLE);
progressBar.setMax(100); // progressBar.setMax(100);
PermissionUtils.verifyReadAndWritePermissions(this,Constants.RE_CODE_STORAGE_PERMISSION); PermissionUtils.verifyReadAndWritePermissions(this,Constants.RE_CODE_STORAGE_PERMISSION);
} }
@ -96,43 +98,62 @@ public class MainActivity extends AppCompatActivity {
if(isDownloading){ if(isDownloading){
showToast("已经在下载中,请勿重复下载。"); showToast("已经在下载中,请勿重复下载。");
}else{ }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 @Override
public void onStart(String url) { public void onStart(String url) {
progressBar.setProgress(0); updateProgress(0,100);
progressBar.setVisibility(View.VISIBLE);
} }
@Override @Override
public void onProgress(long progress, long total, boolean isChange) { public void onProgress(long progress, long total, boolean isChange) {
int currProgress = (int)(progress * 1.0f / total * 100.0f);
if(isChange){ if(isChange){
progressBar.setProgress(currProgress); updateProgress(progress,total);
} }
Log.d(TAG,String.format("onProgress:%d/%d | %d%%",progress,total,currProgress));
} }
@Override @Override
public void onFinish(File file) { public void onFinish(File file) {
progressBar.setVisibility(View.INVISIBLE); AppDialog.INSTANCE.dismissDialog();
showToast("下载完成");
} }
@Override @Override
public void onError(Exception e) { public void onError(Exception e) {
progressBar.setVisibility(View.INVISIBLE); AppDialog.INSTANCE.dismissDialog();
showToast("下载失败");
} }
@Override @Override
public void onCancel() { public void onCancel() {
progressBar.setVisibility(View.INVISIBLE); AppDialog.INSTANCE.dismissDialog();
showToast("取消下载");
} }
}); });
mAppUpdater.start(); 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) .setUrl(mUrl)
.build(getContext()) .build(getContext())
.setUpdateCallback(new AppUpdateCallback() { .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 @Override
public void onProgress(long progress, long total, boolean isChange) { public void onProgress(long progress, long total, boolean isChange) {
Log.d(TAG,String.format("onProgress:%d/%d",progress,total)); Log.d(TAG,String.format("onProgress:%d/%d",progress,total));
@ -168,9 +212,9 @@ public class MainActivity extends AppCompatActivity {
private void clickBtn4(){ private void clickBtn4(){
AppDialogConfig config = new AppDialogConfig(getContext()); AppDialogConfig config = new AppDialogConfig(getContext());
config.setTitle("简单弹框升级") config.setTitle("简单弹框升级")
.setOk("升级") .setConfirm("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
.setOnClickOk(new View.OnClickListener() { .setOnClickConfirm(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mAppUpdater = new AppUpdater(getContext(),mUrl); mAppUpdater = new AppUpdater(getContext(),mUrl);
@ -186,11 +230,11 @@ public class MainActivity extends AppCompatActivity {
*/ */
private void clickBtn5(){ private void clickBtn5(){
AppDialogConfig config = new AppDialogConfig(getContext(),R.layout.dialog); AppDialogConfig config = new AppDialogConfig(getContext(),R.layout.dialog);
config.setOk("升级") config.setConfirm("升级")
.setHideCancel(true) .setHideCancel(true)
.setTitle("简单自定义弹框升级") .setTitle("简单自定义弹框升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
.setOnClickOk(new View.OnClickListener() { .setOnClickConfirm(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mAppUpdater = new AppUpdater.Builder() mAppUpdater = new AppUpdater.Builder()
@ -200,8 +244,7 @@ public class MainActivity extends AppCompatActivity {
AppDialog.INSTANCE.dismissDialog(); AppDialog.INSTANCE.dismissDialog();
} }
}); });
//强制升级,拦截返回 AppDialog.INSTANCE.showDialog(config);
AppDialog.INSTANCE.showDialog(config,false);
} }
/** /**
@ -215,15 +258,15 @@ public class MainActivity extends AppCompatActivity {
TextView tvContent = view.findViewById(R.id.tvContent); TextView tvContent = view.findViewById(R.id.tvContent);
tvContent.setText("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、"); 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() { btnCancel.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
AppDialog.INSTANCE.dismissDialog(); AppDialog.INSTANCE.dismissDialog();
} }
}); });
Button btnOK = view.findViewById(R.id.btnOK); View btnConfirm = view.findViewById(R.id.btnConfirm);
btnOK.setOnClickListener(new View.OnClickListener() { btnConfirm.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mAppUpdater = new AppUpdater.Builder() mAppUpdater = new AppUpdater.Builder()
@ -247,9 +290,9 @@ public class MainActivity extends AppCompatActivity {
private void clickBtn7(){ private void clickBtn7(){
AppDialogConfig config = new AppDialogConfig(getContext()); AppDialogConfig config = new AppDialogConfig(getContext());
config.setTitle("简单DialogFragment升级") config.setTitle("简单DialogFragment升级")
.setOk("升级") .setConfirm("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
.setOnClickOk(new View.OnClickListener() { .setOnClickConfirm(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mAppUpdater = new AppUpdater.Builder() mAppUpdater = new AppUpdater.Builder()

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/text_666"/>
<item android:state_pressed="false" android:color="@color/text_999"/>
</selector>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape>
<solid android:color="@color/colorAccent"/>
<corners android:radius="20dp"/>
</shape>
</item>
<item android:state_pressed="true">
<shape>
<solid android:color="@color/colorPrimaryDark"/>
<corners android:radius="20dp"/>
</shape>
</item>
</selector>

@ -6,16 +6,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>
<Button <Button
android:id="@+id/btn1" android:id="@+id/btn1"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -24,7 +14,6 @@
android:layout_marginRight="20dp" android:layout_marginRight="20dp"
android:layout_marginTop="40dp" android:layout_marginTop="40dp"
android:text="简单一键后台升级" android:text="简单一键后台升级"
app:layout_constraintTop_toBottomOf="@+id/progressBar"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
@ -36,7 +25,7 @@
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" android:layout_marginRight="20dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:text="一键监听进度后台升级" android:text="一键监听进度升级"
app:layout_constraintTop_toBottomOf="@+id/btn1" app:layout_constraintTop_toBottomOf="@+id/btn1"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"

@ -20,7 +20,7 @@
android:id="@+id/tvDialogContent" android:id="@+id/tvDialogContent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="10dp" android:padding="16dp"
android:textSize="@dimen/app_dialog_content_text_size" android:textSize="@dimen/app_dialog_content_text_size"
android:textColor="@color/app_dialog_content_color" android:textColor="@color/app_dialog_content_color"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
@ -40,21 +40,21 @@
android:layout_weight="1" android:layout_weight="1"
android:text="@string/app_dialog_cancel" android:text="@string/app_dialog_cancel"
android:textSize="18sp" android:textSize="18sp"
android:textColor="@color/app_dialog_button_color_selector" android:textColor="@color/app_cancel_color_selector"
android:background="?android:attr/selectableItemBackground"/> android:background="?android:attr/selectableItemBackground"/>
<include <include
android:id="@+id/line" android:id="@+id/line"
layout="@layout/app_dialog_line_v"/> layout="@layout/app_dialog_line_v"/>
<Button <Button
android:id="@+id/btnDialogOK" android:id="@+id/btnDialogConfirm"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp" android:paddingBottom="10dp"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/app_dialog_ok" android:text="@string/app_dialog_confirm"
android:textSize="18sp" android:textSize="18sp"
android:textColor="@color/app_dialog_button_color_selector" android:textColor="@color/app_cancel_color_selector"
android:background="?android:attr/selectableItemBackground"/> android:background="?android:attr/selectableItemBackground"/>
</LinearLayout> </LinearLayout>

@ -4,7 +4,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_margin="30dp" android:layout_margin="30dp"
android:background="@android:color/white" android:background="@drawable/app_dialog_bg"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/tvTitle" android:id="@+id/tvTitle"
@ -13,43 +13,48 @@
android:gravity="center" android:gravity="center"
android:padding="6dp" android:padding="6dp"
android:lines="1" android:lines="1"
android:textSize="16sp" android:textSize="16sp" />
android:background="#F5F5F5" />
<TextView <TextView
android:id="@+id/tvContent" android:id="@+id/tvContent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="10dp" android:padding="16dp"
android:layout_marginBottom="6dp"
android:lineSpacingMultiplier="1" /> android:lineSpacingMultiplier="1" />
<include layout="@layout/app_dialog_line_h"/>
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"> android:gravity="center_horizontal">
<Button <TextView
android:id="@+id/btnCancel" android:id="@+id/btnConfirm"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp" android:paddingBottom="10dp"
android:gravity="center"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/app_dialog_cancel" android:text="升级"
android:textSize="16sp" android:textSize="16sp"
android:textColor="@color/app_dialog_button_color_selector" android:textColor="@color/white"
android:background="?android:attr/selectableItemBackground"/> android:background="@drawable/btn_confirm_selector"/>
<Button <TextView
android:id="@+id/btnOK" android:id="@+id/btnCancel"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp" android:paddingBottom="10dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:gravity="center"
android:layout_weight="1" android:layout_weight="1"
android:text="升级" android:text="@string/ignore"
android:textSize="16sp" android:textSize="16sp"
android:textColor="@color/app_dialog_button_color_selector" android:textColor="@color/btn_cancel_color_selector" />
android:background="?android:attr/selectableItemBackground"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:gravity="center_vertical"
android:background="@drawable/app_dialog_bg">
<ImageView
android:id="@+id/ivIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/ic_launcher"
android:layout_marginRight="4dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/ivIcon"
android:textSize="14sp"
android:textColor="@color/app_dialog_title_color"
android:text="@string/app_updater_start_notification_content"/>
</RelativeLayout>

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:gravity="center_vertical"
android:background="@drawable/app_dialog_bg">
<ImageView
android:id="@+id/ivIcon"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@mipmap/ic_launcher"
android:layout_marginRight="4dp"/>
<TextView
android:id="@+id/tvDialogTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ivIcon"
android:textSize="14sp"
android:textColor="@color/app_dialog_title_color"
android:text="@string/app_updater_progress_notification_title"/>
<TextView
android:id="@+id/tvProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvDialogTitle"
android:layout_marginTop="10dp"
android:text="@string/app_updater_start_notification_content"
android:textSize="14sp"
android:textColor="@color/app_dialog_content_color"
android:lineSpacingMultiplier="1.2" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="6dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:max="100"
android:layout_below="@+id/tvProgress"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>
</RelativeLayout>

@ -1,10 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorPrimary">#3F51B5</color> <color name="colorPrimary">#5588FF</color>
<color name="colorPrimaryDark">#303F9F</color> <color name="colorPrimaryDark">#4B7CFD</color>
<color name="colorAccent">#FF4081</color> <color name="colorAccent">#5588FF</color>
<color name="ic_launcher_background">#FFFFFF</color> <color name="ic_launcher_background">#FFFFFF</color>
<color name="white">#FFFFFF</color>
<color name="text_666">#666666</color>
<color name="text_999">#999999</color>
</resources> </resources>

@ -1,4 +1,6 @@
<resources> <resources>
<string name="app_name">AppUpdater</string> <string name="app_name">AppUpdater</string>
<string name="ignore">忽略</string>
</resources> </resources>

@ -9,6 +9,17 @@
<item name="android:textAllCaps">false</item> <item name="android:textAllCaps">false</item>
</style> </style>
<style name="app_dialog_heads_up" parent="android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowAnimationStyle">@style/app_dialog_top_animation</item>
</style>
<style name="OnClick"> <style name="OnClick">
<item name="android:clickable">true</item> <item name="android:clickable">true</item>
<item name="android:onClick">onClick</item> <item name="android:onClick">onClick</item>

@ -1,23 +1,26 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
apply from: 'versions.gradle' apply from: 'versions.gradle'
addRepos(repositories) repositories {
google()
mavenCentral()
jcenter()
}
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.1.1' classpath "com.android.tools.build:gradle:$versions.gradle"
classpath "com.vanniktech:gradle-maven-publish-plugin:$versions.mavenPublish"
// classpath 'com.novoda:bintray-release:0.9'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.13.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }
} }
allprojects { allprojects {
addRepos(repositories) repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
} }
task clean(type: Delete) { task clean(type: Delete) {
@ -31,8 +34,8 @@ allprojects {
charSet 'UTF-8' charSet 'UTF-8'
links "http://docs.oracle.com/javase/8/docs/api" links "http://docs.oracle.com/javase/8/docs/api"
} }
options.addStringOption('Xdoclint:none', '-quiet') options.addStringOption('Xdoclint:none', '-quiet')
// options.compilerArgs << "-Xlint:unchecked" << "- Xlint:deprecation"
failOnError false failOnError false
} }
} }

@ -15,10 +15,8 @@ android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
VERSION_NAME=1.1.1
VERSION_CODE=20
VERSION_NAME=1.1.0
VERSION_CODE=19
GROUP=com.github.jenly1314.AppUpdater GROUP=com.github.jenly1314.AppUpdater
POM_DESCRIPTION=AppUpdater for Android POM_DESCRIPTION=AppUpdater for Android

@ -1,7 +1,7 @@
//App //App
def app_version = [:] def app_version = [:]
app_version.versionCode = 19 app_version.versionCode = 20
app_version.versionName = "1.1.0" app_version.versionName = "1.1.1"
ext.app_version = app_version ext.app_version = app_version
//build version //build version
@ -14,44 +14,21 @@ ext.build_versions = build_versions
// App dependencies // App dependencies
def versions = [:] def versions = [:]
versions.mavenPublish = '0.13.0'
versions.gradle = "4.1.1"
//androidx //androidx
versions.appcompat = "1.1.0" versions.appcompat = "1.1.0"
versions.constraintLayout = "1.1.3" versions.constraintLayout = "2.0.4"
//test //test
versions.junit = "1.1.0" versions.junit = "1.2.0"
versions.test = "1.2.0" versions.junit = "4.13.1"
versions.runner = "1.2.0" versions.androidExtJunit = "1.1.2"
versions.espresso = "3.2.0" versions.espressoCore = "3.2.0"
versions.okhttp = "4.2.2" versions.okhttp = "4.9.1"
ext.versions = versions ext.versions = versions
ext.deps = [:]
//androidx
def androidx = [:]
androidx.appcompat = "androidx.appcompat:appcompat:$versions.appcompat"
androidx.constraintlayout = "androidx.constraintlayout:constraintlayout:$versions.constraintLayout"
deps.androidx = androidx
//test
def test = [:]
test.junit = "androidx.test.ext:junit:$versions.junit"
test.test = "androidx.test:core:$versions.test"
test.runner = "androidx.test:runner:$versions.runner"
test.espresso = "androidx.test.espresso:espresso-core:$versions.espresso"
deps.test = test
//okHttp
deps.okhttp = "com.squareup.okhttp3:okhttp:$versions.okhttp"
ext.deps = deps
def addRepos(RepositoryHandler handler) {
handler.google()
handler.mavenCentral()
handler.jcenter()
}
ext.addRepos = this.&addRepos
Loading…
Cancel
Save