Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class Tooltip private constructor(private val context: Context, builder: Builder
private var mPrepareFun: ((tooltip: Tooltip) -> Unit)? = null
private var mShownFunc: ((tooltip: Tooltip) -> Unit)? = null
private var mHiddenFunc: ((tooltip: Tooltip) -> Unit)? = null
private var mClickFunc: ((tooltip: Tooltip) -> Unit)? = null

@Suppress("UNUSED")
fun doOnFailure(func: ((tooltip: Tooltip) -> Unit)?): Tooltip {
Expand All @@ -228,6 +229,12 @@ class Tooltip private constructor(private val context: Context, builder: Builder
return this
}

@Suppress("UNUSED")
fun doOnClick(func: ((tooltip: Tooltip) -> Unit)?): Tooltip {
mClickFunc = func
return this
}

fun update(text: CharSequence?) {
mText = text
if (isShowing && null != mPopupView) {
Expand Down Expand Up @@ -761,12 +768,17 @@ class Tooltip private constructor(private val context: Context, builder: Builder
mTextView.getGlobalVisibleRect(r1)
val containsTouch = r1.contains(event.x.toInt(), event.y.toInt())

if (mClosePolicy.anywhere()) {
hide()
} else if (mClosePolicy.inside() && containsTouch) {
hide()
} else if (mClosePolicy.outside() && !containsTouch) {
hide()
when {
mClosePolicy.inside() && containsTouch -> {
hide()
mClickFunc?.invoke(this@Tooltip)
}
mClosePolicy.outside() && !containsTouch -> {
hide()
}
mClosePolicy.anywhere() -> {
hide()
}
}

return mClosePolicy.consume()
Expand Down