Advertisement
Guest User

gg

a guest
Dec 3rd, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. package com.umrohku.paketumroh.Utils;
  2.  
  3. /**
  4.  * Created by root on 03/12/16.
  5.  */
  6.  
  7. import android.content.Context;
  8. import android.graphics.Typeface;
  9.  
  10. public class FontUtils {
  11.     private static Typeface mContentFont;
  12.     private static Typeface mTitleFont;
  13.  
  14.     public enum FontType {
  15.         TITLE_FONT {
  16.             public String toString() {
  17.                 return "Montserrat-Hairline.otf";
  18.             }
  19.         },
  20.         CONTENT_FONT {
  21.             public String toString() {
  22.                 return "montseratreg.otf";
  23.             }
  24.         };
  25.     }
  26.  
  27.     private static Typeface getTypeface(Context context, String typefaceName) {
  28.         try {
  29.             if (typefaceName.equals(FontType.TITLE_FONT.toString())) {
  30.                 if (mTitleFont == null) {
  31.                     mTitleFont = Typeface.createFromAsset(context.getAssets(), "fonts/" + typefaceName);
  32.                     mTitleFont = Typeface.create(mTitleFont, 1);
  33.                 }
  34.                 return mTitleFont;
  35.             } else if (!typefaceName.equals(FontType.CONTENT_FONT.toString())) {
  36.                 return null;
  37.             } else {
  38.                 if (mContentFont == null) {
  39.                     mContentFont = Typeface.createFromAsset(context.getAssets(), "fonts/" + typefaceName);
  40.                 }
  41.                 return mContentFont;
  42.             }
  43.         } catch (Exception ex) {
  44.             ex.printStackTrace();
  45.             return Typeface.DEFAULT;
  46.         }
  47.     }
  48.  
  49.     public static Typeface getTypeface(Context context, FontType typefaceName) {
  50.         return getTypeface(context, typefaceName.toString());
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement