80,351
社区成员
发帖
与我相关
我的任务
分享
RequestParams params = new RequestParams(downloadurl);
params.setAutoRename(true);//断点下载
params.setSaveFilePath(path+ filename);//
params.setExecutor(new PriorityExecutor(2));//自定义线程池,有效的值范围[1, 3], 设置为3时, 可能阻塞图片加载.
params.setCancelFast(true);//是否可以被立即停止.
cancelable = x.http().post(params, new Callback.ProgressCallback<File>() {
@Override
public void onSuccess(File file) {
isDownLoad = false;
db.updateDownLoadMessageType(spDto,DownLoadDbCst.DOWNLOADFINISH,"100");//下载完成
}
@Override
public void onError(Throwable throwable, boolean b) {
Toast.makeText(context,"下载失败"+throwable.getMessage(),Toast.LENGTH_SHORT).show();
isDownLoad = false;
}
@Override
public void onCancelled(CancelledException e) {
isDownLoad = false;
db.updateDownLoadMessageType(spDto, DownLoadDbCst.DOWNLOADDING,seekBarPercent+"");
}
@Override
public void onFinished() {
}
@Override
public void onWaiting() {
}
@Override
public void onStarted() {
}
@Override
public void onLoading(long l, long l1, boolean b) {
if (l1<l){
// dialog.setProgressWheel((float)l1/l);
// seekBar = l1/l;
System.out.println("xxxxxxxxx==="+ll+"~~~~"+l+"~~~~~~~"+(float)l1/l);
progressBar.setMax((int)ll);
progressBar.setProgress((int)(ll*((float)l1/l)));
}
}
});
public interface Callback {
public static class CancelledException extends RuntimeException {
public CancelledException(String detailMessage) {
super(detailMessage);
}
}
public interface Cancelable {
void cancel();
boolean isCancelled();
}
看了下源码 里面实现的cancel也是用Cancelable接口里的 跟我那个问题中的就是一样了