package com.khmer9.lotto.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;


import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import com.khmer9.lotto.R;

public class SettingButtonView  extends FrameLayout {
    ImageView imageViewIcon;
    View bgView;

    public SettingButtonView(@NonNull Context context) {
        super(context);
        init();

    }

    public SettingButtonView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
        setStyle(attrs);

    }

    public SettingButtonView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
        setStyle(attrs);
    }

    public SettingButtonView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
        setStyle(attrs);
    }
    private void init() {
        View view = LayoutInflater.from(getContext()).inflate(
                R.layout.view_setting_button, this, true);
        bgView = view.findViewById(R.id.v_bg);
        imageViewIcon = view.findViewById(R.id.iv_icon) ;


    }

    private void setStyle(AttributeSet attrs){
        TypedArray a = getContext().getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.SettingButtonView,
                0, 0);

        try {
            Drawable bgDrawable = a.getDrawable(R.styleable.SettingButtonView_bgDrawable);
            int bigSmall_resID = a.getResourceId(R.styleable.SettingButtonView_textIcon, R.drawable.text_save);
            bgView.setBackground(bgDrawable);
            imageViewIcon.setImageResource(bigSmall_resID);

        } finally {
            a.recycle();
        }
    }

    public void setImageViewIcon(@DrawableRes int drawable) {
        imageViewIcon.setImageResource(drawable);
    }
}