public static java.lang.String | formatFileSize(android.content.Context context, long number)Formats a content size to be in the form of bytes, kilobytes, megabytes, etc
if (context == null) {
return "";
}
float result = number;
int suffix = com.android.internal.R.string.byteShort;
if (result > 900) {
suffix = com.android.internal.R.string.kilobyteShort;
result = result / 1024;
}
if (result > 900) {
suffix = com.android.internal.R.string.megabyteShort;
result = result / 1024;
}
if (result > 900) {
suffix = com.android.internal.R.string.gigabyteShort;
result = result / 1024;
}
if (result > 900) {
suffix = com.android.internal.R.string.terabyteShort;
result = result / 1024;
}
if (result > 900) {
suffix = com.android.internal.R.string.petabyteShort;
result = result / 1024;
}
if (result < 100) {
return String.format("%.2f%s", result, context.getText(suffix).toString());
}
return String.format("%.0f%s", result, context.getText(suffix).toString());
|