From d502a7ae77b8545b212f023cb9a8057c61f6afa4 Mon Sep 17 00:00:00 2001 From: jsjem Date: Wed, 17 May 2017 14:50:24 +0300 Subject: [PATCH 1/2] Fix closest ratio size lookup --- .../florent37/camerafragment/internal/utils/CameraHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/utils/CameraHelper.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/utils/CameraHelper.java index a893f4f..cc90048 100644 --- a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/utils/CameraHelper.java +++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/utils/CameraHelper.java @@ -251,7 +251,7 @@ public final class CameraHelper { double ratio = (double) size.getHeight() / size.getWidth(); - if (Math.abs(ratio - targetRatio) < MIN_TOLERANCE) MIN_TOLERANCE = ratio; + if (Math.abs(ratio - targetRatio) < MIN_TOLERANCE) MIN_TOLERANCE = Math.abs(ratio - targetRatio); else continue; if (Math.abs(size.getHeight() - targetHeight) < minDiff) { @@ -325,7 +325,7 @@ public final class CameraHelper { double ratio = (double) size.getHeight() / size.getWidth(); - if (Math.abs(ratio - targetRatio) < MIN_TOLERANCE) MIN_TOLERANCE = ratio; + if (Math.abs(ratio - targetRatio) < MIN_TOLERANCE) MIN_TOLERANCE = Math.abs(ratio - targetRatio); else continue; if (Math.abs(size.getHeight() - targetHeight) < minDiff) { From dc3fd9c509513c1e6b140bfed25b85898b8ebfdd Mon Sep 17 00:00:00 2001 From: jsjem Date: Wed, 17 May 2017 15:55:27 +0300 Subject: [PATCH 2/2] improve preview size lookup --- .../camerafragment/internal/utils/CameraHelper.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/utils/CameraHelper.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/utils/CameraHelper.java index cc90048..8a59493 100644 --- a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/utils/CameraHelper.java +++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/utils/CameraHelper.java @@ -251,7 +251,10 @@ public final class CameraHelper { double ratio = (double) size.getHeight() / size.getWidth(); - if (Math.abs(ratio - targetRatio) < MIN_TOLERANCE) MIN_TOLERANCE = Math.abs(ratio - targetRatio); + if (Math.abs(ratio - targetRatio) < MIN_TOLERANCE) { + MIN_TOLERANCE = Math.abs(ratio - targetRatio); + minDiff = Double.MAX_VALUE; + } else continue; if (Math.abs(size.getHeight() - targetHeight) < minDiff) { @@ -325,7 +328,10 @@ public final class CameraHelper { double ratio = (double) size.getHeight() / size.getWidth(); - if (Math.abs(ratio - targetRatio) < MIN_TOLERANCE) MIN_TOLERANCE = Math.abs(ratio - targetRatio); + if (Math.abs(ratio - targetRatio) < MIN_TOLERANCE) { + MIN_TOLERANCE = Math.abs(ratio - targetRatio); + minDiff = Double.MAX_VALUE; + } else continue; if (Math.abs(size.getHeight() - targetHeight) < minDiff) {