Skip to content

Commit

Permalink
Allow match_parent/wrap_content view dimensions
Browse files Browse the repository at this point in the history
By default if the view has wrap_content for either
the width or the height (or both), we will load
the image in at the original size. Trying to apply
either FitCenter or CenterCrop to the load will
still result in an exception since we would need
concrete sizes to transform the image.
  • Loading branch information
Sam Judd committed Sep 3, 2013
1 parent e3fd7cf commit 0815f83
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion library/src/com/bumptech/glide/Glide.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public void teardown() {
}
}


/**
* Return the current {@link ImageManager} or create and return a new one if one is not currently set.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ private void releaseAcquired() {

protected boolean isHandled(int width, int height) {
return width >= 0 && height >= 0 ||
(downsampler == Downsampler.NONE && width == WRAP_CONTENT && height == WRAP_CONTENT);
(downsampler == Downsampler.NONE && (width == WRAP_CONTENT || height == WRAP_CONTENT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public abstract class Transformation {
public static Transformation CENTER_CROP = new Transformation() {
@Override
public Bitmap transform(Bitmap bitmap, BitmapPool pool, int outWidth, int outHeight) {
if (outWidth <= 0 || outHeight <= 0) {
throw new IllegalArgumentException("Cannot center crop image to width=" + outWidth + " and height="
+ outHeight);
}
return ImageResizer.centerCrop(pool.get(outWidth, outHeight), bitmap, outWidth, outHeight);
}
};
Expand All @@ -29,6 +33,10 @@ public Bitmap transform(Bitmap bitmap, BitmapPool pool, int outWidth, int outHei
public static Transformation FIT_CENTER = new Transformation() {
@Override
public Bitmap transform(Bitmap bitmap, BitmapPool pool, int outWidth, int outHeight) {
if (outWidth <= 0 || outHeight <= 0) {
throw new IllegalArgumentException("Cannot fit center image to within width=" + outWidth + " or height="
+ outHeight);
}
return ImageResizer.fitInSpace(bitmap, outWidth, outHeight);
}
};
Expand Down
8 changes: 8 additions & 0 deletions library/tests/src/com/bumptech/glide/GlideTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ public void testCanHandleWrapContent() {
assertNotNull(getImagePresenterFromView());
}

public void testCanHandleWrapContentMatchParent() {
imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT));
Glide.load("fake").into(imageView);

assertNotNull(getImagePresenterFromView());
}

public void testDifferentModelTypesReplacesPresenters() {
assertDifferentPresenters(
Glide.load(4),
Expand Down

0 comments on commit 0815f83

Please sign in to comment.