Search in sources :

Example 41 with Typeface

use of android.graphics.Typeface in project qksms by moezbhatti.

the class TypefaceManager method obtainTypeface.

public static Typeface obtainTypeface(Context context, int typefaceValue) throws IllegalArgumentException {
    android.graphics.Typeface typeface = mTypefaces.get(typefaceValue);
    if (typeface == null) {
        typeface = createTypeface(context, typefaceValue);
        mTypefaces.put(typefaceValue, typeface);
    }
    return typeface;
}
Also used : Typeface(android.graphics.Typeface)

Example 42 with Typeface

use of android.graphics.Typeface in project qksms by moezbhatti.

the class RobotoTextView method initTypeface.

private void initTypeface(TextView textView, Context context, AttributeSet attrs) {
    Typeface typeface = null;
    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RobotoTextView);
        if (a.hasValue(R.styleable.RobotoTextView_typeface)) {
            int typefaceValue = a.getInt(R.styleable.RobotoTextView_typeface, TypefaceManager.Typefaces.ROBOTO_REGULAR);
            typeface = TypefaceManager.obtainTypeface(context, typefaceValue);
        }
        a.recycle();
    }
    if (typeface == null) {
        typeface = TypefaceManager.obtainTypeface(context, TypefaceManager.Typefaces.ROBOTO_REGULAR);
    }
    textView.setPaintFlags(textView.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
    textView.setTypeface(typeface);
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) Paint(android.graphics.Paint)

Example 43 with Typeface

use of android.graphics.Typeface in project Jota-Text-Editor-old by jiro-aqua.

the class TextAppearanceSpan method updateMeasureState.

@Override
public void updateMeasureState(TextPaint ds) {
    if (mTypeface != null || mStyle != 0) {
        Typeface tf = ds.getTypeface();
        int style = 0;
        if (tf != null) {
            style = tf.getStyle();
        }
        style |= mStyle;
        if (mTypeface != null) {
            tf = Typeface.create(mTypeface, style);
        } else if (tf == null) {
            tf = Typeface.defaultFromStyle(style);
        } else {
            tf = Typeface.create(tf, style);
        }
        int fake = style & ~tf.getStyle();
        if ((fake & Typeface.BOLD) != 0) {
            ds.setFakeBoldText(true);
        }
        if ((fake & Typeface.ITALIC) != 0) {
            ds.setTextSkewX(-0.25f);
        }
        ds.setTypeface(tf);
    }
    if (mTextSize > 0) {
        ds.setTextSize(mTextSize);
    }
}
Also used : Typeface(android.graphics.Typeface) TextPaint(android.text.TextPaint)

Example 44 with Typeface

use of android.graphics.Typeface in project material-dialogs by afollestad.

the class TypefaceHelper method get.

public static Typeface get(Context c, String name) {
    synchronized (cache) {
        if (!cache.containsKey(name)) {
            try {
                Typeface t = Typeface.createFromAsset(c.getAssets(), String.format("fonts/%s", name));
                cache.put(name, t);
                return t;
            } catch (RuntimeException e) {
                return null;
            }
        }
        return cache.get(name);
    }
}
Also used : Typeface(android.graphics.Typeface)

Example 45 with Typeface

use of android.graphics.Typeface in project LuaViewSDK by alibaba.

the class LuaResourceFinder method findTypeface.

/**
     * 在 asset 或者 文件系统 找字体文件
     * TODO 优化
     *
     * @param nameOrPath
     * @return
     */
public Typeface findTypeface(final String nameOrPath) {
    Typeface typeface = null;
    if (!TextUtils.isEmpty(nameOrPath)) {
        //如果没有后缀,则处理成.ttf
        final String typefaceNameOrPath = FileUtil.hasPostfix(nameOrPath) ? nameOrPath : ParamUtil.getFileNameWithPostfix(nameOrPath, "ttf");
        String filepath = buildPathInSdcardIfExists(typefaceNameOrPath);
        if (filepath != null) {
            //从文件系统加载
            typeface = TypefaceUtil.create(filepath);
        }
        if (typeface == null) {
            //从asset下加载
            filepath = buildPathInAssetsIfExists(typefaceNameOrPath);
            if (filepath != null) {
                typeface = TypefaceUtil.create(mContext, filepath);
            }
        }
        if (typeface == null) {
            //default name
            typeface = TypefaceUtil.create(mContext, nameOrPath);
        }
    }
    return typeface != null ? typeface : Typeface.DEFAULT;
}
Also used : Typeface(android.graphics.Typeface)

Aggregations

Typeface (android.graphics.Typeface)266 Paint (android.graphics.Paint)57 TextPaint (android.text.TextPaint)40 TypedArray (android.content.res.TypedArray)34 TextView (android.widget.TextView)21 View (android.view.View)20 Canvas (android.graphics.Canvas)15 Bitmap (android.graphics.Bitmap)13 Context (android.content.Context)11 Resources (android.content.res.Resources)10 Test (org.junit.Test)8 ColorStateList (android.content.res.ColorStateList)7 Legend (com.github.mikephil.charting.components.Legend)7 File (java.io.File)7 Intent (android.content.Intent)6 Attributes (com.cengalabs.flatui.Attributes)6 XAxis (com.github.mikephil.charting.components.XAxis)6 YAxis (com.github.mikephil.charting.components.YAxis)6 ContentResolver (android.content.ContentResolver)5 Drawable (android.graphics.drawable.Drawable)5