Example usage for android.graphics Typeface createFromAsset

List of usage examples for android.graphics Typeface createFromAsset

Introduction

In this page you can find the example usage for android.graphics Typeface createFromAsset.

Prototype

public static Typeface createFromAsset(AssetManager mgr, String path) 

Source Link

Document

Create a new typeface from the specified font data.

Usage

From source file:com.aniruddhc.acemusic.player.Utils.TypefaceSpan.java

public TypefaceSpan(Context context, String typefaceName) {
    mTypeface = sTypefaceCache.get(typefaceName);

    if (mTypeface == null) {
        mTypeface = Typeface.createFromAsset(context.getApplicationContext().getAssets(),
                String.format("fonts/%s.ttf", typefaceName));

        // Cache the loaded Typeface
        sTypefaceCache.put(typefaceName, mTypeface);
    }/*  w ww  .  ja va 2 s .  com*/
}

From source file:com.mobicage.rogerthat.util.TextUtils.java

public static void overrideFonts(final Context context, final View v) {
    try {//from  ww  w  .ja  v  a2  s  .c o m
        if (v instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) v;
            for (int i = 0; i < vg.getChildCount(); i++) {
                View child = vg.getChildAt(i);
                overrideFonts(context, child);
            }
        } else if (v instanceof EditText) {
            ((EditText) v).setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/lato_light.ttf"));
            ((EditText) v).setTextColor(ContextCompat.getColor(context, R.color.mc_words_color));
        } else if (v instanceof Button) {
            ((Button) v).setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/lato_bold.ttf"));
            ((Button) v).setTextColor(ContextCompat.getColor(context, android.R.color.white));
        } else if (v instanceof TextView) {
            ((TextView) v).setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/lato_light.ttf"));
            ((TextView) v).setTextColor(ContextCompat.getColor(context, R.color.mc_words_color));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.android.quiz.util.TypefaceApplication.java

/**
 * Load the {@link Typeface} and apply to a {@link Spannable}.
 */// ww  w  .ja  va2 s .co m
public TypefaceApplication(Context context, String typefaceName) {
    mTypeface = sTypefaceCache.get(typefaceName);

    if (mTypeface == null) {
        mTypeface = Typeface.createFromAsset(context.getApplicationContext().getAssets(),
                String.format("fonts/%s.otf", typefaceName));
        sTypefaceCache.put(typefaceName, mTypeface);
    }
}

From source file:com.honeyjam.toaster.CustomTypefaceSpan.java

public CustomTypefaceSpan(Context context, String typefaceName) {
    mTypeface = sTypefaceCache.get(typefaceName);

    if (mTypeface == null) {
        mTypeface = Typeface.createFromAsset(context.getApplicationContext().getAssets(),
                String.format("fonts/%s", typefaceName));

        // Cache the loaded Typeface
        sTypefaceCache.put(typefaceName, mTypeface);
    }/*from  w  w w. j a v  a  2  s.  c  om*/
}

From source file:io.github.hidroh.materialistic.FontCache.java

public Typeface get(Context context, String typefaceName) {
    if (TextUtils.isEmpty(typefaceName)) {
        return null;
    }//from w w  w  .j a va  2 s.  c o m
    if (!mTypefaceMap.containsKey(typefaceName)) {
        mTypefaceMap.put(typefaceName, Typeface.createFromAsset(context.getAssets(), typefaceName));
    }
    return mTypefaceMap.get(typefaceName);
}

From source file:com.example.android.capstone.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from  www .  j  a v a2s  .  c  o  m*/
    TextView myTitle = (TextView) toolbar.getChildAt(0);
    Typeface tf = Typeface.createFromAsset(getAssets(), getResources().getString(R.string.font_name));
    myTitle.setTypeface(tf, Typeface.BOLD);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(getResources().getString(R.string.ad_device_test)).build();
    mAdView.loadAd(adRequest);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
    TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    tabLayout.setupWithViewPager(viewPager);
}

From source file:com.claireshu.flickster.TypefaceSpan.java

public TypefaceSpan(Context context, String typefaceName) {
    mTypeface = sTypefaceCache.get(typefaceName);

    if (mTypeface == null) {
        mTypeface = Typeface.createFromAsset(context.getApplicationContext().getAssets(),
                String.format("fonts/%s", typefaceName));

        // Cache the loaded Typeface
        sTypefaceCache.put(typefaceName, mTypeface);
    }// w  ww.j a va2  s  .  com
}

From source file:io.vit.vitio.Extras.TypeFaceSpan.java

public TypeFaceSpan(Context context, String typefaceName) {
    mTypeface = sTypefaceCache.get(typefaceName);
    if (mTypeface == null) {
        mTypeface = Typeface.createFromAsset(context.getApplicationContext().getAssets(),
                String.format("fonts/%s", typefaceName));
        sTypefaceCache.put(typefaceName, mTypeface);
    }// www. ja va  2s  .  c  om
}

From source file:bijznas.notify.crouton.TypefaceSpan.java

/**
 * Load the {@link Typeface} and apply to a spannable.
 *//*from w w  w  .j  a  v a 2  s .  com*/
public TypefaceSpan(Context context, String typefaceName) {
    mTypeface = sTypefaceCache.get(typefaceName);

    if (mTypeface == null) {
        mTypeface = Typeface.createFromAsset(context.getApplicationContext().getAssets(),
                String.format("%s", typefaceName));

        // Cache the loaded Typeface
        sTypefaceCache.put(typefaceName, mTypeface);
    }
}

From source file:gr.sepals.eshop.info.gui.OrderSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_info_order, container, false);
    title = (TextView) rootView.findViewById(R.id.info_order_title_textview);
    desc = (TextView) rootView.findViewById(R.id.info_order_description_textview);
    Typeface titleFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Pyrsos.otf");
    Typeface descFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Goschen-Italic.otf");
    title.setTypeface(titleFont, Typeface.BOLD);
    desc.setTypeface(descFont);/*from ww  w .j  av  a2s .co  m*/
    return rootView;
}