diff options
author | lookshe <github@lookshe.org> | 2015-10-05 13:55:43 +0200 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2015-10-05 13:55:43 +0200 |
commit | b98478e57c088efc63fd470e429f791dd664707a (patch) | |
tree | e722ed48ee2ec125d8ad9250f79d8e1ca95666a7 /src/main/java/eu/siacs/conversations/utils | |
parent | 5850cbcf9c3e72580f3288c582737a04e8148b79 (diff) | |
parent | 6f17b06ad008cc7ac89174ba7ac7cc96ee0881eb (diff) |
Merge branch 'trz/rename' into trz/rebase
Conflicts:
build.gradle
src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
Diffstat (limited to 'src/main/java/eu/siacs/conversations/utils')
-rw-r--r-- | src/main/java/eu/siacs/conversations/utils/UIHelper.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 76f48037..7562c446 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -1,5 +1,7 @@ package eu.siacs.conversations.utils; +import java.math.BigDecimal; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; import java.net.URLConnection; @@ -287,4 +289,20 @@ public class UIHelper { body = body.replace("?","").replace("¿",""); return LOCATION_QUESTIONS.contains(body); } + + public static String getHumanReadableFileSize(long filesize) { + if (0 > filesize) { + return "?"; + } + double size = Double.valueOf(filesize); + String[] sizes = {" bytes", " Kb", " Mb", " Gb", " Tb"}; + int i = 0; + while (1023 < size) { + size /= 1024d; + ++i; + } + BigDecimal readableSize = new BigDecimal(size); + readableSize = readableSize.setScale(2, BigDecimal.ROUND_HALF_UP); + return readableSize.doubleValue() + sizes[i]; + } } |