Android Open Source - Android-RobotoTextView Roboto Typeface Span






From Project

Back to project page Android-RobotoTextView.

License

The source code is released under:

Apache License

If you think the Android project Android-RobotoTextView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.devspark.robototextview.style;
//from  w ww.  j a  va2  s.  c o  m
import android.content.Context;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.MetricAffectingSpan;

import com.devspark.robototextview.util.RobotoTextViewUtils;
import com.devspark.robototextview.util.RobotoTypefaceManager;

/**
 * Span for replacing typeface.
 */
public class RobotoTypefaceSpan extends MetricAffectingSpan {

    /**
     * Created typefaces.
     */
    private final Typeface mTypeface;

    /**
     * Constructor to use with default typeface (regular).
     *
     * @param context The Context the span is using in, through which it can
     *                access the current theme, resources, etc.
     */
    public RobotoTypefaceSpan(Context context) {
        this(context, RobotoTypefaceManager.Typeface.ROBOTO_REGULAR);
    }

    /**
     * Constructor to use with typeface id.
     *
     * @param context    The Context the span is using in, through which it can
     *                   access the current theme, resources, etc.
     * @param typefaceId Typeface id ({@link RobotoTypefaceManager.Typeface})
     */
    public RobotoTypefaceSpan(Context context, int typefaceId) {
        mTypeface = RobotoTypefaceManager.obtainTypeface(context, typefaceId);
    }

    /**
     * Constructor to use with set of parameters.
     *
     * @param context    The Context the span is using in, through which it can
     *                   access the current theme, resources, etc.
     * @param fontFamily The value of "fontFamily" attribute ({@link RobotoTypefaceManager.FontFamily})
     * @param textWeight The value of "textWeight" attribute ({@link RobotoTypefaceManager.TextWeight})
     * @param textStyle  The value of "textStyle" attribute ({@link RobotoTypefaceManager.TextStyle})
     */
    public RobotoTypefaceSpan(Context context, int fontFamily, int textWeight, int textStyle) {
        mTypeface = RobotoTypefaceManager.obtainTypeface(context, fontFamily, textWeight, textStyle);
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        RobotoTextViewUtils.setTypeface(ds, mTypeface);
    }

    @Override
    public void updateMeasureState(TextPaint paint) {
        RobotoTextViewUtils.setTypeface(paint, mTypeface);
    }

}




Java Source Code List

com.devspark.robototextview.sample.MainActivity.java
com.devspark.robototextview.style.RobotoTypefaceSpan.java
com.devspark.robototextview.util.RobotoTextViewUtils.java
com.devspark.robototextview.util.RobotoTypefaceManager.java
com.devspark.robototextview.widget.RobotoAutoCompleteTextView.java
com.devspark.robototextview.widget.RobotoButton.java
com.devspark.robototextview.widget.RobotoCheckBox.java
com.devspark.robototextview.widget.RobotoCheckedTextView.java
com.devspark.robototextview.widget.RobotoChronometer.java
com.devspark.robototextview.widget.RobotoCompoundButton.java
com.devspark.robototextview.widget.RobotoDigitalClock.java
com.devspark.robototextview.widget.RobotoEditText.java
com.devspark.robototextview.widget.RobotoExtractEditText.java
com.devspark.robototextview.widget.RobotoMultiAutoCompleteTextView.java
com.devspark.robototextview.widget.RobotoRadioButton.java
com.devspark.robototextview.widget.RobotoSwitch.java
com.devspark.robototextview.widget.RobotoTextClock.java
com.devspark.robototextview.widget.RobotoTextView.java
com.devspark.robototextview.widget.RobotoToggleButton.java