69 lines
2.0 KiB
Java
69 lines
2.0 KiB
Java
package com.ubtech.view.widget;
|
|
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import android.view.LayoutInflater;
|
|
import android.view.ViewGroup;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
import com.ubtech.R$id;
|
|
import com.ubtech.R$layout;
|
|
import com.ubtech.utils.DisplayUtil;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class ToastView {
|
|
private static ToastView c;
|
|
private Toast a = null;
|
|
private long b = 0;
|
|
|
|
public enum Type {
|
|
NORMAL,
|
|
SUCCESS,
|
|
ERROR
|
|
}
|
|
|
|
private ToastView() {
|
|
}
|
|
|
|
public static ToastView a(Context context, CharSequence charSequence, Type type) {
|
|
if (c == null) {
|
|
c = new ToastView();
|
|
}
|
|
ToastView toastView = c;
|
|
if (toastView.a == null) {
|
|
toastView.a = new Toast(context);
|
|
c.a.setView(LayoutInflater.from(context).inflate(R$layout.comm_layout_toast, (ViewGroup) null));
|
|
c.a.setGravity(17, 0, 0);
|
|
}
|
|
TextView textView = (TextView) c.a.getView().findViewById(R$id.textView);
|
|
textView.setText(charSequence);
|
|
if (!TextUtils.isEmpty(charSequence)) {
|
|
float b = (DisplayUtil.b(context) / 3.0f) * 2.0f;
|
|
if (textView.getPaint().measureText(charSequence.toString()) > b) {
|
|
ViewGroup.LayoutParams layoutParams = textView.getLayoutParams();
|
|
layoutParams.width = (int) b;
|
|
textView.setLayoutParams(layoutParams);
|
|
}
|
|
}
|
|
return c;
|
|
}
|
|
|
|
public static ToastView a(Context context, CharSequence charSequence) {
|
|
return a(context, charSequence, Type.NORMAL);
|
|
}
|
|
|
|
public static ToastView a(Context context, int i) {
|
|
return a(context, context.getResources().getString(i), Type.NORMAL);
|
|
}
|
|
|
|
public void a() {
|
|
Log.e("Test", "显示Toast");
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
if (currentTimeMillis - this.b > 1000) {
|
|
this.a.show();
|
|
this.b = currentTimeMillis;
|
|
}
|
|
}
|
|
}
|