Search in sources :

Example 21 with TextPaint

use of android.text.TextPaint in project plaid by nickbutcher.

the class DynamicTextView method fitMultiline.

private void fitMultiline() {
    int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    int targetHeight = getHeight() - getPaddingTop() - getPaddingBottom();
    if (targetWidth > 0 && targetHeight > 0) {
        int textSize = mMaxTextSize;
        TextPaint paint = getPaint();
        paint.setTextSize(textSize);
        StaticLayout staticLayout = new StaticLayout(getText(), paint, targetWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
        int currentHeight = staticLayout.getHeight();
        while (currentHeight > targetHeight && textSize > mMinTextSize) {
            textSize--;
            paint.setTextSize(textSize);
            staticLayout = new StaticLayout(getText(), paint, targetWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
            currentHeight = staticLayout.getHeight();
        }
        setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        setTextAlignment(TEXT_ALIGNMENT_TEXT_START);
        mCalculated = true;
    }
}
Also used : StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint)

Example 22 with TextPaint

use of android.text.TextPaint in project plaid by nickbutcher.

the class DynamicTextView method fitSnappedMultiLine.

private void fitSnappedMultiLine() {
    int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    int targetHeight = getHeight() - getPaddingTop() - getPaddingBottom();
    if (targetWidth > 0 && targetHeight > 0) {
        int style = 0;
        MaterialTypeStyle currentStyle = mStyles[style];
        TextPaint paint = getPaint();
        StaticLayout staticLayout = null;
        int currentHeight = Integer.MAX_VALUE;
        int lines = 0;
        boolean maxLinesSet = getMaxLines() != Integer.MAX_VALUE;
        while ((currentHeight > targetHeight || (maxLinesSet && lines > getMaxLines())) && style <= mStyles.length - 1 && currentStyle.size * scaledDensity >= mMinTextSize && currentStyle.size * scaledDensity <= mMaxTextSize) {
            currentStyle = mStyles[style];
            paint.setTextSize(currentStyle.size * scaledDensity);
            paint.setTypeface(Typeface.create(currentStyle.fontFamily, Typeface.NORMAL));
            staticLayout = new StaticLayout(getText(), paint, targetWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
            currentHeight = staticLayout.getHeight();
            lines = staticLayout.getLineCount();
            style++;
        }
        super.setTextSize(TypedValue.COMPLEX_UNIT_SP, currentStyle.size);
        setTypeface(Typeface.create(currentStyle.fontFamily, Typeface.NORMAL));
        int currentColour = getCurrentTextColor();
        setTextColor(Color.argb(currentStyle.opacity, Color.red(currentColour), Color.green(currentColour), Color.blue(currentColour)));
        if (style == mStyles.length) {
            setEllipsize(TextUtils.TruncateAt.END);
        }
        if (currentStyle.size * scaledDensity < mMinTextSize) {
            // wanted to make text smaller but hit min text size.  Need to set max lines.
            setMaxLines((int) Math.floor((((float) targetHeight / (float) currentHeight) * lines)));
            setEllipsize(TextUtils.TruncateAt.END);
        }
        setTextAlignment(TEXT_ALIGNMENT_TEXT_START);
        mCalculated = true;
    }
}
Also used : StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint)

Example 23 with TextPaint

use of android.text.TextPaint in project plaid by nickbutcher.

the class FabOverlapTextView method init.

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FabOverlapTextView);
    float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP, getResources().getDisplayMetrics());
    setFabOverlapGravity(a.getInt(R.styleable.FabOverlapTextView_fabGravity, Gravity.BOTTOM | Gravity.RIGHT));
    setFabOverlapHeight(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayHeight, 0));
    setFabOverlapWidth(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayWidth, 0));
    if (a.hasValue(R.styleable.FabOverlapTextView_android_textAppearance)) {
        final int textAppearance = a.getResourceId(R.styleable.FabOverlapTextView_android_textAppearance, android.R.style.TextAppearance);
        TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.FontTextAppearance);
        paint.setColor(atp.getColor(R.styleable.FontTextAppearance_android_textColor, Color.BLACK));
        paint.setTextSize(atp.getDimensionPixelSize(R.styleable.FontTextAppearance_android_textSize, (int) defaultTextSize));
        if (atp.hasValue(R.styleable.FontTextAppearance_font)) {
            paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.FontTextAppearance_font)));
        }
        atp.recycle();
    }
    if (a.hasValue(R.styleable.FabOverlapTextView_font)) {
        setFont(a.getString(R.styleable.FabOverlapTextView_font));
    }
    if (a.hasValue(R.styleable.FabOverlapTextView_android_textColor)) {
        setTextColor(a.getColor(R.styleable.FabOverlapTextView_android_textColor, 0));
    }
    if (a.hasValue(R.styleable.FabOverlapTextView_android_textSize)) {
        setTextSize(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_android_textSize, (int) defaultTextSize));
    }
    lineHeightHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_lineHeightHint, 0);
    unalignedTopPadding = getPaddingTop();
    unalignedBottomPadding = getPaddingBottom();
    breakStrategy = a.getInt(R.styleable.FabOverlapTextView_android_breakStrategy, Layout.BREAK_STRATEGY_BALANCED);
    a.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint)

Example 24 with TextPaint

use of android.text.TextPaint in project weiciyuan by qii.

the class AbstractAppListAdapter method buildHolder.

//weibo image widgets and its forward weibo image widgets are the same
private ViewHolder buildHolder(View convertView) {
    ViewHolder holder = new ViewHolder();
    holder.username = ViewUtility.findViewById(convertView, R.id.username);
    TextPaint tp = holder.username.getPaint();
    if (tp != null) {
        tp.setFakeBoldText(true);
    }
    holder.content = ViewUtility.findViewById(convertView, R.id.content);
    holder.repost_content = ViewUtility.findViewById(convertView, R.id.repost_content);
    holder.time = ViewUtility.findViewById(convertView, R.id.time);
    holder.avatar = (TimeLineAvatarImageView) convertView.findViewById(R.id.avatar);
    holder.repost_content_pic = (IWeiciyuanDrawable) convertView.findViewById(R.id.repost_content_pic);
    holder.repost_content_pic_multi = ViewUtility.findViewById(convertView, R.id.repost_content__pic_multi);
    holder.content_pic = holder.repost_content_pic;
    holder.content_pic_multi = holder.repost_content_pic_multi;
    holder.listview_root = ViewUtility.findViewById(convertView, R.id.listview_root);
    holder.repost_layout = ViewUtility.findViewById(convertView, R.id.repost_layout);
    holder.repost_flag = ViewUtility.findViewById(convertView, R.id.repost_flag);
    holder.count_layout = ViewUtility.findViewById(convertView, R.id.count_layout);
    holder.repost_count = ViewUtility.findViewById(convertView, R.id.repost_count);
    holder.comment_count = ViewUtility.findViewById(convertView, R.id.comment_count);
    holder.timeline_gps = ViewUtility.findViewById(convertView, R.id.timeline_gps_iv);
    holder.timeline_pic = ViewUtility.findViewById(convertView, R.id.timeline_pic_iv);
    holder.replyIV = ViewUtility.findViewById(convertView, R.id.replyIV);
    holder.source = ViewUtility.findViewById(convertView, R.id.source);
    return holder;
}
Also used : TextPaint(android.text.TextPaint)

Example 25 with TextPaint

use of android.text.TextPaint in project weiciyuan by qii.

the class BrowserWeiboMsgCommentAndRepostAdapter method buildHolder.

private ViewHolder buildHolder(View convertView) {
    ViewHolder holder = new ViewHolder();
    holder.username = ViewUtility.findViewById(convertView, R.id.username);
    TextPaint tp = holder.username.getPaint();
    tp.setFakeBoldText(true);
    holder.content = ViewUtility.findViewById(convertView, R.id.content);
    holder.time = ViewUtility.findViewById(convertView, R.id.time);
    holder.avatar = (TimeLineAvatarImageView) convertView.findViewById(R.id.avatar);
    holder.listview_root = ViewUtility.findViewById(convertView, R.id.listview_root);
    holder.reply = ViewUtility.findViewById(convertView, R.id.replyIV);
    return holder;
}
Also used : TextPaint(android.text.TextPaint)

Aggregations

TextPaint (android.text.TextPaint)216 Paint (android.graphics.Paint)86 StaticLayout (android.text.StaticLayout)29 View (android.view.View)17 Bitmap (android.graphics.Bitmap)14 Typeface (android.graphics.Typeface)14 TypedArray (android.content.res.TypedArray)12 SpannableString (android.text.SpannableString)12 RectF (android.graphics.RectF)11 Spanned (android.text.Spanned)11 TextView (android.widget.TextView)11 Rect (android.graphics.Rect)8 StyleSpan (android.text.style.StyleSpan)8 ClickableSpan (android.text.style.ClickableSpan)7 PackageManager (android.content.pm.PackageManager)6 Canvas (android.graphics.Canvas)6 IBinder (android.os.IBinder)6 SpannableStringBuilder (android.text.SpannableStringBuilder)6 Context (android.content.Context)5 Resources (android.content.res.Resources)5