@@ -46,6 +46,9 @@ protected void onFinishInflate() {
46
46
}
47
47
}
48
48
49
+ private int swipeActionLimit = 200 ;
50
+ private float swipeStartX = -1 ;
51
+
49
52
@ SuppressLint ("ClickableViewAccessibility" )
50
53
@ Override
51
54
public boolean onTouchEvent (@ NonNull MotionEvent ev ) {
@@ -73,9 +76,20 @@ public void fling(int velocityY) {
73
76
public void commOnTouchEvent (@ NonNull MotionEvent ev ) {
74
77
int action = ev .getAction ();
75
78
switch (action ) {
76
- /* case MotionEvent.ACTION_DOWN:
77
- break; **/
79
+ case MotionEvent .ACTION_DOWN :
80
+ swipeActionLimit = Math .min (getWidth () / 4 , getHeight () * 10 );
81
+ Timber .i (
82
+ "commOnTouchEvent limit = "
83
+ + swipeActionLimit
84
+ + ", "
85
+ + getWidth () / 4
86
+ + ", "
87
+ + getHeight () * 4 );
88
+ if (swipeActionLimit < 50 ) swipeActionLimit = 100 ;
89
+ break ;
90
+
78
91
case MotionEvent .ACTION_UP :
92
+ swipeStartX = -1 ;
79
93
isMoving = false ;
80
94
// Fingers loose
81
95
if (isNeedAnimation ()) {
@@ -92,19 +106,39 @@ public void commOnTouchEvent(@NonNull MotionEvent ev) {
92
106
}
93
107
94
108
// TODO: 翻页后、手指抬起前,降低滑动速度增加阻尼感
95
- if (inner .getLeft () > 100 && Rime .hasLeft ()) {
109
+ if (inner .getLeft () > swipeActionLimit && Rime .hasLeft ()) {
96
110
if (pageUpAction != null ) pageUpAction .run ();
97
111
if (inner .getWidth () > this .getWidth ())
98
112
scrollTo (this .getWidth () - inner .getWidth () + 400 , 0 );
99
- } else if (inner .getWidth () - inner .getRight () > 100
100
- && Trime .getService ().hasCandidateExPage ()) {
101
- if (pageExAction != null ) pageExAction .run ();
102
- } else if (inner .getWidth () - inner .getRight () > 100 && Rime .hasRight ()) {
103
- if (pageDownAction != null ) pageDownAction .run ();
104
- if (inner .getWidth () > this .getWidth ()) {
105
- scrollTo (-400 , 0 );
106
- }
107
113
} else {
114
+ // Timber.d("commOnTouchEvent "+getWidth() + "-" + inner.getWidth() +"+" +
115
+ // getScrollX()+", p=" +scrollEndPosition+", x="+ev.getX());
116
+ Timber .d (
117
+ "commOnTouchEvent dif=" + (swipeStartX - ev .getX ()) + " limit=" + swipeActionLimit );
118
+
119
+ if (swipeStartX < 0 ) {
120
+ if (getWidth () - inner .getWidth () + getScrollX () >= 0 ) {
121
+ swipeStartX = ev .getX ();
122
+ }
123
+ } else if (swipeStartX - ev .getX () > swipeActionLimit ) {
124
+ if (Trime .getService ().hasCandidateExPage ()) {
125
+ if (pageExAction != null ) pageExAction .run ();
126
+ return ;
127
+ } else if (Rime .hasRight ()) {
128
+ if (pageDownAction != null ) pageDownAction .run ();
129
+ swipeStartX = -1 ;
130
+ if (inner .getWidth () > this .getWidth ()) {
131
+ scrollTo (-swipeActionLimit , 0 );
132
+ inner .layout (
133
+ inner .getRight (),
134
+ inner .getTop (),
135
+ inner .getRight () + inner .getWidth (),
136
+ inner .getBottom ());
137
+ }
138
+ return ;
139
+ }
140
+ }
141
+
108
142
// When the scroll to the top or the most when it will not scroll, then move the layout.
109
143
isNeedMove ();
110
144
// Log.d("MotionEvent "+isMoveing," d="+deltaX+" left="+left+" LR="+inner.getLeft()+",
0 commit comments