diff --git a/app/src/main/java/eu/faircode/email/ContactInfo.java b/app/src/main/java/eu/faircode/email/ContactInfo.java index ed3e231f5c..98301d4db4 100644 --- a/app/src/main/java/eu/faircode/email/ContactInfo.java +++ b/app/src/main/java/eu/faircode/email/ContactInfo.java @@ -317,6 +317,7 @@ public class ContactInfo { else info.bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); else { + final int scaleToPixels = Helper.dp2pixels(context, 48); final URL base = new URL("https://" + domain); final URL www = new URL("https://www." + domain); @@ -325,28 +326,28 @@ public class ContactInfo { futures.add(executorFavicon.submit(new Callable() { @Override public Bitmap call() throws Exception { - return parseFavicon(base); + return parseFavicon(base, scaleToPixels); } })); futures.add(executorFavicon.submit(new Callable() { @Override public Bitmap call() throws Exception { - return parseFavicon(www); + return parseFavicon(www, scaleToPixels); } })); futures.add(executorFavicon.submit(new Callable() { @Override public Bitmap call() throws Exception { - return getFavicon(new URL(base, "favicon.ico")); + return getFavicon(new URL(base, "favicon.ico"), scaleToPixels); } })); futures.add(executorFavicon.submit(new Callable() { @Override public Bitmap call() throws Exception { - return getFavicon(new URL(www, "favicon.ico")); + return getFavicon(new URL(www, "favicon.ico"), scaleToPixels); } })); @@ -421,7 +422,7 @@ public class ContactInfo { return info; } - private static Bitmap parseFavicon(URL base) throws IOException { + private static Bitmap parseFavicon(URL base, int scaleToPixels) throws IOException { Log.i("GET favicon " + base); HttpsURLConnection connection = (HttpsURLConnection) base.openConnection(); connection.setRequestMethod("GET"); @@ -452,13 +453,13 @@ public class ContactInfo { } if (!TextUtils.isEmpty(favicon)) - return getFavicon(new URL(base, favicon)); + return getFavicon(new URL(base, favicon), scaleToPixels); return null; } @NonNull - private static Bitmap getFavicon(URL url) throws IOException { + private static Bitmap getFavicon(URL url, int scaleToPixels) throws IOException { Log.i("GET favicon " + url); if (!"https".equals(url.getProtocol())) @@ -472,7 +473,7 @@ public class ContactInfo { connection.connect(); try { - Bitmap bitmap = BitmapFactory.decodeStream(connection.getInputStream()); + Bitmap bitmap = ImageHelper.getScaledBitmap(connection.getInputStream(), url.toString(), scaleToPixels); if (bitmap == null) throw new FileNotFoundException("decodeStream"); else { diff --git a/app/src/main/java/eu/faircode/email/ImageHelper.java b/app/src/main/java/eu/faircode/email/ImageHelper.java index 9b8e11f3d4..5092879fd2 100644 --- a/app/src/main/java/eu/faircode/email/ImageHelper.java +++ b/app/src/main/java/eu/faircode/email/ImageHelper.java @@ -623,7 +623,7 @@ class ImageHelper { break; } - bm = getScaledBitmap(urlConnection.getInputStream(), source, dm); + bm = getScaledBitmap(urlConnection.getInputStream(), source, dm.widthPixels); } finally { if (urlConnection != null) urlConnection.disconnect(); @@ -646,7 +646,7 @@ class ImageHelper { return d; } - private static Bitmap getScaledBitmap(InputStream is, String source, DisplayMetrics dm) throws IOException { + static Bitmap getScaledBitmap(InputStream is, String source, int scaleToPixels) throws IOException { BufferedInputStream bis = new BufferedInputStream(is); Log.i("Probe " + source); @@ -655,7 +655,6 @@ class ImageHelper { options.inJustDecodeBounds = true; BitmapFactory.decodeStream(bis, null, options); - int scaleToPixels = dm.widthPixels; int factor = 1; while (options.outWidth / factor > scaleToPixels) factor *= 2;