package com.winfo.update;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.winfo.update.download.httpdownload.DownInfo;
import com.winfo.update.download.httpdownload.DownState;
import com.winfo.update.download.httpdownload.HttpDownManager;
import com.winfo.update.download.listener.HttpProgressOnNextListener;
import com.winfo.update.version_update.utils.ApkUtils;
import java.io.File;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ProgressBar qqProgressBar, alipayProgressBar, weixinProgressbar;
private TextView tvQQMsg, tvAlipayMsg, tvWeixinMsg;
private TextView tvQQProgress, tvAlipayProgress, tvWeixinProgress;
private Button btnQQStart, btnQQPause, btnAlipayStart, btnAlipayPause, btnWeixinStart, btnWeixinPause;
private DownInfo qqDownInfo, alipayDownInfo, weixinDownInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
qqProgressBar = findViewById(R.id.progressBar_qq);
alipayProgressBar = findViewById(R.id.progressBar_alipay);
weixinProgressbar = findViewById(R.id.progressBar_weixin);
tvQQProgress = findViewById(R.id.tv_text_qq);
tvAlipayProgress = findViewById(R.id.tv_text_alipay);
tvWeixinProgress = findViewById(R.id.tv_text_weixin);
tvQQMsg = findViewById(R.id.tv_msg_qq);
tvAlipayMsg = findViewById(R.id.tv_msg_alipay);
tvWeixinMsg = findViewById(R.id.tv_msg_weixin);
btnQQStart = findViewById(R.id.btn_startDown_qq);
btnQQPause = findViewById(R.id.btn_pauseDown_qq);
btnAlipayStart = findViewById(R.id.btn_startDown_alipay);
btnAlipayPause = findViewById(R.id.btn_pauseDown_alipay);
btnWeixinStart = findViewById(R.id.btn_startDown_weixin);
btnWeixinPause = findViewById(R.id.btn_pauseDown_weixin);
btnQQStart.setOnClickListener(this);
btnQQPause.setOnClickListener(this);
btnAlipayStart.setOnClickListener(this);
btnAlipayPause.setOnClickListener(this);
btnWeixinStart.setOnClickListener(this);
btnWeixinPause.setOnClickListener(this);
String weixinDwonloadUrl = "http://dldir1.qq.com/weixin/android/weixin667android1320.apk";
weixinDownInfo = new DownInfo(weixinDwonloadUrl);
String weixinApkName = weixinDwonloadUrl.substring(weixinDwonloadUrl.lastIndexOf("/") + 1, weixinDwonloadUrl.length());
File weixinApkFile = new File(getExternalCacheDir(), weixinApkName);
weixinDownInfo.setSavePath(weixinApkFile.getAbsolutePath());
weixinDownInfo.setState(DownState.START);
String qqDwonloadUrl = "https://qd.myapp.com/myapp/qqteam/AndroidQQ/mobileqq_android.apk";
qqDownInfo = new DownInfo(qqDwonloadUrl);
String qqApkName = qqDwonloadUrl.substring(qqDwonloadUrl.lastIndexOf("/") + 1, qqDwonloadUrl.length());
File qqApkFile = new File(getExternalCacheDir(), qqApkName);
qqDownInfo.setSavePath(qqApkFile.getAbsolutePath());
qqDownInfo.setState(DownState.START);
String alipayDwonloadUrl = "http://gdown.baidu.com/data/wisegame/87b1af6e50012cb5/zhifubao_128.apk";
alipayDownInfo = new DownInfo(alipayDwonloadUrl);
String alipayApkName = alipayDwonloadUrl.substring(alipayDwonloadUrl.lastIndexOf("/") + 1, alipayDwonloadUrl.length());
File alipayApkFile = new File(getExternalCacheDir(), alipayApkName);
alipayDownInfo.setSavePath(alipayApkFile.getAbsolutePath());
alipayDownInfo.setState(DownState.START);
}
@SuppressLint("SetTextI18n")
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_startDown_qq:
HttpDownManager.getInstance().startDown(qqDownInfo, new HttpProgressOnNextListener<DownInfo>() {
@Override
public void onNext(DownInfo downInfo) {
tvQQMsg.setText("QQ下载完成" + downInfo.getSavePath());
ApkUtils.installAPk(MainActivity.this, new File(downInfo.getSavePath()));
}
@Override
public void updateProgress(long readLength, long countLength) {
qqProgressBar.setMax((int) countLength);
qqProgressBar.setProgress((int) readLength);
tvQQProgress.setText(readLength * 100 / countLength + "%");
}
@Override
public void onError(Throwable e) {
tvQQMsg.setText(e.getMessage());
}
});
break;
case R.id.btn_pauseDown_qq:
String tag = (String) btnQQPause.getTag();
if (tag.equals("true")) {
btnQQPause.setText("继续下载");
btnQQPause.setTag("false");
HttpDownManager.getInstance().pause(qqDownInfo);
} else {
btnQQPause.setText("暂停下载");
btnQQPause.setTag("true");
HttpDownManager.getInstance().continueDownload(qqDownInfo);
}
break;
case R.id.btn_startDown_alipay:
HttpDownManager.getInstance().startDown(alipayDownInfo, new HttpProgressOnNextListener<DownInfo>() {
@Override
public void onNext(DownInfo downInfo) {
tvAlipayMsg.setText("下载完成" + downInfo.getSavePath());
ApkUtils.installAPk(MainActivity.this, new File(downInfo.getSavePath()));
}
@Override
public void updateProgress(long readLength, long countLength) {
alipayProgressBar.setMax((int) countLength);
alipayProgressBar.setProgress((int) readLength);
tvAlipayProgress.setText(readLength * 100 / countLength + "%");
}
@Override
public void onError(Throwable e) {
tvAlipayMsg.setText(e.getMessage());
}
});
break;
case R.id.btn_pauseDown_alipay:
String tag1 = (String) btnAlipayPause.getTag();
if (tag1.equals("true")) {
btnAlipayPause.setText("继续下载");
btnAlipayPause.setTag("false");
HttpDownManager.getInstance().pause(alipayDownInfo);
} else {
btnAlipayPause.setText("暂停下载");
btnAlipayPause.setTag("true");
HttpDownManager.getInstance().continueDownload(alipayDownInfo);
}
break;
case R.id.btn_startDown_weixin:
HttpDownManager.getInstance().startDown(weixinDownInfo, new HttpProgressOnNextListener<DownInfo>() {
@Override
public void onNext(DownInfo downInfo) {
tvWeixinMsg.setText("下载完成" + downInfo.getSavePath());
ApkUtils.installAPk(MainActivity.this, new File(downInfo.getSavePath()));
}
@Override
public void updateProgress(long readLength, long countLength) {
weixinProgressbar.setMax((int) countLength);
weixinProgressbar.setProgress((int) readLength);
tvWeixinProgress.setText(readLength * 100 / countLength + "%"
没有合适的资源?快使用搜索试试~ 我知道了~
安卓retrofit2 + rxjava2 + okhttp3多线程下载
共46个文件
java:15个
png:10个
xml:10个
需积分: 3 0 下载量 111 浏览量
2023-07-08
09:26:15
上传
评论 1
收藏 149KB ZIP 举报
温馨提示
安卓retrofit2 + rxjava2 + okhttp3多线程下载
资源推荐
资源详情
资源评论
收起资源包目录
Downloadupdate-master.zip (46个子文件)
Downloadupdate-master
gradle.properties 726B
gradle
wrapper
gradle-wrapper.jar 53KB
gradle-wrapper.properties 232B
app
src
androidTest
java
com
winfo
update
ExampleInstrumentedTest.java 716B
test
java
com
winfo
update
ExampleUnitTest.java 377B
main
java
com
winfo
update
version_update
utils
ApkUtils.java 3KB
MainActivity.java 9KB
download
httpdownload
DownState.java 167B
DownInfo.java 3KB
HttpDownManager.java 8KB
ProgressDownSubscriber.java 4KB
downloadlistener
DownloadResponseBody.java 2KB
DownloadProgressListener.java 289B
DownloadInterceptor.java 757B
http
HttpService.java 597B
exception
HttpTimeException.java 828B
RetryWhenNetworkException.java 2KB
listener
HttpProgressOnNextListener.java 1KB
res
mipmap-xxhdpi
ic_launcher_round.png 10KB
ic_launcher.png 6KB
mipmap-hdpi
ic_launcher_round.png 5KB
ic_launcher.png 3KB
drawable-v24
ic_launcher_foreground.xml 2KB
mipmap-anydpi-v26
ic_launcher.xml 272B
ic_launcher_round.xml 272B
mipmap-mdpi
ic_launcher_round.png 3KB
ic_launcher.png 2KB
mipmap-xxxhdpi
ic_launcher_round.png 15KB
ic_launcher.png 9KB
mipmap-xhdpi
ic_launcher_round.png 7KB
ic_launcher.png 4KB
xml
update_apk_paths.xml 499B
values
colors.xml 208B
strings.xml 778B
styles.xml 383B
layout
activity_main.xml 6KB
drawable
ic_launcher_background.xml 5KB
AndroidManifest.xml 1KB
proguard-rules.pro 751B
build.gradle 2KB
.gitignore 7B
gradlew.bat 2KB
build.gradle 546B
settings.gradle 15B
gradlew 5KB
.gitignore 137B
共 46 条
- 1
资源评论
来之梦
- 粉丝: 351
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功