From: tobiasKaminsky Date: Wed, 12 Nov 2014 08:02:23 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/develop' into beautifyTimestamps X-Git-Tag: oc-android-1.7.0_signed~108^2~2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/79cb6106fd3fc83aa84d18fb472788833b980ea8?hp=--cc Merge remote-tracking branch 'upstream/develop' into beautifyTimestamps Conflicts: src/com/owncloud/android/utils/DisplayUtils.java --- 79cb6106fd3fc83aa84d18fb472788833b980ea8 diff --cc src/com/owncloud/android/utils/DisplayUtils.java index 3d51f1f6,804a4dd0..cdd86836 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@@ -27,12 -26,11 +26,14 @@@ import java.util.HashMap import java.util.HashSet; import java.util.Set; + import android.annotation.TargetApi; +import android.content.Context; + import android.os.Build; +import android.text.format.DateFormat; +import android.text.format.DateUtils; + import com.owncloud.android.MainApp; import com.owncloud.android.R; - import com.owncloud.android.lib.common.utils.Log_OC; /** * A helper class for some string operations. @@@ -243,14 -244,34 +247,45 @@@ public class DisplayUtils } } + /** + * Converts an internationalized domain name (IDN) in an URL to and from ASCII/Unicode. + * @param url the URL where the domain name should be converted + * @param toASCII if true converts from Unicode to ASCII, if false converts from ASCII to Unicode + * @return the URL containing the converted domain name + */ + @TargetApi(Build.VERSION_CODES.GINGERBREAD) + public static String convertIdn(String url, boolean toASCII) { + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { + // Find host name after '//' or '@' + int hostStart = 0; + if (url.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); + host = (toASCII ? IDN.toASCII(host) : IDN.toUnicode(host)); + + return url.substring(0, hostStart) + host + url.substring(hostEnd); + } else { + return url; + } + } ++ + public static CharSequence getRelativeDateTimeString(Context c, long time, long minResolution, long transitionResolution, int flags){ + if (time > System.currentTimeMillis()){ + return DisplayUtils.unixTimeToHumanReadable(time); + } else if ((System.currentTimeMillis() - time) < 60000) { + return c.getString(R.string.file_list_seconds_ago) + ", " + + DateFormat.getTimeFormat(c).format(new Date(time)); + } else { + return DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags); + } + } }