2010-12-12 20:02:39 -05:00
|
|
|
package com.fsck.k9.helper;
|
2009-02-12 16:49:20 -05:00
|
|
|
|
|
|
|
import android.content.Context;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.R;
|
2009-02-12 16:49:20 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public class SizeFormatter {
|
2010-12-12 20:02:35 -05:00
|
|
|
/*
|
|
|
|
* Formats the given size as a String in bytes, kB, MB or GB with a single digit
|
|
|
|
* of precision. Ex: 12,315,000 = 12.3 MB
|
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
public static String formatSize(Context context, long size) {
|
|
|
|
if (size > 1024000000) {
|
2009-11-21 17:45:39 -05:00
|
|
|
return ((float)(size / 102400000) / 10) + context.getString(R.string.abbrev_gigabytes);
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
if (size > 1024000) {
|
2009-11-21 17:45:39 -05:00
|
|
|
return ((float)(size / 102400) / 10) + context.getString(R.string.abbrev_megabytes);
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
if (size > 1024) {
|
2009-11-21 17:45:39 -05:00
|
|
|
return ((float)(size / 102) / 10) + context.getString(R.string.abbrev_kilobytes);
|
|
|
|
}
|
|
|
|
return size + context.getString(R.string.abbrev_bytes);
|
2009-02-12 16:49:20 -05:00
|
|
|
}
|
2009-11-21 17:45:39 -05:00
|
|
|
|
2009-02-12 16:49:20 -05:00
|
|
|
}
|
2010-12-12 20:02:35 -05:00
|
|
|
|
|
|
|
|