lmw
2025-04-24 718f31c92e2029d05260810435a2c70cef6e6ce5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.lzf.easyfloat.interfaces
 
import android.view.MotionEvent
import android.view.View
 
/**
 * @author: liuzhenfeng
 * @function: 通过Kotlin DSL实现接口回调效果
 * @date: 2019-08-26  17:06
 */
class FloatCallbacks {
 
    lateinit var builder: Builder
 
    // 带Builder返回值的lambda
    fun registerListener(builder: Builder.() -> Unit) {
        this.builder = Builder().also(builder)
    }
 
    inner class Builder {
        internal var createdResult: ((Boolean, String?, View?) -> Unit)? = null
        internal var show: ((View) -> Unit)? = null
        internal var hide: ((View) -> Unit)? = null
        internal var dismiss: (() -> Unit)? = null
        internal var touchEvent: ((View, MotionEvent) -> Unit)? = null
        internal var drag: ((View, MotionEvent) -> Unit)? = null
        internal var dragEnd: ((View) -> Unit)? = null
 
        fun createResult(action: (Boolean, String?, View?) -> Unit) {
            createdResult = action
        }
 
        fun show(action: (View) -> Unit) {
            show = action
        }
 
        fun hide(action: (View) -> Unit) {
            hide = action
        }
 
        fun dismiss(action: () -> Unit) {
            dismiss = action
        }
 
        fun touchEvent(action: (View, MotionEvent) -> Unit) {
            touchEvent = action
        }
 
        fun drag(action: (View, MotionEvent) -> Unit) {
            drag = action
        }
 
        fun dragEnd(action: (View) -> Unit) {
            dragEnd = action
        }
    }
 
}