diff --git a/picasso/src/main/java/com/squareup/picasso/Request.java b/picasso/src/main/java/com/squareup/picasso/Request.java index 1a3fe045f3..342748ab03 100644 --- a/picasso/src/main/java/com/squareup/picasso/Request.java +++ b/picasso/src/main/java/com/squareup/picasso/Request.java @@ -54,6 +54,10 @@ public final class Request { public final String stableKey; /** List of custom transformations to be applied after the built-in transformations. */ public final List transformations; + /** Original image width. */ + public final int width; + /** Original image height. */ + public final int height; /** Target image width for resizing. */ public final int targetWidth; /** Target image height for resizing. */ @@ -85,9 +89,9 @@ public final class Request { public final Priority priority; private Request(Uri uri, int resourceId, String stableKey, List transformations, - int targetWidth, int targetHeight, boolean centerCrop, boolean centerInside, - boolean onlyScaleDown, float rotationDegrees, float rotationPivotX, float rotationPivotY, - boolean hasRotationPivot, Bitmap.Config config, Priority priority) { + int width, int height, int targetWidth, int targetHeight, boolean centerCrop, + boolean centerInside, boolean onlyScaleDown, float rotationDegrees, float rotationPivotX, + float rotationPivotY, boolean hasRotationPivot, Bitmap.Config config, Priority priority) { this.uri = uri; this.resourceId = resourceId; this.stableKey = stableKey; @@ -96,6 +100,8 @@ private Request(Uri uri, int resourceId, String stableKey, List } else { this.transformations = unmodifiableList(transformations); } + this.width = width; + this.height = height; this.targetWidth = targetWidth; this.targetHeight = targetHeight; this.centerCrop = centerCrop; @@ -167,6 +173,10 @@ String getName() { return Integer.toHexString(resourceId); } + public boolean hasOriginalSize() { + return width != 0 || height != 0; + } + public boolean hasSize() { return targetWidth != 0 || targetHeight != 0; } @@ -192,6 +202,8 @@ public static final class Builder { private Uri uri; private int resourceId; private String stableKey; + private int width; + private int height; private int targetWidth; private int targetHeight; private boolean centerCrop; @@ -225,6 +237,8 @@ private Builder(Request request) { uri = request.uri; resourceId = request.resourceId; stableKey = request.stableKey; + width = request.width; + height = request.height; targetWidth = request.targetWidth; targetHeight = request.targetHeight; centerCrop = request.centerCrop; @@ -245,6 +259,10 @@ boolean hasImage() { return uri != null || resourceId != 0; } + boolean hasOriginalSize() { + return width != 0 || height != 0; + } + boolean hasSize() { return targetWidth != 0 || targetHeight != 0; } @@ -290,6 +308,15 @@ public Builder stableKey(String stableKey) { return this; } + /** + * Set the original image size. + */ + public Builder originalSize(int width, int height) { + this.width = width; + this.height = height; + return this; + } + /** * Resize the image to the specified size in pixels. * Use 0 as desired dimension to resize keeping aspect ratio. @@ -465,9 +492,9 @@ public Request build() { if (priority == null) { priority = Priority.NORMAL; } - return new Request(uri, resourceId, stableKey, transformations, targetWidth, targetHeight, - centerCrop, centerInside, onlyScaleDown, rotationDegrees, rotationPivotX, rotationPivotY, - hasRotationPivot, config, priority); + return new Request(uri, resourceId, stableKey, transformations, width, height, targetWidth, + targetHeight, centerCrop, centerInside, onlyScaleDown, rotationDegrees, rotationPivotX, + rotationPivotY, hasRotationPivot, config, priority); } } } diff --git a/picasso/src/main/java/com/squareup/picasso/RequestCreator.java b/picasso/src/main/java/com/squareup/picasso/RequestCreator.java index ae9da6b079..b7f0071976 100644 --- a/picasso/src/main/java/com/squareup/picasso/RequestCreator.java +++ b/picasso/src/main/java/com/squareup/picasso/RequestCreator.java @@ -206,6 +206,12 @@ RequestCreator unfit() { return this; } + /** Set the original image size. */ + public RequestCreator originalSize(int width, int height) { + data.originalSize(width, height); + return this; + } + /** Resize the image to the specified dimension size. */ public RequestCreator resizeDimen(int targetWidthResId, int targetHeightResId) { Resources resources = picasso.context.getResources();