made image preview size smaller for low res images

This commit is contained in:
Daniel Gultsch 2016-08-25 13:46:33 +02:00
parent 6f72128c45
commit f1ecbf2ff8
1 changed files with 14 additions and 8 deletions

View File

@ -448,16 +448,22 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.image.setVisibility(View.VISIBLE); viewHolder.image.setVisibility(View.VISIBLE);
FileParams params = message.getFileParams(); FileParams params = message.getFileParams();
double target = metrics.density * 288; double target = metrics.density * 288;
int scalledW; int scaledW;
int scalledH; int scaledH;
if (params.width <= params.height) { if (Math.max(params.height, params.width) * metrics.density <= target) {
scalledW = (int) (params.width / ((double) params.height / target)); scaledW = (int) (params.width * metrics.density);
scalledH = (int) target; 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 { } else {
scalledW = (int) target; scaledW = (int) target;
scalledH = (int) (params.height / ((double) params.width / 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)); layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4));
viewHolder.image.setLayoutParams(layoutParams); viewHolder.image.setLayoutParams(layoutParams);
activity.loadBitmap(message, viewHolder.image); activity.loadBitmap(message, viewHolder.image);