/
BirdLeon
/
ROBLOX2016
Обзор
Документация
Войти
/
BirdLeon
/
ROBLOX2016
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
Android/NativeShell/src/com/roblox/client/components/RbxFontHelper.java
56 строк
2 KB
PatoFlamejanteTV
full source code
19 дек 2024, 19:11
19 дек 2024, 19:11
05db15d
Код
Авторство
О чём код?
package com.roblox.client.components; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Typeface; import android.util.AttributeSet; import android.widget.TextView; import com.roblox.client.R; import java.util.Hashtable; public class RbxFontHelper { private static final String DEFAULT_FONT = "SourceSansPro-Light.ttf"; // Sets a font for our view based on the com.roblox.client:font attribute // Note: font is optional, defaults to SourceSansPro public static void setCustomFont(TextView view, Context context, AttributeSet attr) { TypedArray a = context.obtainStyledAttributes(attr, R.styleable.RbxFont); String font = a.getString(R.styleable.RbxFont_fontName); if (font == null) font = DEFAULT_FONT; setCustomFont(view, context, font); a.recycle(); } public static void setCustomFont(TextView view, Context context, String font) { if (font != null) { Typeface tf = RbxFontCache.get(font, context); if (tf != null) view.setTypeface(tf); } } static class RbxFontCache { private static String TAG = "RbxFontCache"; private static Hashtable<String, Typeface> fontCache = new Hashtable<String, Typeface>(); public static Typeface get(String name, Context context) { Typeface tf = fontCache.get(name); if (tf == null) { try { tf = Typeface.createFromAsset(context.getAssets(), "fonts/" + name); fontCache.put(name, tf); } catch (Exception e) { return null; } } return tf; } } }