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:Main.java

private static Typeface loadTypeface(AssetManager assetsManager, String path) {
    try {//from  w w w  . ja  v a2s. c om
        return Typeface.createFromAsset(assetsManager, "fonts/roboto/Roboto-Regular.ttf");
    } catch (RuntimeException e) {
        // May occur rarely, on a few devices
        Log.d("SentacaAccordionView", "Unable to load Typeface from " + path, e);
    }
    return null;
}

From source file:com.ryan.ryanreader.views.SubredditHeader.java

public SubredditHeader(final Context context, final RedditSubreddit subreddit) {

    super(context);

    final float dpScale = context.getResources().getDisplayMetrics().density;

    setOrientation(LinearLayout.VERTICAL);

    final int sidesPadding = (int) (15.0f * dpScale);
    final int topPadding = (int) (10.0f * dpScale);

    setPadding(sidesPadding, topPadding, sidesPadding, topPadding);

    final Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Light.ttf");

    final TextView title = new TextView(context);
    title.setTextSize(22.0f);// w ww.j  a  v a2 s . c om
    title.setTypeface(tf);
    title.setText(StringEscapeUtils.unescapeHtml4(subreddit.title));
    title.setTextColor(Color.WHITE);
    addView(title);

    final TextView subs = new TextView(context);
    subs.setTextSize(14.0f);

    if (subreddit.subscribers == null) {
        subs.setText("Subscriber count is unknown");
    } else {
        subs.setText(NumberFormat.getNumberInstance(Locale.getDefault()).format(subreddit.subscribers)
                + " subscribers");
    }

    subs.setTextColor(Color.rgb(200, 200, 200));
    addView(subs);

    setBackgroundColor(Color.rgb(50, 50, 50)); // TODO theme color
}

From source file:com.netpace.expressit.android.ui.TypefaceEditText.java

public TypefaceEditText(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Get our custom attributes
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TypefaceTextView, 0, 0);

    try {//from   ww w.j a v  a 2s . c om
        String typefaceName = a.getString(R.styleable.TypefaceTextView_typeface);

        if (!isInEditMode() && !TextUtils.isEmpty(typefaceName)) {
            Typeface typeface = sTypefaceCache.get(typefaceName);

            if (typeface == null) {
                typeface = Typeface.createFromAsset(context.getAssets(),
                        String.format("fonts/%s_0.otf", typefaceName));

                // Cache the Typeface object
                sTypefaceCache.put(typefaceName, typeface);
            }
            setTypeface(typeface);

            // Note: This flag is required for proper typeface rendering
            setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
        }
    } finally {
        a.recycle();
    }
}

From source file:com.somethoughts.chinmay.game.Dice.DiceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.dice_layout, container, false);
    Button button = (Button) view.findViewById(R.id.dice_start_button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override/* ww w  .  j  a v a  2 s  . c  om*/
        public void onClick(View viewv) {
            spin();
        }
    });
    Typeface custom_font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/myfnt.ttf");
    TextView textView = (TextView) view.findViewById(R.id.dice_result_textview);
    textView.setTypeface(custom_font);
    textView = (TextView) view.findViewById(R.id.dice_head);
    textView.setTypeface(custom_font);
    return view;
}

From source file:fr.outadev.splatcompanion.FragmentRotationSchedule.java

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    typeface = Typeface.createFromAsset(getContext().getAssets(), "project_paintball_beta_2.otf");

    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_SCHEDULE)) {
        schedule = (Schedule) savedInstanceState.getSerializable(KEY_SCHEDULE);
    }//from  www .  j  a va2 s.  co  m
}

From source file:com.axum.darivb.searchview.SlidingTabLayout.java

public SlidingTabLayout(Context context) {

    this(context, null);

    bariol_regular_tf = Typeface.createFromAsset(context.getAssets(), "fonts/Bariol_Regular.otf");
}

From source file:com.beemindz.photogalley.util.TypefaceSpan.java

/**
* Load the {@link Typeface} and apply to a {@link Spannable}.
*///from w w w . j av 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("fonts/%s", typefaceName));

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

From source file:com.rachelgrau.rachel.health4theworldstroke.Activities.InfoActivity.java

private void setUpToolbar() {
    Toolbar myToolbar = (Toolbar) findViewById(R.id.info_toolbar);
    myToolbar.setTitle("");
    Typeface font = Typeface.createFromAsset(getAssets(), "Roboto-Light.ttf");
    TextView toolbarTitle = (TextView) myToolbar.findViewById(R.id.toolbar_title);
    toolbarTitle.setText(this.title);
    toolbarTitle.setTypeface(font);/*from  ww w . j av a2s .  c o  m*/
    setSupportActionBar(myToolbar);
}

From source file:com.appndroid.ipl2013.SwipeyTabsSampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_swipeytab);

    String fontPath = "fonts/Face Your Fears.ttf";
    TextView txtHead = (TextView) findViewById(R.id.title);
    Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
    txtHead.setTypeface(tf);//from   ww  w  .j a  v  a  2  s.  c om
    navigationImage = (ImageView) findViewById(R.id.nav);
    navigationImage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            callEvent();

        }
    });

    mViewPager = (MultipleScrollViewPager) findViewById(R.id.flipper);
    mTabs = (SwipeyTabs) findViewById(R.id.swipeytabs);
    mfragmentList = new Vector<Fragment>();

    bundle = new Bundle();

    Fragment pointsFragment = Fragment.instantiate(this, PointsTableFragment.class.getName());
    pointsFragment.setArguments(bundle);

    Fragment orangeFragment = Fragment.instantiate(this, OrangeCapFragment.class.getName());
    orangeFragment.setArguments(bundle);

    Fragment purpleFragment = Fragment.instantiate(this, PurpleCapFragment.class.getName());
    purpleFragment.setArguments(bundle);

    mfragmentList.add(pointsFragment);
    mfragmentList.add(orangeFragment);
    mfragmentList.add(purpleFragment);

    SwipeyTabsPagerAdapter adapter = new SwipeyTabsPagerAdapter(this, getSupportFragmentManager(),
            mfragmentList);
    mViewPager.setAdapter(adapter);
    mTabs.setAdapter(adapter);
    mViewPager.setOnPageChangeListener(mTabs);
    mViewPager.setCurrentItem(0);
    mViewPager.setOffscreenPageLimit(2);
}

From source file:com.ubuntuone.android.files.fragment.SignInOrUpFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View content = inflater.inflate(R.layout.fragment_sign_in_or_up, container, false);

    signInButton = (Button) content.findViewById(R.id.sign_in);
    signUpButton = (Button) content.findViewById(R.id.new_account);

    final Typeface ubuntuB = Typeface.createFromAsset(getActivity().getAssets(), "Ubuntu-B.ttf");

    ((TextView) content.findViewById(R.id.u1f)).setTypeface(ubuntuB);
    signInButton.setTypeface(ubuntuB);/*from  w w  w  . j av a 2 s.  co  m*/
    signUpButton.setTypeface(ubuntuB);

    signInButton.setOnClickListener(this);
    signUpButton.setOnClickListener(this);

    return content;
}