Search in sources :

Example 6 with RatioImageView

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);
}
Also used : Format(com.abewy.android.apps.klyph.core.fql.Video.Format) RatioImageView(com.abewy.android.extended.widget.RatioImageView) Image(com.abewy.android.apps.klyph.core.fql.Media.Image)

Example 7 with RatioImageView

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);
        }
    });
}
Also used : ImageActivity(com.abewy.android.apps.klyph.app.ImageActivity) ViewGroup(android.view.ViewGroup) OnClickListener(android.view.View.OnClickListener) RatioImageView(com.abewy.android.extended.widget.RatioImageView) Intent(android.content.Intent) View(android.view.View) RatioImageView(com.abewy.android.extended.widget.RatioImageView)

Aggregations

RatioImageView (com.abewy.android.extended.widget.RatioImageView)7 Intent (android.content.Intent)5 View (android.view.View)5 ViewGroup (android.view.ViewGroup)4 OnClickListener (android.view.View.OnClickListener)3 ImageActivity (com.abewy.android.apps.klyph.app.ImageActivity)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Spannable (android.text.Spannable)2 SpannableString (android.text.SpannableString)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 ImageSpan (android.text.style.ImageSpan)2 TextAppearanceSpan (android.text.style.TextAppearanceSpan)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 CommentHolder (com.abewy.android.apps.klyph.adapter.holder.CommentHolder)2 Image (com.abewy.android.apps.klyph.core.fql.Media.Image)2 Format (com.abewy.android.apps.klyph.core.fql.Video.Format)2 ProfileImageView (com.abewy.android.apps.klyph.widget.ProfileImageView)2 LayoutParams (android.view.ViewGroup.LayoutParams)1 Comment (com.abewy.android.apps.klyph.core.fql.Comment)1