package kr.co.hanwha.hifive.view;

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;

import kr.co.hanwha.hifive.R;

/**
 * Created by sanghoonkwon on 2018. 1. 11..
 */

public class HFToastView extends Toast {

    private Context mContext;
    private ImageView mImageViewIcon;
    private TextView mTextViewMessage;

    public HFToastView(Context context) {
        super(context);
        mContext = context;
    }

    public void showToast(String message, int duration) {
        showToast(message, R.mipmap.temp_ic_tp03, duration);
    }

    public void showToast(String message, int iconRes, int duration) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflater.inflate(R.layout.view_hf_toast, null);

        mImageViewIcon = (ImageView) v.findViewById(R.id.icon_imageView);
        mTextViewMessage = (TextView) v.findViewById(R.id.message_textView);
        mTextViewMessage.setText(message);

        mImageViewIcon.setImageResource(iconRes);

        v.findViewById(R.id.body_linearLayout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                HFToastView.this.cancel();
            }
        });

        show(this, v, duration);
    }

    private void show(Toast toast, View v, int duration) {
        toast.setGravity(Gravity.CENTER | Gravity.FILL_HORIZONTAL, 0, 0);
        toast.setDuration(duration);
        toast.setView(v);
        toast.show();
    }
}
