package com.snotyak.android.ui.roboto;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.widget.AppCompatButton;
import android.util.AttributeSet;

import com.snotyak.android.ui.R;

public class RobotoButton extends AppCompatButton {
    public RobotoButton(Context context) {
        super(context);
        init(context, null);
    }

    public RobotoButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public RobotoButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs){
        if(attrs != null){
            TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.RobotoButton);

            if(attributes != null){
                try{
                    RobotoTypeface robotoTypeface = RobotoTypeface.fromInt(attributes.getInt(R.styleable.RobotoButton_typeface, RobotoTypeface.REGULAR.toInt()));
                    setTypeface(robotoTypeface.getTypeface(context));
                }finally {
                    attributes.recycle();
                }
            }
        }
    }
}
