@@ -70,9 +70,11 @@ public SwipeLayout(Context context, AttributeSet attrs, int defStyle) {
7070
7171
7272 public interface SwipeListener {
73+ public void onStartOpen (SwipeLayout layout );
74+ public void onOpen (SwipeLayout layout );
75+ public void onStartClose (SwipeLayout layout );
7376 public void onClose (SwipeLayout layout );
7477 public void onUpdate (SwipeLayout layout , int leftOffset , int topOffset );
75- public void onOpen (SwipeLayout layout );
7678 public void onHandRelease (SwipeLayout layout , float xvel , float yvel );
7779 }
7880
@@ -324,13 +326,11 @@ public void onViewPositionChanged(View changedView, int left, int top, int dx, i
324326
325327 getSurfaceView ().layout (newLeft , newTop , newLeft + getMeasuredWidth (), newTop + getMeasuredHeight ());
326328 }
327-
328-
329329 }
330330
331331 dispatchRevealEvent (evLeft , evTop , evRight , evBottom );
332332
333- dispatchSwipeEvent (evLeft , evTop );
333+ dispatchSwipeEvent (evLeft , evTop , dx , dy );
334334
335335 invalidate ();
336336 }
@@ -441,29 +441,54 @@ protected Rect getRelativePosition(View child){
441441 return r ;
442442 }
443443
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+ }
450461
462+ protected void dispatchSwipeEvent (int surfaceLeft , int surfaceTop , boolean open ){
451463 safeBottomView ();
464+ Status status = getOpenStatus ();
452465
453- if (mSwipeListeners .isEmpty () == false ){
466+ if (!mSwipeListeners .isEmpty ()){
467+ mEventCounter ++;
454468 for (SwipeListener l : mSwipeListeners ){
469+ if (mEventCounter == 1 ){
470+ if (open ){
471+ l .onStartOpen (this );
472+ }else {
473+ l .onStartClose (this );
474+ }
475+ }
455476 l .onUpdate (SwipeLayout .this , surfaceLeft - getPaddingLeft (), surfaceTop - getPaddingTop ());
456477 }
457478
458- if (getOpenStatus () == Status .Close ){
459- for (SwipeListener l : mSwipeListeners )
479+ if (status == Status .Close ){
480+ for (SwipeListener l : mSwipeListeners ){
460481 l .onClose (SwipeLayout .this );
482+ }
483+ mEventCounter = 0 ;
461484 }
462485
463- if (getOpenStatus () == Status .Open ){
486+ if (status == Status .Open ){
464487 getBottomView ().setEnabled (true );
465- for (SwipeListener l : mSwipeListeners )
488+ for (SwipeListener l : mSwipeListeners ){
466489 l .onOpen (SwipeLayout .this );
490+ }
491+ mEventCounter = 0 ;
467492 }
468493 }
469494 }
@@ -1082,22 +1107,34 @@ private void processBottomLayDownMode(float xvel, float yvel){
10821107 * smoothly open surface.
10831108 */
10841109 public void open (){
1085- open (true );
1110+ open (true , true );
10861111 }
10871112
10881113 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 ;
10891120 Rect rect = computeSurfaceLayoutArea (true );
10901121 if (smooth ) {
10911122 mDragHelper .smoothSlideViewTo (getSurfaceView (), rect .left , rect .top );
10921123 }
10931124 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 );
10951128 if (getShowMode () == ShowMode .PullOut ){
10961129 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 ();
10981137 }
1099- dispatchRevealEvent (rect .left , rect .top , rect .right , rect .bottom );
1100- dispatchSwipeEvent (rect .left , rect .top );
11011138 }
11021139 invalidate ();
11031140 }
@@ -1106,27 +1143,38 @@ public void open(boolean smooth){
11061143 * smoothly close surface.
11071144 */
11081145 public void close (){
1109- close (true );
1146+ close (true , true );
1147+ }
1148+
1149+ public void close (boolean smooth ){
1150+ close (smooth , true );
11101151 }
11111152
11121153 /**
11131154 * close surface
11141155 * @param smooth smoothly or not.
1156+ * @param notify if notify all the listeners.
11151157 */
1116- public void close (boolean smooth ){
1158+ public void close (boolean smooth , boolean notify ){
1159+ ViewGroup surface = getSurfaceView ();
1160+ int dx , dy ;
11171161 if (smooth )
11181162 mDragHelper .smoothSlideViewTo (getSurfaceView (), getPaddingLeft (), getPaddingTop ());
11191163 else {
11201164 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+ }
11241174 }
11251175 invalidate ();
11261176 }
11271177
1128-
1129-
11301178 public void toggle (){
11311179 toggle (true );
11321180 }
0 commit comments