提交项目
This commit is contained in:
38
app/src/main/java/com/gh/common/util/SpeedUtils.java
Normal file
38
app/src/main/java/com/gh/common/util/SpeedUtils.java
Normal file
@ -0,0 +1,38 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
public class SpeedUtils {
|
||||
|
||||
public static String getSpeed(long kSpeed) {
|
||||
if (kSpeed >= 1000) {
|
||||
float mSpeed = kSpeed / 1024f;
|
||||
String str = mSpeed + "";
|
||||
if (str.length() > 4) {
|
||||
str = str.substring(0, 4);
|
||||
}
|
||||
return str + "MB/s";
|
||||
}
|
||||
return kSpeed + "K/s";
|
||||
}
|
||||
|
||||
public static String getRemainTime(long totalSize, long currentSize,
|
||||
long speed) {
|
||||
long remainSize = totalSize - currentSize;
|
||||
long remainTime = 0;
|
||||
if (speed != 0) {
|
||||
remainTime = remainSize / speed;
|
||||
} else {
|
||||
return "0分0秒";
|
||||
}
|
||||
int hour = (int) (remainTime / 3600);
|
||||
remainTime = (remainTime - hour * 3660);
|
||||
int minute = (int) (remainTime / 60);
|
||||
int second = (int) (remainTime - minute * 60);
|
||||
if (hour != 0) {
|
||||
return hour + "时" + minute + "分" + second + "秒";
|
||||
} else if (minute != 0) {
|
||||
return minute + "分" + second + "秒";
|
||||
} else {
|
||||
return second + "秒";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user