package com.yyrh.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;





public class TosUtil {

    private Toast mToast;
    private TextView mTextView;
    private ImageView mImageView;
    public static String TOAST_GREEN = "green";
    public static String TOAST_ERROR = "error";
    public TosUtil(Context context,String color,String msg) {


        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View view = inflater.inflate(ResourceUtil.getLayoutId(context, "hnyy_toast_style"), null);


        mTextView = view.findViewById(ResourceUtil.getId(context, "toast_text"));
        mTextView.setText(msg);

        mImageView = view.findViewById(ResourceUtil.getId(context, "toast_iv"));
        if (color.equals(TOAST_GREEN)) {
            mImageView.setImageResource(ResourceUtil.getMipmapId(context, "hnyy_tips_success"));
        }
        else {
            mImageView.setImageResource(ResourceUtil.getMipmapId(context, "hnyy_tips_error"));
        }

        if (mToast == null) {
            mToast = new Toast(context);

        }

        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.setView(view);
        mToast.setGravity(Gravity.CENTER,0,0);
    }


    public void show() {
        mToast.show();

    }


}
