对外提供更多可配置参数

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. 37
      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 版本
//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标识
* 优化细节

@ -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"
}

@ -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 是否可取消默认为truefalse则拦截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 是否可取消默认为truefalse则拦截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 是否可取消默认为truefalse则拦截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 是否可取消默认为truefalse则拦截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 是否可取消默认为truefalse则拦截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 是否可取消默认为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.setContentView(contentView);
dialog.setCanceledOnTouchOutside(false);
@ -330,7 +381,7 @@ public enum AppDialog {
}
});
setDialogWindow(context,dialog,widthRatio);
setDialogWindow(context, dialog, gravity, widthRatio);
return dialog;
}

@ -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);
}

@ -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);
}

@ -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);
}
}
}

@ -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);
}

@ -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"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:duration="200"
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<scale
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="0.0"

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:duration="200"
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<scale
android:pivotX="50%"
android:pivotY="50%"
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_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" />
<include layout="@layout/app_dialog_line_h"/>
<LinearLayout
@ -40,21 +46,21 @@
android:layout_weight="1"
android:text="@string/app_dialog_cancel"
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"/>
<include
android:id="@+id/line"
layout="@layout/app_dialog_line_v"/>
<Button
android:id="@+id/btnDialogOK"
android:id="@+id/btnDialogConfirm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
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:textColor="@color/app_dialog_button_color_selector"
android:textColor="@color/app_cancel_color_selector"
android:background="?android:attr/selectableItemBackground"/>
</LinearLayout>

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorAccent">#FF4081</color>
<color name="colorAccent">#5588FF</color>
<color name="app_dialog_title_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_pressed_color">@color/colorAccent</color>
<color name="app_dialog_line_color">#f2f2f2</color>
<color name="app_dialog_line_color">#F2F2F2</color>
</resources>

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

@ -2,9 +2,32 @@
<resources>
<!-- dialog animation -->
<style name="app_dialog_animation" parent="android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/app_dialog_in</item>
<item name="android:windowExitAnimation">@anim/app_dialog_out</item>
<style name="app_dialog_scale_animation" parent="android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/app_dialog_scale_in</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>
<!-- dialog style -->
@ -15,7 +38,7 @@
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</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>
</resources>

@ -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"
}

@ -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;

@ -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();
}

@ -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);
}
}

@ -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) {

@ -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);
}

@ -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')

Binary file not shown.

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

@ -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()

@ -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"
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
android:id="@+id/btn1"
android:layout_width="match_parent"
@ -24,7 +14,6 @@
android:layout_marginRight="20dp"
android:layout_marginTop="40dp"
android:text="简单一键后台升级"
app:layout_constraintTop_toBottomOf="@+id/progressBar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
@ -36,7 +25,7 @@
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:text="一键监听进度后台升级"
android:text="一键监听进度升级"
app:layout_constraintTop_toBottomOf="@+id/btn1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"

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

@ -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">
<TextView
android:id="@+id/tvTitle"
@ -13,43 +13,48 @@
android:gravity="center"
android:padding="6dp"
android:lines="1"
android:textSize="16sp"
android:background="#F5F5F5" />
android:textSize="16sp" />
<TextView
android:id="@+id/tvContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="6dp"
android:padding="16dp"
android:lineSpacingMultiplier="1" />
<include layout="@layout/app_dialog_line_h"/>
<LinearLayout
android:orientation="horizontal"
android:orientation="vertical"
android:layout_width="match_parent"
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">
<Button
android:id="@+id/btnCancel"
android:layout_width="0dp"
<TextView
android:id="@+id/btnConfirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:gravity="center"
android:layout_weight="1"
android:text="@string/app_dialog_cancel"
android:text="升级"
android:textSize="16sp"
android:textColor="@color/app_dialog_button_color_selector"
android:background="?android:attr/selectableItemBackground"/>
<Button
android:id="@+id/btnOK"
android:layout_width="0dp"
android:textColor="@color/white"
android:background="@drawable/btn_confirm_selector"/>
<TextView
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:gravity="center"
android:layout_weight="1"
android:text="升级"
android:text="@string/ignore"
android:textSize="16sp"
android:textColor="@color/app_dialog_button_color_selector"
android:background="?android:attr/selectableItemBackground"/>
android:textColor="@color/btn_cancel_color_selector" />
</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"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorPrimary">#5588FF</color>
<color name="colorPrimaryDark">#4B7CFD</color>
<color name="colorAccent">#5588FF</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>

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

@ -9,6 +9,17 @@
<item name="android:textAllCaps">false</item>
</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">
<item name="android:clickable">true</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.
buildscript {
apply from: 'versions.gradle'
addRepos(repositories)
repositories {
google()
mavenCentral()
jcenter()
}
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
// in the individual module build.gradle files
}
}
allprojects {
addRepos(repositories)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
@ -31,8 +34,8 @@ allprojects {
charSet 'UTF-8'
links "http://docs.oracle.com/javase/8/docs/api"
}
options.addStringOption('Xdoclint:none', '-quiet')
// options.compilerArgs << "-Xlint:unchecked" << "- Xlint:deprecation"
failOnError false
}
}

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

@ -1,7 +1,7 @@
//App
def app_version = [:]
app_version.versionCode = 19
app_version.versionName = "1.1.0"
app_version.versionCode = 20
app_version.versionName = "1.1.1"
ext.app_version = app_version
//build version
@ -14,44 +14,21 @@ ext.build_versions = build_versions
// App dependencies
def versions = [:]
versions.mavenPublish = '0.13.0'
versions.gradle = "4.1.1"
//androidx
versions.appcompat = "1.1.0"
versions.constraintLayout = "1.1.3"
versions.constraintLayout = "2.0.4"
//test
versions.junit = "1.1.0"
versions.test = "1.2.0"
versions.runner = "1.2.0"
versions.espresso = "3.2.0"
versions.junit = "1.2.0"
versions.junit = "4.13.1"
versions.androidExtJunit = "1.1.2"
versions.espressoCore = "3.2.0"
versions.okhttp = "4.2.2"
versions.okhttp = "4.9.1"
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