removing android4 calls to actionbar and fragments manager
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / DisplayUtils.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
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.
8 *
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.
13 *
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/>.
16 *
17 */
18
19 package eu.alefzero.owncloud;
20
21 import java.util.HashMap;
22
23 import android.util.Log;
24
25 /**
26 * A helper class for some string operations.
27 * @author Bartek Przybylski
28 *
29 */
30 public class DisplayUtils {
31 public static String bitsToHumanReadable(long bitsLen) {
32 double result = bitsLen;
33 int attachedsuff = 0;
34 while (result > 1024 && attachedsuff < suffixes.length) {
35 result /= 1024.;
36 attachedsuff++;
37 }
38 result = ((int)(result * 100))/100.;
39 return result+suffixes[attachedsuff];
40 }
41
42 public static String HtmlDecode(String s) {
43 String ret = "";
44 for (int i = 0; i < s.length(); ++i) {
45 if (s.charAt(i) == '%') {
46 ret += (char)Integer.parseInt(s.substring(i+1, i+3), 16);
47 i+=2;
48 } else {
49 ret += s.charAt(i);
50 }
51 }
52 return ret;
53 }
54
55 public static String convertMIMEtoPrettyPrint(String mimetype) {
56 if (mimeType2HUmanReadable.containsKey(mimetype)) {
57 return mimeType2HUmanReadable.get(mimetype);
58 }
59 return mimetype.split("/")[1].toUpperCase() + " file";
60 }
61
62 private static final String[] suffixes = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
63
64 private static HashMap<String, String> mimeType2HUmanReadable;
65 static {
66 mimeType2HUmanReadable = new HashMap<String, String>();
67 // images
68 mimeType2HUmanReadable.put("image/jpeg", "JPEG image");
69 mimeType2HUmanReadable.put("image/jpg", "JPEG image");
70 mimeType2HUmanReadable.put("image/png", "PNG image");
71 mimeType2HUmanReadable.put("image/bmp", "Bitmap image");
72 mimeType2HUmanReadable.put("image/gif", "GIF image");
73 mimeType2HUmanReadable.put("image/svg+xml", "JPEG image");
74 mimeType2HUmanReadable.put("image/tiff", "TIFF image");
75 // music
76 mimeType2HUmanReadable.put("audio/mpeg", "MP3 music file");
77 mimeType2HUmanReadable.put("application/ogg", "OGG music file");
78
79 }
80 }