first commit
This commit is contained in:
43
app/src/main/java/com/juhabi/birds/util/ToastUtil.kt
Normal file
43
app/src/main/java/com/juhabi/birds/util/ToastUtil.kt
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.juhabi.birds.util
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
|
||||
/** Toast 统一管理工具。 */
|
||||
object ToastUtil {
|
||||
|
||||
var isShow = true
|
||||
|
||||
private var toast: Toast? = null
|
||||
|
||||
fun showShort(context: Context, message: CharSequence) {
|
||||
show(context, message, Toast.LENGTH_SHORT)
|
||||
}
|
||||
|
||||
fun showShort(context: Context, message: Int) {
|
||||
show(context, message.toString(), Toast.LENGTH_SHORT)
|
||||
}
|
||||
|
||||
fun showLong(context: Context, message: CharSequence) {
|
||||
show(context, message, Toast.LENGTH_LONG)
|
||||
}
|
||||
|
||||
fun showLong(context: Context, message: Int) {
|
||||
show(context, message.toString(), Toast.LENGTH_LONG)
|
||||
}
|
||||
|
||||
fun show(context: Context, message: CharSequence, duration: Int) {
|
||||
val currentToast = toast
|
||||
if (currentToast == null) {
|
||||
toast = Toast.makeText(context, message, duration)
|
||||
} else {
|
||||
currentToast.setText(message)
|
||||
currentToast.duration = duration
|
||||
}
|
||||
toast?.show()
|
||||
}
|
||||
|
||||
fun show(context: Context, message: Int, duration: Int) {
|
||||
show(context, message.toString(), duration)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user