aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorSergei Kozelko <KozelkoS@yandex.ru>2023-01-21 04:51:44 +0000
committerGitHub <noreply@github.com>2023-01-21 04:51:44 +0000
commitc42f18369672769b14c2e8b2ec332dec005c446c (patch)
tree13801c57305a5acba97dec21eec0233ec639854f /app/src/main/java
parentaaa55a6af96c449e15fabf10e94abc6845c7d2a6 (diff)
downloadinfinity-for-reddit-c42f18369672769b14c2e8b2ec332dec005c446c.tar
infinity-for-reddit-c42f18369672769b14c2e8b2ec332dec005c446c.tar.gz
infinity-for-reddit-c42f18369672769b14c2e8b2ec332dec005c446c.tar.bz2
infinity-for-reddit-c42f18369672769b14c2e8b2ec332dec005c446c.tar.lz
infinity-for-reddit-c42f18369672769b14c2e8b2ec332dec005c446c.tar.xz
infinity-for-reddit-c42f18369672769b14c2e8b2ec332dec005c446c.tar.zst
infinity-for-reddit-c42f18369672769b14c2e8b2ec332dec005c446c.zip
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`.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java20
1 files changed, 11 insertions, 9 deletions
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);
+ }
}
}