|
@@ -1,15 +1,12 @@
|
|
|
-package org.yczbj.ycvideoplayer.ui.test3;
|
|
|
|
|
|
|
+package org.yczbj.ycvideoplayer.ui.test3.ui.activity;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.annotation.SuppressLint;
|
|
|
-import android.os.Bundle;
|
|
|
|
|
-import android.support.design.widget.Snackbar;
|
|
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.widget.Button;
|
|
import android.widget.Button;
|
|
|
import android.widget.ProgressBar;
|
|
import android.widget.ProgressBar;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import com.liulishuo.filedownloader.BaseDownloadTask;
|
|
import com.liulishuo.filedownloader.BaseDownloadTask;
|
|
|
-import com.liulishuo.filedownloader.FileDownloadListener;
|
|
|
|
|
import com.liulishuo.filedownloader.FileDownloadSampleListener;
|
|
import com.liulishuo.filedownloader.FileDownloadSampleListener;
|
|
|
import com.liulishuo.filedownloader.FileDownloader;
|
|
import com.liulishuo.filedownloader.FileDownloader;
|
|
|
import com.liulishuo.filedownloader.util.FileDownloadUtils;
|
|
import com.liulishuo.filedownloader.util.FileDownloadUtils;
|
|
@@ -24,7 +21,6 @@ import java.io.File;
|
|
|
import java.lang.ref.WeakReference;
|
|
import java.lang.ref.WeakReference;
|
|
|
|
|
|
|
|
import butterknife.Bind;
|
|
import butterknife.Bind;
|
|
|
-import butterknife.ButterKnife;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -32,6 +28,10 @@ import butterknife.ButterKnife;
|
|
|
* Update:2018/1/2
|
|
* Update:2018/1/2
|
|
|
* CreatedTime:2017/12/29
|
|
* CreatedTime:2017/12/29
|
|
|
* Author:yc
|
|
* Author:yc
|
|
|
|
|
+ * 启动单任务下载
|
|
|
|
|
+ * 1.下载遇到的问题,如果下载没有完成,则无法删除下载的文件,这不太友好
|
|
|
|
|
+ *
|
|
|
|
|
+ *
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
public class DLSingleTestActivity extends BaseActivity implements View.OnClickListener {
|
|
public class DLSingleTestActivity extends BaseActivity implements View.OnClickListener {
|
|
@@ -83,6 +83,14 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
TextView speedTv4;
|
|
TextView speedTv4;
|
|
|
@Bind(R.id.progressBar_4)
|
|
@Bind(R.id.progressBar_4)
|
|
|
ProgressBar progressBar4;
|
|
ProgressBar progressBar4;
|
|
|
|
|
+ @Bind(R.id.state_tv_1)
|
|
|
|
|
+ TextView stateTv1;
|
|
|
|
|
+ @Bind(R.id.state_tv_2)
|
|
|
|
|
+ TextView stateTv2;
|
|
|
|
|
+ @Bind(R.id.state_tv_3)
|
|
|
|
|
+ TextView stateTv3;
|
|
|
|
|
+ @Bind(R.id.state_tv_4)
|
|
|
|
|
+ TextView stateTv4;
|
|
|
private String filePath1;
|
|
private String filePath1;
|
|
|
private String filePath2;
|
|
private String filePath2;
|
|
|
private String filePath3;
|
|
private String filePath3;
|
|
@@ -98,6 +106,8 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
FileDownloader.getImpl().pause(downloadId1);
|
|
FileDownloader.getImpl().pause(downloadId1);
|
|
|
FileDownloader.getImpl().pause(downloadId2);
|
|
FileDownloader.getImpl().pause(downloadId2);
|
|
|
|
|
+ FileDownloader.getImpl().pause(downloadId3);
|
|
|
|
|
+ FileDownloader.getImpl().pause(downloadId4);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -136,54 +146,58 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
* 设置文件路径
|
|
* 设置文件路径
|
|
|
*/
|
|
*/
|
|
|
private void setFilePath() {
|
|
private void setFilePath() {
|
|
|
- filePath1 = FileDownloadUtils.getDefaultSaveRootPath() + File.separator + "_1_" + File.separator +"yc.apk";
|
|
|
|
|
|
|
+ filePath1 = FileDownloadUtils.getDefaultSaveRootPath() + File.separator + "_1_";
|
|
|
filePath2 = FileDownloadUtils.getDefaultSaveRootPath() + File.separator + "_2_";
|
|
filePath2 = FileDownloadUtils.getDefaultSaveRootPath() + File.separator + "_2_";
|
|
|
filePath3 = FileDownloadUtils.getDefaultSaveRootPath() + File.separator + "_3_";
|
|
filePath3 = FileDownloadUtils.getDefaultSaveRootPath() + File.separator + "_3_";
|
|
|
filePath4 = FileDownloadUtils.getDefaultSaveRootPath() + File.separator + "_4_";
|
|
filePath4 = FileDownloadUtils.getDefaultSaveRootPath() + File.separator + "_4_";
|
|
|
- LogUtils.e(this.getClass().getName()+"--filePath1---"+filePath1);
|
|
|
|
|
- LogUtils.e(this.getClass().getName()+"--filePath2---"+filePath2);
|
|
|
|
|
- LogUtils.e(this.getClass().getName()+"--filePath3---"+filePath3);
|
|
|
|
|
- LogUtils.e(this.getClass().getName()+"--filePath4---"+filePath4);
|
|
|
|
|
|
|
+ LogUtils.e(this.getClass().getName() + "--filePath1---" + filePath1);
|
|
|
|
|
+ LogUtils.e(this.getClass().getName() + "--filePath2---" + filePath2);
|
|
|
|
|
+ LogUtils.e(this.getClass().getName() + "--filePath3---" + filePath3);
|
|
|
|
|
+ LogUtils.e(this.getClass().getName() + "--filePath4---" + filePath4);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
public void onClick(View v) {
|
|
|
- switch (v.getId()){
|
|
|
|
|
|
|
+ switch (v.getId()) {
|
|
|
case R.id.start_btn_1:
|
|
case R.id.start_btn_1:
|
|
|
downloadId1 = createDownloadTask(1).start();
|
|
downloadId1 = createDownloadTask(1).start();
|
|
|
break;
|
|
break;
|
|
|
case R.id.start_btn_2:
|
|
case R.id.start_btn_2:
|
|
|
-
|
|
|
|
|
|
|
+ downloadId2 = createDownloadTask(2).start();
|
|
|
break;
|
|
break;
|
|
|
case R.id.start_btn_3:
|
|
case R.id.start_btn_3:
|
|
|
-
|
|
|
|
|
|
|
+ downloadId3 = createDownloadTask(3).start();
|
|
|
break;
|
|
break;
|
|
|
case R.id.start_btn_4:
|
|
case R.id.start_btn_4:
|
|
|
-
|
|
|
|
|
|
|
+ downloadId4 = createDownloadTask(4).start();
|
|
|
break;
|
|
break;
|
|
|
case R.id.pause_btn_1:
|
|
case R.id.pause_btn_1:
|
|
|
-
|
|
|
|
|
|
|
+ FileDownloader.getImpl().pause(downloadId1);
|
|
|
break;
|
|
break;
|
|
|
case R.id.pause_btn_2:
|
|
case R.id.pause_btn_2:
|
|
|
-
|
|
|
|
|
|
|
+ FileDownloader.getImpl().pause(downloadId2);
|
|
|
break;
|
|
break;
|
|
|
case R.id.pause_btn_3:
|
|
case R.id.pause_btn_3:
|
|
|
-
|
|
|
|
|
|
|
+ FileDownloader.getImpl().pause(downloadId3);
|
|
|
break;
|
|
break;
|
|
|
case R.id.pause_btn_4:
|
|
case R.id.pause_btn_4:
|
|
|
-
|
|
|
|
|
|
|
+ FileDownloader.getImpl().pause(downloadId4);
|
|
|
break;
|
|
break;
|
|
|
case R.id.delete_btn_1:
|
|
case R.id.delete_btn_1:
|
|
|
-
|
|
|
|
|
|
|
+ new File(filePath1).delete();
|
|
|
|
|
+ new File(FileDownloadUtils.getTempPath(filePath1)).delete();
|
|
|
break;
|
|
break;
|
|
|
case R.id.delete_btn_2:
|
|
case R.id.delete_btn_2:
|
|
|
-
|
|
|
|
|
|
|
+ new File(filePath2).delete();
|
|
|
|
|
+ new File(FileDownloadUtils.getTempPath(filePath2)).delete();
|
|
|
break;
|
|
break;
|
|
|
case R.id.delete_btn_3:
|
|
case R.id.delete_btn_3:
|
|
|
-
|
|
|
|
|
|
|
+ new File(filePath3).delete();
|
|
|
|
|
+ new File(FileDownloadUtils.getTempPath(filePath3)).delete();
|
|
|
break;
|
|
break;
|
|
|
case R.id.delete_btn_4:
|
|
case R.id.delete_btn_4:
|
|
|
-
|
|
|
|
|
|
|
+ new File(filePath4).delete();
|
|
|
|
|
+ new File(FileDownloadUtils.getTempPath(filePath4)).delete();
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|
|
@@ -191,54 +205,64 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private BaseDownloadTask createDownloadTask(int i) {
|
|
private BaseDownloadTask createDownloadTask(int i) {
|
|
|
- final TaskTag taskTag ;
|
|
|
|
|
|
|
+ final TaskTag taskTag;
|
|
|
//创建下载的链接地址
|
|
//创建下载的链接地址
|
|
|
- String url = ConstantVideo.VideoPlayerList[0];
|
|
|
|
|
|
|
+ String url;
|
|
|
//是否
|
|
//是否
|
|
|
boolean isDir = false;
|
|
boolean isDir = false;
|
|
|
//文件路径
|
|
//文件路径
|
|
|
String path = null;
|
|
String path = null;
|
|
|
|
|
|
|
|
- switch (i){
|
|
|
|
|
|
|
+ switch (i) {
|
|
|
case 1:
|
|
case 1:
|
|
|
url = ConstantVideo.VideoPlayerList[0];
|
|
url = ConstantVideo.VideoPlayerList[0];
|
|
|
path = filePath1;
|
|
path = filePath1;
|
|
|
- taskTag = new TaskTag(new WeakReference<>(this),filenameTv1, progressBar1, null, speedTv1, 1);
|
|
|
|
|
|
|
+ taskTag = new TaskTag(new WeakReference<>(this), filenameTv1, progressBar1, null, speedTv1, stateTv1,1);
|
|
|
break;
|
|
break;
|
|
|
case 2:
|
|
case 2:
|
|
|
url = ConstantVideo.VideoPlayerList[1];
|
|
url = ConstantVideo.VideoPlayerList[1];
|
|
|
- taskTag = new TaskTag(new WeakReference<>(this), filenameTv1, progressBar2, null, speedTv2, 2);
|
|
|
|
|
|
|
+ taskTag = new TaskTag(new WeakReference<>(this), filenameTv1, progressBar2, null, speedTv2, stateTv2,2);
|
|
|
path = filePath2;
|
|
path = filePath2;
|
|
|
isDir = true;
|
|
isDir = true;
|
|
|
break;
|
|
break;
|
|
|
case 3:
|
|
case 3:
|
|
|
url = ConstantVideo.VideoPlayerList[2];
|
|
url = ConstantVideo.VideoPlayerList[2];
|
|
|
- taskTag = new TaskTag(new WeakReference<>(this),null, progressBar3, null, speedTv3, 3);
|
|
|
|
|
|
|
+ taskTag = new TaskTag(new WeakReference<>(this), null, progressBar3, null, speedTv3, stateTv3,3);
|
|
|
path = filePath3;
|
|
path = filePath3;
|
|
|
break;
|
|
break;
|
|
|
case 4:
|
|
case 4:
|
|
|
- url = ConstantVideo.VideoPlayerList[2];
|
|
|
|
|
- taskTag = new TaskTag(new WeakReference<>(this),null, progressBar4, detailTv4, speedTv4, 4);
|
|
|
|
|
|
|
+ url = ConstantVideo.VideoPlayerList[3];
|
|
|
|
|
+ taskTag = new TaskTag(new WeakReference<>(this), null, progressBar4, detailTv4, speedTv4,stateTv4, 4);
|
|
|
path = filePath4;
|
|
path = filePath4;
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
- url = ConstantVideo.VideoPlayerList[2];
|
|
|
|
|
- taskTag = new TaskTag(new WeakReference<>(this),null, progressBar4, detailTv4, speedTv4, 4);
|
|
|
|
|
|
|
+ url = ConstantVideo.VideoPlayerList[3];
|
|
|
|
|
+ taskTag = new TaskTag(new WeakReference<>(this), null, progressBar4, detailTv4, speedTv4, stateTv4,4);
|
|
|
path = filePath4;
|
|
path = filePath4;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return FileDownloader.getImpl().create(url)
|
|
return FileDownloader.getImpl().create(url)
|
|
|
.setPath(path, isDir)
|
|
.setPath(path, isDir)
|
|
|
.setCallbackProgressTimes(300)
|
|
.setCallbackProgressTimes(300)
|
|
|
.setMinIntervalUpdateSpeed(400)
|
|
.setMinIntervalUpdateSpeed(400)
|
|
|
.setTag(taskTag)
|
|
.setTag(taskTag)
|
|
|
.setListener(new FileDownloadSampleListener() {
|
|
.setListener(new FileDownloadSampleListener() {
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 等待,已经进入下载队列
|
|
|
|
|
+ * 带回数据:数据库中的soFarBytes与totalBytes
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
protected void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) {
|
|
protected void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) {
|
|
|
super.pending(task, soFarBytes, totalBytes);
|
|
super.pending(task, soFarBytes, totalBytes);
|
|
|
((TaskTag) task.getTag()).updatePending(task);
|
|
((TaskTag) task.getTag()).updatePending(task);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 下载进度回调
|
|
|
|
|
+ * 带回数据:soFarBytes
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
protected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) {
|
|
protected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) {
|
|
|
super.progress(task, soFarBytes, totalBytes);
|
|
super.progress(task, soFarBytes, totalBytes);
|
|
@@ -246,40 +270,95 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
task.getSpeed());
|
|
task.getSpeed());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 下载出现错误
|
|
|
|
|
+ * 带回数据:抛出的Throwable
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
protected void error(BaseDownloadTask task, Throwable e) {
|
|
protected void error(BaseDownloadTask task, Throwable e) {
|
|
|
super.error(task, e);
|
|
super.error(task, e);
|
|
|
((TaskTag) task.getTag()).updateError(e, task.getSpeed());
|
|
((TaskTag) task.getTag()).updateError(e, task.getSpeed());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 已经连接上
|
|
|
|
|
+ * 带回数据:ETag, 是否断点续传, soFarBytes, totalBytes
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
protected void connected(BaseDownloadTask task, String etag, boolean isContinue, int soFarBytes, int totalBytes) {
|
|
protected void connected(BaseDownloadTask task, String etag, boolean isContinue, int soFarBytes, int totalBytes) {
|
|
|
super.connected(task, etag, isContinue, soFarBytes, totalBytes);
|
|
super.connected(task, etag, isContinue, soFarBytes, totalBytes);
|
|
|
((TaskTag) task.getTag()).updateConnected(etag, task.getFilename());
|
|
((TaskTag) task.getTag()).updateConnected(etag, task.getFilename());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 暂停下载
|
|
|
|
|
+ * 带回数据:soFarBytes
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
protected void paused(BaseDownloadTask task, int soFarBytes, int totalBytes) {
|
|
protected void paused(BaseDownloadTask task, int soFarBytes, int totalBytes) {
|
|
|
super.paused(task, soFarBytes, totalBytes);
|
|
super.paused(task, soFarBytes, totalBytes);
|
|
|
((TaskTag) task.getTag()).updatePaused(task.getSpeed());
|
|
((TaskTag) task.getTag()).updatePaused(task.getSpeed());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 完成整个下载过程
|
|
|
|
|
+ * 带回数据:
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
protected void completed(BaseDownloadTask task) {
|
|
protected void completed(BaseDownloadTask task) {
|
|
|
super.completed(task);
|
|
super.completed(task);
|
|
|
((TaskTag) task.getTag()).updateCompleted(task);
|
|
((TaskTag) task.getTag()).updateCompleted(task);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 在下载队列中(正在等待/正在下载)已经存在相同下载连接与相同存储路径的任务
|
|
|
|
|
+ * 带回数据:
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
protected void warn(BaseDownloadTask task) {
|
|
protected void warn(BaseDownloadTask task) {
|
|
|
super.warn(task);
|
|
super.warn(task);
|
|
|
((TaskTag) task.getTag()).updateWarn();
|
|
((TaskTag) task.getTag()).updateWarn();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 在完成前同步调用该方法,此时已经下载完成
|
|
|
|
|
+ * 带回数据:
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void blockComplete(BaseDownloadTask task) {
|
|
|
|
|
+ super.blockComplete(task);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected boolean isInvalid() {
|
|
|
|
|
+ return super.isInvalid();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 结束了pending,并且开始当前任务的Runnable
|
|
|
|
|
+ * 带回数据:
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void started(BaseDownloadTask task) {
|
|
|
|
|
+ super.started(task);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 重试之前把将要重试是第几次回调回来
|
|
|
|
|
+ * 带回数据:之所以重试遇到Throwable, 将要重试是第几次, soFarBytes
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void retry(BaseDownloadTask task, Throwable ex, int retryingTimes, int soFarBytes) {
|
|
|
|
|
+ super.retry(task, ex, retryingTimes, soFarBytes);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
public static class TaskTag {
|
|
public static class TaskTag {
|
|
|
|
|
|
|
|
|
|
+ private TextView stateTv;
|
|
|
private TextView filenameTv;
|
|
private TextView filenameTv;
|
|
|
private ProgressBar pb;
|
|
private ProgressBar pb;
|
|
|
private TextView detailTv;
|
|
private TextView detailTv;
|
|
@@ -287,13 +366,14 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
private int position;
|
|
private int position;
|
|
|
private WeakReference<DLSingleTestActivity> activityWeakReference;
|
|
private WeakReference<DLSingleTestActivity> activityWeakReference;
|
|
|
|
|
|
|
|
- TaskTag(WeakReference<DLSingleTestActivity> activityWeakReference,TextView filenameTv
|
|
|
|
|
- , ProgressBar pb, TextView detailTv, TextView speedTv, int position) {
|
|
|
|
|
|
|
+ TaskTag(WeakReference<DLSingleTestActivity> activityWeakReference, TextView filenameTv
|
|
|
|
|
+ , ProgressBar pb, TextView detailTv, TextView speedTv,TextView stateTv , int position) {
|
|
|
this.activityWeakReference = activityWeakReference;
|
|
this.activityWeakReference = activityWeakReference;
|
|
|
this.filenameTv = filenameTv;
|
|
this.filenameTv = filenameTv;
|
|
|
this.pb = pb;
|
|
this.pb = pb;
|
|
|
this.detailTv = detailTv;
|
|
this.detailTv = detailTv;
|
|
|
this.speedTv = speedTv;
|
|
this.speedTv = speedTv;
|
|
|
|
|
+ this.stateTv = stateTv;
|
|
|
this.position = position;
|
|
this.position = position;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -302,8 +382,10 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
if (filenameTv != null) {
|
|
if (filenameTv != null) {
|
|
|
filenameTv.setText(task.getFilename());
|
|
filenameTv.setText(task.getFilename());
|
|
|
}
|
|
}
|
|
|
|
|
+ stateTv.setText("下载状态:下载等待中");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ boolean isProgress = true;
|
|
|
@SuppressLint("DefaultLocale")
|
|
@SuppressLint("DefaultLocale")
|
|
|
public void updateProgress(final int sofar, final int total, final int speed) {
|
|
public void updateProgress(final int sofar, final int total, final int speed) {
|
|
|
if (total == -1) {
|
|
if (total == -1) {
|
|
@@ -317,6 +399,10 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
if (detailTv != null) {
|
|
if (detailTv != null) {
|
|
|
detailTv.setText(String.format("sofar: %d total: %d", sofar, total));
|
|
detailTv.setText(String.format("sofar: %d total: %d", sofar, total));
|
|
|
}
|
|
}
|
|
|
|
|
+ if(isProgress){
|
|
|
|
|
+ stateTv.setText("下载状态:下载中");
|
|
|
|
|
+ isProgress = false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("DefaultLocale")
|
|
@SuppressLint("DefaultLocale")
|
|
@@ -325,12 +411,14 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
updateSpeed(speed);
|
|
updateSpeed(speed);
|
|
|
pb.setIndeterminate(false);
|
|
pb.setIndeterminate(false);
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
|
+ stateTv.setText("下载状态:下载错误");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void updateConnected(String etag, String filename) {
|
|
public void updateConnected(String etag, String filename) {
|
|
|
if (filenameTv != null) {
|
|
if (filenameTv != null) {
|
|
|
filenameTv.setText(filename);
|
|
filenameTv.setText(filename);
|
|
|
}
|
|
}
|
|
|
|
|
+ stateTv.setText("下载状态:链接中");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("DefaultLocale")
|
|
@SuppressLint("DefaultLocale")
|
|
@@ -338,6 +426,7 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
toast(String.format("paused %d", position));
|
|
toast(String.format("paused %d", position));
|
|
|
updateSpeed(speed);
|
|
updateSpeed(speed);
|
|
|
pb.setIndeterminate(false);
|
|
pb.setIndeterminate(false);
|
|
|
|
|
+ stateTv.setText("下载状态:暂停");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("DefaultLocale")
|
|
@SuppressLint("DefaultLocale")
|
|
@@ -352,29 +441,30 @@ public class DLSingleTestActivity extends BaseActivity implements View.OnClickLi
|
|
|
pb.setIndeterminate(false);
|
|
pb.setIndeterminate(false);
|
|
|
pb.setMax(task.getSmallFileTotalBytes());
|
|
pb.setMax(task.getSmallFileTotalBytes());
|
|
|
pb.setProgress(task.getSmallFileSoFarBytes());
|
|
pb.setProgress(task.getSmallFileSoFarBytes());
|
|
|
|
|
+ stateTv.setText("下载状态:完成");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("DefaultLocale")
|
|
@SuppressLint("DefaultLocale")
|
|
|
public void updateWarn() {
|
|
public void updateWarn() {
|
|
|
toast(String.format("warn %d", position));
|
|
toast(String.format("warn %d", position));
|
|
|
pb.setIndeterminate(false);
|
|
pb.setIndeterminate(false);
|
|
|
|
|
+ stateTv.setText("下载状态:完成");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("DefaultLocale")
|
|
@SuppressLint("DefaultLocale")
|
|
|
private void updateSpeed(int speed) {
|
|
private void updateSpeed(int speed) {
|
|
|
- if(speedTv!=null){
|
|
|
|
|
- speedTv.setText(String.format("%dKB/s", speed));
|
|
|
|
|
|
|
+ if (speedTv != null) {
|
|
|
|
|
+ speedTv.setText(String.format("下载速度"+"%dKB/s", speed));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void toast(final String msg) {
|
|
private void toast(final String msg) {
|
|
|
if (this.activityWeakReference != null && this.activityWeakReference.get() != null) {
|
|
if (this.activityWeakReference != null && this.activityWeakReference.get() != null) {
|
|
|
- ToastUtil.showToast(activityWeakReference.get(),msg);
|
|
|
|
|
|
|
+ ToastUtil.showToast(activityWeakReference.get(), msg);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|