Java Code Examples for com.lzy.okgo.model.Progress#LOADING

The following examples show how to use com.lzy.okgo.model.Progress#LOADING . 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 vote down vote up
@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 vote down vote up
@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: UploadAdapter.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
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 4
Source File: DownloadAdapter.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
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 5
Source File: DesActivity.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
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 6
Source File: DesActivity.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: UploadTask.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
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 8
Source File: UploadTask.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
/** 暂停的方法 */
public void pause() {
    executor.remove(priorityRunnable);
    if (progress.status == Progress.WAITING) {
        postPause(progress);
    } else if (progress.status == Progress.LOADING) {
        progress.speed = 0;
        progress.status = Progress.PAUSE;
    } else {
        OkLogger.w("only the task with status WAITING(1) or LOADING(2) can pause, current status is " + progress.status);
    }
}
 
Example 9
Source File: UploadTask.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    progress.status = Progress.LOADING;
    postLoading(progress);
    final Response<T> response;
    try {
        //noinspection unchecked
        Request<T, ? extends Request> request = (Request<T, ? extends Request>) progress.request;
        final Call rawCall = request.getRawCall();
        request.uploadInterceptor(new ProgressRequestBody.UploadInterceptor() {
            @Override
            public void uploadProgress(Progress innerProgress) {
                if (rawCall.isCanceled()) return;
                if (progress.status != Progress.LOADING) {
                    rawCall.cancel();
                    return;
                }
                progress.from(innerProgress);
                postLoading(progress);
            }
        });
        response = request.adapt().execute();
    } catch (Exception e) {
        postOnError(progress, e);
        return;
    }

    if (response.isSuccessful()) {
        postOnFinish(progress, response.body());
    } else {
        postOnError(progress, response.getException());
    }
}
 
Example 10
Source File: DownloadTask.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
/** 暂停的方法 */
public void pause() {
    executor.remove(priorityRunnable);
    if (progress.status == Progress.WAITING) {
        postPause(progress);
    } else if (progress.status == Progress.LOADING) {
        progress.speed = 0;
        progress.status = Progress.PAUSE;
    } else {
        OkLogger.w("only the task with status WAITING(1) or LOADING(2) can pause, current status is " + progress.status);
    }
}
 
Example 11
Source File: OkDownload.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
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 12
Source File: OkUpload.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
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);
}