优化细节

pull/27/head 1.1.2
Jenly 3 years ago
parent ac88d07c1b
commit 08e5c8fbb6
  1. 7
      README.md
  2. 135
      app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
  3. 5
      app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
  4. 118
      app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java
  5. 6
      app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java
  6. 25
      app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java
  7. 2
      app-updater/src/main/java/com/king/app/updater/AppUpdater.java
  8. 2
      app-updater/src/main/java/com/king/app/updater/callback/UpdateCallback.java
  9. 20
      app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
  10. BIN
      app/release/app-release.apk
  11. 4
      app/release/output-metadata.json
  12. 2
      app/src/main/java/com/king/appupdater/MainActivity.java
  13. 4
      gradle.properties
  14. 4
      versions.gradle

@ -60,9 +60,9 @@ allprojects {
//----------AndroidX 版本
//app-updater
implementation 'com.github.jenly1314.AppUpdater:app-updater:1.1.1'
implementation 'com.github.jenly1314.AppUpdater:app-updater:1.1.2'
//app-dialog
implementation 'com.github.jenly1314.AppUpdater:app-dialog:1.1.1'
implementation 'com.github.jenly1314.AppUpdater:app-dialog:1.1.2'
```
@ -140,6 +140,9 @@ allprojects {
## 版本记录
#### v1.1.2:2021-11-18
* AppDialog对外提供更多与WindowManager.LayoutParams相关的配置
#### v1.1.1:2021-9-14
* 对外提供更多可配置参数
* 优化细节

@ -135,7 +135,9 @@ public enum AppDialog {
* @param isCancel 是否可取消默认为truefalse则拦截back键
*/
public void showDialog(Context context,AppDialogConfig config,boolean isCancel){
showDialog(context,config.buildAppDialogView(),config.getStyleId(),config.getGravity(),config.getWidthRatio(),isCancel);
showDialog(context, config.buildAppDialogView(), config.getStyleId(), config.getGravity(),
config.getWidthRatio(), config.x, config.y, config.horizontalMargin, config.verticalMargin,
config.horizontalWeight, config.verticalWeight, isCancel);
}
/**
@ -223,8 +225,63 @@ public enum AppDialog {
* @param isCancel 是否可取消默认为truefalse则拦截back键
*/
public void showDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio,final boolean isCancel){
showDialog(context, contentView, styleId, gravity, widthRatio, 0, 0, isCancel);
}
/**
* 显示弹框
* @param context
* @param contentView 弹框内容视图
* @param styleId Dialog样式
* @param gravity Dialog的对齐方式
* @param widthRatio 宽度比例根据屏幕宽度计算得来
* @param x x轴偏移量需与 gravity 结合使用
* @param y y轴偏移量需与 gravity 结合使用
* @param isCancel 是否可取消默认为truefalse则拦截back键
* @return
*/
public void showDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio, int x, int y, final boolean isCancel){
showDialog(context, contentView, styleId, gravity, widthRatio, x, y, 0, 0, isCancel);
}
/**
* 显示弹框
* @param context
* @param contentView 弹框内容视图
* @param styleId Dialog样式
* @param gravity Dialog的对齐方式
* @param widthRatio 宽度比例根据屏幕宽度计算得来
* @param x x轴偏移量需与 gravity 结合使用
* @param y y轴偏移量需与 gravity 结合使用
* @param horizontalMargin 水平方向边距
* @param verticalMargin 垂直方向边距
* @param isCancel 是否可取消默认为truefalse则拦截back键
* @return
*/
public void showDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio, int x, int y, float horizontalMargin, float verticalMargin, final boolean isCancel){
showDialog(context, contentView, styleId, gravity, widthRatio, x, y, horizontalMargin, verticalMargin, 0, 0, isCancel);
}
/**
* 显示弹框
* @param context
* @param contentView 弹框内容视图
* @param styleId Dialog样式
* @param gravity Dialog的对齐方式
* @param widthRatio 宽度比例根据屏幕宽度计算得来
* @param x x轴偏移量需与 gravity 结合使用
* @param y y轴偏移量需与 gravity 结合使用
* @param horizontalMargin 水平方向边距
* @param verticalMargin 垂直方向边距
* @param horizontalWeight 水平方向权重
* @param verticalWeight 垂直方向权重
* @param isCancel 是否可取消默认为truefalse则拦截back键
* @return
*/
public void showDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio, int x, int y, float horizontalMargin, float verticalMargin, float horizontalWeight, float verticalWeight, final boolean isCancel){
dismissDialog();
mDialog = createDialog(context, contentView, styleId, gravity, widthRatio, isCancel);
mDialog = createDialog(context, contentView, styleId, gravity, widthRatio, x, y, horizontalMargin, verticalMargin, horizontalWeight, verticalWeight, isCancel);
mDialog.show();
}
@ -232,14 +289,26 @@ public enum AppDialog {
* 设置弹框窗口配置
* @param context
* @param dialog
* @param gravity
* @param widthRatio
* @param gravity Dialog的对齐方式
* @param widthRatio 宽度比例根据屏幕宽度计算得来
* @param x x轴偏移量需与 gravity 结合使用
* @param y y轴偏移量需与 gravity 结合使用
* @param horizontalMargin 水平方向边距
* @param verticalMargin 垂直方向边距
* @param horizontalWeight 水平方向权重
* @param verticalWeight 垂直方向权重
*/
private void setDialogWindow(Context context,Dialog dialog,int gravity,float widthRatio){
private void setDialogWindow(Context context,Dialog dialog,int gravity,float widthRatio, int x, int y, float horizontalMargin, float verticalMargin, float horizontalWeight, float verticalWeight){
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
lp.width = (int)(context.getResources().getDisplayMetrics().widthPixels * widthRatio);
lp.gravity = gravity;
lp.x = x;
lp.y = y;
lp.horizontalMargin = horizontalMargin;
lp.verticalMargin = verticalMargin;
lp.horizontalWeight = horizontalWeight;
lp.verticalWeight = verticalWeight;
window.setAttributes(lp);
}
@ -365,6 +434,60 @@ public enum AppDialog {
* @param isCancel 是否可取消默认为truefalse则拦截back键
*/
public Dialog createDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio,final boolean isCancel){
return createDialog(context, contentView, styleId, gravity, widthRatio, 0, 0, isCancel);
}
/**
* 创建弹框
* @param context
* @param contentView 弹框内容视图
* @param styleId Dialog样式
* @param gravity Dialog的对齐方式
* @param widthRatio 宽度比例根据屏幕宽度计算得来
* @param x x轴偏移量需与 gravity 结合使用
* @param y y轴偏移量需与 gravity 结合使用
* @param isCancel 是否可取消默认为truefalse则拦截back键
* @return
*/
public Dialog createDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio, int x, int y,final boolean isCancel){
return createDialog(context, contentView, styleId, gravity, widthRatio, x, y, 0, 0, isCancel);
}
/**
* 创建弹框
* @param context
* @param contentView 弹框内容视图
* @param styleId Dialog样式
* @param gravity Dialog的对齐方式
* @param widthRatio 宽度比例根据屏幕宽度计算得来
* @param x x轴偏移量需与 gravity 结合使用
* @param y y轴偏移量需与 gravity 结合使用
* @param horizontalMargin 水平方向边距
* @param verticalMargin 垂直方向边距
* @param isCancel 是否可取消默认为truefalse则拦截back键
* @return
*/
public Dialog createDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio, int x, int y, float horizontalMargin, float verticalMargin,final boolean isCancel){
return createDialog(context, contentView, styleId, gravity, widthRatio, x, y, horizontalMargin, verticalMargin, 0, 0, isCancel);
}
/**
* 创建弹框
* @param context
* @param contentView 弹框内容视图
* @param styleId Dialog样式
* @param gravity Dialog的对齐方式
* @param widthRatio 宽度比例根据屏幕宽度计算得来
* @param x x轴偏移量需与 gravity 结合使用
* @param y y轴偏移量需与 gravity 结合使用
* @param horizontalMargin 水平方向边距
* @param verticalMargin 垂直方向边距
* @param horizontalWeight 水平方向权重
* @param verticalWeight 垂直方向权重
* @param isCancel 是否可取消默认为truefalse则拦截back键
* @return
*/
public Dialog createDialog(Context context, View contentView, @StyleRes int styleId,int gravity, float widthRatio, int x, int y, float horizontalMargin, float verticalMargin, float horizontalWeight, float verticalWeight,final boolean isCancel){
Dialog dialog = new Dialog(context,styleId);
dialog.setContentView(contentView);
dialog.setCanceledOnTouchOutside(false);
@ -381,7 +504,7 @@ public enum AppDialog {
}
});
setDialogWindow(context, dialog, gravity, widthRatio);
setDialogWindow(context, dialog, gravity, widthRatio, x, y, horizontalMargin, verticalMargin, horizontalWeight, verticalWeight);
return dialog;
}

@ -42,10 +42,10 @@ public class AppDialogConfig extends BaseDialogConfig{
private ViewHolder viewHolder;
public AppDialogConfig(@NonNull Context context){
this(context,R.layout.app_dialog);
this(context, R.layout.app_dialog);
}
public AppDialogConfig(@NonNull Context context,@LayoutRes int layoutId){
public AppDialogConfig(@NonNull Context context, @LayoutRes int layoutId){
super(layoutId);
this.context = context;
views = new SparseArray<>();
@ -55,7 +55,6 @@ public class AppDialogConfig extends BaseDialogConfig{
return context;
}
/**
*
* @param context

@ -3,6 +3,7 @@ package com.king.app.dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
@ -81,14 +82,41 @@ public class BaseDialogConfig {
float widthRatio = AppDialog.INSTANCE.DEFAULT_WIDTH_RATIO;
/**
* Dialog对齐方式
* Dialog对齐方式 {@link WindowManager.LayoutParams#gravity}
*
*/
int gravity = Gravity.NO_GRAVITY;
/**
* {@link WindowManager.LayoutParams#x}
*/
int x;
/**
* {@link WindowManager.LayoutParams#y}
*/
int y;
/**
* {@link WindowManager.LayoutParams#verticalMargin}
*/
float verticalMargin;
/**
* {@link WindowManager.LayoutParams#horizontalMargin}
*/
float horizontalMargin;
/**
* {@link WindowManager.LayoutParams#horizontalWeight}
*/
float horizontalWeight;
/**
* {@link WindowManager.LayoutParams#verticalWeight}
*/
float verticalWeight;
View.OnClickListener onClickCancel;
View.OnClickListener onClickConfirm;
public BaseDialogConfig(){
this(R.layout.app_dialog);
}
@ -408,7 +436,7 @@ public class BaseDialogConfig {
}
/**
* 设置Dialog的对齐方式
* 设置Dialog的对齐方式 {@link WindowManager.LayoutParams#gravity}
* @param gravity
* @return
*/
@ -465,5 +493,91 @@ public class BaseDialogConfig {
return setOnClickConfirm(onClickOk);
}
/**
* {@link WindowManager.LayoutParams#x}
*/
public int getX() {
return x;
}
/**
* {@link WindowManager.LayoutParams#x}
*/
public BaseDialogConfig setX(int x) {
this.x = x;
return this;
}
/**
* {@link WindowManager.LayoutParams#y}
*/
public int getY() {
return y;
}
/**
* {@link WindowManager.LayoutParams#y}
*/
public BaseDialogConfig setY(int y) {
this.y = y;
return this;
}
/**
* {@link WindowManager.LayoutParams#verticalMargin}
*/
public float getVerticalMargin() {
return verticalMargin;
}
/**
* {@link WindowManager.LayoutParams#verticalMargin}
*/
public void setVerticalMargin(float verticalMargin) {
this.verticalMargin = verticalMargin;
}
/**
* {@link WindowManager.LayoutParams#horizontalMargin}
*/
public float getHorizontalMargin() {
return horizontalMargin;
}
/**
* {@link WindowManager.LayoutParams#horizontalMargin}
*/
public BaseDialogConfig setHorizontalMargin(float horizontalMargin) {
this.horizontalMargin = horizontalMargin;
return this;
}
/**
* {@link WindowManager.LayoutParams#horizontalWeight}
*/
public float getHorizontalWeight() {
return horizontalWeight;
}
/**
* {@link WindowManager.LayoutParams#horizontalWeight}
*/
public BaseDialogConfig setHorizontalWeight(float horizontalWeight) {
this.horizontalWeight = horizontalWeight;
return this;
}
/**
* {@link WindowManager.LayoutParams#verticalWeight}
*/
public float getVerticalWeight() {
return verticalWeight;
}
/**
* {@link WindowManager.LayoutParams#verticalWeight}
*/
public BaseDialogConfig setVerticalWeight(float verticalWeight) {
this.verticalWeight = verticalWeight;
return this;
}
}

@ -70,11 +70,11 @@ public class AppDialogFragment extends BaseDialogFragment {
@Override
protected void initDialogWindow(Context context, Dialog dialog, int gravity, float widthRatio, int animationStyleId) {
protected void initDialogWindow(Context context, Dialog dialog, int gravity, float widthRatio, int x, int y, float horizontalMargin, float verticalMargin, float horizontalWeight, float verticalWeight, int animationStyleId) {
if(config != null){
super.initDialogWindow(context,dialog,config.getGravity(), config.getWidthRatio(), config.getAnimationStyleId());
super.initDialogWindow(context,dialog,config.getGravity(), config.getWidthRatio(), config.getX(), config.getY(), config.getHorizontalMargin(), config.getVerticalMargin(), config.getHorizontalWeight(), config.getVerticalWeight(), config.getAnimationStyleId());
}else{
super.initDialogWindow(context, dialog, gravity, widthRatio, animationStyleId);
super.initDialogWindow(context, dialog, gravity, widthRatio, x, y, horizontalMargin, verticalMargin, horizontalWeight, verticalWeight, animationStyleId);
}
}
}

@ -44,28 +44,41 @@ public abstract class BaseDialogFragment extends DialogFragment {
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);
initDialogWindow(getContext(),dialog,Gravity.NO_GRAVITY,DEFAULT_WIDTH_RATIO,0, 0, 0, 0, 0, 0, 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);
protected void initDialogWindow(Context context,Dialog dialog,int gravity,float widthRatio, int x, int y, float horizontalMargin, float verticalMargin, float horizontalWeight, float verticalWeight, int animationStyleId){
setDialogWindow(context, dialog, gravity, widthRatio, x, y, horizontalMargin, verticalMargin, horizontalWeight, verticalWeight, animationStyleId);
}
/**
* 设置弹框窗口配置
* @param context
* @param dialog
* @param gravity
* @param widthRatio
* @param gravity Dialog的对齐方式
* @param widthRatio 宽度比例根据屏幕宽度计算得来
* @param x x轴偏移量需与 gravity 结合使用
* @param y y轴偏移量需与 gravity 结合使用
* @param horizontalMargin 水平方向边距
* @param verticalMargin 垂直方向边距
* @param horizontalWeight 水平方向权重
* @param verticalWeight 垂直方向权重
* @param animationStyleId 动画样式
*/
private void setDialogWindow(Context context,Dialog dialog,int gravity,float widthRatio,int animationStyleId){
private void setDialogWindow(Context context,Dialog dialog,int gravity,float widthRatio,int x, int y, float horizontalMargin, float verticalMargin, float horizontalWeight, float verticalWeight, 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;
lp.x = x;
lp.y = y;
lp.horizontalMargin = horizontalMargin;
lp.verticalMargin = verticalMargin;
lp.horizontalWeight = horizontalWeight;
lp.verticalWeight = verticalWeight;
window.setAttributes(lp);
}

@ -84,7 +84,7 @@ public class AppUpdater {
* 开始下载
*/
public void start(){
if(mConfig!=null && !TextUtils.isEmpty(mConfig.getUrl())){
if(mConfig != null && !TextUtils.isEmpty(mConfig.getUrl())){
//如果mContext是Activity,并且配置了下载路径,则默认会校验一次动态权限。
if(mContext instanceof Activity && !TextUtils.isEmpty(mConfig.getPath())){
PermissionUtils.verifyReadAndWritePermissions((Activity) mContext,Constants.RE_CODE_STORAGE_PERMISSION);

@ -9,7 +9,7 @@ public interface UpdateCallback {
/**
* 最开始调用(在onStart之前调用)
* @param isDownloading true 表示已经在下载false表示准备刚调用下载
* @param isDownloading true 表示已经在下载false表示当前未开始下载即将开始下载
*/
void onDownloading(boolean isDownloading);

@ -274,7 +274,7 @@ public class DownloadService extends Service {
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){
callback.onStart(url);
}
}
@ -290,9 +290,9 @@ public class DownloadService extends Service {
int currProgress = Math.round(progress * 1.0f / total * 100.0f);
if(currProgress != mLastProgress){//百分比改变了才更新
isChange = true;
mLastProgress = currProgress;
String percentage = currProgress + "%";
if(isShowNotification) {
mLastProgress = currProgress;
String content = getString(R.string.app_updater_progress_notification_content);
if (isShowPercentage) {
content += percentage;
@ -317,7 +317,7 @@ public class DownloadService extends Service {
if(isInstallApk){
AppUtils.installApk(getContext(),file,authority);
}
if(callback!=null){
if(callback != null){
callback.onFinish(file);
}
stopService();
@ -327,12 +327,14 @@ public class DownloadService extends Service {
public void onError(Exception e) {
Log.w(Constants.TAG,"onError:"+ e.getMessage());
isDownloading = false;
//支持下载失败时重新下载,当重新下载次数不超过限制时才被允许
boolean isReDownload = this.isReDownload && mCount < reDownloads;
String content = isReDownload ? getString(R.string.app_updater_error_notification_content_re_download) : getString(R.string.app_updater_error_notification_content);
NotificationUtils.showErrorNotification(getContext(),notifyId,channelId,notificationIcon,getString(R.string.app_updater_error_notification_title),content,isReDownload,config);
if(isShowNotification){
//支持下载失败时重新下载,当重新下载次数不超过限制时才被允许
boolean isReDownload = this.isReDownload && mCount < reDownloads;
String content = isReDownload ? getString(R.string.app_updater_error_notification_content_re_download) : getString(R.string.app_updater_error_notification_content);
NotificationUtils.showErrorNotification(getContext(),notifyId,channelId,notificationIcon,getString(R.string.app_updater_error_notification_title),content,isReDownload,config);
}
if(callback!=null){
if(callback != null){
callback.onError(e);
}
if(!isReDownload){
@ -346,7 +348,7 @@ public class DownloadService extends Service {
Log.d(Constants.TAG,"onCancel");
isDownloading = false;
NotificationUtils.cancelNotification(getContext(),notifyId);
if(callback!=null){
if(callback != null){
callback.onCancel();
}
if(isDeleteCancelFile && mFile!=null){

Binary file not shown.

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

@ -177,7 +177,7 @@ public class MainActivity extends AppCompatActivity {
.setWidthRatio(.95f)
.setGravity(Gravity.TOP);
AppDialog.INSTANCE.showDialog(getContext(),config);
new CountDownTimer(1500,500){
new CountDownTimer(2000,500){
@Override
public void onTick(long millisUntilFinished) {

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

@ -1,7 +1,7 @@
//App
def app_version = [:]
app_version.versionCode = 20
app_version.versionName = "1.1.1"
app_version.versionCode = 21
app_version.versionName = "1.1.2"
ext.app_version = app_version
//build version

Loading…
Cancel
Save