@@ -323,7 +323,11 @@ public int clampViewPositionVertical(View child, int top, int dy) {
323
323
324
324
@ Override
325
325
public boolean tryCaptureView (View child , int pointerId ) {
326
- return child == getSurfaceView () || getBottomViews ().contains (child );
326
+ boolean result = child == getSurfaceView () || getBottomViews ().contains (child );
327
+ if (result ){
328
+ isCloseBeforeDrag = getOpenStatus () == Status .Close ;
329
+ }
330
+ return result ;
327
331
}
328
332
329
333
@ Override
@@ -336,13 +340,14 @@ public int getViewVerticalDragRange(View child) {
336
340
return mDragDistance ;
337
341
}
338
342
343
+ boolean isCloseBeforeDrag = true ;
339
344
@ Override
340
345
public void onViewReleased (View releasedChild , float xvel , float yvel ) {
341
346
super .onViewReleased (releasedChild , xvel , yvel );
342
347
for (SwipeListener l : mSwipeListeners )
343
348
l .onHandRelease (SwipeLayout .this , xvel , yvel );
344
349
if (releasedChild == getSurfaceView ()) {
345
- processSurfaceRelease (xvel , yvel );
350
+ processSurfaceRelease (xvel , yvel , isCloseBeforeDrag );
346
351
} else if (getBottomViews ().contains (releasedChild )) {
347
352
if (getShowMode () == ShowMode .PullOut ) {
348
353
processBottomPullOutRelease (xvel , yvel );
@@ -1284,37 +1289,58 @@ public Status getOpenStatus() {
1284
1289
return Status .Middle ;
1285
1290
}
1286
1291
1292
+
1287
1293
/**
1288
1294
* Process the surface release event.
1289
1295
*
1290
- * @param xvel
1291
- * @param yvel
1296
+ * @param xvel xVelocity
1297
+ * @param yvel yVelocity
1298
+ * @param isCloseBeforeDragged the open state before drag
1292
1299
*/
1293
- private void processSurfaceRelease (float xvel , float yvel ) {
1294
- if (xvel == 0 && getOpenStatus () == Status .Middle ) close ();
1295
-
1296
- if (mDragEdges .get (mCurrentDirectionIndex ) == DragEdge .Left
1297
- || mDragEdges .get (mCurrentDirectionIndex ) == DragEdge .Right ) {
1298
- if (xvel > 0 ) {
1299
- if (mDragEdges .get (mCurrentDirectionIndex ) == DragEdge .Left )
1300
- open ();
1300
+ private void processSurfaceRelease (float xvel , float yvel , boolean isCloseBeforeDragged ) {
1301
+ float minVelocity = mDragHelper .getMinVelocity ();
1302
+ View surfaceView = getSurfaceView ();
1303
+ DragEdge currentDragEdge = null ;
1304
+ try {
1305
+ currentDragEdge = mDragEdges .get (mCurrentDirectionIndex );
1306
+ } catch (Exception e ) {
1307
+ e .printStackTrace ();
1308
+ }
1309
+ if (currentDragEdge == null || surfaceView == null ){
1310
+ return ;
1311
+ }
1312
+ float willOpenPercent = (isCloseBeforeDragged ? .3f : .7f );
1313
+ if (currentDragEdge == DragEdge .Left ){
1314
+ if (xvel > minVelocity ) open ();
1315
+ else if (xvel < -minVelocity ) close ();
1316
+ else {
1317
+ float openPercent = 1f * getSurfaceView ().getLeft () / mDragDistance ;
1318
+ if (openPercent > willOpenPercent ) open ();
1301
1319
else close ();
1302
1320
}
1303
- if (xvel < 0 ) {
1304
- if (mDragEdges .get (mCurrentDirectionIndex ) == DragEdge .Left )
1305
- close ();
1306
- else open ();
1321
+ }else if (currentDragEdge == DragEdge .Right ){
1322
+ if (xvel > minVelocity ) close ();
1323
+ else if (xvel < -minVelocity ) open ();
1324
+ else {
1325
+ float openPercent = 1f * (-getSurfaceView ().getLeft ()) / mDragDistance ;
1326
+ if (openPercent > willOpenPercent ) open ();
1327
+ else close ();
1307
1328
}
1308
- } else {
1309
- if (yvel > 0 ) {
1310
- if (mDragEdges .get (mCurrentDirectionIndex ) == DragEdge .Top )
1311
- open ();
1329
+ }else if (currentDragEdge == DragEdge .Top ){
1330
+ if (yvel > minVelocity ) open ();
1331
+ else if (yvel < -minVelocity ) close ();
1332
+ else {
1333
+ float openPercent = 1f * getSurfaceView ().getTop () / mDragDistance ;
1334
+ if (openPercent > willOpenPercent ) open ();
1312
1335
else close ();
1313
1336
}
1314
- if (yvel < 0 ) {
1315
- if (mDragEdges .get (mCurrentDirectionIndex ) == DragEdge .Top )
1316
- close ();
1317
- else open ();
1337
+ }else if (currentDragEdge == DragEdge .Bottom ){
1338
+ if (yvel > minVelocity ) close ();
1339
+ else if (yvel < -minVelocity ) open ();
1340
+ else {
1341
+ float openPercent = 1f * (-getSurfaceView ().getTop ()) / mDragDistance ;
1342
+ if (openPercent > willOpenPercent ) open ();
1343
+ else close ();
1318
1344
}
1319
1345
}
1320
1346
}
0 commit comments