Skip to content

Commit

Permalink
Setting a default image, or an error image, will clear previous image…
Browse files Browse the repository at this point in the history
…s. (google#243)

The most recent call to the setter will be what determines the default/error
image, instead of erroring out on conflicts.
  • Loading branch information
aaijazi authored and jpd236 committed Nov 29, 2018
1 parent 1ec8e6e commit 4c1a945
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/main/java/com/android/volley/toolbox/NetworkImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,51 +100,43 @@ public void setImageUrl(String url, ImageLoader imageLoader) {
* Sets the default image resource ID to be used for this view until the attempt to load it
* completes.
*
* <p>Cannot be called with {@link NetworkImageView#setDefaultImageBitmap}.
* <p>This will clear anything set by {@link NetworkImageView#setDefaultImageBitmap}.
*/
public void setDefaultImageResId(int defaultImage) {
if (mDefaultImageBitmap != null) {
throw new IllegalArgumentException("Can't have a default image resource ID and bitmap");
}
mDefaultImageBitmap = null;
mDefaultImageId = defaultImage;
}

/**
* Sets the default image bitmap to be used for this view until the attempt to load it
* completes.
*
* <p>Cannot be called with {@link NetworkImageView#setDefaultImageResId}.
* <p>This will clear anything set by {@link NetworkImageView#setDefaultImageResId}.
*/
public void setDefaultImageBitmap(Bitmap defaultImage) {
if (mDefaultImageId != 0) {
throw new IllegalArgumentException("Can't have a default image resource ID and bitmap");
}
mDefaultImageId = 0;
mDefaultImageBitmap = defaultImage;
}

/**
* Sets the error image resource ID to be used for this view in the event that the image
* requested fails to load.
*
* <p>Cannot be called with {@link NetworkImageView#setErrorImageBitmap}.
* <p>This will clear anything set by {@link NetworkImageView#setErrorImageBitmap}.
*/
public void setErrorImageResId(int errorImage) {
if (mErrorImageBitmap != null) {
throw new IllegalArgumentException("Can't have an error image resource ID and bitmap");
}
mErrorImageBitmap = null;
mErrorImageId = errorImage;
}

/**
* Sets the error image bitmap to be used for this view in the event that the image requested
* fails to load.
*
* <p>Cannot be called with {@link NetworkImageView#setErrorImageResId}.
* <p>This will clear anything set by {@link NetworkImageView#setErrorImageResId}.
*/
public void setErrorImageBitmap(Bitmap errorImage) {
if (mErrorImageId != 0) {
throw new IllegalArgumentException("Can't have an error image resource ID and bitmap");
}
mErrorImageId = 0;
mErrorImageBitmap = errorImage;
}

Expand Down

0 comments on commit 4c1a945

Please sign in to comment.