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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations