Skip to content

Commit e018625

Browse files
author
Issac
committed
修正滑动判断不精确的问题
1 parent 1bb9a5a commit e018625

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

library/src/main/java/me/imid/swipebacklayout/lib/SwipeBackLayout.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ public class SwipeBackLayout extends FrameLayout {
6767

6868
private static final int OVERSCROLL_DISTANCE = 10;
6969

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+
7274
private int mEdgeFlag;
73-
75+
7476
/**
7577
* Threshold of scroll, we will close the activity, when scrollPercent over
7678
* this value;
@@ -119,22 +121,26 @@ public SwipeBackLayout(Context context) {
119121
public SwipeBackLayout(Context context, AttributeSet attrs) {
120122
this(context, attrs, R.attr.SwipeBackLayoutStyle);
121123
}
122-
124+
123125
public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) {
124126
super(context, attrs);
125127
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+
129132
int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1);
130-
if(edgeSize >0 )
133+
if (edgeSize > 0)
131134
setEdgeSize(edgeSize);
132135
int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)];
133136
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);
138144
setShadow(shadowLeft, EDGE_LEFT);
139145
setShadow(shadowRight, EDGE_RIGHT);
140146
setShadow(shadowBottom, EDGE_BOTTOM);
@@ -311,9 +317,9 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
311317
if (!mEnable) {
312318
return false;
313319
}
314-
try{
320+
try {
315321
return mDragHelper.shouldInterceptTouchEvent(event);
316-
}catch(ArrayIndexOutOfBoundsException e){
322+
} catch (ArrayIndexOutOfBoundsException e) {
317323
// FIXME: handle exception
318324
// issues #9
319325
return false;
@@ -332,10 +338,10 @@ public boolean onTouchEvent(MotionEvent event) {
332338
@Override
333339
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
334340
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());
339345
mInLayout = false;
340346
}
341347

@@ -446,12 +452,12 @@ public boolean tryCaptureView(View view, int i) {
446452

447453
@Override
448454
public int getViewHorizontalDragRange(View child) {
449-
return 1;
455+
return mEdgeFlag & (EDGE_LEFT | EDGE_RIGHT);
450456
}
451457

452458
@Override
453459
public int getViewVerticalDragRange(View child) {
454-
return 1;
460+
return mEdgeFlag & EDGE_BOTTOM;
455461
}
456462

457463
@Override
@@ -477,8 +483,8 @@ public void onViewPositionChanged(View changedView, int left, int top, int dx, i
477483
}
478484

479485
if (mScrollPercent >= 1) {
480-
if(!mActivity.isFinishing())
481-
mActivity.finish();
486+
if (!mActivity.isFinishing())
487+
mActivity.finish();
482488
}
483489
}
484490

0 commit comments

Comments
 (0)