X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/04b77aa2f4c35fefe2436630611c7950ec441b56..c04d9c21986e6ea093a7f60f08aae81cabdec262:/src/com/owncloud/android/utils/DisplayUtils.java diff --git a/src/com/owncloud/android/utils/DisplayUtils.java b/src/com/owncloud/android/utils/DisplayUtils.java index e22b6de8..91dfc47c 100644 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@ -1,6 +1,10 @@ -/* ownCloud Android client application +/** + * ownCloud Android client application + * + * @author Bartek Przybylski + * @author David A. Velasco * Copyright (C) 2011 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -40,9 +44,6 @@ import com.owncloud.android.datamodel.OCFile; /** * A helper class for some string operations. - * - * @author Bartek Przybylski - * @author David A. Velasco */ public class DisplayUtils { @@ -52,8 +53,6 @@ public class DisplayUtils { private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; - private final static Double THUMBNAIL_THRESHOLD = 0.5; - private static HashMap mimeType2HUmanReadable; static { mimeType2HUmanReadable = new HashMap(); @@ -258,26 +257,33 @@ public class DisplayUtils { */ @TargetApi(Build.VERSION_CODES.GINGERBREAD) public static String convertIdn(String url, boolean toASCII) { - + + String urlNoDots = url; + String dots=""; + while (urlNoDots.startsWith(".")) { + urlNoDots = url.substring(1); + dots = dots + "."; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { // Find host name after '//' or '@' int hostStart = 0; - if (url.indexOf("//") != -1) { + if (urlNoDots.indexOf("//") != -1) { hostStart = url.indexOf("//") + "//".length(); } else if (url.indexOf("@") != -1) { hostStart = url.indexOf("@") + "@".length(); } - + int hostEnd = url.substring(hostStart).indexOf("/"); // Handle URL which doesn't have a path (path is implicitly '/') - hostEnd = (hostEnd == -1 ? url.length() : hostStart + hostEnd); - - String host = url.substring(hostStart, hostEnd); + hostEnd = (hostEnd == -1 ? urlNoDots.length() : hostStart + hostEnd); + + String host = urlNoDots.substring(hostStart, hostEnd); host = (toASCII ? IDN.toASCII(host) : IDN.toUnicode(host)); - - return url.substring(0, hostStart) + host + url.substring(hostEnd); + + return dots + urlNoDots.substring(0, hostStart) + host + urlNoDots.substring(hostEnd); } else { - return url; + return dots + url; } } @@ -344,30 +350,4 @@ public class DisplayUtils { return path; } - /** - * - * @param mFiles - * @return true: imageView, false: listView - */ - public static boolean decideViewLayout(Vector mFiles){ - // decide image vs. file view - double countImages = 0; - double countFiles = 0; - - for (OCFile file : mFiles){ - if (!file.isFolder()){ - countFiles++; - - if (file.isImage()){ - countImages++; - } - } - } - - if ((countImages / countFiles) >= THUMBNAIL_THRESHOLD){ - return true; - } else { - return false; - } - } }