ToastUtil.java 3.09 KB
package com.glsx.libble.util;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.Toast;

import com.blankj.utilcode.util.ToastUtils;

public class ToastUtil {
    private static Toast lastToast = null;

    public final static int LENGTH_SHORT = Toast.LENGTH_SHORT;
    public final static int LENGTH_LONG = Toast.LENGTH_LONG;

    public static void clear() {
        if (lastToast != null) {
            lastToast.cancel();
        }
    }

    public static void show(int i) {
        ToastUtils toastUtils = ToastUtils.make();
        toastUtils.setDurationIsLong(false);
        toastUtils.setBgColor(Color.BLACK);
        toastUtils.setTextColor(Color.WHITE);
        toastUtils.show(i);
    }

    public static void show(Context context, int i) {
        ToastUtils toastUtils = ToastUtils.make();
        toastUtils.setDurationIsLong(false);
        toastUtils.setBgColor(Color.BLACK);
        toastUtils.setTextColor(Color.WHITE);
        toastUtils.show(i);
    }


    public static void showLongText( int i) {
        ToastUtils toastUtils = ToastUtils.make();
        toastUtils.setDurationIsLong(true);
        toastUtils.setBgColor(Color.BLACK);
        toastUtils.setTextColor(Color.WHITE);
        toastUtils.show(i);
    }
    public static void showLongText(  CharSequence charsequence) {
        ToastUtils toastUtils = ToastUtils.make();
        toastUtils.setDurationIsLong(true);
        toastUtils.setBgColor(Color.BLACK);
        toastUtils.setTextColor(Color.WHITE);
        toastUtils.show(charsequence);
    }

    public static void show(Context context, CharSequence charsequence) {
        ToastUtils toastUtils = ToastUtils.make();
        toastUtils.setDurationIsLong(true);
        toastUtils.setBgColor(Color.BLACK);
        toastUtils.setTextColor(Color.WHITE);
        toastUtils.show(charsequence);
    }

    public static void show(CharSequence charsequence) {
        ToastUtils toastUtils = ToastUtils.make();
        toastUtils.setDurationIsLong(false);
        toastUtils.setBgColor(Color.BLACK);
        toastUtils.setTextColor(Color.WHITE);
        toastUtils.show(charsequence);
    }

    public static void showCenterTop(int msg) {
        ToastUtils toastUtils = ToastUtils.make();
        toastUtils.setGravity(Gravity.CENTER, 0, -300);
        toastUtils.setDurationIsLong(false);
        toastUtils.setBgColor(Color.BLACK);
        toastUtils.setTextColor(Color.WHITE);
        toastUtils.show(msg);
    }

    public static void showCenterTop(String msg) {
        ToastUtils toastUtils = ToastUtils.make();
        toastUtils.setGravity(Gravity.CENTER, 0, -300);
        toastUtils.setDurationIsLong(false);
        toastUtils.setBgColor(Color.BLACK);
        toastUtils.setTextColor(Color.WHITE);
        toastUtils.show(msg);
    }
    private static final boolean isShow = false;

    /**
     * 调试使用
     *
     * @param charsequence
     */
//    public static void showTest(CharSequence charsequence) {
//        if (isShow)
//            Toast.makeText(CommonResApp.getContext(), charsequence, Toast.LENGTH_SHORT).show();
//    }
}