Search in sources :

Example 1 with RatioImageView

use of com.abewy.android.extended.widget.RatioImageView in project Klyph by jonathangerbaud.

the class PhotoAlbumAdapter method mergeViewWithData.

@Override
protected void mergeViewWithData(View view, GraphObject data) {
    super.mergeViewWithData(view, data);
    final RatioImageView rImageView = (RatioImageView) view;
    Photo photo = (Photo) data;
    Collections.sort(photo.getImages(), new Comparator<Image>() {

        @Override
        public int compare(Image lhs, Image rhs) {
            if (lhs.getWidth() > rhs.getWidth())
                return 1;
            else if (lhs.getWidth() < rhs.getWidth())
                return -1;
            return 0;
        }
    });
    Image selectedImage = photo.getImages().get(0);
    rImageView.setImageSize(selectedImage.getWidth(), selectedImage.getHeight());
    if (placeHolder == -1)
        placeHolder = AttrUtil.getResourceId(getContext(view), R.attr.squarePlaceHolderIcon);
    loadImage(rImageView, selectedImage.getSrc(), placeHolder, data);
}
Also used : RatioImageView(com.abewy.android.extended.widget.RatioImageView) Photo(com.abewy.android.apps.klyph.core.fql.Media.Photo) Image(com.abewy.android.apps.klyph.core.fql.Media.Image)

Example 2 with RatioImageView

use of com.abewy.android.extended.widget.RatioImageView in project Klyph by jonathangerbaud.

the class StreamLink method manageVideoLink.

private void manageVideoLink(StreamHolder holder, Stream stream) {
    final Link link = stream.getLink();
    final View view = holder.getAuthorProfileImage();
    if (!stream.getActor_id().equals(link.getOwner()))
        new StreamHeader(specialLayout).mergeData(holder, stream, link);
    new StreamButtonBar(getParentAdapter(), specialLayout).mergeData(holder, stream, link);
    String url = "";
    int width = -1;
    int height = -1;
    if (link.isYoutubeLink()) {
        url = YoutubeUtil.getThumbUrl(link.getUrl());
        Log.d("StreamLink", "Youtube Link = " + link.getUrl() + " " + url);
        width = YoutubeUtil.THUMB_WIDTH;
        height = YoutubeUtil.THUMB_HEIGHT;
    } else if (link.isDailymotionLink()) {
        url = DailymotionUtil.getThumbUrl(link.getUrl());
        width = DailymotionUtil.THUMB_WIDTH;
        height = DailymotionUtil.THUMB_HEIGHT;
    } else if (link.isVimeoLink()) {
        url = VimeoUtil.getThumbUrl(link.getUrl());
        width = VimeoUtil.THUMB_WIDTH;
        height = VimeoUtil.THUMB_HEIGHT;
    }
    RatioImageView ratioImageView = (RatioImageView) holder.getPostPhoto();
    ratioImageView.setImageSize(width, height);
    loadImage(holder.getPostPhoto(), url, stream);
    holder.getPostPhoto().setVisibility(View.VISIBLE);
    holder.getPostVideoPlay().setVisibility(View.VISIBLE);
    ((ViewGroup) holder.getPostPhoto().getParent()).setVisibility(View.VISIBLE);
    if (link.getTitle().length() > 0) {
        holder.getVideoTitle().setText(link.getTitle());
        holder.getVideoTitle().setVisibility(View.VISIBLE);
        ((ViewGroup) holder.getVideoTitle().getParent()).setVisibility(View.VISIBLE);
    }
    if (link.getSummary().length() > 0) {
        holder.getMessage().setText(link.getSummary());
        holder.getMessage().setVisibility(View.VISIBLE);
    }
    holder.getPostPhoto().setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String url = link.getUrl();
            if (YoutubeUtil.isYoutubeLink(url) && YoutubeUtil.getVideoIdFromUrl(url).length() > 0) {
                Log.d("StreamLink", "isYoutubeVideo " + YoutubeUtil.getVideoIdFromUrl(url));
                try {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + YoutubeUtil.getVideoIdFromUrl(url)));
                    getContext(view).startActivity(intent);
                } catch (ActivityNotFoundException ex) {
                    Log.d("StreamLink", "ActivityNotFoundException");
                    PhoneUtil.openURL(getContext(view), url);
                }
            } else {
                Log.d("StreamLink", "not YoutubeVideo");
                PhoneUtil.openURL(getContext(view), url);
            }
        }
    });
}
Also used : 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) Link(com.abewy.android.apps.klyph.core.fql.Link)

Example 3 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 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 4 with RatioImageView

use of com.abewy.android.extended.widget.RatioImageView in project Klyph by jonathangerbaud.

the class CommentAdapter method mergeViewWithData.

@Override
protected void mergeViewWithData(View view, GraphObject data) {
    super.mergeViewWithData(view, data);
    Comment comment = (Comment) data;
    final CommentHolder holder = (CommentHolder) getHolder(view);
    holder.getDepthBar().setVisibility(comment.hasParentComment() ? View.VISIBLE : View.GONE);
    holder.getAuthorName().setAutoLinkMask(0);
    holder.getAuthorName().setText("");
    String name = comment.getFrom().getName();
    String time = DateUtil.timeAgoInWords(getContext(view), comment.getCreated_time());
    String text = name + "  " + time + "  ";
    holder.getAuthorName().setText(text);
    TextViewUtil.setElementClickable(getContext(view), holder.getAuthorName(), comment.getFrom().getName(), comment.getFrom().getId(), "user", false);
    Spannable styledText = new SpannableString(holder.getAuthorName().getText());
    TextAppearanceSpan span1 = new TextAppearanceSpan(getContext(holder.getAuthorName()), R.style.Klyph_CommentTextName);
    TextAppearanceSpan span2 = new TextAppearanceSpan(getContext(holder.getAuthorName()), R.style.Klyph_CommentTextTime);
    if (Android.isMinAPI(11))
        styledText.setSpan(span1, 0, name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    styledText.setSpan(span2, name.length() + 2, name.length() + 2 + time.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    holder.getAuthorName().setText(styledText);
    String commentText = comment.getMessage();
    int numLikes = comment.getLike_count();
    if (numLikes > 0) {
        if (commentText.length() > 0)
            commentText += "  ";
        commentText += numLikes + "  ";
    }
    final SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append(commentText);
    if (numLikes > 0) {
        ImageSpan span3 = new ImageSpan(getContext(holder.getAuthorName()), AttrUtil.getResourceId(getContext(holder.getAuthorName()), comment.getUser_likes() ? R.attr.userLikeSmallIcon : R.attr.likeIconSmall), DynamicDrawableSpan.ALIGN_BASELINE);
        TextAppearanceSpan span4 = new TextAppearanceSpan(getContext(holder.getAuthorName()), R.style.Klyph_CommentTextTime);
        int likesLength = String.valueOf(numLikes).length();
        sb.setSpan(span3, commentText.length() - 2, commentText.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        sb.setSpan(span4, commentText.length() - (likesLength + 2), commentText.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    holder.getCommentText().setText(sb);
    if (placeHolder == -1)
        placeHolder = KlyphUtil.getPlaceHolder(view.getContext());
    if (profilePlaceHolder == -1)
        profilePlaceHolder = KlyphUtil.getProfilePlaceHolder(view.getContext());
    ((ProfileImageView) holder.getAuthorPicture()).disableBorder();
    String url = comment.getFrom().getPicture().getUrl();
    loadImage(holder.getAuthorPicture(), url, profilePlaceHolder, data);
    holder.getCommentImage().setOnClickListener(null);
    holder.getCommentLinkImage().setOnClickListener(null);
    if (comment.getAttachment().isPhoto() || comment.getAttachment().isVideoShare()) {
        Image image = comment.getAttachment().getMedia().getImage();
        RatioImageView rImageview = (RatioImageView) holder.getCommentImage();
        rImageview.setImageSize(image.getWidth(), image.getHeight());
        int parentWidth = ((ViewGroup) holder.getCommentImage().getParent()).getWidth();
        if (parentWidth > 0) {
            LayoutParams params = holder.getCommentImage().getLayoutParams();
            params.width = Math.min(parentWidth, image.getWidth());
            holder.getCommentImage().setLayoutParams(params);
        }
        loadImage(holder.getCommentImage(), image.getSrc(), placeHolder, data);
        final Target target = comment.getAttachment().getTarget();
        holder.getCommentLinkImage().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(holder.getCommentImage()), ImageActivity.class);
                intent.putExtra(KlyphBundleExtras.PHOTO_ID, target.getId());
                getContext(holder.getCommentLinkImage()).startActivity(intent);
            }
        });
    } else if (comment.getAttachment().isShare()) {
        final Attachment att = comment.getAttachment();
        Image image = comment.getAttachment().getMedia().getImage();
        holder.getCommentLinkImageBackground().setColorFilter(colorFilter, PorterDuff.Mode.SRC_OVER);
        loadImage(holder.getCommentLinkImage(), image.getSrc(), placeHolder, data);
        loadImage(holder.getCommentLinkImageBackground(), image.getSrc(), placeHolder, data);
        holder.getCommentLinkName().setText(att.getTitle());
        holder.getCommentLinkUrl().setText(att.getUrl());
        holder.getCommentLinkDescription().setText(att.getDescription());
        holder.getCommentLinkImage().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                PhoneUtil.openURL(getContext(holder.getCommentLinkImage()), att.getUrl());
            }
        });
    }
    if (comment.getAttachment().isVideoShare())
        holder.getCommentImagePlay().setVisibility(View.VISIBLE);
    else
        holder.getCommentImagePlay().setVisibility(View.GONE);
    ((View) holder.getCommentImage().getParent()).setVisibility(comment.getAttachment().isPhoto() || comment.getAttachment().isVideoShare() ? View.VISIBLE : View.GONE);
    ((View) holder.getCommentLinkImage().getParent()).setVisibility(comment.getAttachment().isShare() ? View.VISIBLE : View.GONE);
}
Also used : Comment(com.abewy.android.apps.klyph.core.graph.Comment) ProfileImageView(com.abewy.android.apps.klyph.widget.ProfileImageView) TextAppearanceSpan(android.text.style.TextAppearanceSpan) LayoutParams(android.view.ViewGroup.LayoutParams) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) Attachment(com.abewy.android.apps.klyph.core.graph.Comment.Attachment) SpannableString(android.text.SpannableString) Image(com.abewy.android.apps.klyph.core.graph.Comment.Attachment.Media.Image) ImageView(android.widget.ImageView) View(android.view.View) ProfileImageView(com.abewy.android.apps.klyph.widget.ProfileImageView) TextView(android.widget.TextView) RatioImageView(com.abewy.android.extended.widget.RatioImageView) SpannableString(android.text.SpannableString) ImageActivity(com.abewy.android.apps.klyph.app.ImageActivity) Target(com.abewy.android.apps.klyph.core.graph.Comment.Attachment.Target) RatioImageView(com.abewy.android.extended.widget.RatioImageView) CommentHolder(com.abewy.android.apps.klyph.adapter.holder.CommentHolder) Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 5 with RatioImageView

use of com.abewy.android.extended.widget.RatioImageView in project Klyph by jonathangerbaud.

the class CommentAdapter method mergeViewWithData.

@Override
protected void mergeViewWithData(View view, GraphObject data) {
    super.mergeViewWithData(view, data);
    Comment comment = (Comment) data;
    final CommentHolder holder = (CommentHolder) getHolder(view);
    holder.getDepthBar().setVisibility(comment.hasParentComment() ? View.VISIBLE : View.GONE);
    holder.getAuthorName().setAutoLinkMask(0);
    holder.getAuthorName().setText("");
    String name = comment.getFrom_name();
    String time = DateUtil.timeAgoInWords(getContext(view), comment.getTime());
    String text = name + "  " + time + "  ";
    holder.getAuthorName().setText(text);
    TextViewUtil.setElementClickable(getContext(view), holder.getAuthorName(), comment.getFrom_name(), comment.getFromid(), comment.getFrom_type(), true);
    Spannable styledText = new SpannableString(holder.getAuthorName().getText());
    TextAppearanceSpan span1 = new TextAppearanceSpan(getContext(holder.getAuthorName()), R.style.Klyph_CommentTextName);
    TextAppearanceSpan span2 = new TextAppearanceSpan(getContext(holder.getAuthorName()), R.style.Klyph_CommentTextTime);
    if (Android.isMinAPI(11))
        styledText.setSpan(span1, 0, name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    styledText.setSpan(span2, name.length() + 2, name.length() + 2 + time.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    holder.getAuthorName().setText(styledText);
    String commentText = comment.getText();
    int numLikes = comment.getLikes();
    if (numLikes > 0) {
        if (commentText.length() > 0)
            commentText += "  ";
        commentText += numLikes + "  ";
    }
    final SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append(commentText);
    if (numLikes > 0) {
        ImageSpan span3 = new ImageSpan(getContext(holder.getAuthorName()), AttrUtil.getResourceId(getContext(holder.getAuthorName()), comment.getUser_likes() ? R.attr.userLikeSmallIcon : R.attr.likeIconSmall), DynamicDrawableSpan.ALIGN_BASELINE);
        TextAppearanceSpan span4 = new TextAppearanceSpan(getContext(holder.getAuthorName()), R.style.Klyph_CommentTextTime);
        int likesLength = String.valueOf(numLikes).length();
        sb.setSpan(span3, commentText.length() - 2, commentText.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        sb.setSpan(span4, commentText.length() - (likesLength + 2), commentText.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    holder.getCommentText().setText(sb);
    if (placeHolder == -1)
        placeHolder = AttrUtil.getResourceId(getContext(holder.getAuthorName()), R.attr.squarePlaceHolderIcon);
    if (profilePlaceHolder == -1)
        profilePlaceHolder = AttrUtil.getResourceId(getContext(holder.getAuthorName()), R.attr.circlePlaceHolderIcon);
    String url = comment.getFrom_pic();
    loadImage(holder.getAuthorPicture(), "http://www.google.com/abc/9.jpg", profilePlaceHolder, data);
    holder.getCommentImage().setOnClickListener(null);
    holder.getCommentLinkImage().setOnClickListener(null);
    if (comment.getAttachment().isPhoto()) {
        Image image = comment.getAttachment().getMedia().getImage();
        RatioImageView rImageView = (RatioImageView) holder.getCommentImage();
        rImageView.setImageSize(image.getWidth(), image.getHeight());
        loadImage(holder.getCommentImage(), image.getSrc(), placeHolder, data);
        final Target target = comment.getAttachment().getTarget();
        holder.getCommentLinkImage().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(holder.getCommentImage()), ImageActivity.class);
                intent.putExtra(KlyphBundleExtras.PHOTO_ID, target.getId());
                getContext(holder.getCommentLinkImage()).startActivity(intent);
            }
        });
    } else if (comment.getAttachment().isShare()) {
        final Attachment att = comment.getAttachment();
        Image image = comment.getAttachment().getMedia().getImage();
        holder.getCommentLinkImageBackground().setColorFilter(colorFilter, PorterDuff.Mode.SRC_OVER);
        loadImage(holder.getCommentLinkImage(), image.getSrc(), placeHolder, data);
        loadImage(holder.getCommentLinkImageBackground(), image.getSrc(), placeHolder, data);
        holder.getCommentLinkName().setText(att.getTitle());
        holder.getCommentLinkUrl().setText(att.getUrl());
        holder.getCommentLinkDescription().setText(att.getDescription());
        holder.getCommentLinkImage().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                PhoneUtil.openURL(getContext(holder.getCommentLinkImage()), att.getUrl());
            }
        });
    }
    holder.getCommentImage().setVisibility(comment.getAttachment().isPhoto() ? View.VISIBLE : View.GONE);
    ((View) holder.getCommentLinkImage().getParent()).setVisibility(comment.getAttachment().isShare() ? View.VISIBLE : View.GONE);
}
Also used : Comment(com.abewy.android.apps.klyph.core.fql.Comment) TextAppearanceSpan(android.text.style.TextAppearanceSpan) Intent(android.content.Intent) Attachment(com.abewy.android.apps.klyph.core.fql.Comment.Attachment) SpannableString(android.text.SpannableString) Image(com.abewy.android.apps.klyph.core.fql.Comment.Attachment.Media.Image) ImageView(android.widget.ImageView) View(android.view.View) ProfileImageView(com.abewy.android.apps.klyph.widget.ProfileImageView) TextView(android.widget.TextView) RatioImageView(com.abewy.android.extended.widget.RatioImageView) SpannableString(android.text.SpannableString) ImageActivity(com.abewy.android.apps.klyph.app.ImageActivity) Target(com.abewy.android.apps.klyph.core.fql.Comment.Attachment.Target) RatioImageView(com.abewy.android.extended.widget.RatioImageView) CommentHolder(com.abewy.android.apps.klyph.adapter.holder.CommentHolder) Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

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