Example usage for android.text TextPaint setFlags

List of usage examples for android.text TextPaint setFlags

Introduction

In this page you can find the example usage for android.text TextPaint setFlags.

Prototype

public void setFlags(int flags) 

Source Link

Document

Set the paint's flags.

Usage

From source file:se.attentec.attenhome.TypefaceSpan.java

@Override
public void updateDrawState(TextPaint tp) {
    tp.setTypeface(mTypeface);/*  w w w.j a va 2  s .  c  o m*/
    tp.setTextSize(mTextSize);
    tp.setColor(mColor);
    // Note: This flag is required for proper typeface rendering
    tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}

From source file:com.raspi.chatapp.util.Notification.java

private Bitmap getLargeIcon(int bgColor, char letter, float width, boolean round) {
    Bitmap b = Bitmap.createBitmap((int) width, (int) width, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);

    RectF mInnerRectF = new RectF();
    mInnerRectF.set(0, 0, width, width);
    mInnerRectF.offset(0, 0);/*  w  w  w . ja va  2s  . co m*/

    Paint mBgPaint = new Paint();
    mBgPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mBgPaint.setStyle(Paint.Style.FILL);
    mBgPaint.setColor(bgColor);

    TextPaint mTitleTextPaint = new TextPaint();
    mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTitleTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    mTitleTextPaint.setTextAlign(Paint.Align.CENTER);
    mTitleTextPaint.setLinearText(true);
    mTitleTextPaint.setColor(Color.WHITE);
    mTitleTextPaint.setTextSize(width * 0.8f);

    float centerX = mInnerRectF.centerX();
    float centerY = mInnerRectF.centerY();

    int xPos = (int) centerX;
    int yPos = (int) (centerY - (mTitleTextPaint.descent() + mTitleTextPaint.ascent()) / 2);

    if (round)
        c.drawOval(mInnerRectF, mBgPaint);
    else
        c.drawRect(mInnerRectF, mBgPaint);
    c.drawText(String.valueOf(letter), xPos, yPos, mTitleTextPaint);

    return b;
}

From source file:org.telegram.ui.ArticleViewer.java

private TextPaint getTextPaint(TLRPC.RichText parentRichText, TLRPC.RichText richText,
        TLRPC.PageBlock parentBlock) {/*  ww  w.ja  v  a 2s.  c o m*/
    int flags = getTextFlags(richText);
    HashMap<Integer, TextPaint> currentMap = null;
    int textSize = AndroidUtilities.dp(14);
    int textColor = 0xffff0000;

    if (parentBlock instanceof TLRPC.TL_pageBlockPhoto) {
        currentMap = captionTextPaints;
        textSize = AndroidUtilities.dp(14);
        textColor = 0xff838c96;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockTitle) {
        currentMap = titleTextPaints;
        textSize = AndroidUtilities.dp(24);
        textColor = 0xff000000;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockAuthorDate) {
        currentMap = authorTextPaints;
        textSize = AndroidUtilities.dp(14);
        textColor = 0xff838c96;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockFooter) {
        currentMap = footerTextPaints;
        textSize = AndroidUtilities.dp(14);
        textColor = 0xff838c96;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockSubtitle) {
        currentMap = subtitleTextPaints;
        textSize = AndroidUtilities.dp(21);
        textColor = 0xff000000;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockHeader) {
        currentMap = headerTextPaints;
        textSize = AndroidUtilities.dp(21);
        textColor = 0xff000000;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockSubheader) {
        currentMap = subheaderTextPaints;
        textSize = AndroidUtilities.dp(18);
        textColor = 0xff000000;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockBlockquote
            || parentBlock instanceof TLRPC.TL_pageBlockPullquote) {
        if (parentBlock.text == parentRichText) {
            currentMap = quoteTextPaints;
            textSize = AndroidUtilities.dp(15);
            textColor = 0xff000000;
        } else if (parentBlock.caption == parentRichText) {
            currentMap = subquoteTextPaints;
            textSize = AndroidUtilities.dp(14);
            textColor = 0xff838c96;
        }
    } else if (parentBlock instanceof TLRPC.TL_pageBlockPreformatted) {
        currentMap = preformattedTextPaints;
        textSize = AndroidUtilities.dp(14);
        textColor = 0xff000000;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockParagraph) {
        if (parentBlock.caption == parentRichText) {
            currentMap = embedPostCaptionTextPaints;
            textSize = AndroidUtilities.dp(14);
            textColor = 0xff838c96;
        } else {
            currentMap = paragraphTextPaints;
            textSize = AndroidUtilities.dp(16);
            textColor = 0xff000000;
        }
    } else if (parentBlock instanceof TLRPC.TL_pageBlockList) {
        currentMap = listTextPaints;
        textSize = AndroidUtilities.dp(15);
        textColor = 0xff000000;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockEmbed) {
        currentMap = embedTextPaints;
        textSize = AndroidUtilities.dp(14);
        textColor = 0xff838c96;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockSlideshow) {
        currentMap = slideshowTextPaints;
        textSize = AndroidUtilities.dp(14);
        textColor = 0xff838c96;
    } else if (parentBlock instanceof TLRPC.TL_pageBlockEmbedPost) {
        if (richText != null) {
            currentMap = embedPostTextPaints;
            textSize = AndroidUtilities.dp(14);
            textColor = 0xff000000;
        }
    } else if (parentBlock instanceof TLRPC.TL_pageBlockVideo) {
        currentMap = videoTextPaints;
        textSize = AndroidUtilities.dp(14);
        textColor = 0xff000000;
    }
    if (currentMap == null) {
        if (errorTextPaint == null) {
            errorTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
            errorTextPaint.setColor(0xffff0000);
        }
        errorTextPaint.setTextSize(AndroidUtilities.dp(14));
        return errorTextPaint;
    }
    TextPaint paint = currentMap.get(flags);
    if (paint == null) {
        paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        if ((flags & TEXT_FLAG_MONO) != 0) {
            paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmono.ttf"));
        } else {
            if (parentBlock instanceof TLRPC.TL_pageBlockTitle
                    || parentBlock instanceof TLRPC.TL_pageBlockHeader
                    || parentBlock instanceof TLRPC.TL_pageBlockSubtitle
                    || parentBlock instanceof TLRPC.TL_pageBlockSubheader) {
                if ((flags & TEXT_FLAG_MEDIUM) != 0 && (flags & TEXT_FLAG_ITALIC) != 0) {
                    paint.setTypeface(Typeface.create("serif", Typeface.BOLD_ITALIC));
                } else if ((flags & TEXT_FLAG_MEDIUM) != 0) {
                    paint.setTypeface(Typeface.create("serif", Typeface.BOLD));
                } else if ((flags & TEXT_FLAG_ITALIC) != 0) {
                    paint.setTypeface(Typeface.create("serif", Typeface.ITALIC));
                } else {
                    paint.setTypeface(Typeface.create("serif", Typeface.NORMAL));
                }
            } else {
                if ((flags & TEXT_FLAG_MEDIUM) != 0 && (flags & TEXT_FLAG_ITALIC) != 0) {
                    paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmediumitalic.ttf"));
                } else if ((flags & TEXT_FLAG_MEDIUM) != 0) {
                    paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
                } else if ((flags & TEXT_FLAG_ITALIC) != 0) {
                    paint.setTypeface(AndroidUtilities.getTypeface("fonts/ritalic.ttf"));
                }
            }
        }
        if ((flags & TEXT_FLAG_STRIKE) != 0) {
            paint.setFlags(paint.getFlags() | TextPaint.STRIKE_THRU_TEXT_FLAG);
        }
        if ((flags & TEXT_FLAG_UNDERLINE) != 0) {
            paint.setFlags(paint.getFlags() | TextPaint.UNDERLINE_TEXT_FLAG);
        }
        if ((flags & TEXT_FLAG_URL) != 0) {
            textColor = 0xff4d83b3;
        }
        paint.setColor(textColor);
        currentMap.put(flags, paint);
    }
    paint.setTextSize(textSize);
    return paint;
}