@@ -67,10 +67,12 @@ public class SwipeBackLayout extends FrameLayout {
67
67
68
68
private static final int OVERSCROLL_DISTANCE = 10 ;
69
69
70
- private static final int [] EDGE_FLAGS = {EDGE_LEFT , EDGE_RIGHT , EDGE_BOTTOM , EDGE_ALL };
71
-
70
+ private static final int [] EDGE_FLAGS = {
71
+ EDGE_LEFT , EDGE_RIGHT , EDGE_BOTTOM , EDGE_ALL
72
+ };
73
+
72
74
private int mEdgeFlag ;
73
-
75
+
74
76
/**
75
77
* Threshold of scroll, we will close the activity, when scrollPercent over
76
78
* this value;
@@ -119,22 +121,26 @@ public SwipeBackLayout(Context context) {
119
121
public SwipeBackLayout (Context context , AttributeSet attrs ) {
120
122
this (context , attrs , R .attr .SwipeBackLayoutStyle );
121
123
}
122
-
124
+
123
125
public SwipeBackLayout (Context context , AttributeSet attrs , int defStyle ) {
124
126
super (context , attrs );
125
127
mDragHelper = ViewDragHelper .create (this , new ViewDragCallback ());
126
-
127
- TypedArray a = context .obtainStyledAttributes (attrs ,R .styleable .SwipeBackLayout ,defStyle ,R .style .SwipeBackLayout );
128
-
128
+
129
+ TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .SwipeBackLayout , defStyle ,
130
+ R .style .SwipeBackLayout );
131
+
129
132
int edgeSize = a .getDimensionPixelSize (R .styleable .SwipeBackLayout_edge_size , -1 );
130
- if (edgeSize >0 )
133
+ if (edgeSize > 0 )
131
134
setEdgeSize (edgeSize );
132
135
int mode = EDGE_FLAGS [a .getInt (R .styleable .SwipeBackLayout_edge_flag , 0 )];
133
136
setEdgeTrackingEnabled (mode );
134
-
135
- int shadowLeft = a .getResourceId (R .styleable .SwipeBackLayout_shadow_left , R .drawable .shadow_left );
136
- int shadowRight = a .getResourceId (R .styleable .SwipeBackLayout_shadow_right , R .drawable .shadow_right );
137
- int shadowBottom = a .getResourceId (R .styleable .SwipeBackLayout_shadow_bottom , R .drawable .shadow_bottom );
137
+
138
+ int shadowLeft = a .getResourceId (R .styleable .SwipeBackLayout_shadow_left ,
139
+ R .drawable .shadow_left );
140
+ int shadowRight = a .getResourceId (R .styleable .SwipeBackLayout_shadow_right ,
141
+ R .drawable .shadow_right );
142
+ int shadowBottom = a .getResourceId (R .styleable .SwipeBackLayout_shadow_bottom ,
143
+ R .drawable .shadow_bottom );
138
144
setShadow (shadowLeft , EDGE_LEFT );
139
145
setShadow (shadowRight , EDGE_RIGHT );
140
146
setShadow (shadowBottom , EDGE_BOTTOM );
@@ -311,9 +317,9 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
311
317
if (!mEnable ) {
312
318
return false ;
313
319
}
314
- try {
320
+ try {
315
321
return mDragHelper .shouldInterceptTouchEvent (event );
316
- }catch (ArrayIndexOutOfBoundsException e ){
322
+ } catch (ArrayIndexOutOfBoundsException e ) {
317
323
// FIXME: handle exception
318
324
// issues #9
319
325
return false ;
@@ -332,10 +338,10 @@ public boolean onTouchEvent(MotionEvent event) {
332
338
@ Override
333
339
protected void onLayout (boolean changed , int left , int top , int right , int bottom ) {
334
340
mInLayout = true ;
335
- if (mContentView != null )
336
- mContentView .layout (mContentLeft , mContentTop ,
337
- mContentLeft + mContentView .getMeasuredWidth (),
338
- mContentTop + mContentView .getMeasuredHeight ());
341
+ if (mContentView != null )
342
+ mContentView .layout (mContentLeft , mContentTop ,
343
+ mContentLeft + mContentView .getMeasuredWidth (),
344
+ mContentTop + mContentView .getMeasuredHeight ());
339
345
mInLayout = false ;
340
346
}
341
347
@@ -446,12 +452,12 @@ public boolean tryCaptureView(View view, int i) {
446
452
447
453
@ Override
448
454
public int getViewHorizontalDragRange (View child ) {
449
- return 1 ;
455
+ return mEdgeFlag & ( EDGE_LEFT | EDGE_RIGHT ) ;
450
456
}
451
457
452
458
@ Override
453
459
public int getViewVerticalDragRange (View child ) {
454
- return 1 ;
460
+ return mEdgeFlag & EDGE_BOTTOM ;
455
461
}
456
462
457
463
@ Override
@@ -477,8 +483,8 @@ public void onViewPositionChanged(View changedView, int left, int top, int dx, i
477
483
}
478
484
479
485
if (mScrollPercent >= 1 ) {
480
- if (!mActivity .isFinishing ())
481
- mActivity .finish ();
486
+ if (!mActivity .isFinishing ())
487
+ mActivity .finish ();
482
488
}
483
489
}
484
490
0 commit comments