Android TextPaint - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android TextPaint class.

This code example shows how to use the following methods:setAntiAlias, setFakeBoldText, setTextSize
            mHugePaint = new Paint();
            mHugePaint.setAntiAlias(true);
            mHugePaint.setColor(0xff000000);
            mHugePaint.setTextSize(300f);
 
            mEventPaint = new TextPaint();
            mEventPaint.setFakeBoldText(true);
            mEventPaint.setAntiAlias(true);
            mEventPaint.setTextSize(14);
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRGB(255, 255, 255);
 
            canvas.drawText("Hello OpenGL renderer!", 300, 20, mEventPaint);
             
            mMediumPaint.setStyle(Paint.Style.FILL_AND_STROKE);
            mMediumPaint.setStrokeWidth(2.0f);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setColor, setShadowLayer, setTextSize, setTypeface
		if (valuePaint == null) {
			if (typefaceWeight == Typeface.BOLD) {
				valuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG
						| Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG);
			} else { 
				valuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG
						| Paint.DITHER_FLAG);
			} 
			//valuePaint.density = getResources().getDisplayMetrics().density; 
			valuePaint.setTextSize(textSize);
			valuePaint.setShadowLayer(0.5f, 0, 0.5f, 0xFFFFFFFF);
			valuePaint.setTypeface(typeface);
			valuePaint.setColor((textColor == NOVAL) ? ITEMS_TEXT_COLOR : textColor);
		} 
 
		if (centerDrawable == null) {
			centerDrawable = getWheelValDrawable(); //getContext().getResources().getDrawable(R.drawable.wheel_val);
		} 
 
		if (topShadow == null) {
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setAntiAlias, setColor, setStrokeWidth, setStyle, setTextSize
This code example shows how to use the following methods:setColor, setTextAlign, setTextSize
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        final int width = getWidth();
        final int height = getHeight();
 
        final TextPaint paint = new TextPaint();
        paint.setTextSize(mSize);
        paint.setColor(mColor);
        paint.setTextAlign(Align.CENTER);
 
        canvas.drawText(mText, width / 2, height * 2 / 3, paint);
    } 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setAntiAlias, setColor, setStyle, setTextAlign, setTypeface
     * @param icon    The icon you want this drawable to display. 
     */ 
    public IconDrawable(Context context, Iconify.IconValue icon) {
        this.context = context;
        this.icon = icon;
        paint = new TextPaint();
        paint.setTypeface(Iconify.getTypeface(context));
        paint.setStyle(Paint.Style.STROKE);
        paint.setTextAlign(Paint.Align.CENTER);
        paint.setUnderlineText(false);
        paint.setColor(Color.BLACK);
        paint.setAntiAlias(true);
    } 
 
    /** 
     * Set the size of this icon to the standard Android ActionBar. 
     * @return The current IconDrawable for chaining. 
     */ 
    public IconDrawable actionBarSize() { 
        return sizeDp(ANDROID_ACTIONBAR_ICON_SIZE_DP);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setAlpha, setAntiAlias, setTextSize, setTypeface, getDesiredWidth
    ++n;
    return (n <= 0) ? 1 : n;
  } 
 
  private void prepareLayout() { 
    float desiredWidth = Layout.getDesiredWidth(text, paint);
 
    textWidth = (int)Math.ceil(desiredWidth);
    if (textWidth > maxWidthPixels) {
      textWidth = maxWidthPixels;
    } 
    else if (textWidth <= 0) {
      textWidth = 1;
    } 
 
    Layout.Alignment _alignment = Layout.Alignment.ALIGN_NORMAL;
 
    if (alignment == 1) {
      _alignment = Layout.Alignment.ALIGN_CENTER;
    } 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setAntiAlias, setFakeBoldText, setTextSize
            mHugePaint = new Paint();
            mHugePaint.setAntiAlias(true);
            mHugePaint.setColor(0xff000000);
            mHugePaint.setTextSize(300f);
 
            mEventPaint = new TextPaint();
            mEventPaint.setFakeBoldText(true);
            mEventPaint.setAntiAlias(true);
            mEventPaint.setTextSize(14);
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRGB(255, 255, 255);
 
            canvas.drawText("Hello OpenGL renderer!", 300, 20, mEventPaint);
             
            mMediumPaint.setStyle(Paint.Style.FILL_AND_STROKE);
            mMediumPaint.setStrokeWidth(2.0f);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getTypeface, setColor, setFakeBoldText, setTextSize, setTextSkewX
    @Override 
    public void updateDrawState(TextPaint ds) {
        updateMeasureState(ds);
 
        if (mTextColor != null) {
            ds.setColor(mTextColor.getColorForState(ds.drawableState, 0));
        } 
 
        if (mTextColorLink != null) {
            ds.linkColor = mTextColor.getColorForState(ds.drawableState, 0);
        } 
    } 
 
    @Override 
    public void updateMeasureState(TextPaint ds) {
        if (mTypeface != null || mStyle != 0) {
            Typeface tf = ds.getTypeface();
            int style = 0;
 
            if (tf != null) {

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getTypeface, setFakeBoldText, setTextSkewX, setTypeface
            final int typefaceStyle = tf != null ? tf.getStyle() : 0;
            final int need = style & ~typefaceStyle;
            mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
            mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
        } else { 
            mTextPaint.setFakeBoldText(false);
            mTextPaint.setTextSkewX(0);
            setSwitchTypeface(tf);
        } 
    } 
 
    /** 
     * Sets the typeface in which the text should be displayed on the switch. 
     * Note that not all Typeface families actually have bold and italic 
     * variants, so you may need to use {@link #setSwitchTypeface(Typeface, int)} to get the appearance 
     * that you actually want. 
     *  
     * @attr ref android.R.styleable#TextView_typeface 
     * @attr ref android.R.styleable#TextView_textStyle 
     */ 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getFontMetrics, measureText, setTextSize, setTypeface
        // grab hold of our test-font. 
        m_testface = Typeface.createFromAsset
            (ctx.getAssets(), "DroidSansMono.ttf");
 
        m_testpaint = new TextPaint
            (Paint.ANTI_ALIAS_FLAG     |
             Paint.SUBPIXEL_TEXT_FLAG  |
             Paint.DEV_KERN_TEXT_FLAG);
 
        m_testpaint.setTypeface(m_testface);
        m_testpaint.setTextSize(2048);
 
        Paint.FontMetrics fm = m_testpaint.getFontMetrics();
        assertEquals(TEST_LEADING, m_testpaint.getFontMetrics(null));
        assertEquals(TEST_WIDTH, m_testpaint.measureText("x"));
        assertEquals(TEST_WIDTH, m_testpaint.measureText(" "));
    } 
 
    protected TextPaint getTestPaint()
    { return m_testpaint; }
    protected Typeface  getTestTypeface()
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android TextPaint Questions & Answers:

See Code Examples for Android TextPaint Methods: