From 4b60560a9fb4a3936d58d33d79a9201f1f083967 Mon Sep 17 00:00:00 2001 From: inorichi Date: Thu, 28 Jan 2016 18:26:43 +0100 Subject: [PATCH] Add smart fit. Closes #85 --- app/src/main/res/values/arrays.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ .../subscaleview/SubsamplingScaleImageView.java | 13 +++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index a2399ed968..6bf5ed0823 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -54,6 +54,7 @@ @string/scale_type_fit_width @string/scale_type_fit_height @string/scale_type_original_size + @string/scale_type_smart_fit @@ -62,6 +63,7 @@ 3 4 5 + 6 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2e4b5775be..1424644e7d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -103,6 +103,8 @@ Fit width Fit height Original size + Smart fit + Downloads directory diff --git a/libs/SubsamplingScaleImageView/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java b/libs/SubsamplingScaleImageView/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java index 0c86220999..40830d40a2 100644 --- a/libs/SubsamplingScaleImageView/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java +++ b/libs/SubsamplingScaleImageView/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java @@ -124,11 +124,12 @@ public class SubsamplingScaleImageView extends View { public static final int SCALE_TYPE_FIT_WIDTH = 3; public static final int SCALE_TYPE_FIT_HEIGHT = 4; public static final int SCALE_TYPE_ORIGINAL_SIZE = 5; + public static final int SCALE_TYPE_SMART_FIT = 6; /** Scale the image so that both dimensions of the image will be equal to or less than the maxScale and equal to or larger than minScale. The image is then centered in the view. */ - public static final int SCALE_TYPE_CUSTOM = 6; + public static final int SCALE_TYPE_CUSTOM = 7; - private static final List VALID_SCALE_TYPES = Arrays.asList(SCALE_TYPE_CENTER_CROP, SCALE_TYPE_CENTER_INSIDE, SCALE_TYPE_CUSTOM, SCALE_TYPE_FIT_WIDTH, SCALE_TYPE_FIT_HEIGHT, SCALE_TYPE_ORIGINAL_SIZE); + private static final List VALID_SCALE_TYPES = Arrays.asList(SCALE_TYPE_CENTER_CROP, SCALE_TYPE_CENTER_INSIDE, SCALE_TYPE_CUSTOM, SCALE_TYPE_FIT_WIDTH, SCALE_TYPE_FIT_HEIGHT, SCALE_TYPE_SMART_FIT, SCALE_TYPE_ORIGINAL_SIZE); // Bitmap (preview or full image) private Bitmap bitmap; @@ -2019,6 +2020,14 @@ public class SubsamplingScaleImageView extends View { return (getHeight() - vPadding) / (float) sHeight(); case SCALE_TYPE_ORIGINAL_SIZE: return 1; + case SCALE_TYPE_SMART_FIT: + if (sWidth <= sHeight) { + // Fit to width + return (getWidth() - hPadding) / (float) sWidth(); + } else { + // Fit to height + return (getHeight() - vPadding) / (float) sHeight(); + } case SCALE_TYPE_CUSTOM: return minScale; }