Add smart fit. Closes #85

This commit is contained in:
inorichi 2016-01-28 18:26:43 +01:00
parent 733b0da461
commit 4b60560a9f
3 changed files with 15 additions and 2 deletions

View File

@ -54,6 +54,7 @@
<item>@string/scale_type_fit_width</item>
<item>@string/scale_type_fit_height</item>
<item>@string/scale_type_original_size</item>
<item>@string/scale_type_smart_fit</item>
</string-array>
<string-array name="image_scale_type_values">
@ -62,6 +63,7 @@
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
</string-array>
<string-array name="library_update_interval">

View File

@ -103,6 +103,8 @@
<string name="scale_type_fit_width">Fit width</string>
<string name="scale_type_fit_height">Fit height</string>
<string name="scale_type_original_size">Original size</string>
<string name="scale_type_smart_fit">Smart fit</string>
<!-- Downloads section -->
<string name="pref_download_directory">Downloads directory</string>

View File

@ -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<Integer> 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<Integer> 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;
}