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