@@ -18,6 +18,9 @@ import com.todou.nestrefresh.base.State.STATE_COLLAPSED
18
18
import com.todou.nestrefresh.base.State.STATE_DRAGGING
19
19
import com.todou.nestrefresh.base.State.STATE_HOVERING
20
20
import com.todou.nestrefresh.base.State.STATE_SETTLING
21
+ import android.icu.lang.UCharacter.GraphemeClusterBreak.V
22
+ import android.support.v4.widget.ViewDragHelper.INVALID_POINTER
23
+
21
24
22
25
abstract class RefreshHeaderBehavior <V : View > : BaseBehavior <V >, RefreshHeader {
23
26
private var flingRunnable: Runnable ? = null
@@ -52,7 +55,7 @@ abstract class RefreshHeaderBehavior<V : View> : BaseBehavior<V>, RefreshHeader
52
55
this .touchSlop = ViewConfiguration .get(parent.context).scaledTouchSlop
53
56
}
54
57
val action = ev.action
55
- if (action == 2 && this .isBeingDragged) {
58
+ if (action == MotionEvent . ACTION_MOVE && this .isBeingDragged) {
56
59
return true
57
60
} else {
58
61
val activePointerId: Int
@@ -62,19 +65,22 @@ abstract class RefreshHeaderBehavior<V : View> : BaseBehavior<V>, RefreshHeader
62
65
if (childInHeaderCanScroll(child, ev.rawX, ev.rawY)) {
63
66
return super .onInterceptTouchEvent(parent, child, ev)
64
67
}
65
- resetTotalSpringOffset()
68
+ isTouching = false
66
69
this .isBeingDragged = false
67
70
activePointerId = ev.x.toInt()
68
71
pointerIndex = ev.y.toInt()
69
72
if (this .canDragView(child) && parent.isPointInChildBounds(child, activePointerId, pointerIndex)) {
70
73
this .lastMotionY = pointerIndex
71
74
this .activePointerId = ev.getPointerId(0 )
72
75
this .ensureVelocityTracker()
76
+ onTouchStart()
77
+ resetTotalSpringOffset()
73
78
}
74
79
}
75
80
MotionEvent .ACTION_UP , MotionEvent .ACTION_CANCEL -> {
76
81
this .isBeingDragged = false
77
82
isTouching = false
83
+ doOnCancel()
78
84
this .activePointerId = - 1
79
85
if (this .velocityTracker != null ) {
80
86
this .velocityTracker?.recycle()
@@ -83,7 +89,7 @@ abstract class RefreshHeaderBehavior<V : View> : BaseBehavior<V>, RefreshHeader
83
89
}
84
90
MotionEvent .ACTION_MOVE -> {
85
91
activePointerId = this .activePointerId
86
- if (activePointerId != - 1 ) {
92
+ if (activePointerId != INVALID_POINTER ) {
87
93
pointerIndex = ev.findPointerIndex(activePointerId)
88
94
if (pointerIndex != - 1 ) {
89
95
val y = ev.getY(pointerIndex).toInt()
@@ -105,6 +111,16 @@ abstract class RefreshHeaderBehavior<V : View> : BaseBehavior<V>, RefreshHeader
105
111
}
106
112
}
107
113
114
+ private fun onPointerUp (e : MotionEvent ) {
115
+ val actionIndex = e.actionIndex
116
+ if (e.getPointerId(actionIndex) == activePointerId) {
117
+ // Pick a new pointer to pick up the slack.
118
+ val newIndex = if (actionIndex == 0 ) 1 else 0
119
+ activePointerId = e.getPointerId(newIndex)
120
+ lastMotionY = (e.getY(newIndex) + 0.5f ).toInt()
121
+ }
122
+ }
123
+
108
124
protected open fun childInHeaderCanScroll (view : V , x : Float , y : Float ): Boolean {
109
125
return false
110
126
}
@@ -115,6 +131,7 @@ abstract class RefreshHeaderBehavior<V : View> : BaseBehavior<V>, RefreshHeader
115
131
}
116
132
117
133
val activePointerIndex: Int
134
+ var actionIndex = ev.actionIndex
118
135
val y: Int
119
136
when (ev.actionMasked) {
120
137
MotionEvent .ACTION_DOWN -> {
@@ -128,6 +145,14 @@ abstract class RefreshHeaderBehavior<V : View> : BaseBehavior<V>, RefreshHeader
128
145
this .activePointerId = ev.getPointerId(0 )
129
146
this .ensureVelocityTracker()
130
147
onTouchStart()
148
+ resetTotalSpringOffset()
149
+ }
150
+ MotionEvent .ACTION_POINTER_DOWN -> {
151
+ this .activePointerId = ev.getPointerId(actionIndex)
152
+ lastMotionY = (ev.getY(actionIndex) + 0.5f ).toInt()
153
+ }
154
+ MotionEvent .ACTION_POINTER_UP -> {
155
+ onPointerUp(ev)
131
156
}
132
157
MotionEvent .ACTION_UP -> {
133
158
this .isTouching = false
@@ -145,6 +170,7 @@ abstract class RefreshHeaderBehavior<V : View> : BaseBehavior<V>, RefreshHeader
145
170
}
146
171
MotionEvent .ACTION_CANCEL -> {
147
172
this .isBeingDragged = false
173
+ isTouching = false
148
174
this .activePointerId = - 1
149
175
if (this .velocityTracker != null ) {
150
176
this .velocityTracker?.recycle()
0 commit comments