Java Code Examples for com.lzy.okgo.model.Progress#NONE
The following examples show how to use
com.lzy.okgo.model.Progress#NONE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UploadAdapter.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
@OnClick(R.id.upload) public void upload() { Progress progress = task.progress; switch (progress.status) { case Progress.PAUSE: case Progress.NONE: case Progress.ERROR: task.start(); break; case Progress.LOADING: task.pause(); break; case Progress.FINISH: break; } refresh(progress); }
Example 2
Source File: DownloadAdapter.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
@OnClick(R.id.start) public void start() { Progress progress = task.progress; switch (progress.status) { case Progress.PAUSE: case Progress.NONE: case Progress.ERROR: task.start(); break; case Progress.LOADING: task.pause(); break; case Progress.FINISH: if (ApkUtils.isAvailable(context, new File(progress.filePath))) { ApkUtils.uninstall(context, ApkUtils.getPackageName(context, progress.filePath)); } else { ApkUtils.install(context, new File(progress.filePath)); } break; } refresh(progress); }
Example 3
Source File: DownloadTask.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
public void start() { if (OkDownload.getInstance().getTask(progress.tag) == null || DownloadManager.getInstance().get(progress.tag) == null) { throw new IllegalStateException("you must call DownloadTask#save() before DownloadTask#start()!"); } if (progress.status == Progress.NONE || progress.status == Progress.PAUSE || progress.status == Progress.ERROR) { postOnStart(progress); postWaiting(progress); priorityRunnable = new PriorityRunnable(progress.priority, this); executor.execute(priorityRunnable); } else if (progress.status == Progress.FINISH) { if (progress.filePath == null) { postOnError(progress, new StorageException("the file of the task with tag:" + progress.tag + " may be invalid or damaged, please call the method restart() to download again!")); } else { File file = new File(progress.filePath); if (file.exists() && file.length() == progress.totalSize) { postOnFinish(progress, new File(progress.filePath)); } else { postOnError(progress, new StorageException("the file " + progress.filePath + " may be invalid or damaged, please call the method restart() to download again!")); } } } else { OkLogger.w("the task with tag " + progress.tag + " is already in the download queue, current task status is " + progress.status); } }
Example 4
Source File: UploadAdapter.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
public void refresh(Progress progress) { String currentSize = Formatter.formatFileSize(context, progress.currentSize); String totalSize = Formatter.formatFileSize(context, progress.totalSize); downloadSize.setText(currentSize + "/" + totalSize); priority.setText(String.format("优先级:%s", progress.priority)); switch (progress.status) { case Progress.NONE: netSpeed.setText("停止"); upload.setText("上传"); break; case Progress.PAUSE: netSpeed.setText("暂停中"); upload.setText("继续"); break; case Progress.ERROR: netSpeed.setText("上传出错"); upload.setText("出错"); break; case Progress.WAITING: netSpeed.setText("等待中"); upload.setText("等待"); break; case Progress.FINISH: upload.setText("完成"); netSpeed.setText("上传成功"); break; case Progress.LOADING: String speed = Formatter.formatFileSize(context, progress.speed); netSpeed.setText(String.format("%s/s", speed)); upload.setText("停止"); break; } tvProgress.setText(numberFormat.format(progress.fraction)); pbProgress.setMax(10000); pbProgress.setProgress((int) (progress.fraction * 10000)); }
Example 5
Source File: DownloadAdapter.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
public void refresh(Progress progress) { String currentSize = Formatter.formatFileSize(context, progress.currentSize); String totalSize = Formatter.formatFileSize(context, progress.totalSize); downloadSize.setText(currentSize + "/" + totalSize); priority.setText(String.format("优先级:%s", progress.priority)); switch (progress.status) { case Progress.NONE: netSpeed.setText("停止"); download.setText("下载"); break; case Progress.PAUSE: netSpeed.setText("暂停中"); download.setText("继续"); break; case Progress.ERROR: netSpeed.setText("下载出错"); download.setText("出错"); break; case Progress.WAITING: netSpeed.setText("等待中"); download.setText("等待"); break; case Progress.FINISH: netSpeed.setText("下载完成"); download.setText("完成"); break; case Progress.LOADING: String speed = Formatter.formatFileSize(context, progress.speed); netSpeed.setText(String.format("%s/s", speed)); download.setText("暂停"); break; } tvProgress.setText(numberFormat.format(progress.fraction)); pbProgress.setMax(10000); pbProgress.setProgress((int) (progress.fraction * 10000)); }
Example 6
Source File: DesActivity.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void refreshUi(Progress progress) { String currentSize = Formatter.formatFileSize(this, progress.currentSize); String totalSize = Formatter.formatFileSize(this, progress.totalSize); downloadSize.setText(currentSize + "/" + totalSize); String speed = Formatter.formatFileSize(this, progress.speed); netSpeed.setText(String.format("%s/s", speed)); tvProgress.setText(numberFormat.format(progress.fraction)); pbProgress.setMax(10000); pbProgress.setProgress((int) (progress.fraction * 10000)); switch (progress.status) { case Progress.NONE: download.setText("下载"); break; case Progress.LOADING: download.setText("暂停"); break; case Progress.PAUSE: download.setText("继续"); break; case Progress.WAITING: download.setText("等待"); break; case Progress.ERROR: download.setText("出错"); break; case Progress.FINISH: if (ApkUtils.isAvailable(this, new File(progress.filePath))) { download.setText("卸载"); } else { download.setText("安装"); } break; } }
Example 7
Source File: DesActivity.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
@OnClick(R.id.start) public void start() { if (task == null) { //这里只是演示,表示请求可以传参,怎么传都行,和okgo使用方法一样 GetRequest<File> request = OkGo.<File>get(apk.url)// .headers("aaa", "111")// .params("bbb", "222"); task = OkDownload.request(apk.url, request)// .priority(apk.priority)// .extra1(apk)// .save()// .register(new DesListener("DesListener"))// .register(new LogDownloadListener()); } switch (task.progress.status) { case Progress.PAUSE: case Progress.NONE: case Progress.ERROR: task.start(); break; case Progress.LOADING: task.pause(); break; case Progress.FINISH: File file = new File(task.progress.filePath); if (ApkUtils.isAvailable(this, file)) { ApkUtils.uninstall(this, ApkUtils.getPackageName(this, file.getAbsolutePath())); } else { ApkUtils.install(this, file); } break; } }
Example 8
Source File: UploadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
public UploadTask(String tag, Request<T, ? extends Request> request) { HttpUtils.checkNotNull(tag, "tag == null"); progress = new Progress(); progress.tag = tag; progress.url = request.getBaseUrl(); progress.status = Progress.NONE; progress.totalSize = -1; progress.request = request; executor = OkUpload.getInstance().getThreadPool().getExecutor(); listeners = new HashMap<>(); }
Example 9
Source File: UploadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
public void restart() { pause(); progress.status = Progress.NONE; progress.currentSize = 0; progress.fraction = 0; progress.speed = 0; UploadManager.getInstance().replace(progress); start(); }
Example 10
Source File: UploadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void postOnStart(final Progress progress) { progress.speed = 0; progress.status = Progress.NONE; updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (UploadListener<T> listener : listeners.values()) { listener.onStart(progress); } } }); }
Example 11
Source File: DownloadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
public DownloadTask(String tag, Request<File, ? extends Request> request) { HttpUtils.checkNotNull(tag, "tag == null"); progress = new Progress(); progress.tag = tag; progress.folder = OkDownload.getInstance().getFolder(); progress.url = request.getBaseUrl(); progress.status = Progress.NONE; progress.totalSize = -1; progress.request = request; executor = OkDownload.getInstance().getThreadPool().getExecutor(); listeners = new HashMap<>(); }
Example 12
Source File: DownloadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
public void restart() { pause(); IOUtils.delFileOrFolder(progress.filePath); progress.status = Progress.NONE; progress.currentSize = 0; progress.fraction = 0; progress.speed = 0; DownloadManager.getInstance().replace(progress); start(); }
Example 13
Source File: DownloadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void postOnStart(final Progress progress) { progress.speed = 0; progress.status = Progress.NONE; updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (DownloadListener listener : listeners.values()) { listener.onStart(progress); } } }); }
Example 14
Source File: OkDownload.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private OkDownload() { folder = Environment.getExternalStorageDirectory() + File.separator + "download" + File.separator; IOUtils.createFolder(folder); threadPool = new DownloadThreadPool(); taskMap = new ConcurrentHashMap<>(); //校验数据的有效性,防止下载过程中退出,第二次进入的时候,由于状态没有更新导致的状态错误 List<Progress> taskList = DownloadManager.getInstance().getDownloading(); for (Progress info : taskList) { if (info.status == Progress.WAITING || info.status == Progress.LOADING || info.status == Progress.PAUSE) { info.status = Progress.NONE; } } DownloadManager.getInstance().replace(taskList); }
Example 15
Source File: OkUpload.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private OkUpload() { threadPool = new UploadThreadPool(); taskMap = new LinkedHashMap<>(); //校验数据的有效性,防止下载过程中退出,第二次进入的时候,由于状态没有更新导致的状态错误 List<Progress> taskList = UploadManager.getInstance().getUploading(); for (Progress info : taskList) { if (info.status == Progress.WAITING || info.status == Progress.LOADING || info.status == Progress.PAUSE) { info.status = Progress.NONE; } } UploadManager.getInstance().replace(taskList); }