[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge branch 'develop' into feature/modularize-editor
Browse files Browse the repository at this point in the history
Conflicts:
	WordPress/src/main/java/org/wordpress/android/ui/accounts/ManageBlogsActivity.java
  • Loading branch information
maxme committed Feb 9, 2015
2 parents ac92a69 + f4ba322 commit d328cf6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +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);
public static String gravatarFromEmail(final String email, int size) {
return "http://gravatar.com/avatar/"
+ StringUtils.getMd5Hash(StringUtils.notNullStr(email))
+ "?d=mm&size=" + Integer.toString(size);
}

return url;
/*
* important: the 404 default means the request will 404 if there is no blavatar
* for the passed site - so the caller needs to trap the 404 to provide a default
*/
public static String blavatarFromUrl(final String url, int size) {
return "http://gravatar.com/blavatar/"
+ StringUtils.getMd5Hash(UrlUtils.getDomainFromUrl(url))
+ "?d=404&size=" + Integer.toString(size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* http://developer.wordpress.com/docs/photon/
*/
public class PhotonUtils {

private PhotonUtils() {
throw new AssertionError();
}
Expand Down Expand Up @@ -73,30 +74,29 @@ public static String getPhotonImageUrl(String imageUrl, int width, int height, Q
return imageUrl + "?w=" + width + "&h=" + height;
}

final String qualityParam;
// strip=all removes EXIF and other non-visual data from JPEGs
String query = "?strip=all";

switch (quality) {
case HIGH:
qualityParam = "quality=100";
query += "&quality=100";
break;
case LOW:
qualityParam = "quality=35";
query += "&quality=35";
break;
default: // medium
qualityParam = "quality=65";
query += "&quality=65";
break;
}

// if both width & height are passed use the "resize" param, use only "w" or "h" if just
// one of them is set
final String query;
if (width > 0 && height > 0) {
query = "?resize=" + width + "," + height + "&" + qualityParam;
query += "&resize=" + width + "," + height;
} else if (width > 0) {
query = "?w=" + width + "&" + qualityParam;
query += "&w=" + width;
} else if (height > 0) {
query = "?h=" + height + "&" + qualityParam;
} else {
query = "?" + qualityParam;
query += "&h=" + height;
}

// return passed url+query if it's already a photon url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;

import org.wordpress.android.util.AppLog.T;

import java.io.UnsupportedEncodingException;
import java.net.IDN;
import java.net.URI;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -52,11 +55,40 @@ public static String convertUrlToPunycodeIfNeeded(String url) {
return url;
}

/**
* Remove leading double slash, and inherit protocol scheme
*/
public static String removeLeadingDoubleSlash(String url, String scheme) {
if (url != null && url.startsWith("//")) {
url = url.substring(2);
if (scheme != null) {
if (scheme.endsWith("://")){
url = scheme + url;
} else {
AppLog.e(T.UTILS, "Invalid scheme used: " + scheme);
}
}
}
return url;
}

/**
* Add scheme prefix to an URL. This method must be called on all user entered or server fetched URLs to ensure
* http client will work as expected.
*
* @param url url entered by the user or fetched from a server
* @param isHTTPS true will make the url starts with https;//
* @return transformed url prefixed by its http;// or https;// scheme
*/
public static String addUrlSchemeIfNeeded(String url, boolean isHTTPS) {
if (url == null) {
return null;
}

// Remove leading double slash (eg. //example.com), needed for some wporg instances configured to
// switch between http or https
url = removeLeadingDoubleSlash(url, (isHTTPS ? "https" : "http") + "://");

if (!URLUtil.isValidUrl(url)) {
if (!(url.toLowerCase().startsWith("http://")) && !(url.toLowerCase().startsWith("https://"))) {
url = (isHTTPS ? "https" : "http") + "://" + url;
Expand All @@ -78,7 +110,8 @@ public static String normalizeUrl(final String urlString) {
// this routine is called from some performance-critical code and creating a URI from a string
// is slow, so skip it when possible - if we know it's not a relative path (and 99.9% of the
// time it won't be for our purposes) then we can normalize it without java.net.URI.normalize()
if (urlString.startsWith("http") && !urlString.contains("build/intermediates/exploded-aar/org.wordpress/graphview/3.1.1")) {
if (urlString.startsWith("http") &&
!urlString.contains("build/intermediates/exploded-aar/org.wordpress/graphview/3.1.1")) {
// return without a trailing slash
if (urlString.endsWith("/")) {
return urlString.substring(0, urlString.length() - 1);
Expand Down

0 comments on commit d328cf6

Please sign in to comment.