package com.atmob.keyboard_android.util

import android.os.Handler
import android.os.Looper
import android.widget.Toast

/**
 * Toast工具类
 */
class ToastUtil private constructor() {
    companion object {
        private val mMainHandler = Handler(Looper.getMainLooper())

        /**
         * 显示Toast
         */
        fun showToast(msg: String?) {
            if (msg == null || msg.isBlank()) {
                return
            }
            val action = {
                Toast.makeText(ContextUtil.getContext(), msg, Toast.LENGTH_SHORT).show()
            }
            if (Thread.currentThread() == Looper.getMainLooper().thread) {
                action.invoke()
            } else {
                mMainHandler.post(action)
            }
        }
    }
}