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

The following examples show how to use android.text.TextPaint#setColor() . 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: FileTypeTextView.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
public FileTypeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setWillNotDraw(false);

    textPaint = new TextPaint();
    FontsManager.set(context, textPaint, R.font.roboto_black);
    textPaint.setAntiAlias(true);

    mDefaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, context.getResources().getDisplayMetrics());

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.FileTypeTextView, defStyleAttr, 0);
    try {
        mMaxHeight = a.getDimensionPixelSize(R.styleable.FileTypeTextView_maxHeight, (int) mDefaultTextSize);
        textPaint.setColor(a.getColor(R.styleable.FileTypeTextView_textColor, Color.BLACK));
    } finally {
        a.recycle();
    }

    if (isInEditMode()) setExtension("XML");
}
 
Example 2
Source File: CanvasPainter.java    From cythara with GNU General Public License v3.0 6 votes vote down vote up
private void drawText(float x, float y, Note note, Paint textPaint) {
    String noteText = getNote(note.getName());
    float offset = textPaint.measureText(noteText) / 2F;

    String sign = note.getSign();
    String octave = String.valueOf(getOctave(note.getOctave()));

    TextPaint paint = new TextPaint(ANTI_ALIAS_FLAG);
    paint.setColor(textColor);
    int textSize = (int) (textPaint.getTextSize() / 2);
    paint.setTextSize(textSize);

    float factor = 0.75f;
    if (useScientificNotation) {
        factor = 1.5f;
    }

    canvas.drawText(sign, x + offset * 1.25f, y - offset * factor, paint);
    canvas.drawText(octave, x + offset * 1.25f, y + offset * 0.5f, paint);

    canvas.drawText(noteText, x - offset, y, textPaint);
}
 
Example 3
Source File: ClockView.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
private void initPaint(Context context) {
    mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCirclePaint.setColor(WHITE);
    mCirclePaint.setStrokeWidth(12);
    mCirclePaint.setStyle(Paint.Style.STROKE);

    mArcPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mArcPaint.setColor(BLACK);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setStrokeWidth(12);

    mTextPaint = new TextPaint();
    mTextPaint.setColor(RED);
    mTextPaint.setTextSize(80);
    mTextPaint.setTextAlign(Paint.Align.CENTER);

    initAnim();

}
 
Example 4
Source File: OutlineTextView.java    From MyHearts with Apache License 2.0 6 votes vote down vote up
private void initPaint() {
  mTextPaint = new TextPaint();
  mTextPaint.setAntiAlias(true);
  mTextPaint.setTextSize(getTextSize());
  mTextPaint.setColor(mColor);
  mTextPaint.setStyle(Paint.Style.FILL);
  mTextPaint.setTypeface(getTypeface());

  mTextPaintOutline = new TextPaint();
  mTextPaintOutline.setAntiAlias(true);
  mTextPaintOutline.setTextSize(getTextSize());
  mTextPaintOutline.setColor(mBorderColor);
  mTextPaintOutline.setStyle(Paint.Style.STROKE);
  mTextPaintOutline.setTypeface(getTypeface());
  mTextPaintOutline.setStrokeWidth(mBorderSize);
}
 
Example 5
Source File: URLSpanUserMention.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateDrawState(TextPaint ds) {
    super.updateDrawState(ds);
    if (currentType == 2) {
        ds.setColor(0xffffffff);
    } else if (currentType == 1) {
        ds.setColor(Theme.getColor(Theme.key_chat_messageLinkOut));
    } else {
        ds.setColor(Theme.getColor(Theme.key_chat_messageLinkIn));
    }

    ds.setUnderlineText(false);
}
 
Example 6
Source File: TextAppearanceSpan.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void updateDrawState(TextPaint ds) {
    updateMeasureState(ds);

    if (mTextColor != null) {
        ds.setColor(mTextColor.getColorForState(ds.drawableState, 0));
    }

    if (mTextColorLink != null) {
        ds.linkColor = mTextColorLink.getColorForState(ds.drawableState, 0);
    }
}
 
Example 7
Source File: TabSwitcherDrawable.java    From delion with Apache License 2.0 5 votes vote down vote up
private TabSwitcherDrawable(Resources resources, boolean useLight, Bitmap bitmap) {
    super(resources, bitmap);
    setTint(ApiCompatibilityUtils.getColorStateList(resources,
            useLight ? R.color.light_mode_tint : R.color.dark_mode_tint));
    mSingleDigitTextSize =
            resources.getDimension(R.dimen.toolbar_tab_count_text_size_1_digit);
    mDoubleDigitTextSize =
            resources.getDimension(R.dimen.toolbar_tab_count_text_size_2_digit);

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextAlign(Align.CENTER);
    mTextPaint.setTypeface(Typeface.create("sans-serif-condensed", Typeface.BOLD));
    mTextPaint.setColor(getColorForState());
}
 
Example 8
Source File: RuleView.java    From RulerView with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化
 */
private void init(Context context) {
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStrokeWidth(shortLineWidth);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextSize(textSize);
    mTextPaint.setColor(textColor);

    mScroller = new Scroller(context);
}
 
Example 9
Source File: SpanParser.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private HtmlObject getStyledObject(StyleSpan span, String content, int start, int end, float thisXOffset){
    TextPaint paint = mPaintHelper.getPaintFromHeap();
    paint.setTypeface(Typeface.defaultFromStyle(span.getStyle()));
    paint.setTextSize(mFlowTextView.getTextsize());
    paint.setColor(mFlowTextView.getColor());

    span.updateDrawState(paint);
    span.updateMeasureState(paint);
    HtmlObject  obj = new HtmlObject(content, start, end, thisXOffset, paint);
    obj.recycle = true;
    return obj;
}
 
Example 10
Source File: ReflowText.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
private Layout createLayout(ReflowData data, Context context, boolean enforceMaxLines) {
    TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(data.textSize);
    paint.setColor(data.textColor);
    paint.setLetterSpacing(data.letterSpacing);
    if (data.fontName != null) {
        paint.setTypeface(FontUtil.get(context, data.fontName));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        StaticLayout.Builder builder =  StaticLayout.Builder.obtain(
                data.text, 0, data.text.length(), paint, data.textWidth)
                .setLineSpacing(data.lineSpacingAdd, data.lineSpacingMult)
                .setBreakStrategy(data.breakStrategy);
        if (enforceMaxLines && data.maxLines != -1) {
            builder.setMaxLines(data.maxLines);
            builder.setEllipsize(TextUtils.TruncateAt.END);
        }
        return builder.build();
    } else {
        return new StaticLayout(
                data.text,
                paint,
                data.textWidth,
                Layout.Alignment.ALIGN_NORMAL,
                data.lineSpacingMult,
                data.lineSpacingAdd,
                true);
    }
}
 
Example 11
Source File: ClickTextView.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateDrawState(TextPaint ds) {

	ds.setColor(context.getResources().getColor(
			R.color.text_color));

	ds.setUnderlineText(false); // 去掉下划线
}
 
Example 12
Source File: TweetTagSpan.java    From Tweetin with Apache License 2.0 5 votes vote down vote up
@Override
public void updateDrawState(TextPaint textPaint) {
    super.updateDrawState(textPaint);

    textPaint.setUnderlineText(false);
    textPaint.setColor(activity.getResources().getColor(R.color.secondary_text));
    textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.ITALIC));
}
 
Example 13
Source File: TextPaintUrlSpan.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateMeasureState(TextPaint p) {
    if (textPaint != null) {
        p.setColor(textPaint.getColor());
        p.setTypeface(textPaint.getTypeface());
        p.setFlags(textPaint.getFlags());
        p.setTextSize(textPaint.getTextSize());
        p.baselineShift = textPaint.baselineShift;
        p.bgColor = textPaint.bgColor;
    }
}
 
Example 14
Source File: LinkSpan.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint ds) {
    super.updateDrawState(ds);
    ds.setUnderlineText(true);
    ds.setColor(linkColor);
}
 
Example 15
Source File: MyURLSpan.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint tp) {
    tp.setColor(ThemeUtility.getColor(R.attr.link_color));
    // tp.setUnderlineText(true);
}
 
Example 16
Source File: CommentAdapter.java    From Pixiv-Shaft with MIT License 4 votes vote down vote up
@Override
public void bindData(CommentsBean target, ViewHolder<RecyCommentListBinding> bindView, int position) {
    Glide.with(mContext).load(GlideUtil.getHead(allIllust.get(position).getUser()))
            .into(bindView.baseBind.userHead);
    bindView.baseBind.userName.setText(allIllust.get(position).getUser().getName());
    bindView.baseBind.time.setText(allIllust.get(position).getDate());
    bindView.baseBind.content.setHtml(allIllust.get(position).getComment(),
            new ImgGetter(bindView.baseBind.content));

    if (allIllust.get(position).getParent_comment() != null &&
            allIllust.get(position).getParent_comment().getUser() != null) {
        bindView.baseBind.replyComment.setVisibility(View.VISIBLE);

        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                mOnItemClickListener.onItemClick(widget, position, 3);
            }

            @Override
            public void updateDrawState(TextPaint ds) {
                ds.setColor(Color.parseColor("#507daf"));
            }
        };

        SpannableString spannableString = new SpannableString(Html.fromHtml(String.format("@%s:%s",
                allIllust.get(position).getParent_comment().getUser().getName(),
                allIllust.get(position).getParent_comment().getComment()),
                new ImgGetter(bindView.baseBind.replyContent), null));
        spannableString.setSpan(clickableSpan,
                0, allIllust.get(position).getParent_comment().getUser().getName().length() + 1,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        bindView.baseBind.replyContent.setMovementMethod(LinkMovementMethod.getInstance());
        bindView.baseBind.replyContent.setText(spannableString);
    } else {
        bindView.baseBind.replyComment.setVisibility(View.GONE);
    }


    if (mOnItemClickListener != null) {
        bindView.itemView.setOnClickListener(v ->
                mOnItemClickListener.onItemClick(v, position, 0));

        bindView.baseBind.userHead.setOnClickListener(v ->
                mOnItemClickListener.onItemClick(v, position, 1));

        bindView.baseBind.userName.setOnClickListener(v ->
                mOnItemClickListener.onItemClick(v, position, 1));

        bindView.baseBind.replyContent.setOnClickListener(v ->
                mOnItemClickListener.onItemClick(v, position, 2));
    }
}
 
Example 17
Source File: URLSpanNoUnderline.java    From RichEditor with Apache License 2.0 4 votes vote down vote up
@Override  
public void updateDrawState(TextPaint ds) {
    super.updateDrawState(ds);  
    ds.setUnderlineText(false);  
    ds.setColor(Color.parseColor("#3194d0"));
}
 
Example 18
Source File: PageLoader.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 作用:设置与文字相关的参数
 */
private void setTextParams() {
    // 文字大小
    mTextSize = ScreenUtils.spToPx(mSettingManager.getTextSize());
    // 行间距
    mTextInterval = ScreenUtils.dpToPx(mSettingManager.getLineSpacing());
    // 段落间距
    mTextPara = ScreenUtils.dpToPx(mSettingManager.getParagraphSpacing());

    Typeface typeface;
    try {
        if (mSettingManager.getFontPath() != null) {
            typeface = Typeface.createFromFile(mSettingManager.getFontPath());
        } else {
            typeface = Typeface.SANS_SERIF;
        }
    } catch (Exception e) {
        ToastUtils.toast(mContext, "字体文件未找,到恢复默认字体");
        mSettingManager.setReadBookFont(null);
        typeface = Typeface.SANS_SERIF;
    }

    // 绘制提示的画笔
    mTipPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTipPaint.setColor(mTextColor);
    mTipPaint.setTextAlign(Paint.Align.LEFT); // 绘制的起始点
    mTipPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE)); // Tip默认的字体大小
    mTipPaint.setTypeface(typeface);
    mTipPaint.setFakeBoldText(mSettingManager.getTextBold());
    mTipPaint.setSubpixelText(true);
    mTipPaint.setDither(true);

    // 绘制标题的画笔
    mTitlePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTitlePaint.setColor(mTextColor);
    mTitlePaint.setTextSize(mTextSize * 1.25f);
    mTitlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mTitlePaint.setTypeface(typeface);
    mTitlePaint.setFakeBoldText(true);
    mTitlePaint.setSubpixelText(true);
    mTitlePaint.setDither(true);

    // 绘制页面内容的画笔
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setTypeface(typeface);
    mTextPaint.setFakeBoldText(mSettingManager.getTextBold());
    mTextPaint.setSubpixelText(true);
    mTextPaint.setDither(true);
}
 
Example 19
Source File: LoadMoreAdapter.java    From BaseRecyclerViewAdapterHelper with MIT License 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint ds) {
    ds.setColor(getContext().getResources().getColor(R.color.clickspan_color));
    ds.setUnderlineText(true);
}
 
Example 20
Source File: FontSpan.java    From Markdown with MIT License 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint tp) {
    super.updateDrawState(tp);
    updateMeasureState(tp);
    tp.setColor(color);
}