Skip to content

Commit

Permalink
Switched to quality enum which defaults to medium
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Jan 24, 2015
1 parent 455855b commit e8555a5
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ public static boolean isMshotsUrl(final String imageUrl) {
/*
* returns a photon url for the passed image with the resize query set to the passed dimensions
*/
private static final String QUALITY_PARAM = "quality=65";
public static enum Quality {
HIGH,
MEDIUM,
LOW,
}
public static String getPhotonImageUrl(String imageUrl, int width, int height) {
return getPhotonImageUrl(imageUrl, width, height, Quality.MEDIUM);
}
public static String getPhotonImageUrl(String imageUrl, int width, int height, Quality quality) {
if (TextUtils.isEmpty(imageUrl)) {
return "";
}
Expand Down Expand Up @@ -68,17 +75,30 @@ public static String getPhotonImageUrl(String imageUrl, int width, int height) {
return imageUrl + "?w=" + width + "&h=" + height;
}

final String qualityParam;
switch (quality) {
case HIGH:
qualityParam = "quality=100";
break;
case LOW:
qualityParam = "quality=35";
break;
default: // medium
qualityParam = "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 - note that the passed quality parameter will only affect JPEGs
final String query;
if (width > 0 && height > 0) {
query = "?resize=" + width + "," + height + "&" + QUALITY_PARAM;
query = "?resize=" + width + "," + height + "&" + qualityParam;
} else if (width > 0) {
query = "?w=" + width + "&" + QUALITY_PARAM;
query = "?w=" + width + "&" + qualityParam;
} else if (height > 0) {
query = "?h=" + height + "&" + QUALITY_PARAM;
query = "?h=" + height + "&" + qualityParam;
} else {
query = "?" + QUALITY_PARAM;
query = "?" + qualityParam;
}

// return passed url+query if it's already a photon url
Expand Down

0 comments on commit e8555a5

Please sign in to comment.