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

The following examples show how to use android.text.TextPaint#setDither() . 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: TextSticker.java    From EasyPhotos with Apache License 2.0 6 votes vote down vote up
private void initPaints() {
    textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setDither(true);
    textPaint.setFilterBitmap(true);
    textPaint.setTypeface(Typeface.DEFAULT_BOLD);
    textPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.sticker_text_size_easy_photos));
    textPaint.setColor(Color.WHITE);


    bitmapPaint = new Paint();
    bitmapPaint.setAntiAlias(true);
    bitmapPaint.setDither(true);
    bitmapPaint.setFilterBitmap(true);

    framePaint = new Paint();
    framePaint.setAntiAlias(true);
    bitmapPaint.setDither(true);
    bitmapPaint.setFilterBitmap(true);
    framePaint.setStrokeWidth(1);
    framePaint.setColor(ContextCompat.getColor(getContext(), android.R.color.white));
}
 
Example 2
Source File: TextSticker.java    From imsdk-android with MIT License 6 votes vote down vote up
private void initPaints() {
    textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setDither(true);
    textPaint.setFilterBitmap(true);
    textPaint.setTypeface(Typeface.DEFAULT_BOLD);
    textPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.sticker_text_size_easy_photos));
    textPaint.setColor(Color.WHITE);


    bitmapPaint = new Paint();
    bitmapPaint.setAntiAlias(true);
    bitmapPaint.setDither(true);
    bitmapPaint.setFilterBitmap(true);

    framePaint = new Paint();
    framePaint.setAntiAlias(true);
    bitmapPaint.setDither(true);
    bitmapPaint.setFilterBitmap(true);
    framePaint.setStrokeWidth(1);
    framePaint.setColor(ContextCompat.getColor(getContext(), android.R.color.white));
}
 
Example 3
Source File: UEFontAwesome.java    From Auie with GNU General Public License v2.0 6 votes vote down vote up
public UEFontAwesomeDrawable(Context context, final View view, String text, int color) {
	this.text = Html.fromHtml(text).toString();
	mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
	mTextPaint.setTypeface(typeface);
	mTextPaint.setDither(true);
	mTextPaint.setColor(color);
	mTextPaint.setTextAlign(Paint.Align.CENTER);
	mTextPaint.measureText(text);
	view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
		@Override
		public boolean onPreDraw() {
			width = view.getWidth();
			height = view.getHeight();
			mTextPaint.setTextSize(Math.min(width, height));
			view.getViewTreeObserver().removeOnPreDrawListener(this);
			return false;
		}
	});
}
 
Example 4
Source File: IconDrawable.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
private IconDrawable(Context context, @NonNull IconState state) {
    iconState = state;
    paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    // We have already confirmed that a typeface exists for this icon during
    // validation, so we can ignore the null pointer warning.
    //noinspection ConstantConditions
    paint.setTypeface(Iconify.findTypefaceOf(state.icon).getTypeface(context));
    paint.setStyle(state.style);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setUnderlineText(false);
    color = state.colorStateList.getColorForState(StateSet.WILD_CARD, DEFAULT_COLOR);
    paint.setColor(color);
    updateTintFilter();
    setModulatedAlpha();
    paint.setDither(iconState.dither);
    text = String.valueOf(iconState.icon.character());
    if (SDK_INT < LOLLIPOP && iconState.bounds != null) {
        setBounds(iconState.bounds);
    }
}
 
Example 5
Source File: MixtureTextView.java    From MixtureTextView with Apache License 2.0 6 votes vote down vote up
public MixtureTextView(Context context, AttributeSet attrs)
{
    super(context, attrs);

    readAttrs(context, attrs);

    //just for text
    if (mText == null)
    {
        mText = getResources().getString(R.string.text1);
    }

    //get text
    if (!TextUtils.isEmpty(mText))
    {
        mNeedRenderText = true;
    }

    if (!mNeedRenderText) return;


    mTextPaint = new TextPaint();
    mTextPaint.setDither(true);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setColor(mTextColor);
}
 
Example 6
Source File: LyricView.java    From MusicPlayer_XiangDa with GNU General Public License v3.0 5 votes vote down vote up
private void initPaint() {
    mTextPaint = new TextPaint();
    mTextPaint.setDither(true);
    mTextPaint.setAntiAlias(true);
    switch (mTextAlign) {
        case LEFT:
            mTextPaint.setTextAlign(Paint.Align.LEFT);
            break;
        case CENTER:
            mTextPaint.setTextAlign(Paint.Align.CENTER);
            break;
        case RIGHT:
            mTextPaint.setTextAlign(Paint.Align.RIGHT);
            break;
    }

    mBtnPlayPaint = new Paint();
    mBtnPlayPaint.setDither(true);
    mBtnPlayPaint.setAntiAlias(true);
    mBtnPlayPaint.setColor(mBtnColor);
    mBtnPlayPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mBtnPlayPaint.setAlpha(128);

    mLinePaint = new Paint();
    mLinePaint.setDither(true);
    mLinePaint.setAntiAlias(true);
    mLinePaint.setColor(mLineColor);
    mLinePaint.setAlpha(64);
    mLinePaint.setStrokeWidth(1.0f);
    mLinePaint.setStyle(Paint.Style.STROKE);

    mTimerPaint = new Paint();
    mTimerPaint.setDither(true);
    mTimerPaint.setAntiAlias(true);
    mTimerPaint.setColor(Color.WHITE);
    mTimerPaint.setTextAlign(Paint.Align.RIGHT);
    mTimerPaint.setTextSize(getRawSize(TypedValue.COMPLEX_UNIT_SP, INDICATOR_TIME_TEXT_SIZE));


}
 
Example 7
Source File: LyricView.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
private void initPaint() {
    mTextPaint = new TextPaint();
    mTextPaint.setDither(true);
    mTextPaint.setAntiAlias(true);
    switch (mTextAlign) {
        case LEFT:
            mTextPaint.setTextAlign(Paint.Align.LEFT);
            break;
        case CENTER:
            mTextPaint.setTextAlign(Paint.Align.CENTER);
            break;
        case RIGHT:
            mTextPaint.setTextAlign(Paint.Align.RIGHT);
            break;
    }

    mBtnPlayPaint = new Paint();
    mBtnPlayPaint.setDither(true);
    mBtnPlayPaint.setAntiAlias(true);
    mBtnPlayPaint.setColor(mBtnColor);
    mBtnPlayPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mBtnPlayPaint.setAlpha(128);

    mLinePaint = new Paint();
    mLinePaint.setDither(true);
    mLinePaint.setAntiAlias(true);
    mLinePaint.setColor(mLineColor);
    mLinePaint.setAlpha(64);
    mLinePaint.setStrokeWidth(1.0f);
    mLinePaint.setStyle(Paint.Style.STROKE);

    mTimerPaint = new Paint();
    mTimerPaint.setDither(true);
    mTimerPaint.setAntiAlias(true);
    mTimerPaint.setColor(Color.WHITE);
    mTimerPaint.setTextAlign(Paint.Align.RIGHT);
    mTimerPaint.setTextSize(getRawSize(TypedValue.COMPLEX_UNIT_SP, INDICATOR_TIME_TEXT_SIZE));


}
 
Example 8
Source File: BatteryView.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
public BatteryView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setDither(true);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setDither(true);
    mTextPaint.setFakeBoldText(true);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mTextPaint.setTypeface(Typeface.createFromAsset(getResources().getAssets() ,"number.ttf"));

    mRect = new RectF();
    mPorPath = new Path();
}
 
Example 9
Source File: MyPieChartView.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
private void initPaint() {
    mPieChartPaint = new Paint();
    //是否开启抗锯齿
    mPieChartPaint.setAntiAlias(true);
    //防抖动
    mPieChartPaint.setDither(true);
    //画笔样式 STROKE 只绘制图形轮廓(描边) FILL 只绘制图形内容 FILL_AND_STROKE 既绘制轮廓也绘制内容
    mPieChartPaint.setStyle(Paint.Style.FILL);
    //画笔宽度
    mPieChartPaint.setStrokeWidth(mPieChartWidth);
    /*mPieChartPaint!!.strokeCap =
      Paint.Cap.SQUARE*///笔刷样式 //当画笔样式为STROKE或FILL_OR_STROKE时,
    // 设置笔刷的图形样式,如圆形样式Cap.ROUND,或方形样式Cap.SQUARE
    //mPieChartPaint!!.color = Color.RED

    mDataPaint = new TextPaint();
    mDataPaint.setDither(true);
    mDataPaint.setAntiAlias(true);
    mDataPaint.setTextSize(mDataSize);
    mDataPaint.setColor(mDataColor);
    //从中间向两边绘制,不需要再次计算文字
    mDataPaint.setTextAlign(Paint.Align.CENTER);

    mUnitPaint = new TextPaint();
    mUnitPaint.setDither(true);
    mUnitPaint.setAntiAlias(true);
    mUnitPaint.setTextSize(mUnitSize);
    mUnitPaint.setColor(mUnitColor);
    //从中间向两边绘制,不需要再次计算文字
    mUnitPaint.setTextAlign(Paint.Align.CENTER);

    mPointingPaint = new Paint();
    mPointingPaint.setDither(true);
    mPointingPaint.setAntiAlias(true);
    mPointingPaint.setColor(mPointingColor);
    //从中间向两边绘制,不需要再次计算文字
    mPointingPaint.setStrokeWidth(mPointingWidth);
}
 
Example 10
Source File: MeiTextPathView.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
private void initView() {
    mPaint = new TextPaint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setTextSize(mTextSize);
    mPaint.setColor(mTextColor);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(mStrokeWidth);

    mFontPath = new Path();
    mDstPath = new Path();
    mPathMeasure = new PathMeasure();
    initTextPath();
}
 
Example 11
Source File: BookAssetsPieChartView.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
private void initPaint() {
    mPieChartPaint = new Paint();
    //是否开启抗锯齿
    mPieChartPaint.setAntiAlias(true);
    //防抖动
    mPieChartPaint.setDither(true);
    //画笔样式 STROKE 只绘制图形轮廓(描边) FILL 只绘制图形内容 FILL_AND_STROKE 既绘制轮廓也绘制内容
    mPieChartPaint.setStyle(Paint.Style.FILL);
    //画笔宽度
    mPieChartPaint.setStrokeWidth(mPieChartWidth);
    ///笔刷样式
    // 当画笔样式为STROKE或FILL_OR_STROKE时,
    mPieChartPaint.setStrokeCap(Paint.Cap.SQUARE);
    // 设置笔刷的图形样式,如圆形样式Cap.ROUND,或方形样式Cap.SQUARE
    mPieChartPaint.setColor(Color.RED);

    //数字
    mDataPaint = new TextPaint();
    mDataPaint.setDither(true);
    mDataPaint.setAntiAlias(true);
    mDataPaint.setTextSize(sp2px(mContext, mDataSize));
    mDataPaint.setColor(mDataColor);

    mPointingPaint = new Paint();
    mPointingPaint.setDither(true);
    mPointingPaint.setAntiAlias(true);
    mPointingPaint.setStyle(Paint.Style.STROKE);
    //从中间向两边绘制,不需要再次计算文字
    mPointingPaint.setStrokeWidth(mPointingWidth);
}
 
Example 12
Source File: PageLoader.java    From MyBookshelf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 初始化画笔
 */
private void initPaint() {
    Typeface typeface;
    try {
        if (!TextUtils.isEmpty(readBookControl.getFontPath())) {
            typeface = Typeface.createFromFile(readBookControl.getFontPath());
        } else {
            typeface = Typeface.SANS_SERIF;
        }
    } catch (Exception e) {
        Toast.makeText(mContext, "字体文件未找,到恢复默认字体", Toast.LENGTH_SHORT).show();
        readBookControl.setReadBookFont(null);
        typeface = Typeface.SANS_SERIF;
    }
    // 绘制提示的画笔
    mTipPaint = new TextPaint();
    mTipPaint.setColor(readBookControl.getTextColor());
    mTipPaint.setTextAlign(Paint.Align.LEFT); // 绘制的起始点
    mTipPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE)); // Tip默认的字体大小
    mTipPaint.setTypeface(Typeface.create(typeface, Typeface.NORMAL));
    mTipPaint.setAntiAlias(true);
    mTipPaint.setSubpixelText(true);

    // 绘制标题的画笔
    mTitlePaint = new TextPaint();
    mTitlePaint.setColor(readBookControl.getTextColor());
    mTitlePaint.setTextSize(mTitleSize);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mTitlePaint.setLetterSpacing(readBookControl.getTextLetterSpacing());
    }
    mTitlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mTitlePaint.setTypeface(Typeface.create(typeface, Typeface.BOLD));
    mTitlePaint.setTextAlign(Paint.Align.CENTER);
    mTitlePaint.setAntiAlias(true);

    // 绘制页面内容的画笔
    mTextPaint = new TextPaint();
    mTextPaint.setColor(readBookControl.getTextColor());
    mTextPaint.setTextSize(mTextSize);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mTextPaint.setLetterSpacing(readBookControl.getTextLetterSpacing());
    }
    int bold = readBookControl.getTextBold() ? Typeface.BOLD : Typeface.NORMAL;
    mTextPaint.setTypeface(Typeface.create(typeface, bold));
    mTextPaint.setAntiAlias(true);

    // 绘制结束的画笔
    mTextEndPaint = new TextPaint();
    mTextEndPaint.setColor(readBookControl.getTextColor());
    mTextEndPaint.setTextSize(mTextEndSize);
    mTextEndPaint.setTypeface(Typeface.create(typeface, Typeface.NORMAL));
    mTextEndPaint.setAntiAlias(true);
    mTextEndPaint.setSubpixelText(true);
    mTextEndPaint.setTextAlign(Paint.Align.CENTER);

    // 绘制电池的画笔
    mBatteryPaint = new TextPaint();
    mBatteryPaint.setAntiAlias(true);
    mBatteryPaint.setDither(true);
    mBatteryPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE - 3));
    mBatteryPaint.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "number.ttf"));

    setupTextInterval();
    // 初始化页面样式
    initPageStyle();
}
 
Example 13
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 14
Source File: KeyImage.java    From mongol-library with MIT License 4 votes vote down vote up
private void init() {
    mImagePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mImagePaint.setFilterBitmap(true);
    mImagePaint.setDither(true);
}
 
Example 15
Source File: TextDrawable.java    From CryptoBuddy with GNU Affero General Public License v3.0 4 votes vote down vote up
public TextDrawable(Context context) {
    super();
    //Used to load and scale resource items
    mResources = context.getResources();
    //Definition of this drawables size
    mTextBounds = new Rect();
    //Paint to use for the text
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.density = mResources.getDisplayMetrics().density;
    mTextPaint.setDither(true);

    int textSize = 15;
    ColorStateList textColor = null;
    int styleIndex = -1;
    int typefaceIndex = -1;

    //Set default parameters from the current theme
    TypedArray a = context.getTheme().obtainStyledAttributes(themeAttributes);
    int appearanceId = a.getResourceId(0, -1);
    a.recycle();

    TypedArray ap = null;
    if (appearanceId != -1) {
        ap = context.obtainStyledAttributes(appearanceId, appearanceAttributes);
    }
    if (ap != null) {
        for (int i=0; i < ap.getIndexCount(); i++) {
            int attr = ap.getIndex(i);
            switch (attr) {
                case 0: //Text Size
                    textSize = a.getDimensionPixelSize(attr, textSize);
                    break;
                case 1: //Typeface
                    typefaceIndex = a.getInt(attr, typefaceIndex);
                    break;
                case 2: //Text Style
                    styleIndex = a.getInt(attr, styleIndex);
                    break;
                case 3: //Text Color
                    textColor = a.getColorStateList(attr);
                    break;
                default:
                    break;
            }
        }

        ap.recycle();
    }

    setTextColor(textColor != null ? textColor : ColorStateList.valueOf(0xFF000000));
    setRawTextSize(textSize);

    Typeface tf = null;
    switch (typefaceIndex) {
        case SANS:
            tf = Typeface.SANS_SERIF;
            break;

        case SERIF:
            tf = Typeface.SERIF;
            break;

        case MONOSPACE:
            tf = Typeface.MONOSPACE;
            break;
    }

    setTypeface(tf, styleIndex);
}
 
Example 16
Source File: TextDrawable.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
public TextDrawable(Context context) {
    super();
    //Used to load and scale resource items
    mResources = context.getResources();
    //Definition of this drawables size
    mTextBounds = new Rect();
    //Paint to use for the text
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.density = mResources.getDisplayMetrics().density;
    mTextPaint.setDither(true);

    int textSize = 15;
    ColorStateList textColor = null;
    int styleIndex = -1;
    int typefaceIndex = -1;

    //Set default parameters from the current theme
    TypedArray a = context.getTheme().obtainStyledAttributes(themeAttributes);
    int appearanceId = a.getResourceId(0, -1);
    a.recycle();

    TypedArray ap = null;
    if (appearanceId != -1) {
        ap = context.obtainStyledAttributes(appearanceId, appearanceAttributes);
    }
    if (ap != null) {
        for (int i=0; i < ap.getIndexCount(); i++) {
            int attr = ap.getIndex(i);
            switch (attr) {
                case 0: //Text Size
                    textSize = a.getDimensionPixelSize(attr, textSize);
                    break;
                case 1: //Typeface
                    typefaceIndex = a.getInt(attr, typefaceIndex);
                    break;
                case 2: //Text Style
                    styleIndex = a.getInt(attr, styleIndex);
                    break;
                case 3: //Text Color
                    textColor = a.getColorStateList(attr);
                    break;
                default:
                    break;
            }
        }

        ap.recycle();
    }

    setTextColor(textColor != null ? textColor : ColorStateList.valueOf(0xFF000000));
    setRawTextSize(textSize);

    Typeface tf = null;
    switch (typefaceIndex) {
        case SANS:
            tf = Typeface.SANS_SERIF;
            break;

        case SERIF:
            tf = Typeface.SERIF;
            break;

        case MONOSPACE:
            tf = Typeface.MONOSPACE;
            break;
    }

    setTypeface(tf, styleIndex);
}
 
Example 17
Source File: TextDrawable.java    From iview-android-tv with MIT License 4 votes vote down vote up
public TextDrawable(Context context) {
    super();
    //Used to load and scale resource items
    mResources = context.getResources();
    //Definition of this drawables size
    mTextBounds = new Rect();
    //Paint to use for the text
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.density = mResources.getDisplayMetrics().density;
    mTextPaint.setDither(true);

    int textSize = 15;
    ColorStateList textColor = null;
    int styleIndex = -1;
    int typefaceIndex = -1;

    //Set default parameters from the current theme
    TypedArray a = context.getTheme().obtainStyledAttributes(themeAttributes);
    int appearanceId = a.getResourceId(0, -1);
    a.recycle();

    TypedArray ap = null;
    if (appearanceId != -1) {
        ap = context.obtainStyledAttributes(appearanceId, appearanceAttributes);
    }
    if (ap != null) {
        for (int i = 0; i < ap.getIndexCount(); i++) {
            int attr = ap.getIndex(i);
            switch (attr) {
                case 0: //Text Size
                    textSize = a.getDimensionPixelSize(attr, textSize);
                    break;
                case 1: //Typeface
                    typefaceIndex = a.getInt(attr, typefaceIndex);
                    break;
                case 2: //Text Style
                    styleIndex = a.getInt(attr, styleIndex);
                    break;
                case 3: //Text Color
                    textColor = a.getColorStateList(attr);
                    break;
                default:
                    break;
            }
        }

        ap.recycle();
    }

    setTextColor(textColor != null ? textColor : ColorStateList.valueOf(0xFF000000));
    setRawTextSize(textSize);

    Typeface tf = null;
    switch (typefaceIndex) {
        case SANS:
            tf = Typeface.SANS_SERIF;
            break;

        case SERIF:
            tf = Typeface.SERIF;
            break;

        case MONOSPACE:
            tf = Typeface.MONOSPACE;
            break;
    }

    setTypeface(tf, styleIndex);
}
 
Example 18
Source File: BookPieChartView.java    From kAndroid with Apache License 2.0 4 votes vote down vote up
private void initPaint() {
    mPieChartPaint = new Paint();
    //是否开启抗锯齿
    mPieChartPaint.setAntiAlias(true);
    //防抖动
    mPieChartPaint.setDither(true);
    //画笔样式 STROKE 只绘制图形轮廓(描边) FILL 只绘制图形内容 FILL_AND_STROKE 既绘制轮廓也绘制内容
    mPieChartPaint.setStyle(Paint.Style.FILL);
    //画笔宽度
    mPieChartPaint.setStrokeWidth(mPieChartWidth);
    ///笔刷样式
    // 当画笔样式为STROKE或FILL_OR_STROKE时,
    mPieChartPaint.setStrokeCap(Paint.Cap.SQUARE);
    // 设置笔刷的图形样式,如圆形样式Cap.ROUND,或方形样式Cap.SQUARE
    mPieChartPaint.setColor(Color.RED);

    //数字
    mDataPaint = new TextPaint();
    mDataPaint.setDither(true);
    mDataPaint.setAntiAlias(true);
    mDataPaint.setTextSize(mDataSize);
    mDataPaint.setColor(mDataColor);
    //从中间向两边绘制,不需要再次计算文字
    mDataPaint.setTextAlign(Paint.Align.CENTER);

    //单位
    mUnitPaint = new TextPaint();
    mUnitPaint.setDither(true);
    mUnitPaint.setAntiAlias(true);
    mUnitPaint.setTextSize(mUnitSize);
    mUnitPaint.setColor(mUnitColor);
    //从中间向两边绘制,不需要再次计算文字
    mUnitPaint.setTextAlign(Paint.Align.CENTER);

    mPointingPaint = new Paint();
    mPointingPaint.setDither(true);
    mPointingPaint.setAntiAlias(true);
    mPointingPaint.setColor(mPointingColor);
    //从中间向两边绘制,不需要再次计算文字
    mPointingPaint.setStrokeWidth(mPointingWidth);
}