Java Code Examples for android.graphics.Typeface#Builder

The following examples show how to use android.graphics.Typeface#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static Typeface getTypeface(String assetPath)
{
    synchronized (typefaceCache)
    {
        if (!typefaceCache.containsKey(assetPath))
        {
            try
            {
                Typeface t;
                if (Build.VERSION.SDK_INT >= 26)
                {
                    Typeface.Builder builder = new Typeface.Builder(ApplicationLoader.applicationContext.getAssets(), assetPath);
                    if (assetPath.contains("medium"))
                    {
                        builder.setWeight(700);
                    }
                    if (assetPath.contains("italic"))
                    {
                        builder.setItalic(true);
                    }
                    t = builder.build();
                }
                else
                {
                    t = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), assetPath);
                }
                typefaceCache.put(assetPath, t);
            }
            catch (Exception e)
            {
                if (BuildVars.LOGS_ENABLED)
                {
                    FileLog.e("Could not get typeface '" + assetPath + "' because " + e.getMessage());
                }
                return null;
            }
        }
        return typefaceCache.get(assetPath);
    }
}
 
Example 2
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static Typeface getTypeface(String assetPath)
{
    synchronized (typefaceCache)
    {
        if (!typefaceCache.containsKey(assetPath))
        {
            try
            {
                Typeface t;
                if (Build.VERSION.SDK_INT >= 26)
                {
                    Typeface.Builder builder = new Typeface.Builder(ApplicationLoader.applicationContext.getAssets(), assetPath);
                    if (assetPath.contains("medium"))
                    {
                        builder.setWeight(700);
                    }
                    if (assetPath.contains("italic"))
                    {
                        builder.setItalic(true);
                    }
                    t = builder.build();
                }
                else
                {
                    t = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), assetPath);
                }
                typefaceCache.put(assetPath, t);
            }
            catch (Exception e)
            {
                if (BuildVars.LOGS_ENABLED)
                {
                    FileLog.e("Could not get typeface '" + assetPath + "' because " + e.getMessage());
                }
                return null;
            }
        }
        return typefaceCache.get(assetPath);
    }
}
 
Example 3
Source File: AndroidUtilities.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static Typeface getTypeface(String assetPath) {
    synchronized (typefaceCache) {
        if (!typefaceCache.containsKey(assetPath)) {
            try {
                Typeface t;
                if (Build.VERSION.SDK_INT >= 26) {
                    Typeface.Builder builder = new Typeface.Builder(ApplicationLoader.applicationContext.getAssets(), assetPath);
                    if (assetPath.contains("medium")) {
                        builder.setWeight(700);
                    }
                    if (assetPath.contains("italic")) {
                        builder.setItalic(true);
                    }
                    t = builder.build();
                } else {
                    t = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), assetPath);
                }
                typefaceCache.put(assetPath, t);
            } catch (Exception e) {
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.e("Could not get typeface '" + assetPath + "' because " + e.getMessage());
                }
                return null;
            }
        }
        return typefaceCache.get(assetPath);
    }
}
 
Example 4
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static Typeface getTypeface(String assetPath) {
    synchronized (typefaceCache) {
        if (!typefaceCache.containsKey(assetPath)) {
            try {
                Typeface t;
                if (Build.VERSION.SDK_INT >= 26) {
                    Typeface.Builder builder = new Typeface.Builder(ApplicationLoader.applicationContext.getAssets(), assetPath);
                    if (assetPath.contains("medium")) {
                        builder.setWeight(700);
                    }
                    if (assetPath.contains("italic")) {
                        builder.setItalic(true);
                    }
                    t = builder.build();
                } else {
                    t = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), assetPath);
                }
                typefaceCache.put(assetPath, t);
            } catch (Exception e) {
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.e("Could not get typeface '" + assetPath + "' because " + e.getMessage());
                }
                return null;
            }
        }
        return typefaceCache.get(assetPath);
    }
}