Merge remote-tracking branch 'upstream/develop' into
[pub/Android/ownCloud.git] / src / com / owncloud / android / utils / DisplayUtils.java
index 680107b..682d2be 100644 (file)
@@ -63,14 +63,28 @@ public class DisplayUtils {
     private static final String TYPE_VIDEO = "video";\r
     \r
     private static final String SUBTYPE_PDF = "pdf";\r
     private static final String TYPE_VIDEO = "video";\r
     \r
     private static final String SUBTYPE_PDF = "pdf";\r
-    private static final String[] SUBTYPES_DOCUMENT = { "msword", "mspowerpoint", "msexcel", \r
-                                                        "vnd.oasis.opendocument.presentation",\r
-                                                        "vnd.oasis.opendocument.spreadsheet",\r
-                                                        "vnd.oasis.opendocument.text"\r
+    private static final String[] SUBTYPES_DOCUMENT = { "msword",\r
+                                                        "vnd.openxmlformats-officedocument.wordprocessingml.document",\r
+                                                        "vnd.oasis.opendocument.text",\r
+                                                        "rtf"\r
                                                         };\r
     private static Set<String> SUBTYPES_DOCUMENT_SET = new HashSet<String>(Arrays.asList(SUBTYPES_DOCUMENT));\r
                                                         };\r
     private static Set<String> SUBTYPES_DOCUMENT_SET = new HashSet<String>(Arrays.asList(SUBTYPES_DOCUMENT));\r
+    private static final String[] SUBTYPES_SPREADSHEET = { "msexcel",\r
+                                                           "vnd.openxmlformats-officedocument.spreadsheetml.sheet",\r
+                                                           "vnd.oasis.opendocument.spreadsheet"\r
+                                                           };\r
+    private static Set<String> SUBTYPES_SPREADSHEET_SET = new HashSet<String>(Arrays.asList(SUBTYPES_SPREADSHEET));\r
+    private static final String[] SUBTYPES_PRESENTATION = { "mspowerpoint",\r
+                                                            "vnd.openxmlformats-officedocument.presentationml.presentation",\r
+                                                            "vnd.oasis.opendocument.presentation"\r
+                                                            };\r
+    private static Set<String> SUBTYPES_PRESENTATION_SET = new HashSet<String>(Arrays.asList(SUBTYPES_PRESENTATION));\r
     private static final String[] SUBTYPES_COMPRESSED = {"x-tar", "x-gzip", "zip"};\r
     private static final Set<String> SUBTYPES_COMPRESSED_SET = new HashSet<String>(Arrays.asList(SUBTYPES_COMPRESSED));\r
     private static final String[] SUBTYPES_COMPRESSED = {"x-tar", "x-gzip", "zip"};\r
     private static final Set<String> SUBTYPES_COMPRESSED_SET = new HashSet<String>(Arrays.asList(SUBTYPES_COMPRESSED));\r
+    private static final String SUBTYPE_OCTET_STREAM = "octet-stream";\r
+    private static final String EXTENSION_RAR = "rar";\r
+    private static final String EXTENSION_RTF = "rtf";\r
+    private static final String EXTENSION_3GP = "3gp";\r
     \r
     /**\r
      * Converts the file size in bytes to human readable output.\r
     \r
     /**\r
      * Converts the file size in bytes to human readable output.\r
@@ -135,9 +149,10 @@ public class DisplayUtils {
      * known MIME type.\r
      * \r
      * @param mimetype      MIME type string.\r
      * known MIME type.\r
      * \r
      * @param mimetype      MIME type string.\r
+     * @param filename      name, with extension\r
      * @return              Resource identifier of an image resource.\r
      */\r
      * @return              Resource identifier of an image resource.\r
      */\r
-    public static int getResourceId(String mimetype) {\r
+    public static int getResourceId(String mimetype, String filename) {\r
 \r
         if (mimetype == null || "DIR".equals(mimetype)) {\r
             return R.drawable.ic_menu_archive;\r
 \r
         if (mimetype == null || "DIR".equals(mimetype)) {\r
             return R.drawable.ic_menu_archive;\r
@@ -167,12 +182,28 @@ public class DisplayUtils {
                 } else if (SUBTYPES_DOCUMENT_SET.contains(subtype)) {\r
                     return R.drawable.file_doc;\r
 \r
                 } else if (SUBTYPES_DOCUMENT_SET.contains(subtype)) {\r
                     return R.drawable.file_doc;\r
 \r
+                } else if (SUBTYPES_SPREADSHEET_SET.contains(subtype)) {\r
+                    return R.drawable.file_xls;\r
+\r
+                } else if (SUBTYPES_PRESENTATION_SET.contains(subtype)) {\r
+                    return R.drawable.file_ppt;\r
+\r
                 } else if (SUBTYPES_COMPRESSED_SET.contains(subtype)) {\r
                     return R.drawable.file_zip;\r
                 } else if (SUBTYPES_COMPRESSED_SET.contains(subtype)) {\r
                     return R.drawable.file_zip;\r
-                }\r
-    \r
+                    \r
+                } else if (SUBTYPE_OCTET_STREAM.equals(subtype) ) {\r
+                    if (getExtension(filename).equalsIgnoreCase(EXTENSION_RAR)) {\r
+                        return R.drawable.file_zip;\r
+                        \r
+                    } else if (getExtension(filename).equalsIgnoreCase(EXTENSION_RTF)) {\r
+                        return R.drawable.file_doc;\r
+                        \r
+                    } else if (getExtension(filename).equalsIgnoreCase(EXTENSION_3GP)) {\r
+                        return R.drawable.file_movie;\r
+                        \r
+                    } \r
+                } \r
             }\r
             }\r
-            // problems: RAR, RTF, 3GP are send as application/octet-stream from the server ; extension in the filename should be explicitly reviewed\r
         }\r
 \r
         // default icon\r
         }\r
 \r
         // default icon\r
@@ -180,7 +211,12 @@ public class DisplayUtils {
     }\r
 \r
     \r
     }\r
 \r
     \r
-\r
+    private static String getExtension(String filename) {\r
+        String extension = filename.substring(filename.lastIndexOf(".") + 1);\r
+        \r
+        return extension;\r
+    }\r
+    \r
     /**\r
      * Converts Unix time to human readable format\r
      * @param miliseconds that have passed since 01/01/1970\r
     /**\r
      * Converts Unix time to human readable format\r
      * @param miliseconds that have passed since 01/01/1970\r