package com.base.util;
import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;
import com.App;
/**
* ToastUtil
*/
public class ToastUtil {
private static Context context = App.getAppContext();
private static Toast mToast;
public static void show(int resId) {
show(context.getResources().getText(resId), Toast.LENGTH_SHORT);
}
public static void show(int resId, int duration) {
show(context.getResources().getText(resId), duration);
}
public static void show(CharSequence text) {
show(text, Toast.LENGTH_SHORT);
}
public static void show(CharSequence text, int duration) {
text = TextUtils.isEmpty(text == null ? "" : text.toString()) ? "请检查您的网络!"
: text;
if (mToast == null) {
mToast = Toast.makeText(context, text, duration);
} else {
mToast.setText(text);
}
mToast.show();
}
public static void show(int resId, Object... args) {
show(String.format(context.getResources().getString(resId), args),
Toast.LENGTH_SHORT);
}
public static void show(String format, Object... args) {
show(String.format(format, args), Toast.LENGTH_SHORT);
}
public static void show(int resId, int duration, Object... args) {
show(String.format(context.getResources().getString(resId), args),
duration);
}
public static void show(String format, int duration, Object... args) {
show(String.format(format, args), duration);
}
}