From: Andy Scherzinger Date: Fri, 11 Sep 2015 11:06:14 +0000 (+0200) Subject: Merge branch 'new_filetype_icons' of https://github.com/owncloud/android into materia... X-Git-Tag: beta-20151128~7^2~30 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/6eccdc25b3e4ac9bb9c5686aa3e53f60ce07b59d Merge branch 'new_filetype_icons' of https://github.com/owncloud/android into material_buttons Conflicts: src/com/owncloud/android/utils/DisplayUtils.java --- 6eccdc25b3e4ac9bb9c5686aa3e53f60ce07b59d diff --cc src/com/owncloud/android/utils/DisplayUtils.java index 236a05f5,8a281e92..46c66737 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@@ -50,94 -37,54 +37,61 @@@ import com.owncloud.android.MainApp import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; ++import java.math.BigDecimal; + import java.net.IDN; + import java.text.DateFormat; + import java.util.Calendar; + import java.util.Date; + import java.util.HashMap; + import java.util.Map; + /** * A helper class for some string operations. */ public class DisplayUtils { private static final String OWNCLOUD_APP_NAME = "ownCloud"; - - //private static String TAG = DisplayUtils.class.getSimpleName(); private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; + private static final int[] sizeScales = { 0, 0, 0, 1, 1, 2, 2, 2, 2 }; - private static HashMap mimeType2HUmanReadable; + private static Map mimeType2HumanReadable; + static { - mimeType2HUmanReadable = new HashMap(); + 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"); + 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"); - + mimeType2HumanReadable.put("audio/mpeg", "MP3 music file"); + mimeType2HumanReadable.put("application/ogg", "OGG music file"); } - private static final String TYPE_APPLICATION = "application"; - private static final String TYPE_AUDIO = "audio"; - private static final String TYPE_IMAGE = "image"; - private static final String TYPE_TXT = "text"; - private static final String TYPE_VIDEO = "video"; - - private static final String SUBTYPE_PDF = "pdf"; - private static final String SUBTYPE_XML = "xml"; - private static final String[] SUBTYPES_DOCUMENT = { - "msword", - "vnd.openxmlformats-officedocument.wordprocessingml.document", - "vnd.oasis.opendocument.text", - "rtf", - "javascript" - }; - private static Set SUBTYPES_DOCUMENT_SET = new HashSet(Arrays.asList(SUBTYPES_DOCUMENT)); - private static final String[] SUBTYPES_SPREADSHEET = { - "msexcel", - "vnd.ms-excel", - "vnd.openxmlformats-officedocument.spreadsheetml.sheet", - "vnd.oasis.opendocument.spreadsheet" - }; - private static Set SUBTYPES_SPREADSHEET_SET = new HashSet(Arrays.asList(SUBTYPES_SPREADSHEET)); - private static final String[] SUBTYPES_PRESENTATION = { - "mspowerpoint", - "vnd.ms-powerpoint", - "vnd.openxmlformats-officedocument.presentationml.presentation", - "vnd.oasis.opendocument.presentation" - }; - private static Set SUBTYPES_PRESENTATION_SET = new HashSet(Arrays.asList(SUBTYPES_PRESENTATION)); - private static final String[] SUBTYPES_COMPRESSED = {"x-tar", "x-gzip", "zip"}; - private static final Set SUBTYPES_COMPRESSED_SET = new HashSet(Arrays.asList(SUBTYPES_COMPRESSED)); - private static final String SUBTYPE_OCTET_STREAM = "octet-stream"; - private static final String EXTENSION_RAR = "rar"; - private static final String EXTENSION_RTF = "rtf"; - private static final String EXTENSION_3GP = "3gp"; - private static final String EXTENSION_PY = "py"; - private static final String EXTENSION_JS = "js"; - /** * Converts the file size in bytes to human readable output. - * + *
    + *
  • appends a size suffix, e.g. B, KB, MB etc.
  • + *
  • rounds the size based on the suffix to 0,1 or 2 decimals
  • + *
+ * * @param bytes Input file size * @return Like something readable like "12 MB" */ public static String bytesToHumanReadable(long bytes) { double result = bytes; -- int attachedsuff = 0; -- while (result > 1024 && attachedsuff < sizeSuffixes.length) { ++ int attachedSuff = 0; ++ while (result > 1024 && attachedSuff < sizeSuffixes.length) { result /= 1024.; -- attachedsuff++; ++ attachedSuff++; } - result = ((int) (result * 100)) / 100.; - return result + " " + sizeSuffixes[attachedsuff]; + + return new BigDecimal(result).setScale( - sizeScales[attachedsuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedsuff]; ++ sizeScales[attachedSuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedSuff]; } /**