()
| 45 | static Callable<ContactInfo.Favicon> getGravatar(String email, int scaleToPixels, Context context) { |
| 46 | return new Callable<ContactInfo.Favicon>() { |
| 47 | @Override |
| 48 | public ContactInfo.Favicon call() throws Exception { |
| 49 | String hash = Helper.md5(email.getBytes()); |
| 50 | URL url = new URL(GRAVATAR_URI + hash + "?d=404"); |
| 51 | Log.i("Gravatar key=" + email + " url=" + url); |
| 52 | |
| 53 | HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); |
| 54 | urlConnection.setRequestMethod("GET"); |
| 55 | urlConnection.setReadTimeout(GRAVATAR_READ_TIMEOUT); |
| 56 | urlConnection.setConnectTimeout(GRAVATAR_CONNECT_TIMEOUT); |
| 57 | ConnectionHelper.setUserAgent(context, urlConnection); |
| 58 | urlConnection.connect(); |
| 59 | |
| 60 | try { |
| 61 | int status = urlConnection.getResponseCode(); |
| 62 | if (status == HttpsURLConnection.HTTP_OK) { |
| 63 | // Positive reply |
| 64 | Bitmap bitmap = ImageHelper.getScaledBitmap(urlConnection.getInputStream(), url.toString(), null, scaleToPixels); |
| 65 | return (bitmap == null ? null : new ContactInfo.Favicon(bitmap, "gravatar", false)); |
| 66 | } else if (status == HttpsURLConnection.HTTP_NOT_FOUND) { |
| 67 | // Negative reply |
| 68 | return null; |
| 69 | } else |
| 70 | throw new IOException("Error " + status + ": " + urlConnection.getResponseMessage()); |
| 71 | } finally { |
| 72 | urlConnection.disconnect(); |
| 73 | } |
| 74 | } |
| 75 | }; |
| 76 | } |
| 77 |
nothing calls this directly
no test coverage detected