当前位置: 首页>>代码示例>>Java>>正文


Java AsyncRun类代码示例

本文整理汇总了Java中com.qiniu.android.utils.AsyncRun的典型用法代码示例。如果您正苦于以下问题:Java AsyncRun类的具体用法?Java AsyncRun怎么用?Java AsyncRun使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AsyncRun类属于com.qiniu.android.utils包,在下文中一共展示了AsyncRun类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import com.qiniu.android.utils.AsyncRun; //导入依赖的package包/类
public void write(Buffer source, long byteCount) throws IOException {
    if (CountingRequestBody.this.cancellationHandler == null && CountingRequestBody.this
            .progress == null) {
        super.write(source, byteCount);
    } else if (CountingRequestBody.this.cancellationHandler == null ||
            !CountingRequestBody.this.cancellationHandler.isCancelled()) {
        super.write(source, byteCount);
        this.bytesWritten = (int) (((long) this.bytesWritten) + byteCount);
        if (CountingRequestBody.this.progress != null) {
            AsyncRun.run(new Runnable() {
                public void run() {
                    try {
                        CountingRequestBody.this.progress.onProgress(CountingSink.this
                                .bytesWritten, (int) CountingRequestBody.this
                                .contentLength());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    } else {
        throw new CancellationException();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:26,代码来源:CountingRequestBody.java

示例2: updateStatus

import com.qiniu.android.utils.AsyncRun; //导入依赖的package包/类
private void updateStatus(final double percentage) {
    long now = System.currentTimeMillis();
    long deltaTime = now - uploadLastTimePoint;
    long currentOffset = (long) (percentage * uploadFileLength);
    long deltaSize = currentOffset - uploadLastOffset;
    if (deltaTime <= 100) {
        return;
    }

    final String speed = Tools.formatSpeed(deltaSize, deltaTime);
    // update
    uploadLastTimePoint = now;
    uploadLastOffset = currentOffset;

    AsyncRun.runInMain(new Runnable() {
        @Override
        public void run() {
            int progress = (int) (percentage * 100);
            uploadProgressBar.setProgress(progress);
            uploadPercentageTextView.setText(progress + " %");
            uploadSpeedTextView.setText(speed);
        }
    });
}
 
开发者ID:qiniudemo,项目名称:qiniu-lab-android,代码行数:25,代码来源:SimpleUploadUseSaveKeyActivity.java

示例3: onRet

import com.qiniu.android.utils.AsyncRun; //导入依赖的package包/类
private void onRet(Response response, String ip, long duration, CompletionHandler complete) {
    int code = response.code();
    String reqId = response.header("X-Reqid");
    reqId = reqId == null ? null : reqId.trim();
    byte[] body = null;
    String error = null;
    try {
        body = response.body().bytes();
    } catch (IOException e) {
        error = e.getMessage();
    }
    JSONObject json = null;
    if (!ctype(response).equals("application/json") || body == null) {
        String str = new String(body);
    } else {
        try {
            json = buildJsonResp(body);
            if (response.code() != 200) {
                error = json.optString("error", new String(body, Constants.UTF_8));
            }
        } catch (Exception e2) {
            if (response.code() < 300) {
                error = e2.getMessage();
            }
        }
    }
    URL u = response.request().url();
    final ResponseInfo info = new ResponseInfo(code, reqId, response.header("X-Log"), via
            (response), u.getHost(), u.getPath(), ip, u.getPort(), (double) duration, 0, error);
    final CompletionHandler completionHandler = complete;
    final JSONObject jSONObject = json;
    AsyncRun.run(new Runnable() {
        public void run() {
            completionHandler.complete(info, jSONObject);
        }
    });
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:38,代码来源:Client.java

示例4: writeLog

import com.qiniu.android.utils.AsyncRun; //导入依赖的package包/类
private void writeLog(final String msg) {
    AsyncRun.runInMain(new Runnable() {
        @Override
        public void run() {
            uploadLogTextView.append(msg);
            uploadLogTextView.append("\r\n");
        }
    });
}
 
开发者ID:qiniudemo,项目名称:qiniu-lab-android,代码行数:10,代码来源:SimpleUploadUseSaveKeyActivity.java

示例5: writeLog

import com.qiniu.android.utils.AsyncRun; //导入依赖的package包/类
private void writeLog(final String msg) {
    AsyncRun.runInMain(new Runnable() {
        @Override
        public void run() {
            uploadLogTextView.append(msg);
            uploadLogTextView.append("\r\n");
        }
    });

}
 
开发者ID:qiniudemo,项目名称:qiniu-lab-android,代码行数:11,代码来源:SimpleUploadWithKeyActivity.java

示例6: writeLog

import com.qiniu.android.utils.AsyncRun; //导入依赖的package包/类
private void writeLog(final String msg) {

        AsyncRun.runInMain(new Runnable() {
            @Override
            public void run() {
                uploadLogTextView.append(msg);
                uploadLogTextView.append("\r\n");
            }
        });

    }
 
开发者ID:qiniudemo,项目名称:qiniu-lab-android,代码行数:12,代码来源:SimpleUploadUseFsizeLimitActivity.java

示例7: uploadFile

import com.qiniu.android.utils.AsyncRun; //导入依赖的package包/类
public void uploadFile(View view) {
    if (this.uploadFilePath == null) {
        return;
    }
    new Thread(new Runnable() {
        @Override
        public void run() {
            final OkHttpClient httpClient = new OkHttpClient();
            Request req = new Request.Builder().url(QiniuLabConfig.makeUrl(
                    QiniuLabConfig.REMOTE_SERVICE_SERVER,
                    QiniuLabConfig.QUICK_START_VIDEO_DEMO_PATH)).method("GET", null).build();
            Response resp = null;
            try {
                resp = httpClient.newCall(req).execute();
                JSONObject jsonObject = new JSONObject(resp.body().string());
                String uploadToken = jsonObject.getString("uptoken");
                String domain = jsonObject.getString("domain");

                upload(uploadToken, domain);
            } catch (Exception e) {
                AsyncRun.runInMain(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(
                                context,
                                context.getString(R.string.qiniu_get_upload_token_failed),
                                Toast.LENGTH_LONG).show();
                    }
                });
            } finally {
                if (resp != null) {
                    resp.body().close();

                }
            }
        }
    }).start();
}
 
开发者ID:qiniudemo,项目名称:qiniu-lab-android,代码行数:39,代码来源:CaptureVideoActivity.java

示例8: uploadFile

import com.qiniu.android.utils.AsyncRun; //导入依赖的package包/类
public void uploadFile(View view) {
    if (this.uploadFilePath == null) {
        return;
    }
    new Thread(new Runnable() {
        @Override
        public void run() {
            final OkHttpClient httpClient = new OkHttpClient();
            Request req = new Request.Builder().url(QiniuLabConfig.makeUrl(
                    QiniuLabConfig.REMOTE_SERVICE_SERVER,
                    QiniuLabConfig.QUICK_START_IMAGE_DEMO_PATH)).method("GET", null).build();
            Response resp = null;
            try {
                resp = httpClient.newCall(req).execute();
                JSONObject jsonObject = new JSONObject(resp.body().string());
                String uploadToken = jsonObject.getString("uptoken");
                String domain = jsonObject.getString("domain");

                upload(uploadToken, domain);
            } catch (Exception e) {
                AsyncRun.runInMain(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(
                                context,
                                context.getString(R.string.qiniu_get_upload_token_failed),
                                Toast.LENGTH_LONG).show();
                    }
                });

            } finally {
                if (resp != null) {
                    resp.body().close();
                }
            }

        }
    }).start();
}
 
开发者ID:qiniudemo,项目名称:qiniu-lab-android,代码行数:40,代码来源:CaptureImageActivity.java

示例9: uploadFile

import com.qiniu.android.utils.AsyncRun; //导入依赖的package包/类
public void uploadFile(View view) {
    if (this.uploadFilePath == null) {
        return;
    }
    new Thread(new Runnable() {
        @Override
        public void run() {
            final OkHttpClient httpClient = new OkHttpClient();
            Request req = new Request.Builder().url(QiniuLabConfig.makeUrl(
                    QiniuLabConfig.REMOTE_SERVICE_SERVER,
                    QiniuLabConfig.QUICK_START_IMAGE_DEMO_PATH)).method("GET", null).build();
            Response resp = null;
            try {
                resp = httpClient.newCall(req).execute();
                JSONObject jsonObject = new JSONObject(resp.body().string());
                String uploadToken = jsonObject.getString("uptoken");
                String domain = jsonObject.getString("domain");

                upload(uploadToken, domain);
            } catch (Exception e) {
                AsyncRun.runInMain(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(
                                context,
                                context.getString(R.string.qiniu_get_upload_token_failed),
                                Toast.LENGTH_LONG).show();
                    }
                });
                Log.e(QiniuLabConfig.LOG_TAG, e.getMessage());
            } finally {
                if (resp != null) {
                    resp.body().close();
                }
            }
        }
    }).start();
}
 
开发者ID:qiniudemo,项目名称:qiniu-lab-android,代码行数:39,代码来源:QuickStartImageExampleActivity.java

示例10: uploadFile

import com.qiniu.android.utils.AsyncRun; //导入依赖的package包/类
public void uploadFile(View view) {
    if (this.uploadFilePath == null) {
        return;
    }
    new Thread(new Runnable() {
        @Override
        public void run() {
            final OkHttpClient httpClient = new OkHttpClient();
            Request req = new Request.Builder().url(QiniuLabConfig.makeUrl(
                    QiniuLabConfig.REMOTE_SERVICE_SERVER,
                    QiniuLabConfig.QUICK_START_VIDEO_DEMO_PATH)).method("GET", null).build();

            Response resp = null;
            try {
                resp = httpClient.newCall(req).execute();
                JSONObject jsonObject = new JSONObject(resp.body().string());
                String uploadToken = jsonObject.getString("uptoken");
                String domain = jsonObject.getString("domain");

                upload(uploadToken, domain);
            } catch (Exception e) {
                AsyncRun.runInMain(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(
                                context,
                                context.getString(R.string.qiniu_get_upload_token_failed),
                                Toast.LENGTH_LONG).show();
                    }
                });
            } finally {
                if (resp != null) {
                    resp.body().close();
                }
            }
        }
    }).start();
}
 
开发者ID:qiniudemo,项目名称:qiniu-lab-android,代码行数:39,代码来源:QuickStartVideoExampleActivity.java


注:本文中的com.qiniu.android.utils.AsyncRun类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。