package com.sobot.widget.ui.toast;

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

import com.sobot.widget.ui.utils.SobotResourceUtils;


/**
 * 自定义时长的Toast
 */
public class SobotCustomToast {

	public static Toast makeText(Context context, int resStr,
								 int duration) {

		Toast toast = new Toast(context.getApplicationContext());
		View view = View.inflate(context, SobotResourceUtils.getIdByName(context,"layout","sobot_common_custom_toast_layout_2"), null);
		TextView tv = (TextView) view.findViewById(SobotResourceUtils.getIdByName(context,"id","sobot_tv_content"));
		tv.setText(resStr);
		toast.setView(view);
		toast.setGravity(Gravity.CENTER, 0, 0);
		toast.setDuration(duration);

		return toast;
	}

	public static Toast makeText(Context context, CharSequence text,
								 int duration) {

		Toast toast = new Toast(context.getApplicationContext());
		View view = View.inflate(context, SobotResourceUtils.getResLayoutId(context,"sobot_common_custom_toast_layout_2"), null);
		TextView tv = (TextView) view.findViewById(SobotResourceUtils.getIdByName(context,"id","sobot_tv_content"));
		tv.setText(text);
		toast.setView(view);
		toast.setGravity(Gravity.CENTER, 0, 0);
		toast.setDuration(duration);

		return toast;
	}

	public static Toast makeText(Context context, CharSequence text,
								 int duration, int resId) {
		Toast toast = new Toast(context.getApplicationContext());
		View view = View.inflate(context, SobotResourceUtils.getIdByName(context,"layout","sobot_common_custom_toast_layout"), null);
		TextView tv = (TextView) view.findViewById(SobotResourceUtils.getIdByName(context,"id","sobot_tv_content"));
		tv.setText(text);
		ImageView tv_content = (ImageView) view.findViewById(SobotResourceUtils.getIdByName(context,"id","sobot_iv_content"));
		tv_content.setImageResource(resId);
		toast.setView(view);
		toast.setGravity(Gravity.CENTER, 0, 0);
		toast.setDuration(duration);

		return toast;
	}
}