From: David A. Velasco Date: Thu, 24 Jan 2013 12:34:27 +0000 (+0100) Subject: Code ready to provide different icons for well-known MIME types X-Git-Tag: oc-android-1.4.3~61^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/f440d30e427389effe68000c4af78a1e20316519?ds=inline Code ready to provide different icons for well-known MIME types --- diff --git a/res/drawable-hdpi/file_doc.png b/res/drawable-hdpi/file_doc.png new file mode 100644 index 00000000..bf4b8324 Binary files /dev/null and b/res/drawable-hdpi/file_doc.png differ diff --git a/res/drawable-hdpi/file_image.png b/res/drawable-hdpi/file_image.png new file mode 100644 index 00000000..bf4b8324 Binary files /dev/null and b/res/drawable-hdpi/file_image.png differ diff --git a/res/drawable-hdpi/file_movie.png b/res/drawable-hdpi/file_movie.png new file mode 100644 index 00000000..bf4b8324 Binary files /dev/null and b/res/drawable-hdpi/file_movie.png differ diff --git a/res/drawable-hdpi/file_pdf.png b/res/drawable-hdpi/file_pdf.png new file mode 100644 index 00000000..bf4b8324 Binary files /dev/null and b/res/drawable-hdpi/file_pdf.png differ diff --git a/res/drawable-hdpi/file_sound.png b/res/drawable-hdpi/file_sound.png new file mode 100644 index 00000000..bf4b8324 Binary files /dev/null and b/res/drawable-hdpi/file_sound.png differ diff --git a/res/drawable-hdpi/file_zip.png b/res/drawable-hdpi/file_zip.png new file mode 100644 index 00000000..bf4b8324 Binary files /dev/null and b/res/drawable-hdpi/file_zip.png differ diff --git a/res/drawable-ldpi/file_doc.png b/res/drawable-ldpi/file_doc.png new file mode 100644 index 00000000..8cdfc4f2 Binary files /dev/null and b/res/drawable-ldpi/file_doc.png differ diff --git a/res/drawable-ldpi/file_image.png b/res/drawable-ldpi/file_image.png new file mode 100644 index 00000000..8cdfc4f2 Binary files /dev/null and b/res/drawable-ldpi/file_image.png differ diff --git a/res/drawable-ldpi/file_movie.png b/res/drawable-ldpi/file_movie.png new file mode 100644 index 00000000..8cdfc4f2 Binary files /dev/null and b/res/drawable-ldpi/file_movie.png differ diff --git a/res/drawable-ldpi/file_pdf.png b/res/drawable-ldpi/file_pdf.png new file mode 100644 index 00000000..8cdfc4f2 Binary files /dev/null and b/res/drawable-ldpi/file_pdf.png differ diff --git a/res/drawable-ldpi/file_sound.png b/res/drawable-ldpi/file_sound.png new file mode 100644 index 00000000..8cdfc4f2 Binary files /dev/null and b/res/drawable-ldpi/file_sound.png differ diff --git a/res/drawable-ldpi/file_zip.png b/res/drawable-ldpi/file_zip.png new file mode 100644 index 00000000..8cdfc4f2 Binary files /dev/null and b/res/drawable-ldpi/file_zip.png differ diff --git a/res/drawable-mdpi/file_doc.png b/res/drawable-mdpi/file_doc.png new file mode 100644 index 00000000..561c788a Binary files /dev/null and b/res/drawable-mdpi/file_doc.png differ diff --git a/res/drawable-mdpi/file_image.png b/res/drawable-mdpi/file_image.png new file mode 100644 index 00000000..561c788a Binary files /dev/null and b/res/drawable-mdpi/file_image.png differ diff --git a/res/drawable-mdpi/file_movie.png b/res/drawable-mdpi/file_movie.png new file mode 100644 index 00000000..561c788a Binary files /dev/null and b/res/drawable-mdpi/file_movie.png differ diff --git a/res/drawable-mdpi/file_pdf.png b/res/drawable-mdpi/file_pdf.png new file mode 100644 index 00000000..561c788a Binary files /dev/null and b/res/drawable-mdpi/file_pdf.png differ diff --git a/res/drawable-mdpi/file_sound.png b/res/drawable-mdpi/file_sound.png new file mode 100644 index 00000000..561c788a Binary files /dev/null and b/res/drawable-mdpi/file_sound.png differ diff --git a/res/drawable-mdpi/file_zip.png b/res/drawable-mdpi/file_zip.png new file mode 100644 index 00000000..561c788a Binary files /dev/null and b/res/drawable-mdpi/file_zip.png differ diff --git a/src/com/owncloud/android/DisplayUtils.java b/src/com/owncloud/android/DisplayUtils.java index a9cfe1dc..d6188113 100644 --- a/src/com/owncloud/android/DisplayUtils.java +++ b/src/com/owncloud/android/DisplayUtils.java @@ -1,5 +1,6 @@ /* ownCloud Android client application * Copyright (C) 2011 Bartek Przybylski + * Copyright (2) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,18 +19,25 @@ package com.owncloud.android; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import android.util.Log; /** * A helper class for some string operations. * * @author Bartek Przybylski - * + * @author David A. Velasco */ public class DisplayUtils { - - private static final String[] suffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; + + private static String TAG = DisplayUtils.class.getSimpleName(); + + private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; private static HashMap mimeType2HUmanReadable; static { @@ -48,6 +56,22 @@ public class DisplayUtils { } + 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 = "txt"; + private static final String TYPE_VIDEO = "video"; + + private static final String SUBTYPE_PDF = "pdf"; + private static final String[] SUBTYPES_DOCUMENT = { "msword", "mspowerpoint", "msexcel", + "vnd.oasis.opendocument.presentation", + "vnd.oasis.opendocument.spreadsheet", + "vnd.oasis.opendocument.text" + }; + private static Set SUBTYPES_DOCUMENT_SET = new HashSet(Arrays.asList(SUBTYPES_DOCUMENT)); + private static final String[] SUBTYPES_COMPRESSED = {"x-tar", "x-gzip", "zip"}; + private static final Set SUBTYPES_COMPRESSED_SET = new HashSet(Arrays.asList(SUBTYPES_COMPRESSED)); + /** * Converts the file size in bytes to human readable output. * @@ -57,12 +81,12 @@ public class DisplayUtils { public static String bytesToHumanReadable(long bytes) { double result = bytes; int attachedsuff = 0; - while (result > 1024 && attachedsuff < suffixes.length) { + while (result > 1024 && attachedsuff < sizeSuffixes.length) { result /= 1024.; attachedsuff++; } result = ((int) (result * 100)) / 100.; - return result + " " + suffixes[attachedsuff]; + return result + " " + sizeSuffixes[attachedsuff]; } /** @@ -104,6 +128,58 @@ public class DisplayUtils { return mimetype.split("/")[1].toUpperCase() + " file"; return "Unknown type"; } + + + /** + * Returns the resource identifier of an image resource to use as icon associated to a + * known MIME type. + * + * @param mimetype MIME type string. + * @return Resource identifier of an image resource. + */ + public static int getResourceId(String mimetype) { + + if (mimetype == null || "DIR".equals(mimetype)) { + return R.drawable.ic_menu_archive; + + } else { + String [] parts = mimetype.split("/"); + String type = parts[0]; + String subtype = parts[1]; + + if(TYPE_TXT.equals(type)) { + return R.drawable.file_doc; + + } else if(TYPE_IMAGE.equals(type)) { + return R.drawable.file_image; + + } else if(TYPE_VIDEO.equals(type)) { + return R.drawable.file_movie; + + } else if(TYPE_AUDIO.equals(type)) { + return R.drawable.file_sound; + + } else if(TYPE_APPLICATION.equals(type)) { + + if (SUBTYPE_PDF.equals(subtype)) { + return R.drawable.file_pdf; + + } else if (SUBTYPES_DOCUMENT_SET.contains(subtype)) { + return R.drawable.file_doc; + + } else if (SUBTYPES_COMPRESSED_SET.contains(subtype)) { + return R.drawable.file_zip; + } + + } + // problems: RAR, RTF, 3GP are send as application/octet-stream from the server ; extension in the filename should be explicitly reviewed + } + + // default icon + return R.drawable.file; + } + + /** * Converts Unix time to human readable format diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 503dfffe..b924cc8c 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -115,11 +115,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { fileName.setText(name); ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1); - if (file.getMimetype() == null || !file.getMimetype().equals("DIR")) { - fileIcon.setImageResource(R.drawable.file); - } else { - fileIcon.setImageResource(R.drawable.ic_menu_archive); - } + fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype())); ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2); FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder(); diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index 2c43278f..fc6f1672 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -507,8 +507,7 @@ public class FileDetailFragment extends SherlockFragment implements // set file details setFilename(mFile.getFileName()); - setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile - .getMimetype())); + setFiletype(mFile.getMimetype()); setFilesize(mFile.getFileLength()); if(ocVersionSupportsTimeCreated()){ setTimeCreated(mFile.getCreationTimestamp()); @@ -560,8 +559,14 @@ public class FileDetailFragment extends SherlockFragment implements */ private void setFiletype(String mimetype) { TextView tv = (TextView) getView().findViewById(R.id.fdType); - if (tv != null) - tv.setText(mimetype); + if (tv != null) { + String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype);; + tv.setText(printableMimetype); + } + ImageView iv = (ImageView) getView().findViewById(R.id.fdIcon); + if (iv != null) { + iv.setImageResource(DisplayUtils.getResourceId(mimetype)); + } } /**