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