@@ -70,9 +70,11 @@ public SwipeLayout(Context context, AttributeSet attrs, int defStyle) {
70
70
71
71
72
72
public interface SwipeListener {
73
+ public void onStartOpen (SwipeLayout layout );
74
+ public void onOpen (SwipeLayout layout );
75
+ public void onStartClose (SwipeLayout layout );
73
76
public void onClose (SwipeLayout layout );
74
77
public void onUpdate (SwipeLayout layout , int leftOffset , int topOffset );
75
- public void onOpen (SwipeLayout layout );
76
78
public void onHandRelease (SwipeLayout layout , float xvel , float yvel );
77
79
}
78
80
@@ -324,13 +326,11 @@ public void onViewPositionChanged(View changedView, int left, int top, int dx, i
324
326
325
327
getSurfaceView ().layout (newLeft , newTop , newLeft + getMeasuredWidth (), newTop + getMeasuredHeight ());
326
328
}
327
-
328
-
329
329
}
330
330
331
331
dispatchRevealEvent (evLeft , evTop , evRight , evBottom );
332
332
333
- dispatchSwipeEvent (evLeft , evTop );
333
+ dispatchSwipeEvent (evLeft , evTop , dx , dy );
334
334
335
335
invalidate ();
336
336
}
@@ -441,29 +441,54 @@ protected Rect getRelativePosition(View child){
441
441
return r ;
442
442
}
443
443
444
- /**
445
- * dispatch swipe event.
446
- * @param surfaceLeft
447
- * @param surfaceTop
448
- */
449
- protected void dispatchSwipeEvent (int surfaceLeft , int surfaceTop ){
444
+ private int mEventCounter = 0 ;
445
+
446
+ protected void dispatchSwipeEvent (int surfaceLeft , int surfaceTop , int dx , int dy ){
447
+ DragEdge edge = getDragEdge ();
448
+ boolean open = true ;
449
+ if (edge == DragEdge .Left ){
450
+ if (dx < 0 ) open = false ;
451
+ }else if (edge == DragEdge .Right ){
452
+ if (dx > 0 ) open = false ;
453
+ }else if (edge == DragEdge .Top ){
454
+ if (dy < 0 ) open = false ;
455
+ }else if (edge == DragEdge .Bottom ){
456
+ if (dy > 0 ) open = false ;
457
+ }
458
+
459
+ dispatchSwipeEvent (surfaceLeft , surfaceTop , open );
460
+ }
450
461
462
+ protected void dispatchSwipeEvent (int surfaceLeft , int surfaceTop , boolean open ){
451
463
safeBottomView ();
464
+ Status status = getOpenStatus ();
452
465
453
- if (mSwipeListeners .isEmpty () == false ){
466
+ if (!mSwipeListeners .isEmpty ()){
467
+ mEventCounter ++;
454
468
for (SwipeListener l : mSwipeListeners ){
469
+ if (mEventCounter == 1 ){
470
+ if (open ){
471
+ l .onStartOpen (this );
472
+ }else {
473
+ l .onStartClose (this );
474
+ }
475
+ }
455
476
l .onUpdate (SwipeLayout .this , surfaceLeft - getPaddingLeft (), surfaceTop - getPaddingTop ());
456
477
}
457
478
458
- if (getOpenStatus () == Status .Close ){
459
- for (SwipeListener l : mSwipeListeners )
479
+ if (status == Status .Close ){
480
+ for (SwipeListener l : mSwipeListeners ){
460
481
l .onClose (SwipeLayout .this );
482
+ }
483
+ mEventCounter = 0 ;
461
484
}
462
485
463
- if (getOpenStatus () == Status .Open ){
486
+ if (status == Status .Open ){
464
487
getBottomView ().setEnabled (true );
465
- for (SwipeListener l : mSwipeListeners )
488
+ for (SwipeListener l : mSwipeListeners ){
466
489
l .onOpen (SwipeLayout .this );
490
+ }
491
+ mEventCounter = 0 ;
467
492
}
468
493
}
469
494
}
@@ -1082,22 +1107,34 @@ private void processBottomLayDownMode(float xvel, float yvel){
1082
1107
* smoothly open surface.
1083
1108
*/
1084
1109
public void open (){
1085
- open (true );
1110
+ open (true , true );
1086
1111
}
1087
1112
1088
1113
public void open (boolean smooth ){
1114
+ open (smooth , true );
1115
+ }
1116
+
1117
+ public void open (boolean smooth , boolean notify ){
1118
+ ViewGroup surface = getSurfaceView (), bottom = getBottomView ();
1119
+ int dx ,dy ;
1089
1120
Rect rect = computeSurfaceLayoutArea (true );
1090
1121
if (smooth ) {
1091
1122
mDragHelper .smoothSlideViewTo (getSurfaceView (), rect .left , rect .top );
1092
1123
}
1093
1124
else {
1094
- getSurfaceView ().layout (rect .left , rect .top , rect .right , rect .bottom );
1125
+ dx = rect .left - surface .getLeft ();
1126
+ dy = rect .top - surface .getTop ();
1127
+ surface .layout (rect .left , rect .top , rect .right , rect .bottom );
1095
1128
if (getShowMode () == ShowMode .PullOut ){
1096
1129
Rect bRect = computeBottomLayoutAreaViaSurface (ShowMode .PullOut , rect );
1097
- getBottomView ().layout (bRect .left , bRect .top , bRect .right , bRect .bottom );
1130
+ bottom .layout (bRect .left , bRect .top , bRect .right , bRect .bottom );
1131
+ }
1132
+ if (notify ) {
1133
+ dispatchRevealEvent (rect .left , rect .top , rect .right , rect .bottom );
1134
+ dispatchSwipeEvent (rect .left , rect .top , dx , dy );
1135
+ }else {
1136
+ safeBottomView ();
1098
1137
}
1099
- dispatchRevealEvent (rect .left , rect .top , rect .right , rect .bottom );
1100
- dispatchSwipeEvent (rect .left , rect .top );
1101
1138
}
1102
1139
invalidate ();
1103
1140
}
@@ -1106,27 +1143,38 @@ public void open(boolean smooth){
1106
1143
* smoothly close surface.
1107
1144
*/
1108
1145
public void close (){
1109
- close (true );
1146
+ close (true , true );
1147
+ }
1148
+
1149
+ public void close (boolean smooth ){
1150
+ close (smooth , true );
1110
1151
}
1111
1152
1112
1153
/**
1113
1154
* close surface
1114
1155
* @param smooth smoothly or not.
1156
+ * @param notify if notify all the listeners.
1115
1157
*/
1116
- public void close (boolean smooth ){
1158
+ public void close (boolean smooth , boolean notify ){
1159
+ ViewGroup surface = getSurfaceView ();
1160
+ int dx , dy ;
1117
1161
if (smooth )
1118
1162
mDragHelper .smoothSlideViewTo (getSurfaceView (), getPaddingLeft (), getPaddingTop ());
1119
1163
else {
1120
1164
Rect rect = computeSurfaceLayoutArea (false );
1121
- getSurfaceView ().layout (rect .left , rect .top , rect .right , rect .bottom );
1122
- dispatchRevealEvent (rect .left , rect .top , rect .right , rect .bottom );
1123
- dispatchSwipeEvent (rect .left , rect .top );
1165
+ dx = rect .left - surface .getLeft ();
1166
+ dy = rect .top - surface .getTop ();
1167
+ surface .layout (rect .left , rect .top , rect .right , rect .bottom );
1168
+ if (notify ) {
1169
+ dispatchRevealEvent (rect .left , rect .top , rect .right , rect .bottom );
1170
+ dispatchSwipeEvent (rect .left , rect .top , dx , dy );
1171
+ }else {
1172
+ safeBottomView ();
1173
+ }
1124
1174
}
1125
1175
invalidate ();
1126
1176
}
1127
1177
1128
-
1129
-
1130
1178
public void toggle (){
1131
1179
toggle (true );
1132
1180
}
0 commit comments