Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.umrohku.paketumroh.Utils;
- /**
- * Created by root on 03/12/16.
- */
- import android.content.Context;
- import android.graphics.Typeface;
- public class FontUtils {
- private static Typeface mContentFont;
- private static Typeface mTitleFont;
- public enum FontType {
- TITLE_FONT {
- public String toString() {
- return "Montserrat-Hairline.otf";
- }
- },
- CONTENT_FONT {
- public String toString() {
- return "montseratreg.otf";
- }
- };
- }
- private static Typeface getTypeface(Context context, String typefaceName) {
- try {
- if (typefaceName.equals(FontType.TITLE_FONT.toString())) {
- if (mTitleFont == null) {
- mTitleFont = Typeface.createFromAsset(context.getAssets(), "fonts/" + typefaceName);
- mTitleFont = Typeface.create(mTitleFont, 1);
- }
- return mTitleFont;
- } else if (!typefaceName.equals(FontType.CONTENT_FONT.toString())) {
- return null;
- } else {
- if (mContentFont == null) {
- mContentFont = Typeface.createFromAsset(context.getAssets(), "fonts/" + typefaceName);
- }
- return mContentFont;
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- return Typeface.DEFAULT;
- }
- }
- public static Typeface getTypeface(Context context, FontType typefaceName) {
- return getTypeface(context, typefaceName.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement