MCPcopy Create free account
hub / github.com/M66B/FairEmail / call

Method call

app/src/extra/java/eu/faircode/email/Avatar.java:47–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 11

md5Method · 0.95
iMethod · 0.95
setUserAgentMethod · 0.95
getScaledBitmapMethod · 0.95
getEmailDomainMethod · 0.95
lookupMethod · 0.95
getInputStreamMethod · 0.65
getBytesMethod · 0.45
connectMethod · 0.45
toStringMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected