package com.biermacht.brews.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

import com.biermacht.brews.R;

public class CustomFontTextView extends TextView {

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

    //Typeface.createFromAsset doesn't work in the layout editor. Skipping...
    if (isInEditMode()) {
      return;
    }

    TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.CustomFontTextView);
    String fontName = styledAttrs.getString(R.styleable.CustomFontTextView_typeface);
    styledAttrs.recycle();

    if (fontName != null) {
      Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontName);
      setTypeface(typeface);
    }
  }

}