Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,22 @@ private void showFeaturedImage(final View postView, final ReaderRelatedPost rela
}

// featured image has height set to MATCH_PARENT so wait for parent view's layout to complete
// before loading image so we can set the image height correctly
// before loading image so we can set the image height correctly, then tell the imageView
// to crop the downloaded image to fit the exact width/height of the view
postView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
postView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
String photonUrl = PhotonUtils.getPhotonImageUrl(relatedPost.getFeaturedImageUrl(), mFeaturedImageWidth, postView.getHeight());
imgFeatured.setImageUrl(photonUrl, WPNetworkImageView.ImageType.PHOTO);
int cropWidth = mFeaturedImageWidth;
int cropHeight = postView.getHeight();
String photonUrl = PhotonUtils.getPhotonImageUrl(
relatedPost.getFeaturedImageUrl(), cropWidth, cropHeight);
imgFeatured.setImageUrl(
photonUrl,
WPNetworkImageView.ImageType.PHOTO,
null,
cropWidth,
cropHeight);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.media.ThumbnailUtils;
import android.os.AsyncTask;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
Expand Down Expand Up @@ -60,6 +61,9 @@ public interface ImageLoadListener {
private int mDefaultImageResId;
private int mErrorImageResId;

private int mCropWidth;
private int mCropHeight;

private static final HashSet<String> mUrlSkipList = new HashSet<>();

public WPNetworkImageView(Context context) {
Expand All @@ -77,9 +81,25 @@ public void setImageUrl(String url, ImageType imageType) {
}

public void setImageUrl(String url, ImageType imageType, ImageLoadListener imageLoadListener) {
setImageUrl(url, imageType, imageLoadListener, 0, 0);
}

public void setImageUrl(String url,
ImageType imageType,
ImageLoadListener imageLoadListener,
int cropWidth,
int cropHeight) {
mUrl = url;
mImageType = imageType;

if (cropWidth > 0 && cropHeight > 0) {
mCropWidth = cropWidth;
mCropHeight = cropHeight;
} else {
mCropWidth = 0;
mCropHeight = 0;
}

// The URL has potentially changed. See if we need to load it.
loadImageIfNecessary(false, imageLoadListener);
}
Expand Down Expand Up @@ -258,6 +278,11 @@ private void handleResponse(ImageLoader.ImageContainer response, boolean isCache
setVisibility(View.VISIBLE);
}

// if cropping is requested, do it before further manipulation
if (mCropWidth > 0 && mCropHeight > 0) {
bitmap = ThumbnailUtils.extractThumbnail(bitmap, mCropWidth, mCropHeight);
}

// Apply circular rounding to avatars in a background task
if (mImageType == ImageType.AVATAR) {
new ShapeBitmapTask(ShapeType.CIRCLE, imageLoadListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bitmap);
Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/layout/reader_related_post.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
android:layout_width="@dimen/reader_related_post_image_width"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_large"
android:scaleType="fitXY"
android:scaleType="centerCrop"
android:visibility="gone"
tools:src="@drawable/box_with_pages_top"
tools:visibility="visible" />
Expand Down