From f1ecbf2ff8ea9788341f9e1a33906e2f81c55cc6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 25 Aug 2016 13:46:33 +0200 Subject: [PATCH] made image preview size smaller for low res images --- .../ui/adapter/MessageAdapter.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 56517e3bc..6763f3f52 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -448,16 +448,22 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.image.setVisibility(View.VISIBLE); FileParams params = message.getFileParams(); double target = metrics.density * 288; - int scalledW; - int scalledH; - if (params.width <= params.height) { - scalledW = (int) (params.width / ((double) params.height / target)); - scalledH = (int) target; + int scaledW; + int scaledH; + if (Math.max(params.height, params.width) * metrics.density <= target) { + scaledW = (int) (params.width * metrics.density); + scaledH = (int) (params.height * metrics.density); + } else if (Math.max(params.height,params.width) <= target) { + scaledW = params.width; + scaledH = params.height; + } else if (params.width <= params.height) { + scaledW = (int) (params.width / ((double) params.height / target)); + scaledH = (int) target; } else { - scalledW = (int) target; - scalledH = (int) (params.height / ((double) params.width / target)); + scaledW = (int) target; + scaledH = (int) (params.height / ((double) params.width / target)); } - LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scalledW, scalledH); + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scaledW, scaledH); layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4)); viewHolder.image.setLayoutParams(layoutParams); activity.loadBitmap(message, viewHolder.image);