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