3f278b31a71028b13202e3aae0ae6b3ba1dca529
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package eu
.alefzero
.owncloud
;
21 import java
.util
.HashMap
;
23 import android
.util
.Log
;
25 public class DisplayUtils
{
26 public static String
bitsToHumanReadable(long bitsLen
) {
27 double result
= bitsLen
;
29 while (result
> 1024 && attachedsuff
< suffixes
.length
) {
33 result
= ((int)(result
* 100))/100.;
34 return result
+suffixes
[attachedsuff
];
37 public static String
HtmlDecode(String s
) {
39 for (int i
= 0; i
< s
.length(); ++i
) {
40 if (s
.charAt(i
) == '%') {
41 ret
+= (char)Integer
.parseInt(s
.substring(i
+1, i
+3), 16);
50 public static String
convertMIMEtoPrettyPrint(String mimetype
) {
51 if (mimeType2HUmanReadable
.containsKey(mimetype
)) {
52 return mimeType2HUmanReadable
.get(mimetype
);
54 return mimetype
.split("/")[1].toUpperCase() + " file";
57 private static final String
[] suffixes
= {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
59 private static HashMap
<String
, String
> mimeType2HUmanReadable
;
61 mimeType2HUmanReadable
= new HashMap
<String
, String
>();
63 mimeType2HUmanReadable
.put("image/jpeg", "JPEG image");
64 mimeType2HUmanReadable
.put("image/jpg", "JPEG image");
65 mimeType2HUmanReadable
.put("image/png", "PNG image");
66 mimeType2HUmanReadable
.put("image/bmp", "Bitmap image");
67 mimeType2HUmanReadable
.put("image/gif", "GIF image");
68 mimeType2HUmanReadable
.put("image/svg+xml", "JPEG image");
69 mimeType2HUmanReadable
.put("image/tiff", "TIFF image");
71 mimeType2HUmanReadable
.put("audio/mpeg", "MP3 music file");
72 mimeType2HUmanReadable
.put("application/ogg", "OGG music file");