diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 4f4e779..3d3405e 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 30aa626..2eb81ec 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..8095114 --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,456 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index a73a1f7..f51a717 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,14 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版 更多使用示例请查看[App](app)。 +## 版本记录 +#### v1.0.1:2019-3-18 +* 新增通知栏是否震动和铃声提示配置 +* AppDialogConfig新增getView(Context context)方法; +#### v1.0.1:2019-1-10 +* 升级Gradle到4.6 +#### v1.0:2018-6-29 +* AppUpdater初始版本 ## 关于我 Name: Jenly diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java index 8b14d96..c219152 100644 --- a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java +++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java @@ -3,12 +3,12 @@ package com.king.app.dialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.support.annotation.NonNull; import android.support.annotation.StyleRes; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentManager; import android.text.TextUtils; import android.view.KeyEvent; -import android.view.LayoutInflater; import android.view.View; import android.view.Window; import android.view.WindowManager; @@ -38,34 +38,31 @@ public enum AppDialog { * @param config 弹框配置 {@link AppDialogConfig} * @return */ - public View createAppDialogView(Context context,AppDialogConfig config){ - View view = null; - if(config!=null){ - view = LayoutInflater.from(context).inflate(config.getLayoutId(),null); - TextView tvDialogTitle = view.findViewById(config.getTitleId()); - setText(tvDialogTitle,config.getTitle()); - - TextView tvDialogContent = view.findViewById(config.getContentId()); - setText(tvDialogContent,config.getContent()); - - Button btnDialogCancel = view.findViewById(config.getCancelId()); - setText(btnDialogCancel,config.getCancel()); - btnDialogCancel.setOnClickListener(config.getOnClickCancel() != null ? config.getOnClickCancel() : mOnClickDismissDialog); - btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); - - try{ - //不强制要求要有横线 - View line = view.findViewById(R.id.line); - line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); - }catch (Exception e){ - - } - - Button btnDialogOK = view.findViewById(config.getOkId()); - setText(btnDialogOK,config.getOk()); - btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : mOnClickDismissDialog); + public View createAppDialogView(@NonNull Context context,@NonNull AppDialogConfig config){ + View view = config.getView(context); + TextView tvDialogTitle = view.findViewById(config.getTitleId()); + setText(tvDialogTitle,config.getTitle()); + + TextView tvDialogContent = view.findViewById(config.getContentId()); + setText(tvDialogContent,config.getContent()); + + Button btnDialogCancel = view.findViewById(config.getCancelId()); + setText(btnDialogCancel,config.getCancel()); + btnDialogCancel.setOnClickListener(config.getOnClickCancel() != null ? config.getOnClickCancel() : mOnClickDismissDialog); + btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); + + try{ + //不强制要求要有横线 + View line = view.findViewById(R.id.line); + line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); + }catch (Exception e){ + e.printStackTrace(); } + Button btnDialogOK = view.findViewById(config.getOkId()); + setText(btnDialogOK,config.getOk()); + btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : mOnClickDismissDialog); + return view; } @@ -225,6 +222,7 @@ public enum AppDialog { * @param isCancel 是否可取消(默认为true,false则拦截back键) */ public void showDialog(Context context, View contentView, @StyleRes int resId, float widthRatio,final boolean isCancel){ + dismissDialog(); mDialog = new Dialog(context,resId); mDialog.setContentView(contentView); mDialog.setCanceledOnTouchOutside(false); diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java index a2f619b..1ff8355 100644 --- a/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java +++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java @@ -1,7 +1,10 @@ package com.king.app.dialog; +import android.content.Context; import android.support.annotation.IdRes; import android.support.annotation.LayoutRes; +import android.support.annotation.NonNull; +import android.view.LayoutInflater; import android.view.View; /** @@ -57,6 +60,8 @@ public class AppDialogConfig { private View.OnClickListener onClickOk; + private View view; + public @LayoutRes int getLayoutId() { return layoutId; } @@ -174,5 +179,13 @@ public class AppDialogConfig { return this; } + public View getView(@NonNull Context context){ + if(view == null){ + view = LayoutInflater.from(context).inflate(layoutId,null); + } + return view; + } + + } diff --git a/app-updater/src/main/AndroidManifest.xml b/app-updater/src/main/AndroidManifest.xml index 68b5e1f..1a466ab 100644 --- a/app-updater/src/main/AndroidManifest.xml +++ b/app-updater/src/main/AndroidManifest.xml @@ -1,13 +1,14 @@ + + - - + diff --git a/app-updater/src/main/java/com/king/app/updater/AppUpdater.java b/app-updater/src/main/java/com/king/app/updater/AppUpdater.java index 877465b..a221bd5 100644 --- a/app-updater/src/main/java/com/king/app/updater/AppUpdater.java +++ b/app-updater/src/main/java/com/king/app/updater/AppUpdater.java @@ -8,6 +8,7 @@ import android.content.ServiceConnection; import android.os.IBinder; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; import android.text.TextUtils; import android.util.Log; @@ -41,7 +42,6 @@ public class AppUpdater { private ServiceConnection mServiceConnection; - public AppUpdater(@NonNull Context context,@NonNull UpdateConfig config){ this.mContext = context; this.mConfig = config; @@ -123,7 +123,7 @@ public class AppUpdater { } /** - * + * 设置APK下载地址 * @param url 下载地址 * @return */ @@ -133,7 +133,7 @@ public class AppUpdater { } /** - * + * 设置保存的路径 * @param path 下载保存的文件路径 (默认SD卡/.AppUpdater目录) * @return */ @@ -143,7 +143,7 @@ public class AppUpdater { } /** - * + * 设置保存的文件名 * @param filename 下载的保存的apk文件名 (默认优先取url文件名) * @return */ @@ -153,7 +153,7 @@ public class AppUpdater { } /** - * + * 设置是否显示通知栏 * @param isShowNotification 是否显示通知栏 (默认true) * @return */ @@ -163,7 +163,7 @@ public class AppUpdater { } /** - * + * 设置通知ID * @param notifyId 通知ID * @return */ @@ -173,7 +173,7 @@ public class AppUpdater { } /** - * + * 设置通知渠道ID * @param channelId 通知渠道ID (默认兼容O) * @return */ @@ -183,7 +183,7 @@ public class AppUpdater { } /** - * + * 设置通知渠道名称 * @param channelName 通知渠道名称 (默认兼容O) * @return */ @@ -193,7 +193,7 @@ public class AppUpdater { } /** - * + * 设置通知图标 * @param icon 通知栏图标 (默认取App的icon) * @return */ @@ -203,7 +203,28 @@ public class AppUpdater { } /** - * + * 设置通知是否震动提示 + * @param vibrate 是否震动提示,为true时使用通知默认震动,Android O(8.0)以上设置,只有初次创建channel时有效,后续修改属性无效,想要重新有效需修改channelId或卸载App重装。 + * @return + */ + public Builder setVibrate(boolean vibrate) { + mConfig.setVibrate(vibrate); + return this; + } + + /** + * 设置通知是否铃声提示 + * @param sound 是否铃声提示,为true时使用通知默认铃声,Android O(8.0)以上设置,只有初次创建channel时有效,后续修改属性无效,想要重新有效需修改channelId或卸载App重装。 + * @return + */ + public Builder setSound(boolean sound) { + mConfig.setSound(sound); + return this; + } + + + /** + * 设置下载完成后知否自动触发安装APK * @param isInstallApk 下载完成后是否自动调用安装APK(默认true) * @return */ @@ -213,7 +234,7 @@ public class AppUpdater { } /** - * + * 设置FileProvider的authority * @param authority FileProvider的authority(默认兼容N,默认值context.getPackageName() + ".fileProvider") * @return */ @@ -223,7 +244,7 @@ public class AppUpdater { } /** - * + * 设置下载时,通知栏是否显示下载百分比 * @param showPercentage 下载时通知栏是否显示百分比 * @return */ @@ -233,7 +254,7 @@ public class AppUpdater { } /** - * + * 设置下载失败是是否支持点击通知栏重新下载 * @param reDownload 下载失败时是否支持点击通知栏重新下载,默认true 最多重新下载3次 * @return */ diff --git a/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java b/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java index 7e25b04..a756983 100644 --- a/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java +++ b/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java @@ -64,6 +64,16 @@ public class UpdateConfig implements Parcelable { */ private boolean isShowPercentage = true; + /** + * 是否震动提示,为true时使用通知默认震动 + */ + private boolean isVibrate; + + /** + * 是否铃声提示,为true时使用通知默认铃声 + */ + private boolean isSound; + public UpdateConfig() { @@ -165,6 +175,22 @@ public class UpdateConfig implements Parcelable { isReDownload = reDownload; } + public boolean isVibrate() { + return isVibrate; + } + + public void setVibrate(boolean vibrate) { + isVibrate = vibrate; + } + + public boolean isSound() { + return isSound; + } + + public void setSound(boolean sound) { + isSound = sound; + } + @Override public String toString() { return "UpdateConfig{" + @@ -178,11 +204,14 @@ public class UpdateConfig implements Parcelable { ", mChannelId='" + mChannelId + '\'' + ", mChannelName='" + mChannelName + '\'' + ", mAuthority='" + mAuthority + '\'' + - ", isShowPercentage=" + isShowPercentage + ", isReDownload=" + isReDownload + + ", isShowPercentage=" + isShowPercentage + + ", isVibrate=" + isVibrate + + ", isSound=" + isSound + '}'; } + @Override public int describeContents() { return 0; @@ -202,9 +231,10 @@ public class UpdateConfig implements Parcelable { dest.writeString(this.mAuthority); dest.writeByte(this.isReDownload ? (byte) 1 : (byte) 0); dest.writeByte(this.isShowPercentage ? (byte) 1 : (byte) 0); + dest.writeByte(this.isVibrate ? (byte) 1 : (byte) 0); + dest.writeByte(this.isSound ? (byte) 1 : (byte) 0); } - protected UpdateConfig(Parcel in) { this.mUrl = in.readString(); this.mPath = in.readString(); @@ -218,6 +248,8 @@ public class UpdateConfig implements Parcelable { this.mAuthority = in.readString(); this.isReDownload = in.readByte() != 0; this.isShowPercentage = in.readByte() != 0; + this.isVibrate = in.readByte() != 0; + this.isSound = in.readByte() != 0; } public static final Creator CREATOR = new Creator() { diff --git a/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java b/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java index 236cee2..abf649c 100644 --- a/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java +++ b/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java @@ -138,7 +138,6 @@ public class DownloadService extends Service { HttpManager.getInstance().download(url,path,filename,new AppDownloadCallback(config,callback)); } - } /** @@ -224,7 +223,7 @@ public class DownloadService extends Service { isDownloading = true; mLastProgress = 0; if(isShowNotification){ - showStartNotification(notifyId,channelId,channelName,notificationIcon,getString(R.string.app_updater_start_notification_title),getString(R.string.app_updater_start_notification_content)); + showStartNotification(notifyId,channelId,channelName,notificationIcon,getString(R.string.app_updater_start_notification_title),getString(R.string.app_updater_start_notification_content),config.isVibrate(),config.isSound()); } if(callback!=null){ @@ -320,13 +319,21 @@ public class DownloadService extends Service { * @param title * @param content */ - private void showStartNotification(int notifyId,String channelId, String channelName,@DrawableRes int icon,CharSequence title,CharSequence content){ + private void showStartNotification(int notifyId,String channelId, String channelName,@DrawableRes int icon,CharSequence title,CharSequence content,boolean isVibrate,boolean isSound){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ - createNotificationChannel(channelId,channelName); + createNotificationChannel(channelId,channelName,isVibrate,isSound); } NotificationCompat.Builder builder = buildNotification(channelId,icon,title,content); - builder.setAutoCancel(false); - notifyNotification(notifyId,builder.build()); + if(isVibrate && isSound){ + builder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND); + }else if(isVibrate){ + builder.setDefaults(Notification.DEFAULT_VIBRATE); + }else if(isSound){ + builder.setDefaults(Notification.DEFAULT_SOUND); + } + Notification notification = builder.build(); + notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE; + notifyNotification(notifyId,notification); } /** @@ -341,9 +348,8 @@ public class DownloadService extends Service { */ private void showProgressNotification(int notifyId,String channelId,@DrawableRes int icon,CharSequence title,CharSequence content,int progress,int size){ NotificationCompat.Builder builder = buildNotification(channelId,icon,title,content,progress,size); - builder.setAutoCancel(false); Notification notification = builder.build(); - notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE; + notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE; notifyNotification(notifyId,notification); } @@ -438,8 +444,12 @@ public class DownloadService extends Service { * @param channelName */ @RequiresApi(api = Build.VERSION_CODES.O) - private void createNotificationChannel(String channelId, String channelName){ + private void createNotificationChannel(String channelId, String channelName,boolean isVibrate,boolean isSound){ NotificationChannel channel = new NotificationChannel(channelId,channelName, NotificationManager.IMPORTANCE_DEFAULT); + channel.enableVibration(isVibrate); + if(!isSound){ + channel.setSound(null,null); + } getNotificationManager().createNotificationChannel(channel); } diff --git a/app/release/app-release.apk b/app/release/app-release.apk index 322dec7..3311109 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/release/output.json b/app/release/output.json index bd004be..1caf134 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2,"versionName":"1.0.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":3,"versionName":"1.0.2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1b430ee..8e0b0f8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,6 @@ - -