package com.basic.security.utils;
|
|
import android.view.Gravity;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.basic.security.R;
|
import com.basic.security.base.BaseApplication;
|
import com.basic.security.widget.MyToast;
|
|
public class ToastUtil {
|
|
private static Toast toast;
|
private static Toast toast_short;
|
private static MyToast toast_down;
|
private static MyToast toast_long;
|
|
public static void showNormalToast(final String message) {
|
|
View v = LayoutInflater.from(BaseApplication.getApplication()).inflate(R.layout.eplay_toast, null);
|
TextView textView = v.findViewById(R.id.textView1);
|
textView.setText(message);
|
if (Thread.currentThread().getId() == 1) {
|
if (toast == null) {
|
toast = new Toast(BaseApplication.getApplication());
|
toast.setView(v);
|
toast.setDuration(Toast.LENGTH_LONG);
|
} else {
|
toast.setView(v);
|
}
|
toast.setGravity(Gravity.CENTER, 0, 0);
|
toast.show();
|
} else {
|
BaseApplication.getApplication().activity.runOnUiThread(new Runnable() {
|
@Override
|
public void run() {
|
if (toast == null) {
|
toast = new Toast(BaseApplication.getApplication());
|
toast.setView(v);
|
toast.setDuration(Toast.LENGTH_LONG);
|
} else {
|
toast.setView(v);
|
}
|
toast.setGravity(Gravity.CENTER, 0, 0);
|
toast.show();
|
}
|
});
|
}
|
}
|
|
public static void show(final String message) { // 有多次连续点击不显示问题 参照showNormalToast,
|
View v = LayoutInflater.from(BaseApplication.getApplication()).inflate(R.layout.eplay_toast, null);
|
TextView textView = v.findViewById(R.id.textView1);
|
textView.setText(message);
|
if (Thread.currentThread().getId() == 1) {
|
if (toast == null) {
|
toast = new Toast(BaseApplication.getApplication());
|
toast.setView(v);
|
toast.setDuration(Toast.LENGTH_LONG);
|
} else {
|
toast.setView(v);
|
}
|
toast.setGravity(Gravity.CENTER, 0, 0);
|
toast.show();
|
} else {
|
BaseApplication.getApplication().activity.runOnUiThread(new Runnable() {
|
@Override
|
public void run() {
|
if (toast == null) {
|
toast = new Toast(BaseApplication.getApplication());
|
toast.setView(v);
|
toast.setDuration(Toast.LENGTH_LONG);
|
} else {
|
toast.setView(v);
|
}
|
toast.setGravity(Gravity.CENTER, 0, 0);
|
toast.show();
|
}
|
});
|
}
|
// if (Thread.currentThread().getId() == 1) {
|
// if (toast_short == null) {
|
// toast_short = MyToast.makeText(BaseApplication.getApplication().activity, message, Toast.LENGTH_SHORT);
|
// } else {
|
// toast_short.setFaceDetailUI(message);
|
// toast_short.setDuration(Toast.LENGTH_SHORT);
|
// }
|
// toast_short.setGravity(Gravity.CENTER, 0, 0);
|
// toast_short.show();
|
// } else {
|
// BaseApplication.getApplication().activity.runOnUiThread(new Runnable() {
|
// @Override
|
// public void run() {
|
// if (toast_short == null) {
|
// toast_short = MyToast.makeText(BaseApplication.getApplication().activity, message, Toast.LENGTH_SHORT);
|
// toast_short.setGravity(Gravity.CENTER, 0, 0);
|
// } else {
|
// toast_short.setFaceDetailUI(message);
|
// }
|
// toast_short.show();
|
// }
|
// });
|
// }
|
}
|
|
public static void showInDown(final String message) {
|
if (Thread.currentThread().getId() == 1) {
|
|
if (toast_down == null) {
|
toast_down = MyToast.makeText(BaseApplication.getApplication().activity, message, Toast.LENGTH_SHORT);
|
toast_down.setGravity(Gravity.CENTER, 0, 120);
|
} else {
|
toast_down.setText(message);
|
}
|
toast_down.show();
|
|
} else {
|
BaseApplication.getApplication().activity.runOnUiThread(new Runnable() {
|
@Override
|
public void run() {
|
if (toast_down == null) {
|
toast_down = MyToast.makeText(BaseApplication.getApplication().activity, message, Toast.LENGTH_SHORT);
|
toast_down.setGravity(Gravity.CENTER, 0, 120);
|
} else {
|
toast_down.setText(message);
|
}
|
toast_down.show();
|
}
|
});
|
}
|
}
|
|
public static void showLong(final String message) {
|
|
if (Thread.currentThread().getId() == 1) {
|
if (toast_long == null) {
|
toast_long = MyToast.makeText(BaseApplication.getApplication().activity, message, Toast.LENGTH_LONG);
|
|
toast_long.setGravity(Gravity.CENTER, 0, 0);
|
} else {
|
toast_long.setText(message);
|
}
|
toast_long.show();
|
|
} else {
|
BaseApplication.getApplication().activity.runOnUiThread(new Runnable() {
|
@Override
|
public void run() {
|
if (toast_long == null) {
|
toast_long = MyToast.makeText(BaseApplication.getApplication().activity, message, Toast.LENGTH_LONG);
|
|
toast_long.setGravity(Gravity.CENTER, 0, 0);
|
} else {
|
toast_long.setText(message);
|
}
|
toast_long.show();
|
}
|
});
|
}
|
}
|
|
}
|