package com.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.Button;
import android.widget.Toast;
public class ToastUtil {
public static String TAG = "RadioVideo";
public static byte[] mData = new byte[5];
public static boolean bElectric = false;
protected static Toast toast = null;
private static long oneTime = 0;
private static long twoTime = 0;
private static String oldMsg;
@SuppressLint("ShowToast")
public static void showToast(Context context, String s) {
if (toast == null) {
toast = Toast.makeText(context, s, Toast.LENGTH_LONG);
buttonStyle(context, s);
oneTime = System.currentTimeMillis();
} else {
twoTime = System.currentTimeMillis();
if (s.equals(oldMsg)) {
if (twoTime - oneTime > Toast.LENGTH_LONG) {
buttonStyle(context, s);
}
} else {
oldMsg = s;
buttonStyle(context, s);
}
}
oneTime = twoTime;
}
private static void buttonStyle(Context context, String s) {
Button bt = new Button(context);
// bt.setBackgroundColor(Color.TRANSPARENT);
// bt.setWidth(500);
bt.setText(s);
// bt.setTextColor(Color.BLACK);
bt.setTextSize(20);
toast.setView(bt);
toast.show();
}
public static void toastHide(){
if (toast != null){
toast.cancel();
}
}
}