Java Code Examples for android.text.style.CharacterStyle#updateDrawState()

The following examples show how to use android.text.style.CharacterStyle#updateDrawState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpansV1.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
@Override
        public void draw(@NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
//            bitmapCanvas.drawColor(Color.GRAY, PorterDuff.Mode.CLEAR);
            int color = /*paint instanceof TextPaint ? ((TextPaint) paint).bgColor :*/ paint.getColor();
            bitmapCanvas.drawColor(color);
            for (CharacterStyle style : styles) {
                if (style instanceof ReplacementSpan) {
                    ((ReplacementSpan) style).draw(bitmapCanvas, text, start, end, 0, top, y, bottom, paint);
                } else if (paint instanceof TextPaint) {
                    style.updateDrawState((TextPaint) paint);
                }
            }
            paint.setXfermode(xfermode);
            bitmapCanvas.drawText(text, start, end, 0, y, paint);
            canvas.drawBitmap(bitmap, x, 0, null);
        }
 
Example 2
Source File: SpansV1.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
@Override
        public void draw(@NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
//            bitmapCanvas.drawColor(Color.GRAY, PorterDuff.Mode.CLEAR);
            int color = /*paint instanceof TextPaint ? ((TextPaint) paint).bgColor :*/ paint.getColor();
            bitmapCanvas.drawColor(color);
            for (CharacterStyle style : styles) {
                if (style instanceof ReplacementSpan) {
                    ((ReplacementSpan) style).draw(bitmapCanvas, text, start, end, 0, top, y, bottom, paint);
                } else if (paint instanceof TextPaint) {
                    style.updateDrawState((TextPaint) paint);
                }
            }
            paint.setXfermode(xfermode);
            bitmapCanvas.drawText(text, start, end, 0, y, paint);
            canvas.drawBitmap(bitmap, x, 0, null);
        }
 
Example 3
Source File: LabelSpan.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
private void setupFontMetrics(CharSequence text, int start, int end, FontMetricsInt fm, Paint p) {
    txtPaint.set(p);
    final CharacterStyle[] otherSpans = ((Spanned) text).getSpans(start, end, CharacterStyle.class);
    for (CharacterStyle otherSpan : otherSpans) {
        otherSpan.updateDrawState(txtPaint);
    }
    txtPaint.setTextSize(p.getTextSize());
    if (fm != null) {
        txtPaint.getFontMetricsInt(fm);
    }
}
 
Example 4
Source File: Spans.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(@NonNull Rect outRect, @NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
    for (CharacterStyle style : styles) {
        if (style instanceof SupportSpan) {
            ((SupportSpan) style).draw(frame, canvas, text, start, end, x, top, y, bottom, paint);
        } else if (style instanceof ReplacementSpan) {
            ((ReplacementSpan) style).draw(canvas, text, start, end, x, top, y, bottom, paint);
        } else if (paint instanceof TextPaint) {
            style.updateDrawState((TextPaint) paint);
        }
    }
}
 
Example 5
Source File: Spans.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(@NonNull Rect outRect, @NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
    for (CharacterStyle style : styles) {
        if (style instanceof SupportSpan) {
            ((SupportSpan) style).draw(frame, canvas, text, start, end, x, top, y, bottom, paint);
        } else if (style instanceof ReplacementSpan) {
            ((ReplacementSpan) style).draw(canvas, text, start, end, x, top, y, bottom, paint);
        } else if (paint instanceof TextPaint) {
            style.updateDrawState((TextPaint) paint);
        }
    }
}