Created
August 26, 2014 18:47
-
-
Save px-amaac/89c9aba413ea39fc6eef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void bindTo(FSStore item, Picasso picasso) { | |
targetImage = item.getImage(); | |
picasso.setLoggingEnabled(true); | |
imageRequest = picasso.load(targetImage.getUrl()); | |
distance.setText(String.valueOf(item.getDistance()) + "miles away"); | |
imageAspectRatio = 1f * targetImage.getWidth() / targetImage.getHeight(); | |
requestLayout(); | |
} | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
int mode = MeasureSpec.getMode(widthMeasureSpec); | |
if (mode != MeasureSpec.EXACTLY) { | |
throw new IllegalStateException("layout_width must be match_parent"); | |
} | |
int columnWidth = MeasureSpec.getSize(widthMeasureSpec); | |
if(mContext != null) { | |
distanceHeight = Utils.getTextHeight(mContext, distance.getText() + "miles away", distance.getTextSize(), columnWidth); | |
} | |
// Honor aspect ratio for height but no larger than 2x width. | |
int imageHeight = Math.min((int) (columnWidth / imageAspectRatio), columnWidth * 2); | |
int imageHeightMeasureSpec = MeasureSpec.makeMeasureSpec(imageHeight, MeasureSpec.EXACTLY); | |
int textHeightMeasureSpec = MeasureSpec.makeMeasureSpec(distanceHeight, MeasureSpec.EXACTLY); | |
super.onMeasure(widthMeasureSpec, imageHeightMeasureSpec + textHeightMeasureSpec); | |
if (imageRequest != null) { | |
imageRequest.resize(columnWidth, imageHeight).into(image); | |
imageRequest = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment