Search in sources :

Example 11 with Typeface

use of android.graphics.Typeface in project RobotoViews by eeVoskos.

the class RobotoSwitch method robotize.

private void robotize(Context context, AttributeSet attrs, int defStyle) {
    if (isInEditMode()) {
        return;
    }
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RobotoSwitch, defStyle, 0);
    int value = 0;
    try {
        value = a.getInteger(R.styleable.RobotoSwitch_typeface, 0);
    } finally {
        a.recycle();
    }
    Typeface typeface = Roboto.getInstance(context).getTypeface(value);
    setTypeface(typeface);
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray)

Example 12 with Typeface

use of android.graphics.Typeface in project RobotoViews by eeVoskos.

the class RobotoTextView method robotize.

private void robotize(Context context, AttributeSet attrs, int defStyle) {
    if (isInEditMode()) {
        return;
    }
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RobotoTextView, defStyle, 0);
    int value = 0;
    try {
        value = a.getInteger(R.styleable.RobotoTextView_typeface, 0);
    } finally {
        a.recycle();
    }
    Typeface typeface = Roboto.getInstance(context).getTypeface(value);
    setTypeface(typeface);
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray)

Example 13 with Typeface

use of android.graphics.Typeface in project RobotoViews by eeVoskos.

the class RobotoToggleButton method robotize.

private void robotize(Context context, AttributeSet attrs, int defStyle) {
    if (isInEditMode()) {
        return;
    }
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RobotoToggleButton, defStyle, 0);
    int value = 0;
    try {
        value = a.getInteger(R.styleable.RobotoToggleButton_typeface, 0);
    } finally {
        a.recycle();
    }
    Typeface typeface = Roboto.getInstance(context).getTypeface(value);
    setTypeface(typeface);
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray)

Example 14 with Typeface

use of android.graphics.Typeface in project RobotoViews by eeVoskos.

the class Roboto method getTypeface.

/**
     * Returns the appropriate Roboto {@code Typeface} based on the input xml
     * value. If the typeface exists in the internal array, it is returned
     * immediately. Else, it is lazily created and returned. The lazily created
     * typeface is kept for future use.
     * 
     * @param value
     *            The typeface xml value.
     * @return The appropriate Roboto {@code Typeface}.
     */
public Typeface getTypeface(int value) {
    if (DEBUG) {
        Log.d(TAG, "Getting Typeface for value " + value);
    }
    Typeface tf = mTypefaces.get(value);
    if (tf != null) {
        if (DEBUG) {
            Log.i(TAG, "Typeface was loaded from memory.");
        }
        return tf;
    }
    int resourceId = getResourceId(value);
    tf = getFontFromRes(resourceId);
    mTypefaces.put(value, tf);
    if (DEBUG) {
        Log.i(TAG, "Typeface was lazily created.");
    }
    return tf;
}
Also used : Typeface(android.graphics.Typeface)

Example 15 with Typeface

use of android.graphics.Typeface in project RobotoViews by eeVoskos.

the class Roboto method getFontFromRes.

private Typeface getFontFromRes(int resource) {
    Typeface tf = null;
    InputStream is;
    try {
        is = mContext.getResources().openRawResource(resource);
    } catch (NotFoundException e) {
        if (DEBUG) {
            e.printStackTrace();
        }
        return Typeface.DEFAULT;
    }
    String outPath = mContext.getCacheDir() + "/tmp.raw";
    try {
        byte[] buffer = new byte[is.available()];
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outPath));
        int l = 0;
        while ((l = is.read(buffer)) > 0) bos.write(buffer, 0, l);
        bos.close();
        tf = Typeface.createFromFile(outPath);
        // clean up
        new File(outPath).delete();
    } catch (IOException e) {
        if (DEBUG) {
            e.printStackTrace();
        }
        // Fallback to default font
        return Typeface.DEFAULT;
    }
    return tf;
}
Also used : Typeface(android.graphics.Typeface) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) NotFoundException(android.content.res.Resources.NotFoundException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Aggregations

Typeface (android.graphics.Typeface)263 Paint (android.graphics.Paint)56 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