-/* ownCloud Android client application\r
+/**\r
+ * ownCloud Android client application\r
+ *\r
+ * @author Bartek Przybylski\r
+ * @author David A. Velasco\r
* Copyright (C) 2011 Bartek Przybylski\r
- * Copyright (C) 2012-2013 ownCloud Inc.\r
+ * Copyright (C) 2015 ownCloud Inc.\r
*\r
* This program is free software: you can redistribute it and/or modify\r
* it under the terms of the GNU General Public License version 2,\r
import java.util.Vector;\r
\r
import android.annotation.TargetApi;\r
+import android.app.Activity;\r
import android.content.Context;\r
+import android.graphics.Point;\r
import android.os.Build;\r
import android.text.format.DateUtils;\r
+import android.view.Display;\r
import android.webkit.MimeTypeMap;\r
\r
import com.owncloud.android.MainApp;\r
\r
/**\r
* A helper class for some string operations.\r
- * \r
- * @author Bartek Przybylski\r
- * @author David A. Velasco\r
*/\r
public class DisplayUtils {\r
\r
\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
*/\r
@TargetApi(Build.VERSION_CODES.GINGERBREAD)\r
public static String convertIdn(String url, boolean toASCII) {\r
- \r
+\r
+ String urlNoDots = url;\r
+ String dots="";\r
+ while (urlNoDots.startsWith(".")) {\r
+ urlNoDots = url.substring(1);\r
+ dots = dots + ".";\r
+ }\r
+\r
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {\r
// Find host name after '//' or '@'\r
int hostStart = 0;\r
- if (url.indexOf("//") != -1) {\r
+ if (urlNoDots.indexOf("//") != -1) {\r
hostStart = url.indexOf("//") + "//".length();\r
} else if (url.indexOf("@") != -1) {\r
hostStart = url.indexOf("@") + "@".length();\r
}\r
- \r
+\r
int hostEnd = url.substring(hostStart).indexOf("/");\r
// Handle URL which doesn't have a path (path is implicitly '/')\r
- hostEnd = (hostEnd == -1 ? url.length() : hostStart + hostEnd);\r
- \r
- String host = url.substring(hostStart, hostEnd);\r
+ hostEnd = (hostEnd == -1 ? urlNoDots.length() : hostStart + hostEnd);\r
+\r
+ String host = urlNoDots.substring(hostStart, hostEnd);\r
host = (toASCII ? IDN.toASCII(host) : IDN.toUnicode(host));\r
- \r
- return url.substring(0, hostStart) + host + url.substring(hostEnd);\r
+\r
+ return dots + urlNoDots.substring(0, hostStart) + host + urlNoDots.substring(hostEnd);\r
} else {\r
- return url;\r
+ return dots + url;\r
}\r
}\r
\r
return path;\r
}\r
\r
+\r
/**\r
+ * Gets the screen size in pixels in a backwards compatible way\r
*\r
- * @param mFiles\r
- * @return true: imageView, false: listView\r
+ * @param caller Activity calling; needed to get access to the {@link android.view.WindowManager}\r
+ * @return Size in pixels of the screen, or default {@link Point} if caller is null\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
+ public static Point getScreenSize(Activity caller) {\r
+ Point size = new Point();\r
+ if (caller != null) {\r
+ Display display = caller.getWindowManager().getDefaultDisplay();\r
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {\r
+ display.getSize(size);\r
+ } else {\r
+ size.set(display.getWidth(), display.getHeight());\r
}\r
}\r
-\r
- if ((countImages / countFiles) >= THUMBNAIL_THRESHOLD){\r
- return true;\r
- } else {\r
- return false;\r
- }\r
+ return size;\r
}\r
+\r
}\r