package com.tenlionsoft.baselib.core.widget.views;

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

import com.tenlionsoft.baselib.R;

import androidx.annotation.Nullable;

/**
 * 作者: adam
 * 日期: 2020/6/3 - 4:58 PM
 * 邮箱: itgaojian@163.com
 * 描述:
 */
public class TypeFaceTextView extends androidx.appcompat.widget.AppCompatTextView {
    private Typeface mTypeface;

    public TypeFaceTextView(Context context) {
        this(context, null);
    }

    public TypeFaceTextView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);

    }

    public TypeFaceTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TypeFaceTextView, defStyleAttr, 0);
        int type = a.getInteger(R.styleable.TypeFaceTextView_text_type_cus, 0);
        if (type == 1) {
            mTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/zhangti.TTF");
            setTextSize(16);
        } else if(type==2) {
            mTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/zhangti.TTF");
            setTextSize(18);
        }else{
            mTypeface = Typeface.DEFAULT;
        }
        setTypeface(mTypeface);
    }

    public void setTypeFaceType(int type) {
        if (type == 1) {
            mTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/zhangti.TTF");
            setTextSize(16);
        } else if(type==2) {
            mTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/zhangti.TTF");
            setTextSize(18);
        }else{
            mTypeface = Typeface.DEFAULT;
        }
        setTypeface(mTypeface);
        postInvalidate();
    }
}
