Java Code Examples for android.text.TextPaint.setAntiAlias()

The following are Jave code examples for showing how to use setAntiAlias() of the android.text.TextPaint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Demos   File: CustomTextView.java   Source Code and License Vote up 8 votes
/**
 * 绘制多行居中文本(方式1)
 *
 * @param canvas 画布
 */
private void drawCenterMultiText1(Canvas canvas) {
    String text = "ABC";

    // 画笔
    TextPaint textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setColor(Color.GRAY);

    // 设置宽度超过50dp时换行
    StaticLayout staticLayout = new StaticLayout(text, textPaint, dp2px(50),
            Layout.Alignment.ALIGN_CENTER, 1, 0, false);
    canvas.save();
    // StaticLayout默认从(0,0)点开始绘制
    // 如果需要调整位置,只能在绘制之前移动Canvas的起始坐标
    canvas.translate(-staticLayout.getWidth() / 2, -staticLayout.getHeight() / 2);
    staticLayout.draw(canvas);
    canvas.restore();
}
 
Example 2
Project: FriendBook   File: PageLoader.java   Source Code and License Vote up 6 votes
private void initPaint() {
    //绘制提示的画笔
    mTipPaint = new Paint();
    mTipPaint.setColor(mPageView.getTextColor());
    mTipPaint.setTextAlign(Paint.Align.LEFT);//绘制的起始点
    mTipPaint.setTextSize(ScreenUtils.spToPx(mContext, DEFAULT_TIP_SIZE));//Tip默认的字体大小
    mTipPaint.setAntiAlias(true);
    mTipPaint.setSubpixelText(true);

    //绘制页面内容的画笔
    mTextPaint = new TextPaint();
    mTextPaint.setColor(mPageView.getTextColor());
    mTextPaint.setTextSize(mPageView.getTextSize());
    mTextPaint.setAntiAlias(true);

    mBgPaint = new Paint();
    mBgPaint.setColor(mPageView.getPageBackground());

    mBatteryPaint = new Paint();
    mBatteryPaint.setAntiAlias(true);
    mBatteryPaint.setDither(true);
    mBatteryPaint.setColor(mPageView.getTextColor());

}
 
Example 3
Project: Virtualview-Android   File: TMReminderTagsView.java   Source Code and License Vote up 6 votes
public TMReminderTagsView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    if (mDensity == -1) {
        initWith(context);
    }
    textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setColor(Color.rgb(255, 59, 68));
    textPaint.setTextSize(dp2px(10));

    bgPaint = new Paint();
    bgPaint.setColor(Color.rgb(250, 211, 213));

    tagsGap = dp2px(7);

    hPadding = dp2px(3);

    tagRect = new Rect();

    textFontMetrics = textPaint.getFontMetrics();
}
 
Example 4
Project: BilibiliClient   File: OutlineTextView.java   Source Code and License Vote up 6 votes
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
Project: QuanMinTV   File: OutlineTextView.java   Source Code and License Vote up 6 votes
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 6
Project: mongol-library   File: MongolLabel.java   Source Code and License Vote up 6 votes
private void init() {
    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    if (mTextSizePx <= 0) {
        mTextSizePx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
                DEFAULT_FONT_SIZE_SP, getResources().getDisplayMetrics());
    }
    mTextPaint.setTextSize(mTextSizePx);
    mTextPaint.setColor(mTextColor);
    mTypeface = MongolFont.get(MongolFont.QAGAN, mContext);
    mTextPaint.setTypeface(mTypeface);
    mRenderer = MongolCode.INSTANCE;
    if (mUnicodeText == null) {
        mUnicodeText = "";
    }
    mGlyphText = mRenderer.unicodeToMenksoft(mUnicodeText);
}
 
Example 7
Project: JBase   File: FlowViewVertical.java   Source Code and License Vote up 6 votes
private void init() {
    bgPaint = new Paint();
    bgPaint.setAntiAlias(true);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setColor(bgColor);
    bgPaint.setStrokeWidth(lineBgWidth);

    proPaint = new Paint();
    proPaint.setAntiAlias(true);
    proPaint.setStyle(Paint.Style.FILL);
    proPaint.setColor(proColor);
    proPaint.setStrokeWidth(lineProWidth);

    textPaint = new TextPaint();
    textPaint.setTextSize(textsize);
    textPaint.setAntiAlias(true);
}
 
Example 8
Project: SDHtmlTextView   File: TableHandler.java   Source Code and License Vote up 5 votes
private TextPaint getTextPaint() {
	TextPaint textPaint = new TextPaint();
	textPaint.setColor(this.textColor);
       textPaint.linkColor = this.textColor;
	textPaint.setAntiAlias(true);
	textPaint.setTextSize(this.textSize);
	textPaint.setTypeface(this.typeFace);

	return textPaint;
}
 
Example 9
Project: AndroidPDF   File: Page.java   Source Code and License Vote up 5 votes
private TextPaint textPaint() {
    final TextPaint paint = new TextPaint();
    paint.setColor(Color.BLACK);
    paint.setAntiAlias(true);
    paint.setTextSize(24);
    paint.setTextAlign(Paint.Align.CENTER);
    return paint;
}
 
Example 10
Project: baselibrary-master   File: AutoWrapTextView.java   Source Code and License Vote up 5 votes
private void initPaint()
{
    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextAlign(Paint.Align.LEFT);
}
 
Example 11
Project: Rxjava2.0Demo   File: NineGridViewWrapper.java   Source Code and License Vote up 5 votes
public NineGridViewWrapper(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    //转化单位
    textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSize, getContext().getResources().getDisplayMetrics());

    textPaint = new TextPaint();
    textPaint.setTextAlign(Paint.Align.CENTER);  //文字居中对齐
    textPaint.setAntiAlias(true);                //抗锯齿
    textPaint.setTextSize(textSize);             //设置文字大小
    textPaint.setColor(textColor);               //设置文字颜色
}
 
Example 12
Project: PaoMovie   File: CircleProgress.java   Source Code and License Vote up 5 votes
protected void initPainters() {
    textPaint = new TextPaint();
    textPaint.setColor(textColor);
    textPaint.setTextSize(textSize);
    textPaint.setAntiAlias(true);

    paint.setAntiAlias(true);
}
 
Example 13
Project: aos-MediaLib   File: ArtworkFactory.java   Source Code and License Vote up 5 votes
private StaticLayout createTextLayout(String text, int color, float fontSize, int width) {
    TextPaint paint = new TextPaint();
    paint.setColor(color);
    paint.setTextSize(fontSize);
    paint.setTypeface(Typeface.SANS_SERIF);
    paint.setAntiAlias(true);

    return (new StaticLayout(text, paint, width, Layout.Alignment.ALIGN_CENTER, 1.1f, 0f, true));
}
 
Example 14
Project: AndroidPedometer   File: StepProgress.java   Source Code and License Vote up 5 votes
private void initPaint() {
    mValuePaint = new TextPaint();
    mValuePaint.setAntiAlias(antiAlias);
    mValuePaint.setTextSize(mValueSize);
    mValuePaint.setColor(mValueColor);
    mValuePaint.setTypeface(Typeface.DEFAULT_BOLD);
    mValuePaint.setTextAlign(Paint.Align.CENTER);

    mUnitPaint = new TextPaint();
    mUnitPaint.setAntiAlias(antiAlias);
    mUnitPaint.setTextSize(mUnitSize);
    mUnitPaint.setColor(mUnitColor);
    mUnitPaint.setTextAlign(Paint.Align.CENTER);

    mArcPaint = new Paint();
    mArcPaint.setAntiAlias(antiAlias);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setStrokeWidth(mArcWidth);
    mArcPaint.setStrokeCap(Paint.Cap.ROUND);

    mBgArcPaint = new Paint();
    mBgArcPaint.setAntiAlias(antiAlias);
    mBgArcPaint.setColor(mBgArcColor);
    mBgArcPaint.setStyle(Paint.Style.STROKE);
    mBgArcPaint.setStrokeWidth(mBgArcWidth);
    mBgArcPaint.setStrokeCap(Paint.Cap.ROUND);

    mDialPaint = new Paint();
    mDialPaint.setAntiAlias(antiAlias);
    mDialPaint.setColor(mDialColor);
    mDialPaint.setStrokeWidth(mDialWidth);
}
 
Example 15
Project: Hitalk   File: NineGridViewWrapper.java   Source Code and License Vote up 5 votes
public NineGridViewWrapper(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    //转化单位
    textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSize, getContext().getResources().getDisplayMetrics());

    textPaint = new TextPaint();
    textPaint.setTextAlign(Paint.Align.CENTER);  //文字居中对齐
    textPaint.setAntiAlias(true);                //抗锯齿
    textPaint.setTextSize(textSize);             //设置文字大小
    textPaint.setColor(textColor);               //设置文字颜色
}
 
Example 16
Project: WavePullLayout   File: HeaderLayout.java   Source Code and License Vote up 5 votes
private void init() {
    float dSize = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_SP,
            15,
            getContext().getResources().getDisplayMetrics());
    tBuilder = new StringBuilder("");
    setText("");
    mTpaint = new TextPaint();
    mTpaint.setColor(Color.BLUE);
    mTpaint.setAntiAlias(true);
    mTpaint.setTextSize(dSize);
    mTpaint.setStyle(Paint.Style.FILL);
    tRect = new Rect();
    setWillNotDraw(false);
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setFilterBitmap(true);
    camera = new Camera();
    matrix = new Matrix();
    mPath = new Path();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mViewOutlineProvider = new ViewOutlineProvider() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                if (mPath.isConvex()) outline.setConvexPath(mPath);
            }
        };

    }
}
 
Example 17
Project: Building-Android-UIs-with-Custom-Views   File: PrimitiveDrawer.java   Source Code and License Vote up 5 votes
public PrimitiveDrawer(Context context, AttributeSet attributeSet) {
    super(context, attributeSet);

    paint = new TextPaint();
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);
    paint.setColor(0xffffffff);
    paint.setStrokeWidth(1.f);
    paint.setTextSize(35.f);
    paint.setTextAlign(Paint.Align.LEFT);
}
 
Example 18
Project: android-slidr   File: Slidr.java   Source Code and License Vote up 5 votes
public Settings(Slidr slidr) {
    this.slidr = slidr;

    paintIndicator = new Paint();
    paintIndicator.setAntiAlias(true);
    paintIndicator.setStrokeWidth(2);

    paintBar = new Paint();
    paintBar.setAntiAlias(true);
    paintBar.setStrokeWidth(2);
    paintBar.setColor(colorBackground);

    paintStep = new Paint();
    paintStep.setAntiAlias(true);
    paintStep.setStrokeWidth(5);
    paintStep.setColor(colorStoppover);

    paintTextTop = new TextPaint();
    paintTextTop.setAntiAlias(true);
    paintTextTop.setStyle(Paint.Style.FILL);
    paintTextTop.setColor(textColor);
    paintTextTop.setTextSize(textTopSize);

    paintTextBottom = new TextPaint();
    paintTextBottom.setAntiAlias(true);
    paintTextBottom.setStyle(Paint.Style.FILL);
    paintTextBottom.setColor(textColor);
    paintTextBottom.setTextSize(textBottomSize);

    paintBubbleTextCurrent = new TextPaint();
    paintBubbleTextCurrent.setAntiAlias(true);
    paintBubbleTextCurrent.setStyle(Paint.Style.FILL);
    paintBubbleTextCurrent.setColor(Color.WHITE);
    paintBubbleTextCurrent.setStrokeWidth(2);
    paintBubbleTextCurrent.setTextSize(dpToPx(textSizeBubbleCurrent));

    paintBubble = new Paint();
    paintBubble.setAntiAlias(true);
    paintBubble.setStrokeWidth(3);
}
 
Example 19
Project: QMUI_Android   File: QMUIQQFaceView.java   Source Code and License Vote up 4 votes
public QMUIQQFaceView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray array = getContext().obtainStyledAttributes(attrs,
            R.styleable.QMUIQQFaceView, defStyleAttr, 0);
    mQQFaceSizeAddon = -QMUIDisplayHelper.dp2px(context, 2); // 默认表情小一点好看
    mTextSize = array.getDimensionPixelSize(R.styleable.QMUIQQFaceView_android_textSize,
            QMUIDisplayHelper.dp2px(context, 14));
    mTextColor = array.getColor(R.styleable.QMUIQQFaceView_android_textColor, Color.BLACK);
    mIsSingleLine = array.getBoolean(R.styleable.QMUIQQFaceView_android_singleLine, false);
    mMaxLine = array.getInt(R.styleable.QMUIQQFaceView_android_maxLines, mMaxLine);
    int lineSpace = array.getDimensionPixelOffset(R.
            styleable.QMUIQQFaceView_android_lineSpacingExtra, 0);
    setLineSpace(lineSpace);
    int ellipsize = -1;
    ellipsize = array.getInt(R.styleable.QMUIQQFaceView_android_ellipsize, ellipsize);
    switch (ellipsize) {
        case 1:
            mEllipsize = TextUtils.TruncateAt.START;
            break;
        case 2:
            mEllipsize = TextUtils.TruncateAt.MIDDLE;
            break;
        case 3:
        default:
            mEllipsize = TextUtils.TruncateAt.END;
            break;
    }
    mMaxWidth = array.getDimensionPixelSize(R.styleable.QMUIQQFaceView_android_maxWidth, mMaxWidth);
    mSpecialDrawablePadding = array.getDimensionPixelSize(R.styleable.QMUIQQFaceView_qmui_special_drawable_padding, 0);
    final String text = array.getString(R.styleable.QMUIQQFaceView_android_text);
    if (!QMUILangHelper.isNullOrEmpty(text)) {
        mDelayTextSetter = new Runnable() {
            @Override
            public void run() {
                setText(text);
            }
        };
    }
    mMoreActionText = array.getString(R.styleable.QMUIQQFaceView_qmui_more_action_text);
    mMoreActionColor = array.getColor(R.styleable.QMUIQQFaceView_qmui_more_action_color, mTextColor);

    array.recycle();
    mPaint = new TextPaint();
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(mTextSize);
    mPaint.setColor(mTextColor);
    mEllipsizeTextLength = (int) Math.ceil(mPaint.measureText(mEllipsizeText));
    measureMoreActionTextLength();
    mSpanBgPaint = new Paint();
    mSpanBgPaint.setAntiAlias(true);
    mSpanBgPaint.setStyle(Paint.Style.FILL);
}
 
Example 20
Project: blockvote   File: HistoryView.java   Source Code and License Vote up 4 votes
public HistoryView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
	super(context, attrs, defStyleAttr);

	padding = getResources().getDimensionPixelSize(R.dimen.history_padding);
	labelHeight = getResources().getDimensionPixelSize(R.dimen.history_label);
	strokeWidth = getResources().getDimensionPixelSize(R.dimen.history_strokewidth);

	sw1dPaint = makePaint(Option.SW, Interval.D1, strokeWidth);
	sw7dPaint = makePaint(Option.SW, Interval.D7, strokeWidth);
	sw30dPaint = makePaint(Option.SW, Interval.D30, strokeWidth);
	bu1dPaint = makePaint(Option.BU, Interval.D1, strokeWidth);
	bu7dPaint = makePaint(Option.BU, Interval.D7, strokeWidth);
	bu30dPaint = makePaint(Option.BU, Interval.D30, strokeWidth);

	// axes
	axisPaint = new Paint();
	axisPaint.setStrokeWidth(3.0f);
	axisPaint.setColor(Color.DKGRAY);
	axisPaint.setStyle(Paint.Style.STROKE);
	axisPath = new Path();

	// marks
	marksPaint = new Paint();
	marksPaint.setStrokeWidth(3.0f);
	marksPaint.setColor(Color.LTGRAY);
	marksPaint.setStyle(Paint.Style.STROKE);
	marksPath = new Path();

	// labels
	yLabelTextPaint = new TextPaint();
	yLabelTextPaint.setColor(Color.GRAY);
	yLabelTextPaint.setTextSize(labelHeight);
	yLabelTextPaint.setAntiAlias(true);
	yLabelTextPaint.setTextAlign(Paint.Align.RIGHT);
	xLabelTextPaint = new TextPaint();
	xLabelTextPaint.setColor(Color.GRAY);
	xLabelTextPaint.setTextSize(labelHeight);
	xLabelTextPaint.setAntiAlias(true);
	xLabelTextPaint.setTextAlign(Paint.Align.CENTER);

	labelWidth = Layout.getDesiredWidth("100%", yLabelTextPaint);

	if (isInEditMode()) {
		setData(new MainViewModel.Data(
				new Date(), new Date(), new float[]{0.1f, 0.2f, 0.15f, 0.18f},
						new float[]{0.3f, 0.5f, 0.1f, 0.5f},
						new float[]{0.3f, 0.5f, 0.1f, 0.5f},
						new float[]{0.3f, 0.5f, 0.1f, 0.5f},
						new float[]{0.3f, 0.5f, 0.1f, 0.5f},
						new float[]{0.3f, 0.5f, 0.1f, 0.5f}
				)
		);
	}
}