1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

remove a duplicated and divergent size formatter

This commit is contained in:
Jesse Vincent 2010-12-13 01:02:35 +00:00
parent 936b2779d6
commit 23b57b4502
2 changed files with 8 additions and 28 deletions

View File

@ -89,6 +89,7 @@ import com.fsck.k9.mail.store.LocalStore.LocalTextBody;
import com.fsck.k9.provider.AttachmentProvider;
import com.fsck.k9.view.AccessibleWebView;
import com.fsck.k9.view.ToggleScrollView;
import com.fsck.k9.activity.SizeFormatter;
public class MessageView extends K9Activity implements OnClickListener
{
@ -2111,33 +2112,6 @@ public class MessageView extends K9Activity implements OnClickListener
}
}
/*
* 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
*/
public static String formatSize(float size)
{
long kb = 1024;
long mb = (kb * 1024);
long gb = (mb * 1024);
if (size < kb)
{
return String.format("%d bytes", (int) size);
}
else if (size < mb)
{
return String.format("%.1f kB", size / kb);
}
else if (size < gb)
{
return String.format("%.1f MB", size / mb);
}
else
{
return String.format("%.1f GB", size / gb);
}
}
private void renderAttachments(Part part, int depth) throws MessagingException
{
String contentType = MimeUtility.unfoldAndDecode(part.getContentType());
@ -2218,7 +2192,7 @@ public class MessageView extends K9Activity implements OnClickListener
attachmentDownload.setTag(attachment);
attachmentName.setText(name);
attachmentInfo.setText(formatSize(size));
attachmentInfo.setText(SizeFormatter.formatSize(getApplication(),size));
Bitmap previewIcon = getPreviewIcon(attachment);
if (previewIcon != null)

View File

@ -5,6 +5,10 @@ import com.fsck.k9.R;
public class SizeFormatter
{
/*
* 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
*/
public static String formatSize(Context context, long size)
{
if (size > 1024000000)
@ -23,3 +27,5 @@ public class SizeFormatter
}
}