X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/1083eb8683b5c6b486bf8c16c081d7109aced91c..4c1ca7dc4874ef10a30929ee059c274f5214030b:/src/eu/alefzero/owncloud/DisplayUtils.java?ds=inline diff --git a/src/eu/alefzero/owncloud/DisplayUtils.java b/src/eu/alefzero/owncloud/DisplayUtils.java index 9e8a5956..40bcb5e8 100644 --- a/src/eu/alefzero/owncloud/DisplayUtils.java +++ b/src/eu/alefzero/owncloud/DisplayUtils.java @@ -22,57 +22,59 @@ import java.util.HashMap; /** * A helper class for some string operations. + * * @author Bartek Przybylski - * + * */ public class DisplayUtils { - public static String bitsToHumanReadable(long bitsLen) { - double result = bitsLen; - int attachedsuff = 0; - while (result > 1024 && attachedsuff < suffixes.length) { - result /= 1024.; - attachedsuff++; + public static String bitsToHumanReadable(long bitsLen) { + double result = bitsLen; + int attachedsuff = 0; + while (result > 1024 && attachedsuff < suffixes.length) { + result /= 1024.; + attachedsuff++; + } + result = ((int) (result * 100)) / 100.; + return result + suffixes[attachedsuff]; + } + + public static String HtmlDecode(String s) { + String ret = ""; + for (int i = 0; i < s.length(); ++i) { + if (s.charAt(i) == '%') { + ret += (char) Integer.parseInt(s.substring(i + 1, i + 3), 16); + i += 2; + } else { + ret += s.charAt(i); + } + } + return ret; } - result = ((int)(result * 100))/100.; - return result+suffixes[attachedsuff]; - } - - public static String HtmlDecode(String s) { - String ret = ""; - for (int i = 0; i < s.length(); ++i) { - if (s.charAt(i) == '%') { - ret += (char)Integer.parseInt(s.substring(i+1, i+3), 16); - i+=2; - } else { - ret += s.charAt(i); - } + + public static String convertMIMEtoPrettyPrint(String mimetype) { + if (mimeType2HUmanReadable.containsKey(mimetype)) { + return mimeType2HUmanReadable.get(mimetype); + } + return mimetype.split("/")[1].toUpperCase() + " file"; } - return ret; - } - public static String convertMIMEtoPrettyPrint(String mimetype) { - if (mimeType2HUmanReadable.containsKey(mimetype)) { - return mimeType2HUmanReadable.get(mimetype); + private static final String[] suffixes = { "B", "KB", "MB", "GB", "TB", + "PB", "EB", "ZB", "YB" }; + + private static HashMap mimeType2HUmanReadable; + static { + mimeType2HUmanReadable = new HashMap(); + // images + mimeType2HUmanReadable.put("image/jpeg", "JPEG image"); + mimeType2HUmanReadable.put("image/jpg", "JPEG image"); + mimeType2HUmanReadable.put("image/png", "PNG image"); + mimeType2HUmanReadable.put("image/bmp", "Bitmap image"); + mimeType2HUmanReadable.put("image/gif", "GIF image"); + mimeType2HUmanReadable.put("image/svg+xml", "JPEG image"); + mimeType2HUmanReadable.put("image/tiff", "TIFF image"); + // music + mimeType2HUmanReadable.put("audio/mpeg", "MP3 music file"); + mimeType2HUmanReadable.put("application/ogg", "OGG music file"); + } - return mimetype.split("/")[1].toUpperCase() + " file"; - } - - private static final String[] suffixes = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; - - private static HashMap mimeType2HUmanReadable; - static { - mimeType2HUmanReadable = new HashMap(); - // images - mimeType2HUmanReadable.put("image/jpeg", "JPEG image"); - mimeType2HUmanReadable.put("image/jpg", "JPEG image"); - mimeType2HUmanReadable.put("image/png", "PNG image"); - mimeType2HUmanReadable.put("image/bmp", "Bitmap image"); - mimeType2HUmanReadable.put("image/gif", "GIF image"); - mimeType2HUmanReadable.put("image/svg+xml", "JPEG image"); - mimeType2HUmanReadable.put("image/tiff", "TIFF image"); - // music - mimeType2HUmanReadable.put("audio/mpeg", "MP3 music file"); - mimeType2HUmanReadable.put("application/ogg", "OGG music file"); - - } }