diff options
author | Aurash Mahbod <aurash@google.com> | 2013-08-14 13:37:39 -0700 |
---|---|---|
committer | Ficus Kirkpatrick <ficus@android.com> | 2014-02-08 15:09:17 -0800 |
commit | baa2ff70bea2dbfb89d6732902e6b2bd6de7d207 (patch) | |
tree | 34b76c8024590ebd7f44d14023133a886dbb257d /src | |
parent | 4e82015ef5f5de09ed03f58692b7c7e2295509c8 (diff) | |
download | volley-baa2ff70bea2dbfb89d6732902e6b2bd6de7d207.tar.gz |
Use the view size to restrict NIV requests.
Change-Id: Ib09a68c815f147ade31233d03267df687d8341e0
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/volley/toolbox/NetworkImageView.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/com/android/volley/toolbox/NetworkImageView.java b/src/com/android/volley/toolbox/NetworkImageView.java index 6fe857f..692e988 100644 --- a/src/com/android/volley/toolbox/NetworkImageView.java +++ b/src/com/android/volley/toolbox/NetworkImageView.java @@ -100,15 +100,19 @@ public class NetworkImageView extends ImageView { * Loads the image for the view if it isn't already loaded. * @param isInLayoutPass True if this was invoked from a layout pass, false otherwise. */ - private void loadImageIfNecessary(final boolean isInLayoutPass) { + void loadImageIfNecessary(final boolean isInLayoutPass) { int width = getWidth(); int height = getHeight(); - boolean isFullyWrapContent = getLayoutParams() != null - && getLayoutParams().height == LayoutParams.WRAP_CONTENT - && getLayoutParams().width == LayoutParams.WRAP_CONTENT; + boolean wrapWidth = false, wrapHeight = false; + if (getLayoutParams() != null) { + wrapWidth = getLayoutParams().width == LayoutParams.WRAP_CONTENT; + wrapHeight = getLayoutParams().height == LayoutParams.WRAP_CONTENT; + } + // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content // view, hold off on loading the image. + boolean isFullyWrapContent = wrapWidth && wrapHeight; if (width == 0 && height == 0 && !isFullyWrapContent) { return; } @@ -136,6 +140,10 @@ public class NetworkImageView extends ImageView { } } + // Calculate the max image width / height to use while ignoring WRAP_CONTENT dimens. + int maxWidth = wrapWidth ? 0 : width; + int maxHeight = wrapHeight ? 0 : height; + // The pre-existing content of this view didn't match the current URL. Load the new image // from the network. ImageContainer newContainer = mImageLoader.get(mUrl, @@ -169,7 +177,7 @@ public class NetworkImageView extends ImageView { setImageResource(mDefaultImageId); } } - }); + }, maxWidth, maxHeight); // update the ImageContainer to be the new bitmap container. mImageContainer = newContainer; |