Skip to content

Commit 39d3bcd

Browse files
committed
Merge branch 'dev'
2 parents a77c89c + 898244d commit 39d3bcd

File tree

6 files changed

+46
-21
lines changed

6 files changed

+46
-21
lines changed

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import android.view.ViewGroup;
1515
import android.widget.FrameLayout;
1616

17-
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;
18-
1917
public class SwipeBackLayout extends FrameLayout {
2018
/**
2119
* Minimum velocity that will be detected as a fling
@@ -69,8 +67,10 @@ public class SwipeBackLayout extends FrameLayout {
6967

7068
private static final int OVERSCROLL_DISTANCE = 10;
7169

70+
private static final int[] EDGE_FLAGS = {EDGE_LEFT, EDGE_RIGHT, EDGE_BOTTOM, EDGE_ALL};
71+
7272
private int mEdgeFlag;
73-
73+
7474
/**
7575
* Threshold of scroll, we will close the activity, when scrollPercent over
7676
* this value;
@@ -119,19 +119,30 @@ public SwipeBackLayout(Context context) {
119119
public SwipeBackLayout(Context context, AttributeSet attrs) {
120120
this(context, attrs, R.attr.SwipeBackLayoutStyle);
121121
}
122-
122+
123123
public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) {
124124
super(context, attrs);
125+
mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());
126+
127+
TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.SwipeBackLayout,defStyle,0);
128+
129+
int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1);
130+
if(edgeSize >0 )
131+
setEdgeSize(edgeSize);
132+
int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)];
133+
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);
138+
setShadow(shadowLeft, EDGE_LEFT);
139+
setShadow(shadowRight, EDGE_RIGHT);
140+
setShadow(shadowBottom, EDGE_BOTTOM);
141+
a.recycle();
125142
final float density = getResources().getDisplayMetrics().density;
126143
final float minVel = MIN_FLING_VELOCITY * density;
127-
128-
mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());
129144
mDragHelper.setMinVelocity(minVel);
130-
setEdgeTrackingEnabled(EDGE_LEFT);
131145

132-
setShadow(R.drawable.shadow_left, EDGE_LEFT);
133-
setShadow(R.drawable.shadow_right, EDGE_RIGHT);
134-
setShadow(R.drawable.shadow_bottom, EDGE_BOTTOM);
135146
}
136147

137148
/**
@@ -315,6 +326,7 @@ public boolean onTouchEvent(MotionEvent event) {
315326
@Override
316327
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
317328
mInLayout = true;
329+
if(mContentView != null)
318330
mContentView.layout(mContentLeft, mContentTop,
319331
mContentLeft + mContentView.getMeasuredWidth(),
320332
mContentTop + mContentView.getMeasuredHeight());
@@ -459,6 +471,7 @@ public void onViewPositionChanged(View changedView, int left, int top, int dx, i
459471
}
460472

461473
if (mScrollPercent >= 1) {
474+
if(!mActivity.isFinishing())
462475
mActivity.finish();
463476
}
464477
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class ViewDragHelper {
9797
*/
9898
public static final int DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
9999

100-
private static final int EDGE_SIZE = 20; // dp
100+
public static final int EDGE_SIZE = 20; // dp
101101

102102
private static final int BASE_SETTLE_DURATION = 256; // ms
103103

library/src/main/java/me/imid/swipebacklayout/lib/app/SwipeBackActivityHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import me.imid.swipebacklayout.lib.SwipeBackLayout;
44
import android.app.Activity;
55
import android.graphics.drawable.ColorDrawable;
6+
import android.view.LayoutInflater;
67
import android.view.View;
78

89
/**
@@ -21,7 +22,7 @@ public SwipeBackActivityHelper(Activity activity) {
2122
public void onActivtyCreate(){
2223
mActivity.getWindow().setBackgroundDrawable(new ColorDrawable(0));
2324
mActivity.getWindow().getDecorView().setBackgroundDrawable(null);
24-
mSwipeBackLayout = new SwipeBackLayout(mActivity);
25+
mSwipeBackLayout = (SwipeBackLayout) LayoutInflater.from(mActivity).inflate(me.imid.swipebacklayout.lib.R.layout.swipeback_layout,null);
2526
}
2627

2728
public void onPostCreate(){
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<me.imid.swipebacklayout.lib.SwipeBackLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/swipe"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent" />
6+

library/src/main/res/values/attrs.xml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<declare-styleable name="SwipeBackLayout">
4-
<attr name="EdgeSize" format="dimension"/>
5-
<attr name="EdgeFlag" format="enum"/>
6-
<attr name="ShadowLeft" format="reference"/>
7-
<attr name="ShadowRight" format="reference"/>
8-
<attr name="ShadowBottom" format="reference"/>
4+
<attr name="edge_size" format="dimension"/>
5+
<attr name="edge_flag">
6+
<enum name="left" value="0" />
7+
<enum name="right" value="1" />
8+
<enum name="bottom" value="2" />
9+
<enum name="all" value="3" />
10+
</attr>
11+
<attr name="shadow_left" format="reference"/>
12+
<attr name="shadow_right" format="reference"/>
13+
<attr name="shadow_bottom" format="reference"/>
914
</declare-styleable>
1015

1116
<attr name="SwipeBackLayoutStyle" format="reference"/>

library/src/main/res/values/styles.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<resources>
33

44
<style name="SwipeBackLayout">
5-
<item name="EdgeSize">20dip</item>
6-
<item name="ShadowLeft">@drawable/shadow_left</item>
7-
<item name="ShadowRight">@drawable/shadow_right</item>
8-
<item name="ShadowBottom">@drawable/shadow_bottom</item>
5+
<item name="edge_size">50dip</item>
6+
<item name="shadow_left">@drawable/shadow_left</item>
7+
<item name="shadow_right">@drawable/shadow_right</item>
8+
<item name="shadow_bottom">@drawable/shadow_bottom</item>
99
</style>
1010

1111
</resources>

0 commit comments

Comments
 (0)