|
|
@ -28,7 +28,7 @@ import com.android.volley.toolbox.ImageLoader.ImageListener; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Custom version of NetworkImageView |
|
|
|
* Custom version of NetworkImageView |
|
|
|
* |
|
|
|
* <p/> |
|
|
|
* Handles fetching an image from a URL as well as the life-cycle of the |
|
|
|
* Handles fetching an image from a URL as well as the life-cycle of the |
|
|
|
* associated request. |
|
|
|
* associated request. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -66,6 +66,9 @@ public class CustomNetworkImageView extends ImageView { |
|
|
|
|
|
|
|
|
|
|
|
private int mFadeTime; |
|
|
|
private int mFadeTime; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int mForcedWidth = -1; |
|
|
|
|
|
|
|
private int mForcedHeight = -1; |
|
|
|
|
|
|
|
|
|
|
|
public CustomNetworkImageView(Context context) { |
|
|
|
public CustomNetworkImageView(Context context) { |
|
|
|
this(context, null); |
|
|
|
this(context, null); |
|
|
|
} |
|
|
|
} |
|
|
@ -91,6 +94,11 @@ public class CustomNetworkImageView extends ImageView { |
|
|
|
return mMaxScale; |
|
|
|
return mMaxScale; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void forceImageDimensions(int w, int h) { |
|
|
|
|
|
|
|
mForcedWidth = w; |
|
|
|
|
|
|
|
mForcedHeight = h; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getUrl() { |
|
|
|
public String getUrl() { |
|
|
|
return mUrl; |
|
|
|
return mUrl; |
|
|
|
} |
|
|
|
} |
|
|
@ -109,7 +117,7 @@ public class CustomNetworkImageView extends ImageView { |
|
|
|
* calling this will immediately either set the cached image (if available) |
|
|
|
* calling this will immediately either set the cached image (if available) |
|
|
|
* or the default image specified by |
|
|
|
* or the default image specified by |
|
|
|
* {@link CustomNetworkImageView#setDefaultImageResId(int)} on the view. |
|
|
|
* {@link CustomNetworkImageView#setDefaultImageResId(int)} on the view. |
|
|
|
* |
|
|
|
* <p/> |
|
|
|
* NOTE: If applicable, |
|
|
|
* NOTE: If applicable, |
|
|
|
* {@link CustomNetworkImageView#setDefaultImageResId(int)} and |
|
|
|
* {@link CustomNetworkImageView#setDefaultImageResId(int)} and |
|
|
|
* {@link CustomNetworkImageView#setErrorImageResId(int)} should be called |
|
|
|
* {@link CustomNetworkImageView#setErrorImageResId(int)} should be called |
|
|
@ -150,10 +158,14 @@ public class CustomNetworkImageView extends ImageView { |
|
|
|
* @param isInLayoutPass True if this was invoked from a layout pass, false otherwise. |
|
|
|
* @param isInLayoutPass True if this was invoked from a layout pass, false otherwise. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void loadImageIfNecessary(final boolean isInLayoutPass) { |
|
|
|
void loadImageIfNecessary(final boolean isInLayoutPass) { |
|
|
|
int width = getWidth(); |
|
|
|
int width; |
|
|
|
int height = getHeight(); |
|
|
|
int height; |
|
|
|
|
|
|
|
|
|
|
|
boolean wrapWidth = false, wrapHeight = false; |
|
|
|
boolean wrapWidth = false, wrapHeight = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mForcedWidth < 0 || mForcedHeight < 0) { |
|
|
|
|
|
|
|
width = getWidth(); |
|
|
|
|
|
|
|
height = getHeight(); |
|
|
|
|
|
|
|
|
|
|
|
if (getLayoutParams() != null) { |
|
|
|
if (getLayoutParams() != null) { |
|
|
|
wrapWidth = getLayoutParams().width == LayoutParams.WRAP_CONTENT; |
|
|
|
wrapWidth = getLayoutParams().width == LayoutParams.WRAP_CONTENT; |
|
|
|
wrapHeight = getLayoutParams().height == LayoutParams.WRAP_CONTENT; |
|
|
|
wrapHeight = getLayoutParams().height == LayoutParams.WRAP_CONTENT; |
|
|
@ -166,6 +178,10 @@ public class CustomNetworkImageView extends ImageView { |
|
|
|
if (width == 0 && height == 0 && !isFullyWrapContent) { |
|
|
|
if (width == 0 && height == 0 && !isFullyWrapContent) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
width = mForcedWidth; |
|
|
|
|
|
|
|
height = mForcedHeight; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// if the URL to be loaded in this view is empty, cancel any old
|
|
|
|
// if the URL to be loaded in this view is empty, cancel any old
|
|
|
|
// requests and clear the
|
|
|
|
// requests and clear the
|
|
|
|