Convert accessRootFolderRemoteOperation method in AsyncTask
[pub/Android/ownCloud.git] / src / com / owncloud / android / utils / DisplayUtils.java
index f0f5265..e22b6de 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Date;
 import java.util.HashMap;\r
 import java.util.HashSet;\r
 import java.util.Set;\r
+import java.util.Vector;\r
 \r
 import android.annotation.TargetApi;\r
 import android.content.Context;\r
@@ -51,6 +52,8 @@ public class DisplayUtils {
     \r
     private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };\r
 \r
+    private final static Double THUMBNAIL_THRESHOLD = 0.5;\r
+\r
     private static HashMap<String, String> mimeType2HUmanReadable;\r
     static {\r
         mimeType2HUmanReadable = new HashMap<String, String>();\r
@@ -222,20 +225,19 @@ public class DisplayUtils {
 \r
     \r
     private static String getExtension(String filename) {\r
-        String extension = filename.toLowerCase().substring(filename.lastIndexOf(".") + 1);\r
+        String extension = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();\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
+     * @param milliseconds that have passed since 01/01/1970\r
      * @return The human readable time for the users locale\r
      */\r
     public static String unixTimeToHumanReadable(long milliseconds) {\r
         Date date = new Date(milliseconds);\r
         DateFormat df = DateFormat.getDateTimeInstance();\r
-        //return date.toLocaleString();\r
-        return df.format(date); \r
+        return df.format(date);\r
     }\r
     \r
     \r
@@ -341,4 +343,31 @@ public class DisplayUtils {
         }\r
         return path;\r
     }\r
+\r
+    /**\r
+     *\r
+     * @param mFiles\r
+     * @return true: imageView, false: listView\r
+     */\r
+    public static boolean decideViewLayout(Vector<OCFile> mFiles){\r
+        // decide image vs. file view\r
+        double countImages = 0;\r
+        double countFiles = 0;\r
+\r
+        for (OCFile file : mFiles){\r
+            if (!file.isFolder()){\r
+                countFiles++;\r
+\r
+                if (file.isImage()){\r
+                    countImages++;\r
+                }\r
+            }\r
+        }\r
+\r
+        if ((countImages / countFiles) >= THUMBNAIL_THRESHOLD){\r
+            return true;\r
+        } else {\r
+            return false;\r
+        }\r
+    }\r
 }\r