Search in sources :

Example 21 with LayoutParams

use of android.view.ViewGroup.LayoutParams 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 22 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project SmartAndroidSource by jaychou2012.

the class RatioDrawable method getWidth.

private int getWidth(ImageView iv) {
    int width = 0;
    LayoutParams lp = iv.getLayoutParams();
    if (lp != null)
        width = lp.width;
    if (width <= 0) {
        width = iv.getWidth();
    }
    if (width > 0) {
        width = width - iv.getPaddingLeft() - iv.getPaddingRight();
    }
    return width;
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams)

Example 23 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project Klyph by jonathangerbaud.

the class AlbumAdapter method setLayoutParams.

@Override
public void setLayoutParams(View view) {
    int cellWidth = getCellWidth(view);
    LayoutParams lp = view.getLayoutParams();
    lp.height = (int) cellWidth / 2;
    view.setLayoutParams(lp);
// int padding = (int) getContext(view).getResources().getDimension(R.dimen.ckoobafe_list_padding) / 2;
// view.setPadding(view.getPaddingLeft(), padding, view.getPaddingRight(), padding);
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams)

Example 24 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project SmartAndroidSource by jaychou2012.

the class AbstractAQuery method margin.

/**
	 * Set the margin of a view. Notes all parameters are in DIP, not in pixel.
	 *
	 * @param leftDip the left dip
	 * @param topDip the top dip
	 * @param rightDip the right dip
	 * @param bottomDip the bottom dip
	 * @return self
	 */
public T margin(float leftDip, float topDip, float rightDip, float bottomDip) {
    if (view != null) {
        LayoutParams lp = view.getLayoutParams();
        if (lp instanceof MarginLayoutParams) {
            Context context = getContext();
            int left = AQUtility.dip2pixel(context, leftDip);
            int top = AQUtility.dip2pixel(context, topDip);
            int right = AQUtility.dip2pixel(context, rightDip);
            int bottom = AQUtility.dip2pixel(context, bottomDip);
            ((MarginLayoutParams) lp).setMargins(left, top, right, bottom);
            view.setLayoutParams(lp);
        }
    }
    return self();
}
Also used : Context(android.content.Context) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LayoutParams(android.view.ViewGroup.LayoutParams) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) Paint(android.graphics.Paint)

Example 25 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project SmartAndroidSource by jaychou2012.

the class AbstractAQuery method size.

private void size(boolean width, int n, boolean dip) {
    if (view != null) {
        LayoutParams lp = view.getLayoutParams();
        Context context = getContext();
        if (n > 0 && dip) {
            n = AQUtility.dip2pixel(context, n);
        }
        if (width) {
            lp.width = n;
        } else {
            lp.height = n;
        }
        view.setLayoutParams(lp);
    }
}
Also used : Context(android.content.Context) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LayoutParams(android.view.ViewGroup.LayoutParams)

Aggregations

LayoutParams (android.view.ViewGroup.LayoutParams)263 TextView (android.widget.TextView)54 View (android.view.View)50 ViewGroup (android.view.ViewGroup)50 FrameLayout (android.widget.FrameLayout)35 LinearLayout (android.widget.LinearLayout)32 ImageView (android.widget.ImageView)30 Test (org.junit.Test)26 ListView (android.widget.ListView)22 ScrollView (android.widget.ScrollView)22 Paint (android.graphics.Paint)21 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)19 Context (android.content.Context)18 AdapterView (android.widget.AdapterView)17 RelativeLayout (android.widget.RelativeLayout)14 DisplayMetrics (android.util.DisplayMetrics)12 CheckedTextView (android.widget.CheckedTextView)12 Rect (android.graphics.Rect)9 ViewParent (android.view.ViewParent)9 TypedArray (android.content.res.TypedArray)8