addresses = null;
+
+ Geocoder gcd = getGeocoder(context);
+
+ if (gcd == null) {
+ return null;
+ }
+
+ try {
+ addresses = gcd.getFromLocationName(locationName, maxResults);
+ } catch (IOException e) {
+ AppLog.e(AppLog.T.UTILS, "Failed to get coordinates from location", e);
+ }
+
+ // addresses may be null or empty if network isn't connected
+ if (addresses != null && addresses.size() > 0) {
+ address = addresses.get(0);
+ }
+
+ return address;
+ }
+
+ public static String getLocationNameFromAddress(Address address) {
+ String locality = "", adminArea = "", country = "";
+ if (address.getLocality() != null) {
+ locality = address.getLocality();
+ }
+
+ if (address.getAdminArea() != null) {
+ adminArea = address.getAdminArea();
+ }
+
+ if (address.getCountryName() != null) {
+ country = address.getCountryName();
+ }
+
+ return ((locality.equals("")) ? locality : locality + ", ")
+ + ((adminArea.equals("")) ? adminArea : adminArea + " ") + country;
+ }
+
+ public static double[] getCoordsFromAddress(Address address) {
+ double[] coordinates = new double[2];
+
+ if (address.hasLatitude() && address.hasLongitude()) {
+ coordinates[0] = address.getLatitude();
+ coordinates[1] = address.getLongitude();
+ }
+
+ return coordinates;
+ }
+}
diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/GravatarUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/GravatarUtils.java
new file mode 100644
index 000000000000..c10ce69c81e8
--- /dev/null
+++ b/WordPressUtils/src/main/java/org/wordpress/android/util/GravatarUtils.java
@@ -0,0 +1,22 @@
+package org.wordpress.android.util;
+
+import android.text.TextUtils;
+
+public class GravatarUtils {
+ /*
+ * see https://en.gravatar.com/site/implement/images/
+ */
+ public static String gravatarUrlFromEmail(final String email, int size) {
+ if (TextUtils.isEmpty(email))
+ return "";
+
+ String url = "http://gravatar.com/avatar/"
+ + StringUtils.getMd5Hash(email)
+ + "?d=mm";
+
+ if (size > 0)
+ url += "&s=" + Integer.toString(size);
+
+ return url;
+ }
+}
diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/HtmlUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/HtmlUtils.java
new file mode 100644
index 000000000000..c79fe0ecb079
--- /dev/null
+++ b/WordPressUtils/src/main/java/org/wordpress/android/util/HtmlUtils.java
@@ -0,0 +1,138 @@
+package org.wordpress.android.util;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.text.Html;
+import android.text.SpannableStringBuilder;
+import android.text.Spanned;
+import android.text.TextUtils;
+import android.text.style.ForegroundColorSpan;
+import android.text.style.QuoteSpan;
+
+import org.apache.commons.lang.StringEscapeUtils;
+
+public class HtmlUtils {
+ /*
+ * removes html from the passed string - relies on Html.fromHtml which handles invalid HTML,
+ * but it's very slow, so avoid using this where performance is important
+ */
+ public static String stripHtml(final String text) {
+ if (TextUtils.isEmpty(text)) {
+ return "";
+ }
+ return Html.fromHtml(text).toString().trim();
+ }
+
+ /*
+ * this is much faster than stripHtml() but should only be used when we know the html is valid
+ * since the regex will be unpredictable with invalid html
+ */
+ public static String fastStripHtml(String str) {
+ if (TextUtils.isEmpty(str)) {
+ return str;
+ }
+
+ // insert a line break before P tags unless the only one is at the start
+ if (str.lastIndexOf(" 0) {
+ str = str.replaceAll("
", "\n
");
+ }
+
+ // convert BR tags to line breaks
+ if (str.contains("
", "\n");
+ }
+
+ // use regex to strip tags, then convert entities in the result
+ return trimStart(fastUnescapeHtml(str.replaceAll("<(.|\n)*?>", "")));
+ }
+
+ /*
+ * same as apache.commons.lang.StringUtils.stripStart() but also removes non-breaking
+ * space (160) chars
+ */
+ private static String trimStart(final String str) {
+ int strLen;
+ if (str == null || (strLen = str.length()) == 0) {
+ return "";
+ }
+ int start = 0;
+ while (start != strLen && (Character.isWhitespace(str.charAt(start)) || str.charAt(start) == 160)) {
+ start++;
+ }
+ return str.substring(start);
+ }
+
+ /*
+ * convert html entities to actual Unicode characters - relies on commons apache lang
+ */
+ public static String fastUnescapeHtml(final String text) {
+ if (text == null || !text.contains("&")) {
+ return text;
+ }
+ return StringEscapeUtils.unescapeHtml(text);
+ }
+
+ /*
+ * converts an R.color.xxx resource to an HTML hex color
+ */
+ public static String colorResToHtmlColor(Context context, int resId) {
+ try {
+ return String.format("#%06X", 0xFFFFFF & context.getResources().getColor(resId));
+ } catch (Resources.NotFoundException e) {
+ return "#000000";
+ }
+ }
+
+ /*
+ * remove blocks from the passed string - added to project after noticing
+ * comments on posts that use the "Sociable" plugin ( http://wordpress.org/plugins/sociable/ )
+ * may have a script block which contains followed by a CDATA section followed by ,
+ * all of which will show up if we don't strip it here (example: http://cl.ly/image/0J0N3z3h1i04 )
+ * first seen at http://houseofgeekery.com/2013/11/03/13-terrible-x-men-we-wont-see-in-the-movies/
+ */
+ public static String stripScript(final String text) {
+ if (text == null) {
+ return null;
+ }
+
+ StringBuilder sb = new StringBuilder(text);
+ int start = sb.indexOf("", start);
+ if (end == -1) {
+ return sb.toString();
+ }
+ sb.delete(start, end + 9);
+ start = sb.indexOf("