Java Code Examples for com.lzy.okgo.model.Progress#FINISH
The following examples show how to use
com.lzy.okgo.model.Progress#FINISH .
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 |
private void postOnFinish(final Progress progress, final T t) { progress.speed = 0; progress.fraction = 1.0f; progress.status = Progress.FINISH; updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (UploadListener<T> listener : listeners.values()) { listener.onProgress(progress); listener.onFinish(t, progress); } } }); }
Example 9
Source File: DownloadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void postOnFinish(final Progress progress, final File file) { progress.speed = 0; progress.fraction = 1.0f; progress.status = Progress.FINISH; updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (DownloadListener listener : listeners.values()) { listener.onProgress(progress); listener.onFinish(file, progress); } } }); }