import java.util.HashSet;\r
import java.util.Set;\r
\r
+ import android.annotation.TargetApi;\r
+import android.content.Context;\r
+ import android.os.Build;\r
+import android.text.format.DateFormat;\r
+import android.text.format.DateUtils;\r
\r
+ import com.owncloud.android.MainApp;\r
import com.owncloud.android.R;\r
- import com.owncloud.android.lib.common.utils.Log_OC;\r
\r
/**\r
* A helper class for some string operations.\r
}\r
}\r
\r
+ /**\r
+ * Converts an internationalized domain name (IDN) in an URL to and from ASCII/Unicode.\r
+ * @param url the URL where the domain name should be converted\r
+ * @param toASCII if true converts from Unicode to ASCII, if false converts from ASCII to Unicode\r
+ * @return the URL containing the converted domain name\r
+ */\r
+ @TargetApi(Build.VERSION_CODES.GINGERBREAD)\r
+ public static String convertIdn(String url, boolean toASCII) {\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
+ hostStart = url.indexOf("//") + "//".length();\r
+ } else if (url.indexOf("@") != -1) {\r
+ hostStart = url.indexOf("@") + "@".length();\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
+ host = (toASCII ? IDN.toASCII(host) : IDN.toUnicode(host));\r
+ \r
+ return url.substring(0, hostStart) + host + url.substring(hostEnd);\r
+ } else {\r
+ return url;\r
+ }\r
+ }\r
++ \r
+ public static CharSequence getRelativeDateTimeString(Context c, long time, long minResolution, long transitionResolution, int flags){\r
+ if (time > System.currentTimeMillis()){\r
+ return DisplayUtils.unixTimeToHumanReadable(time);\r
+ } else if ((System.currentTimeMillis() - time) < 60000) {\r
+ return c.getString(R.string.file_list_seconds_ago) + ", " + \r
+ DateFormat.getTimeFormat(c).format(new Date(time));\r
+ } else {\r
+ return DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags);\r
+ }\r
+ }\r
}\r