com.lzy.okgo.model.Progress Java Examples
The following examples show how to use
com.lzy.okgo.model.Progress.
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: DownloadListActivity.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_download_list); initToolBar(toolbar, true, "开始下载"); initData(); OkDownload.getInstance().setFolder(Environment.getExternalStorageDirectory().getAbsolutePath() + "/aaa/"); OkDownload.getInstance().getThreadPool().setCorePoolSize(3); folder.setText(String.format("下载路径: %s", OkDownload.getInstance().getFolder())); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL)); //从数据库中恢复数据 List<Progress> progressList = DownloadManager.getInstance().getAll(); OkDownload.restore(progressList); adapter = new DownloadListAdapter(this); recyclerView.setAdapter(adapter); checkSDCardPermission(); }
Example #2
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 #3
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 #4
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 #5
Source File: FileConvert.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void onProgress(final Progress progress) { HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { callback.downloadProgress(progress); //进度回调的方法 } }); }
Example #6
Source File: UploadAdapter.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
public void bind() { Progress progress = task.progress; ImageItem item = (ImageItem) progress.extra1; Glide.with(context).load(item.path).error(R.mipmap.ic_launcher).into(icon); name.setText(item.name); priority.setText(String.format("优先级:%s", progress.priority)); }
Example #7
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 #8
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 #9
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 #10
Source File: OkGoCallback.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 上传过程中的进度回调, get请求不回调, UI 线程 */ @Override public void uploadProgress(Progress progress) { super.uploadProgress(progress); DevLogger.dTag(TAG, "上传过程中的进度回调: " + url + ", progress: " + progress); }
Example #11
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 #12
Source File: UploadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void postWaiting(final Progress progress) { progress.speed = 0; progress.status = Progress.WAITING; updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (UploadListener<T> listener : listeners.values()) { listener.onProgress(progress); } } }); }
Example #13
Source File: UploadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void postPause(final Progress progress) { progress.speed = 0; progress.status = Progress.PAUSE; updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (UploadListener<T> listener : listeners.values()) { listener.onProgress(progress); } } }); }
Example #14
Source File: UploadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void postOnError(final Progress progress, final Throwable throwable) { progress.speed = 0; progress.status = Progress.ERROR; progress.exception = throwable; updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (UploadListener<T> listener : listeners.values()) { listener.onProgress(progress); listener.onError(progress); } } }); }
Example #15
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 #16
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 #17
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 #18
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 #19
Source File: DownloadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void postWaiting(final Progress progress) { progress.speed = 0; progress.status = Progress.WAITING; updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (DownloadListener listener : listeners.values()) { listener.onProgress(progress); } } }); }
Example #20
Source File: DownloadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void postPause(final Progress progress) { progress.speed = 0; progress.status = Progress.PAUSE; updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (DownloadListener listener : listeners.values()) { listener.onProgress(progress); } } }); }
Example #21
Source File: DownloadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void postLoading(final Progress progress) { updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (DownloadListener listener : listeners.values()) { listener.onProgress(progress); } } }); }
Example #22
Source File: DownloadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void postOnError(final Progress progress, final Throwable throwable) { progress.speed = 0; progress.status = Progress.ERROR; progress.exception = throwable; updateDatabase(progress); HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { for (DownloadListener listener : listeners.values()) { listener.onProgress(progress); listener.onError(progress); } } }); }
Example #23
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); } } }); }
Example #24
Source File: OkDownload.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
/** 从数据库中恢复任务 */ public static DownloadTask restore(Progress progress) { Map<String, DownloadTask> taskMap = OkDownload.getInstance().getTaskMap(); DownloadTask task = taskMap.get(progress.tag); if (task == null) { task = new DownloadTask(progress); taskMap.put(progress.tag, task); } return task; }
Example #25
Source File: OkDownload.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
/** 从数据库中恢复任务 */ public static List<DownloadTask> restore(List<Progress> progressList) { Map<String, DownloadTask> taskMap = OkDownload.getInstance().getTaskMap(); List<DownloadTask> tasks = new ArrayList<>(); for (Progress progress : progressList) { DownloadTask task = taskMap.get(progress.tag); if (task == null) { task = new DownloadTask(progress); taskMap.put(progress.tag, task); } tasks.add(task); } return tasks; }
Example #26
Source File: OkUpload.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
/** 从数据库中恢复任务 */ public static <T> UploadTask<T> restore(Progress progress) { Map<String, UploadTask<?>> taskMap = OkUpload.getInstance().getTaskMap(); //noinspection unchecked UploadTask<T> task = (UploadTask<T>) taskMap.get(progress.tag); if (task == null) { task = new UploadTask<>(progress); taskMap.put(progress.tag, task); } return task; }
Example #27
Source File: OkUpload.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
/** 从数据库中恢复任务 */ public static List<UploadTask<?>> restore(List<Progress> progressList) { Map<String, UploadTask<?>> taskMap = OkUpload.getInstance().getTaskMap(); List<UploadTask<?>> tasks = new ArrayList<>(); for (Progress progress : progressList) { UploadTask<?> task = taskMap.get(progress.tag); if (task == null) { task = new UploadTask<>(progress); taskMap.put(progress.tag, task); } tasks.add(task); } return tasks; }
Example #28
Source File: ProgressRequestBody.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
private void onProgress(final Progress progress) { HttpUtils.runOnUiThread(new Runnable() { @Override public void run() { if (callback != null) { callback.uploadProgress(progress); } } }); }
Example #29
Source File: UploadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
public UploadTask<T> start() { if (OkUpload.getInstance().getTask(progress.tag) == null || UploadManager.getInstance().get(progress.tag) == null) { throw new IllegalStateException("you must call UploadTask#save() before UploadTask#start()!"); } if (progress.status != Progress.WAITING && progress.status != Progress.LOADING) { postOnStart(progress); postWaiting(progress); priorityRunnable = new PriorityRunnable(progress.priority, this); executor.execute(priorityRunnable); } else { OkLogger.w("the task with tag " + progress.tag + " is already in the upload queue, current task status is " + progress.status); } return this; }
Example #30
Source File: DBHelper.java From BaseProject with Apache License 2.0 | 4 votes |
DBHelper(Context context) { super(context, DB_CACHE_NAME, null, DB_CACHE_VERSION); cacheTableEntity.addColumn(new ColumnEntity(CacheEntity.KEY, "VARCHAR", true, true))// .addColumn(new ColumnEntity(CacheEntity.LOCAL_EXPIRE, "INTEGER"))// .addColumn(new ColumnEntity(CacheEntity.HEAD, "BLOB"))// .addColumn(new ColumnEntity(CacheEntity.DATA, "BLOB")); cookieTableEntity.addColumn(new ColumnEntity(SerializableCookie.HOST, "VARCHAR"))// .addColumn(new ColumnEntity(SerializableCookie.NAME, "VARCHAR"))// .addColumn(new ColumnEntity(SerializableCookie.DOMAIN, "VARCHAR"))// .addColumn(new ColumnEntity(SerializableCookie.COOKIE, "BLOB"))// .addColumn(new ColumnEntity(SerializableCookie.HOST, SerializableCookie.NAME, SerializableCookie.DOMAIN)); downloadTableEntity.addColumn(new ColumnEntity(Progress.TAG, "VARCHAR", true, true))// .addColumn(new ColumnEntity(Progress.URL, "VARCHAR"))// .addColumn(new ColumnEntity(Progress.FOLDER, "VARCHAR"))// .addColumn(new ColumnEntity(Progress.FILE_PATH, "VARCHAR"))// .addColumn(new ColumnEntity(Progress.FILE_NAME, "VARCHAR"))// .addColumn(new ColumnEntity(Progress.FRACTION, "VARCHAR"))// .addColumn(new ColumnEntity(Progress.TOTAL_SIZE, "INTEGER"))// .addColumn(new ColumnEntity(Progress.CURRENT_SIZE, "INTEGER"))// .addColumn(new ColumnEntity(Progress.STATUS, "INTEGER"))// .addColumn(new ColumnEntity(Progress.PRIORITY, "INTEGER"))// .addColumn(new ColumnEntity(Progress.DATE, "INTEGER"))// .addColumn(new ColumnEntity(Progress.REQUEST, "BLOB"))// .addColumn(new ColumnEntity(Progress.EXTRA1, "BLOB"))// .addColumn(new ColumnEntity(Progress.EXTRA2, "BLOB"))// .addColumn(new ColumnEntity(Progress.EXTRA3, "BLOB")); uploadTableEntity.addColumn(new ColumnEntity(Progress.TAG, "VARCHAR", true, true))// .addColumn(new ColumnEntity(Progress.URL, "VARCHAR"))// .addColumn(new ColumnEntity(Progress.FOLDER, "VARCHAR"))// .addColumn(new ColumnEntity(Progress.FILE_PATH, "VARCHAR"))// .addColumn(new ColumnEntity(Progress.FILE_NAME, "VARCHAR"))// .addColumn(new ColumnEntity(Progress.FRACTION, "VARCHAR"))// .addColumn(new ColumnEntity(Progress.TOTAL_SIZE, "INTEGER"))// .addColumn(new ColumnEntity(Progress.CURRENT_SIZE, "INTEGER"))// .addColumn(new ColumnEntity(Progress.STATUS, "INTEGER"))// .addColumn(new ColumnEntity(Progress.PRIORITY, "INTEGER"))// .addColumn(new ColumnEntity(Progress.DATE, "INTEGER"))// .addColumn(new ColumnEntity(Progress.REQUEST, "BLOB"))// .addColumn(new ColumnEntity(Progress.EXTRA1, "BLOB"))// .addColumn(new ColumnEntity(Progress.EXTRA2, "BLOB"))// .addColumn(new ColumnEntity(Progress.EXTRA3, "BLOB")); }