Search in sources :

Example 1 with Format

use of com.abewy.android.apps.klyph.core.fql.Video.Format in project Klyph by jonathangerbaud.

the class VideoAdapter method mergeViewWithData.

@Override
protected void mergeViewWithData(View view, GraphObject data) {
    VideoHolder holder = (VideoHolder) view.getTag();
    //holder.getPhoto().setImageDrawable(null);
    Video video = (Video) data;
    Collections.sort(video.getFormat(), new Comparator<Format>() {

        @Override
        public int compare(Format lhs, Format rhs) {
            if (lhs.getWidth() > rhs.getWidth())
                return 1;
            else if (lhs.getWidth() < rhs.getWidth())
                return -1;
            return 0;
        }
    });
    Format selectedFormat = video.getFormat().get(0);
    for (Format format : video.getFormat()) {
        if (format.getWidth() > columnWidth) {
            selectedFormat = format;
            break;
        }
    }
    if (placeHolder == -1)
        placeHolder = AttrUtil.getResourceId(getContext(holder.getName()), R.attr.squarePlaceHolderIcon);
    loadImage(holder.getPhoto(), selectedFormat.getPicture(), placeHolder, data);
    if (video.getTitle().length() == 0) {
        holder.getName().setVisibility(View.GONE);
    } else {
        holder.getName().setText(video.getTitle());
        holder.getName().setVisibility(View.VISIBLE);
    }
}
Also used : VideoHolder(com.abewy.android.apps.klyph.adapter.holder.VideoHolder) Format(com.abewy.android.apps.klyph.core.fql.Video.Format) Video(com.abewy.android.apps.klyph.core.fql.Video)

Example 2 with Format

use of com.abewy.android.apps.klyph.core.fql.Video.Format in project Klyph by jonathangerbaud.

the class StreamPhoto method mergeData.

public void mergeData(StreamHolder holder, final Stream stream, final Video video) {
    if (!stream.getActor_id().equals(video.getOwner())) {
        new StreamHeader(specialLayout).mergeData(holder, stream, video);
    }
    new StreamButtonBar(getParentAdapter(), specialLayout).mergeData(holder, stream, video);
    Format selectedFormat = null;
    for (Format format : video.getFormat()) {
        if (format.getWidth() > KlyphDevice.getDeviceWidth()) {
            selectedFormat = format;
            break;
        }
    }
    if (selectedFormat == null) {
        selectedFormat = video.getFormat().get(video.getFormat().size() - 1);
    }
    holder.getPostPhoto().setScaleType(ScaleType.FIT_XY);
    RatioImageView ratioImageView = (RatioImageView) holder.getPostPhoto();
    ratioImageView.setImageSize(selectedFormat.getWidth(), selectedFormat.getHeight());
    loadImage(holder.getPostPhoto(), selectedFormat.getPicture());
    holder.getPostPhoto().setVisibility(View.VISIBLE);
    holder.getPostVideoPlay().setVisibility(View.VISIBLE);
    ((ViewGroup) holder.getPostPhoto().getParent()).setVisibility(View.VISIBLE);
    if (video.getTitle().length() > 0) {
        holder.getVideoTitle().setText(video.getTitle());
        holder.getVideoTitle().setVisibility(View.VISIBLE);
        ((ViewGroup) holder.getVideoTitle().getParent()).setVisibility(View.VISIBLE);
    }
    if (video.getDescription().length() > 0) {
        holder.getMessage().setText(video.getDescription());
        holder.getMessage().setVisibility(View.VISIBLE);
    }
    final View view = holder.getAuthorProfileImage();
    holder.getPostPhoto().setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.d("StreamPhoto", "onClickVideo " + video.getSrc_hq());
            if (video.getSrc_hq().contains(".mp4") == true) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(video.getSrc_hq()));
                intent.setDataAndType(Uri.parse(video.getSrc_hq()), "video/mp4");
                try {
                    getContext(view).startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    PhoneUtil.openURL(getContext(view), video.getSrc_hq());
                }
            } else {
                PhoneUtil.openURL(getContext(view), video.getSrc_hq());
            }
        }
    });
}
Also used : Format(com.abewy.android.apps.klyph.core.fql.Video.Format) ActivityNotFoundException(android.content.ActivityNotFoundException) 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)

Example 3 with Format

use of com.abewy.android.apps.klyph.core.fql.Video.Format in project Klyph by jonathangerbaud.

the class VideoDeserializer method deserializeObject.

@Override
public GraphObject deserializeObject(JSONObject data) {
    Video video = new Video();
    deserializePrimitives(video, data);
    video.setFormat(new FormatDeserializer().deserializeArray(getJsonArray(data, "format"), Format.class));
    return video;
}
Also used : Format(com.abewy.android.apps.klyph.core.fql.Video.Format) Video(com.abewy.android.apps.klyph.core.fql.Video)

Example 4 with Format

use of com.abewy.android.apps.klyph.core.fql.Video.Format 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)

Aggregations

Format (com.abewy.android.apps.klyph.core.fql.Video.Format)4 Video (com.abewy.android.apps.klyph.core.fql.Video)2 RatioImageView (com.abewy.android.extended.widget.RatioImageView)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ViewGroup (android.view.ViewGroup)1 VideoHolder (com.abewy.android.apps.klyph.adapter.holder.VideoHolder)1 Image (com.abewy.android.apps.klyph.core.fql.Media.Image)1