package com.bonait.bnframework.modules.home.fragment.mode;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bonait.bnframework.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class caidan_control extends LinearLayout {
    @BindView(R.id.caidan_image)
    ImageView image_u;
    @BindView(R.id.caidan_text)
    TextView text_u;
    @BindView(R.id.rea_main)
    RelativeLayout rea_main;
    private View root;
    private int ks_ys = R.mipmap.wlgl;
    private int showbk=-9999;
    public caidan_control(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        root= LayoutInflater.from(context).inflate(R.layout.item_caidan, this);
        ButterKnife.bind(this, root);
        initParams(root.getContext(), attrs);
        Init();
    }

    private void initParams(Context context, AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.caidan_control);
        if (typedArray != null) {
            try {
                ks_ys = typedArray.getResourceId(R.styleable.caidan_control_imagesrc, R.mipmap.wlgl);
                showbk = typedArray.getInt(R.styleable.caidan_control_showbk, -9999);
                typedArray.recycle();
            }catch (Exception exception)
            {
                Log.i("错误", exception.getMessage());
            }

        }
    }

    public void Init()
    {
        String str= this.getTag().toString();
        if(!str.isEmpty())
        {
            text_u.setText(str);
        }else
        {
            text_u.setText("");
        }

        image_u.setImageResource(ks_ys);

        if(showbk!=-9999)
        {
            rea_main.setBackgroundColor(Color.TRANSPARENT);

            LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) rea_main.getLayoutParams(); //取控件textView当前的布局参数
            linearParams.height =130;// 控件的高强制设成20
            rea_main.setLayoutParams(linearParams);


            ViewGroup.LayoutParams params = image_u.getLayoutParams();
            params.width = 60;
            params.height = 60;
            image_u.setLayoutParams(params);
        }
    }
}
