本文整理汇总了Java中com.lzy.okgo.OkGo.REFRESH_TIME属性的典型用法代码示例。如果您正苦于以下问题:Java OkGo.REFRESH_TIME属性的具体用法?Java OkGo.REFRESH_TIME怎么用?Java OkGo.REFRESH_TIME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.lzy.okgo.OkGo
的用法示例。
在下文中一共展示了OkGo.REFRESH_TIME属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeProgress
public static Progress changeProgress(final Progress progress, long writeSize, long totalSize, final Action action) {
progress.totalSize = totalSize;
progress.currentSize += writeSize;
progress.tempSize += writeSize;
long currentTime = SystemClock.elapsedRealtime();
boolean isNotify = (currentTime - progress.lastRefreshTime) >= OkGo.REFRESH_TIME;
if (isNotify || progress.currentSize == totalSize) {
long diffTime = currentTime - progress.lastRefreshTime;
if (diffTime == 0) diffTime = 1;
progress.fraction = progress.currentSize * 1.0f / totalSize;
progress.speed = progress.bufferSpeed(progress.tempSize * 1000 / diffTime);
progress.lastRefreshTime = currentTime;
progress.tempSize = 0;
if (action != null) {
action.call(progress);
}
}
return progress;
}
示例2: write
@Override
public void write(Buffer source, long byteCount) throws IOException {
super.write(source, byteCount);
if (contentLength <= 0) contentLength = contentLength(); //获得contentLength的值,后续不再调用
bytesWritten += byteCount;
long curTime = System.currentTimeMillis();
//每100毫秒刷新一次数据
if (curTime - lastRefreshUiTime >= OkGo.REFRESH_TIME || bytesWritten == contentLength) {
//计算下载速度
long diffTime = (curTime - lastRefreshUiTime) / 1000;
if (diffTime == 0) diffTime += 1;
long diffBytes = bytesWritten - lastWriteBytes;
long networkSpeed = diffBytes / diffTime;
if (listener != null) listener.onRequestProgress(bytesWritten, contentLength, networkSpeed);
lastRefreshUiTime = System.currentTimeMillis();
lastWriteBytes = bytesWritten;
}
}