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

The following are Jave code examples for showing how to use setTypeface() 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: TPlayer   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 2
Project: XERUNG   File: MaterialSpinner.java   Source Code and License Vote up 6 votes
private void initPaintObjects() {

        int labelTextSize = getResources().getDimensionPixelSize(R.dimen.label_text_size);

        paint = new Paint(Paint.ANTI_ALIAS_FLAG);

        textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        textPaint.setTextSize(labelTextSize);
        if (typeface != null) {
            textPaint.setTypeface(typeface);
        }
        textPaint.setColor(baseColor);
        baseAlpha = textPaint.getAlpha();

        selectorPath = new Path();
        selectorPath.setFillType(Path.FillType.EVEN_ODD);

        selectorPoints = new Point[3];
        for (int i = 0; i < 3; i++) {
            selectorPoints[i] = new Point();
        }
    }
 
Example 3
Project: PlusGram   File: TypefaceSpan.java   Source Code and License Vote up 5 votes
@Override
public void updateDrawState(TextPaint tp) {
    if (mTypeface != null) {
        tp.setTypeface(mTypeface);
    }
    if (textSize != 0) {
        tp.setTextSize(textSize);
    }
    if (color != 0) {
        tp.setColor(color);
    }
    tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
 
Example 4
Project: revolution-irc   File: LabelLayout.java   Source Code and License Vote up 5 votes
public LabelLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    setWillNotDraw(false);
    setAddStatesFromChildren(true);

    mInputFrame = new FrameLayout(context);
    mInputFrame.setAddStatesFromChildren(true);
    super.addView(mInputFrame, -1, generateDefaultLayoutParams());

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    mTextPaint.setTypeface(Typeface.DEFAULT);// getTypeface());
    mTextSizeCollapsed = getResources().getDimensionPixelSize(R.dimen.abc_text_size_caption_material);
    mTextSizeExpanded = getResources().getDimensionPixelSize(R.dimen.abc_text_size_medium_material);
    mTextPaint.setTextSize(mTextSizeCollapsed);

    StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(context, attrs,
            new int[] { R.attr.doNotExpand, android.R.attr.hint, android.R.attr.textColorHint });
    try {
        mDoNotExpand = ta.getBoolean(R.attr.doNotExpand, false);
        mHint = ta.getString(android.R.attr.hint);
        mTextColorUnfocused = ta.getColorStateList(android.R.attr.textColorHint);
    } finally {
        ta.recycle();
    }
    mTextColorFocused = ThemeHelper.getAccentColor(context);
    mTextPaint.setColor(mTextColorUnfocused.getColorForState(getDrawableState(), mTextColorUnfocused.getDefaultColor()));

    mAnimator = ValueAnimator.ofFloat(0.f, 1.f);
    mAnimator.setInterpolator(new LinearInterpolator());
    mAnimator.setDuration(200);
    mAnimator.addUpdateListener((ValueAnimator animation) -> {
        mAnimState = (float) animation.getAnimatedValue();
        invalidate();
    });

    updateTopMargin();
    updateTextPositions();
}
 
Example 5
Project: asset-font-views   File: AssetFontSpan.java   Source Code and License Vote up 5 votes
@Override
public void updateMeasureState(TextPaint p) {
    p.setTypeface(mTypeface);

    // Note: This flag is required for proper typeface rendering
    p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
 
Example 6
Project: Neuronizer   File: TypefaceSpan.java   Source Code and License Vote up 5 votes
@Override
public void updateDrawState(TextPaint tp) {
    tp.setTypeface(mTypeface);

    // Note: This flag is required for proper typeface rendering
    tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
 
Example 7
Project: PlusGram   File: CustomHintDialogCell.java   Source Code and License Vote up 5 votes
public CustomHintDialogCell(Context context) {
    super(context);
    setBackgroundResource(R.drawable.list_selector);

    imageView = new BackupImageView(context);
    imageView.setRoundRadius(AndroidUtilities.dp(27));
    addView(imageView, LayoutHelper.createFrame(43, 43, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 7, 0, 0));

    nameTextView = new TextView(context);
    nameTextView.setTextColor(0xff212121);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 9);
    nameTextView.setMaxLines(2);
    nameTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
    nameTextView.setLines(2);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 6, 64, 6, 0));

    if (countDrawable == null) {
        countDrawable = getResources().getDrawable(R.drawable.dialogs_badge);
        countDrawableGrey = getResources().getDrawable(R.drawable.dialogs_badge2);

        countPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
        countPaint.setColor(0xffffffff);
        countPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    }
    countPaint.setTextSize(AndroidUtilities.dp(11));
}
 
Example 8
Project: airgram   File: TypefaceSpan.java   Source Code and License Vote up 5 votes
@Override
public void updateMeasureState(TextPaint p) {
    if (mTypeface != null) {
        p.setTypeface(mTypeface);
    }
    if (textSize != 0) {
        p.setTextSize(textSize);
    }
    p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
 
Example 9
Project: Veggietizer   File: TypefaceSpan.java   Source Code and License Vote up 5 votes
@Override
public void updateDrawState(TextPaint tp) {
    tp.setTypeface(mTypeface);

    // Note: This flag is required for proper typeface rendering
    tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
 
Example 10
Project: revolution-irc   File: StaticLabelTextInputLayout.java   Source Code and License Vote up 5 votes
public StaticLabelTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    mTextPaint.setTypeface(getTypeface());
    mTextPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.abc_text_size_caption_material));
    StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(context,
            new int[] { android.R.attr.textColorHint });
    mTextColorUnfocused = ta.getColor(android.R.attr.textColorHint, 0);
    ta.recycle();
    mTextColorFocused = ThemeHelper.getAccentColor(context);
    mTextPaint.setColor(mTextColorUnfocused);
}
 
Example 11
Project: chromium-for-android-56-debug-video   File: TabSwitcherDrawable.java   Source Code and License Vote up 5 votes
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 12
Project: PlusGram   File: TypefaceSpan.java   Source Code and License Vote up 5 votes
@Override
public void updateMeasureState(TextPaint p) {
    if (mTypeface != null) {
        p.setTypeface(mTypeface);
    }
    if (textSize != 0) {
        p.setTextSize(textSize);
    }
    p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
 
Example 13
Project: MultiContactPicker   File: RoundLetterView.java   Source Code and License Vote up 5 votes
private void init(AttributeSet attrs, int defStyle) {
    final TypedArray a = getContext().obtainStyledAttributes(
            attrs, R.styleable.RoundedLetterView, defStyle, 0);

    if(a.hasValue(R.styleable.RoundedLetterView_rlv_titleText)){
        mTitleText = a.getString(R.styleable.RoundedLetterView_rlv_titleText);
    }

    mTitleColor = a.getColor(R.styleable.RoundedLetterView_rlv_titleColor,DEFAULT_TITLE_COLOR);
    mBackgroundColor = a.getColor(R.styleable.RoundedLetterView_rlv_backgroundColorValue,DEFAULT_BACKGROUND_COLOR);

    mTitleSize = a.getDimension(R.styleable.RoundedLetterView_rlv_titleSize,DEFAULT_TITLE_SIZE);
    a.recycle();

    //Title TextPaint
    mTitleTextPaint = new TextPaint();
    mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTitleTextPaint.setTypeface(mFont);
    mTitleTextPaint.setTextAlign(Paint.Align.CENTER);
    mTitleTextPaint.setLinearText(true);
    mTitleTextPaint.setColor(mTitleColor);
    mTitleTextPaint.setTextSize(mTitleSize);

    //Background Paint
    mBackgroundPaint = new Paint();
    mBackgroundPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setStyle(Paint.Style.FILL);
    mBackgroundPaint.setColor(mBackgroundColor);

    mInnerRectF = new RectF();
}
 
Example 14
Project: Protein   File: BadgedFourThreeImageView.java   Source Code and License Vote up 5 votes
GifBadge(Context context) {
    if (bitmap == null) {
        final DisplayMetrics dm = context.getResources().getDisplayMetrics();
        final float density = dm.density;
        final float scaledDensity = dm.scaledDensity;
        final TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint
                .SUBPIXEL_TEXT_FLAG);
        textPaint.setTypeface(Typeface.create(TYPEFACE, TYPEFACE_STYLE));
        textPaint.setTextSize(TEXT_SIZE * scaledDensity);

        final float padding = PADDING * density;
        final float cornerRadius = CORNER_RADIUS * density;
        final Rect textBounds = new Rect();
        textPaint.getTextBounds(GIF, 0, GIF.length(), textBounds);
        height = (int) (padding + textBounds.height() + padding);
        width = (int) (padding + textBounds.width() + padding);
        bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        bitmap.setHasAlpha(true);
        final Canvas canvas = new Canvas(bitmap);
        final Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        backgroundPaint.setColor(BACKGROUND_COLOR);
        canvas.drawRoundRect(0, 0, width, height, cornerRadius, cornerRadius,
                backgroundPaint);
        // punch out the word 'GIF', leaving transparency
        textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        canvas.drawText(GIF, padding, height - padding, textPaint);
    }
    paint = new Paint();
}
 
Example 15
Project: PlusGram   File: URLSpanNoUnderlineBold.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint ds) {
    super.updateDrawState(ds);
    ds.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    ds.setUnderlineText(false);
}
 
Example 16
Project: airgram   File: URLSpanNoUnderlineBold.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint ds) {
    super.updateDrawState(ds);
    ds.setTypeface(FontManager.instance().getTypeface());
    ds.setUnderlineText(false);
}
 
Example 17
Project: OSchina_resources_android   File: PortraitView.java   Source Code and License Vote up 4 votes
@SuppressWarnings("ResourceAsColor")
private Bitmap buildSrcFromName(final String firstChar, int w, int h) {
    if (w == Target.SIZE_ORIGINAL || w <= 0)
        w = 80;
    if (h == Target.SIZE_ORIGINAL || h <= 0)
        h = 80;

    final int size = Math.max(Math.min(Math.min(w, h), 220), 64);
    final float fontSize = size * 0.4f;
    log("firstChar:" + firstChar + " size:" + size + " fontSize:" + fontSize);

    Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565);

    TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setColor(Color.WHITE);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setTextSize(fontSize);
    paint.setTypeface(Typeface.SANS_SERIF);

    // check ASCII
    final int charNum = Character.getNumericValue(firstChar.charAt(0));
    if (charNum > 0 && charNum < 177) {
        Typeface typeface = getFont(getContext(), "Numans-Regular.otf");
        if (typeface != null)
            paint.setTypeface(typeface);
    }

    Rect rect = new Rect();
    paint.getTextBounds(firstChar, 0, 1, rect);
    int fontHeight = rect.height();
    log(rect.toString());

    int fontHalfH = fontHeight >> 1;
    int centerX = bitmap.getWidth() >> 1;
    int centerY = bitmap.getHeight() >> 1;

    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(getBackgroundColor(firstChar));
    canvas.drawText(firstChar, centerX, centerY + fontHalfH, paint);

    return bitmap;
}
 
Example 18
Project: SetupWizardLibCompat   File: LinkSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint drawState) {
    super.updateDrawState(drawState);
    drawState.setUnderlineText(false);
    drawState.setTypeface(TYPEFACE_MEDIUM);
}
 
Example 19
Project: Quran   File: UthmaniSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint ds) {
  ds.setTypeface(mTypeface);
}
 
Example 20
Project: Quran   File: UthmaniSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateMeasureState(TextPaint paint) {
  paint.setTypeface(mTypeface);
}