use of com.abewy.android.extended.widget.RatioImageView in project Klyph by jonathangerbaud.
the class StreamMedia method loadMedia.
protected void loadMedia(ImageView imageView, Media media, Stream stream, boolean setDimensions) {
int width = 0;
int height = 0;
String source = "";
if (media.isVideo()) {
if (media.isFacebookVideo()) {
Format selectedFormat = null;
for (Format format : media.getVideo().getFormat()) {
if (format.getWidth() > getMaxWidth()) {
selectedFormat = format;
break;
}
}
if (selectedFormat == null) {
selectedFormat = media.getVideo().getFormat().get(media.getVideo().getFormat().size() - 1);
}
width = selectedFormat.getWidth();
height = selectedFormat.getHeight();
source = selectedFormat.getPicture();
} else // Youtube video
if (media.isYoutubeVideo()) {
width = 480;
height = 360;
source = media.getYoutubeThumbnail();
} else // Dailymotion video
if (media.isDailymotionVideo()) {
width = 427;
height = 240;
source = media.getDailymotionThumbnail();
} else if (media.isVimeoVideo()) {
width = 640;
height = 476;
source = media.getVimeoThumbnail();
} else {
width = -1;
height = -1;
source = media.getHref();
Log.d("StreamMedia", "unknownType " + media.getHref());
}
} else {
if (media.getPhoto().getImages().size() > 0) {
/*List<Image> images = media.getPhoto().getImages();
Image selectedImage = images.get(0);
for (int i = 1, n = images.size(); i < n; i++)
{
Image image = images.get(i);
if (image.getWidth() < getMaxWidth())
{
break;
}
selectedImage = image;
}*/
Image selectedImage = null;
for (Image image : media.getPhoto().getImages()) {
if (image.getWidth() > getMaxWidth()) {
selectedImage = image;
break;
}
}
if (selectedImage == null) {
selectedImage = media.getPhoto().getImages().get(media.getPhoto().getImages().size() - 1);
if (media.getPhoto().getWidth() > getMaxWidth()) {
/*
* int imageDifference = maxWidth -
* selectedImage.getWidth();
* int mediaDifference = media.getPhoto().getWidth() -
* maxWidth;
*
* if (imageDifference < mediaDifference)
* {
* width = selectedImage.getWidth();
* height = selectedImage.getHeight();
* source = selectedImage.getSrc();
* }
* else
* {
*/
width = media.getPhoto().getWidth();
height = media.getPhoto().getHeight();
source = getSource(media.getSrc());
// }
} else {
if (media.getPhoto().getWidth() > selectedImage.getWidth()) {
width = media.getPhoto().getWidth();
height = media.getPhoto().getHeight();
source = getSource(media.getSrc());
} else {
width = selectedImage.getWidth();
height = selectedImage.getHeight();
source = selectedImage.getSrc();
}
}
} else {
width = selectedImage.getWidth();
height = selectedImage.getHeight();
source = selectedImage.getSrc();
}
} else {
width = media.getPhoto().getWidth();
height = media.getPhoto().getHeight();
source = getSource(media.getSrc());
}
}
if (setDimensions == true) {
RatioImageView ratioImageView = (RatioImageView) imageView;
ratioImageView.setImageSize(width, height);
}
loadImage(imageView, source, stream);
}
use of com.abewy.android.extended.widget.RatioImageView in project Klyph by jonathangerbaud.
the class StreamPhoto method mergeData.
public void mergeData(StreamHolder holder, final Stream stream, final Photo photo) {
if (!stream.getActor_id().equals(photo.getOwner())) {
new StreamHeader(specialLayout).mergeData(holder, stream, photo);
}
new StreamButtonBar(getParentAdapter(), specialLayout).mergeData(holder, stream, photo);
holder.getPostPhoto().setScaleType(ScaleType.FIT_XY);
RatioImageView i = (RatioImageView) holder.getPostPhoto();
i.setImageSize(photo.getSrc_big_width(), photo.getSrc_big_height());
loadImage(holder.getPostPhoto(), photo.getSrc_big());
holder.getPostPhoto().setVisibility(View.VISIBLE);
((ViewGroup) holder.getPostPhoto().getParent()).setVisibility(View.VISIBLE);
if (photo.getCaption().length() > 0) {
holder.getMessage().setText(photo.getCaption());
holder.getMessage().setVisibility(View.VISIBLE);
}
final View view = holder.getAuthorProfileImage();
holder.getPostPhoto().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(view), ImageActivity.class);
intent.putExtra(KlyphBundleExtras.PHOTO_ID, photo.getObject_id());
intent.putExtra(KlyphBundleExtras.URL_IF_NOT_FOUND, getSource(photo.getSrc_big()));
getContext(view).startActivity(intent);
}
});
}
Aggregations