Force image dimensions in pin thumbnails.

captchafix
Floens 11 years ago
parent 7f3d2a7213
commit 95b8ebe725
  1. 2
      Clover/app/src/main/java/org/floens/chan/ui/adapter/PinnedAdapter.java
  2. 26
      Clover/app/src/main/java/org/floens/chan/ui/view/CustomNetworkImageView.java

@ -35,6 +35,7 @@ import org.floens.chan.R;
import org.floens.chan.core.ChanPreferences; import org.floens.chan.core.ChanPreferences;
import org.floens.chan.core.model.Pin; import org.floens.chan.core.model.Pin;
import org.floens.chan.ui.view.CustomNetworkImageView; import org.floens.chan.ui.view.CustomNetworkImageView;
import org.floens.chan.utils.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -121,6 +122,7 @@ public class PinnedAdapter extends BaseAdapter {
if (pin.thumbnailUrl != null) { if (pin.thumbnailUrl != null) {
imageView.setVisibility(View.VISIBLE); imageView.setVisibility(View.VISIBLE);
imageView.setFadeIn(0); imageView.setFadeIn(0);
imageView.forceImageDimensions(Utils.dp(48), Utils.dp(48));
imageView.setImageUrl(pin.thumbnailUrl, ChanApplication.getVolleyImageLoader()); imageView.setImageUrl(pin.thumbnailUrl, ChanApplication.getVolleyImageLoader());
} else { } else {
imageView.setVisibility(View.GONE); imageView.setVisibility(View.GONE);

@ -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

Loading…
Cancel
Save