Filter only '/' character in user input when version of server is 8.1 or later
[pub/Android/ownCloud.git] / src / com / owncloud / android / utils / DisplayUtils.java
index 32d9017..7030c87 100644 (file)
@@ -1,6 +1,10 @@
-/* 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
@@ -26,11 +30,15 @@ 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.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
@@ -39,9 +47,6 @@ import com.owncloud.android.datamodel.OCFile;
 \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
@@ -228,7 +233,7 @@ public class DisplayUtils {
     \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
@@ -255,26 +260,33 @@ public class DisplayUtils {
      */\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
@@ -340,4 +352,25 @@ public class DisplayUtils {
         }\r
         return path;\r
     }\r
+\r
+\r
+    /**\r
+     * Gets the screen size in pixels in a backwards compatible way\r
+     *\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 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
+        return size;\r
+    }\r
+\r
 }\r