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 905f60b..7030c87 100644 (file)
@@ -33,9 +33,12 @@ import java.util.Set;
 import java.util.Vector;\r
 \r
 import android.annotation.TargetApi;\r
 import java.util.Vector;\r
 \r
 import android.annotation.TargetApi;\r
+import android.app.Activity;\r
 import android.content.Context;\r
 import android.content.Context;\r
+import android.graphics.Point;\r
 import android.os.Build;\r
 import android.text.format.DateUtils;\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
 import android.webkit.MimeTypeMap;\r
 \r
 import com.owncloud.android.MainApp;\r
@@ -257,26 +260,33 @@ public class DisplayUtils {
      */\r
     @TargetApi(Build.VERSION_CODES.GINGERBREAD)\r
     public static String convertIdn(String url, boolean toASCII) {\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 (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
                 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
             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
             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
         } else {\r
-            return url;\r
+            return dots + url;\r
         }\r
     }\r
 \r
         }\r
     }\r
 \r
@@ -343,4 +353,24 @@ public class DisplayUtils {
         return path;\r
     }\r
 \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
 }\r