aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorSam Judd <sam@bu.mp>2013-07-12 20:02:55 -0700
committerSam Judd <sam@bu.mp>2013-07-15 11:41:33 -0700
commit64b6d88e922b1818976a45ed30754b18e9b9e6e7 (patch)
tree28a3a27c3bdd95bdd2e3ec305a5b74ad3caa7fa1 /samples
parent806522ed49bab96c11780a7986bd16767d1a0226 (diff)
downloadglide-64b6d88e922b1818976a45ed30754b18e9b9e6e7.tar.gz
Fix flickr api return url for incorrect image size
HashMap.keySet is not ordered :(
Diffstat (limited to 'samples')
-rw-r--r--samples/flickr/src/com/bumptech/flickr/api/Api.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/samples/flickr/src/com/bumptech/flickr/api/Api.java b/samples/flickr/src/com/bumptech/flickr/api/Api.java
index 8c98f19f..1755d44f 100644
--- a/samples/flickr/src/com/bumptech/flickr/api/Api.java
+++ b/samples/flickr/src/com/bumptech/flickr/api/Api.java
@@ -10,6 +10,7 @@ import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -37,20 +38,25 @@ public class Api {
put(150, "q");
put(240, "m");
put(320, "n");
- put(500, "-");
put(640, "z");
put(1024, "b");
- put(Integer.MAX_VALUE, "o");
}};
+
+ private static final List<Integer> SORTED_SIZE_KEYS = new ArrayList<Integer>(EDGE_TO_SIZE_KEY.size());
+ static {
+ SORTED_SIZE_KEYS.addAll(EDGE_TO_SIZE_KEY.keySet());
+ Collections.sort(SORTED_SIZE_KEYS);
+ }
private final String sizeKey;
private static String getSizeKey(int width, int height) {
- final int largestEdge = width > height ? width : height;
+ final int largestEdge = Math.max(width, height);
- final String result = EDGE_TO_SIZE_KEY.get(Integer.MAX_VALUE);
- for (int edge : EDGE_TO_SIZE_KEY.keySet()) {
+ String result = EDGE_TO_SIZE_KEY.get(SORTED_SIZE_KEYS.get(SORTED_SIZE_KEYS.size() - 1));
+ for (int edge : SORTED_SIZE_KEYS) {
if (largestEdge <= edge) {
- return EDGE_TO_SIZE_KEY.get(edge);
+ result = EDGE_TO_SIZE_KEY.get(edge);
+ break;
}
}
return result;