From c42f18369672769b14c2e8b2ec332dec005c446c Mon Sep 17 00:00:00 2001 From: Sergei Kozelko Date: Sat, 21 Jan 2023 12:51:44 +0800 Subject: Disable aspect ratio logic when it is negative (#1296) Gallery can set aspect ratio to -1 which would result in negative measured height. It seem that Android treats dimensions as unsigned numbers, so negative numbers actually become huge positive numbers resulting in "infinite" height. It should be noted that this change allows to disable aspect ratio logic even when some dimension is set to `wrap_content`. --- .../customviews/AspectRatioGifImageView.java | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java index 5097849f..ebc64f54 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java @@ -44,16 +44,18 @@ public class AspectRatioGifImageView extends GifImageView { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); - int width = this.getMeasuredWidth(); - int height = this.getMeasuredHeight(); - if (width != 0 || height != 0) { - if (width > 0) { - height = (int) ((float) width * this.ratio); - } else { - width = (int) ((float) height / this.ratio); - } + if (this.ratio > 0) { + int width = this.getMeasuredWidth(); + int height = this.getMeasuredHeight(); + if (width != 0 || height != 0) { + if (width > 0) { + height = (int) ((float) width * this.ratio); + } else { + width = (int) ((float) height / this.ratio); + } - this.setMeasuredDimension(width, height); + this.setMeasuredDimension(width, height); + } } } -- cgit v1.2.3