本文整理汇总了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();
}
}
示例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);
}
});
}
示例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);
}
});
}
示例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");
}
});
}
示例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");
}
});
}
示例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");
}
});
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}