Search in sources :

Example 51 with Typeface

use of android.graphics.Typeface in project Carbon by ZieIony.

the class TypefaceUtils method getTypeface.

public static Typeface getTypeface(Context context, String fontFamily, int textStyle) {
    // get from cache
    Typeface t = (Typeface) familyStyleCache[textStyle].get(fontFamily);
    if (t != null)
        return t;
    // Roboto?
    for (Roboto style : Roboto.values()) {
        if (style.getFontFamily().equals(fontFamily) && style.getTextStyle() == textStyle) {
            t = loadRoboto(context, style);
            if (t != null)
                return t;
        }
    }
    // load from system res
    t = Typeface.create(fontFamily, textStyle);
    if (t != null) {
        familyStyleCache[textStyle].put(fontFamily, t);
        return t;
    }
    return Typeface.DEFAULT;
}
Also used : Typeface(android.graphics.Typeface)

Example 52 with Typeface

use of android.graphics.Typeface in project Carbon by ZieIony.

the class TypefaceUtils method getTypeface.

public static Typeface getTypeface(Context context, Roboto roboto) {
    // get from cache
    Typeface t = robotoCache.get(roboto);
    if (t != null)
        return t;
    t = loadRoboto(context, roboto);
    if (t != null)
        return t;
    return Typeface.DEFAULT;
}
Also used : Typeface(android.graphics.Typeface)

Example 53 with Typeface

use of android.graphics.Typeface in project Carbon by ZieIony.

the class InputLayout method initInputLayout.

private void initInputLayout(AttributeSet attrs, int defStyleAttr) {
    View.inflate(getContext(), R.layout.carbon_inputlayout, this);
    errorTextView = (TextView) findViewById(R.id.carbon_error);
    errorTextView.setTextColor(new DefaultTextSecondaryColorStateList(getContext()));
    errorTextView.setValid(false);
    counterTextView = (TextView) findViewById(R.id.carbon_counter);
    counterTextView.setTextColor(new DefaultTextSecondaryColorStateList(getContext()));
    labelTextView = (TextView) findViewById(R.id.carbon_label);
    clearImageView = (ImageView) findViewById(R.id.carbon_clear);
    showPasswordImageView = (ImageView) findViewById(R.id.carbon_showPassword);
    if (isInEditMode())
        return;
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InputLayout, defStyleAttr, 0);
        for (int i = 0; i < a.getIndexCount(); i++) {
            int attr = a.getIndex(i);
            if (!isInEditMode() && attr == R.styleable.InputLayout_carbon_errorFontPath) {
                String path = a.getString(attr);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
                setErrorTypeface(typeface);
            } else if (attr == R.styleable.InputLayout_carbon_errorTextSize) {
                setErrorTextSize(a.getDimension(attr, 0));
            } else if (attr == R.styleable.InputLayout_carbon_errorFontFamily) {
                int textStyle = a.getInt(R.styleable.InputLayout_android_textStyle, 0);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), a.getString(attr), textStyle);
                setErrorTypeface(typeface);
            } else if (!isInEditMode() && attr == R.styleable.InputLayout_carbon_labelFontPath) {
                String path = a.getString(attr);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
                setLabelTypeface(typeface);
            } else if (attr == R.styleable.InputLayout_carbon_counterTextSize) {
                setCounterTextSize(a.getDimension(attr, 0));
            } else if (attr == R.styleable.InputLayout_carbon_labelFontFamily) {
                int textStyle = a.getInt(R.styleable.InputLayout_android_textStyle, 0);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), a.getString(attr), textStyle);
                setLabelTypeface(typeface);
            } else if (!isInEditMode() && attr == R.styleable.InputLayout_carbon_counterFontPath) {
                String path = a.getString(attr);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
                setCounterTypeface(typeface);
            } else if (attr == R.styleable.InputLayout_carbon_labelTextSize) {
                setLabelTextSize(a.getDimension(attr, 0));
            } else if (attr == R.styleable.InputLayout_carbon_counterFontFamily) {
                int textStyle = a.getInt(R.styleable.InputLayout_android_textStyle, 0);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), a.getString(attr), textStyle);
                setCounterTypeface(typeface);
            }
        }
        if (!isInEditMode())
            setError(a.getString(R.styleable.InputLayout_carbon_errorMessage));
        setMinCharacters(a.getInt(R.styleable.InputLayout_carbon_minCharacters, 0));
        setMaxCharacters(a.getInt(R.styleable.InputLayout_carbon_maxCharacters, Integer.MAX_VALUE));
        setLabelStyle(LabelStyle.values()[a.getInt(R.styleable.InputLayout_carbon_labelStyle, LabelStyle.Floating.ordinal())]);
        setLabel(a.getString(R.styleable.InputLayout_carbon_label));
        setRequired(a.getBoolean(R.styleable.InputLayout_carbon_required, false));
        setShowPasswordButtonEnabled(a.getBoolean(R.styleable.InputLayout_carbon_showPassword, false));
        setClearButtonEnabled(a.getBoolean(R.styleable.InputLayout_carbon_showClear, false));
        a.recycle();
    }
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) DefaultTextSecondaryColorStateList(carbon.drawable.DefaultTextSecondaryColorStateList)

Example 54 with Typeface

use of android.graphics.Typeface in project FinestWebView-Android by TheFinestArtist.

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 55 with Typeface

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

the class TypefaceUtil method create.

/**
     * create a typeface
     *
     * @param name
     * @return
     */
public static Typeface create(final String name) {
    Typeface result = SimpleCache.getCache(TAG).get(name);
    if (result == null) {
        final String fontNameOrFilePath = ParamUtil.getFileNameWithPostfix(name, "ttf");
        result = createFromFile(fontNameOrFilePath);
        if (result == null) {
            result = createByName(fontNameOrFilePath);
        }
    }
    //cache name
    SimpleCache.getCache(TAG_TYPEFACE_NAME).put(result, name);
    return SimpleCache.getCache(TAG).put(name, result);
}
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