Java Code Examples for android.text.TextPaint#getColor()

The following examples show how to use android.text.TextPaint#getColor() . 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: TextChipsEditView.java    From talk-android with MIT License 6 votes vote down vote up
private DrawableRecipientChip constructChipSpan(RecipientEntry contact, boolean pressed,
                                                boolean leaveIconSpace) throws NullPointerException {
    if (mChipBackground == null) {
        throw new NullPointerException(
                "Unable to render any chips as setChipDimensions was not called.");
    }

    TextPaint paint = getPaint();
    float defaultSize = paint.getTextSize();
    int defaultColor = paint.getColor();

    Bitmap tmpBitmap = createUnselectedChip(contact, paint, leaveIconSpace);

    // Pass the full text, un-ellipsized, to the chip.
    Drawable result = new BitmapDrawable(getResources(), tmpBitmap);
    result.setBounds(0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight());
    DrawableRecipientChip recipientChip =
            new VisibleRecipientChip(result, contact, getImageSpanAlignment());
    // Return text to the original size.
    paint.setTextSize(defaultSize);
    paint.setColor(defaultColor);
    return recipientChip;
}
 
Example 2
Source File: LinkSpan.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
@Override
public void updateDrawState(TextPaint paint) {
	if (paint.getColor() != Color.TRANSPARENT) {
		if (hidden) {
			paint.setColor(foregroundColor & 0x00ffffff | Color.argb(Color.alpha(foregroundColor) / 2, 0, 0, 0));
			paint.setStrikeThruText(true);
		} else {
			paint.setColor(foregroundColor);
		}
		paint.setUnderlineText(true);
		if (clicked) {
			paint.bgColor = Color.alpha(paint.bgColor) == 0x00 ? clickedColor
					: GraphicsUtils.mixColors(paint.bgColor, clickedColor);
		}
	}
}
 
Example 3
Source File: RecipientEditTextView.java    From ChipsLibrary with Apache License 2.0 6 votes vote down vote up
private DrawableRecipientChip constructChipSpan(final RecipientEntry contact,final boolean pressed,final boolean leaveIconSpace) throws NullPointerException
{
if(mChipBackground==null)
  throw new NullPointerException("Unable to render any chips as setChipDimensions was not called.");
final TextPaint paint=getPaint();
final float defaultSize=paint.getTextSize();
final int defaultColor=paint.getColor();
Bitmap tmpBitmap;
if(pressed)
  tmpBitmap=createSelectedChip(contact,paint);
else tmpBitmap=createUnselectedChip(contact,paint,leaveIconSpace);
// Pass the full text, un-ellipsized, to the chip.
final Drawable result=new BitmapDrawable(getResources(),tmpBitmap);
result.setBounds(0,0,tmpBitmap.getWidth(),tmpBitmap.getHeight());
final DrawableRecipientChip recipientChip=new VisibleRecipientChip(result,contact);
// Return text to the original size.
paint.setTextSize(defaultSize);
paint.setColor(defaultColor);
return recipientChip;
}
 
Example 4
Source File: RecipientEditTextView.java    From talk-android with MIT License 5 votes vote down vote up
private DrawableRecipientChip constructChipSpan(RecipientEntry contact, boolean pressed,
                                                boolean leaveIconSpace) throws NullPointerException {
    if (mChipBackground == null) {
        throw new NullPointerException(
                "Unable to render any chips as setChipDimensions was not called.");
    }

    TextPaint paint = getPaint();
    float defaultSize = paint.getTextSize();
    int defaultColor = paint.getColor();

    Bitmap tmpBitmap;
    if (pressed) {
        tmpBitmap = createSelectedChip(contact, paint);

    } else {
        tmpBitmap = createUnselectedChip(contact, paint, leaveIconSpace);
    }

    // Pass the full text, un-ellipsized, to the chip.
    Drawable result = new BitmapDrawable(getResources(), tmpBitmap);
    result.setBounds(0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight());
    DrawableRecipientChip recipientChip =
            new VisibleRecipientChip(result, contact, getImageSpanAlignment());
    // Return text to the original size.
    paint.setTextSize(defaultSize);
    paint.setColor(defaultColor);
    return recipientChip;
}
 
Example 5
Source File: URLSpanNoUnderline.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateDrawState(TextPaint p) {
    int l = p.linkColor;
    int c = p.getColor();
    super.updateDrawState(p);
    if (style != null) {
        style.applyStyle(p);
    }
    p.setUnderlineText(l == c);
}
 
Example 6
Source File: URLSpanReplacement.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateDrawState(TextPaint p) {
    int color = p.getColor();
    super.updateDrawState(p);
    if (style != null) {
        style.applyStyle(p);
        p.setUnderlineText(p.linkColor == color);
    }
}
 
Example 7
Source File: URLSpanNoUnderline.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateDrawState(TextPaint p) {
    int l = p.linkColor;
    int c = p.getColor();
    super.updateDrawState(p);
    if (style != null) {
        style.applyStyle(p);
    }
    p.setUnderlineText(l == c);
}
 
Example 8
Source File: URLSpanReplacement.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateDrawState(TextPaint p) {
    int color = p.getColor();
    super.updateDrawState(p);
    if (style != null) {
        style.applyStyle(p);
        p.setUnderlineText(p.linkColor == color);
    }
}
 
Example 9
Source File: Letter.java    From FadeInTextView-Android with MIT License 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint tp) {
    int color = ((int) (0xFF * alpha) << 24) | (tp.getColor() & 0x00FFFFFF);
    tp.setColor(color);
}
 
Example 10
Source File: FloatingLabelSpinner.java    From FloatingLabelSpinner with Apache License 2.0 4 votes vote down vote up
private void drawSpannableString(final Canvas canvas, CharSequence hint, final TextPaint paint, final int start_x, final int start_y) {
    // draw each span one at a time
    int next;
    float xStart = start_x;
    float xEnd;

    if (paint != errorPaint)
        hint = TextUtils.ellipsize(hint, paint, getWidth() - padding_left - padding_right - label_horizontal_margin, TextUtils.TruncateAt.END);

    if (hint instanceof SpannableString) {
        SpannableString spannableString = (SpannableString) hint;
        for (int i = 0; i < spannableString.length(); i = next) {

            // find the next span transition
            next = spannableString.nextSpanTransition(i, spannableString.length(), CharacterStyle.class);

            // measure the length of the span
            xEnd = xStart + paint.measureText(spannableString, i, next);

            // draw the highlight (background color) first
            BackgroundColorSpan[] bgSpans = spannableString.getSpans(i, next, BackgroundColorSpan.class);
            if (bgSpans.length > 0) {
                Paint mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
                mHighlightPaint.setColor(bgSpans[0].getBackgroundColor());
                canvas.drawRect(xStart, start_y + paint.getFontMetrics().top, xEnd, start_y + paint.getFontMetrics().bottom, mHighlightPaint);
            }

            // draw the text with an optional foreground color
            ForegroundColorSpan[] fgSpans = spannableString.getSpans(i, next, ForegroundColorSpan.class);
            if (fgSpans.length > 0) {
                int saveColor = paint.getColor();
                paint.setColor(fgSpans[0].getForegroundColor());
                canvas.drawText(spannableString, i, next, xStart, start_y, paint);
                paint.setColor(saveColor);
            } else {
                canvas.drawText(spannableString, i, next, xStart, start_y, paint);
            }

            xStart = xEnd;
        }
    } else {
        canvas.drawText(hint, 0, hint.length(), xStart, start_y, paint);
    }

}
 
Example 11
Source File: QuoteSpan.java    From Dashchan with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint paint) {
	if (paint.getColor() != Color.TRANSPARENT) {
		paint.setColor(foregroundColor);
	}
}
 
Example 12
Source File: GainedColorSpan.java    From Dashchan with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint paint) {
	if (paint.getColor() != Color.TRANSPARENT) {
		paint.setColor(GraphicsUtils.modifyColorGain(foregroundColor, colorGainFactor));
	}
}