JKBaseLib/BaseLibrary/src/main/java/com/tfq/library/utils/ToasterUtil.java

89 lines
2.6 KiB
Java

package com.tfq.library.utils;
import android.view.Gravity;
import com.hjq.toast.ToastParams;
import com.hjq.toast.Toaster;
import com.hjq.toast.style.CustomToastStyle;
import com.hjq.toast.style.WhiteToastStyle;
import com.tfq.library.R;
public class ToasterUtil {
public static void show(String text) {
Toaster.show(text);
}
public static void show(Object object) {
Toaster.show(object);
}
public static void show(CharSequence text) {
Toaster.show(text);
}
public static void show(ToastParams params) {
Toaster.show(params);
}
public static void show(int text, int type) {
show(text + "", type);
}
public static void show(Object text, int type) {
show(text + "", type);
}
/**
* @param text 显示内容
* @param type 类型 0:默认黑色;1:通过样式;2:提示样式;3:警告样式;4:错误样式; 10:白色样式;20:自定义弹窗
*/
public static void show(String text, int type) {
ToastParams params;
switch (type) {
case 0:
show(text);
break;
case 1:
params = new ToastParams();
params.text = text;
params.style = new CustomToastStyle(R.layout.library_toast_success);
Toaster.show(params);
break;
case 2:
params = new ToastParams();
params.text = text;
params.style = new CustomToastStyle(R.layout.library_toast_info);
Toaster.show(params);
break;
case 3:
params = new ToastParams();
params.text = text;
params.style = new CustomToastStyle(R.layout.library_toast_warn);
Toaster.show(params);
break;
case 4:
params = new ToastParams();
params.text = text;
params.style = new CustomToastStyle(R.layout.library_toast_error);
Toaster.show(params);
break;
case 10:
params = new ToastParams();
params.text = text;
params.style = new WhiteToastStyle();
Toaster.show(params);
break;
case 20:
Toaster.setView(R.layout.library_toast_custom_view);
Toaster.setGravity(Gravity.CENTER);
Toaster.show(text);
break;
default:
show(text);
break;
}
}
}