Skip to content

Commit 0d3dc52

Browse files
committed
#23 support selector
1 parent c70c78f commit 0d3dc52

File tree

10 files changed

+101
-101
lines changed

10 files changed

+101
-101
lines changed

demo/src/main/java/com/daimajia/swipedemo/ListViewExample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class ListViewExample extends Activity {
1919

2020
private ListView mListView;
2121
private ListViewAdapter mAdapter;
22-
private int mPositionToTest;
2322

2423
@Override
2524
protected void onCreate(Bundle savedInstanceState) {

demo/src/main/res/drawable/hover_background.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

demo/src/main/res/drawable/hover_border_normal.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

demo/src/main/res/drawable/hover_border_pressed.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item android:drawable="@color/backgroundColorPress" android:state_pressed="true"/>
5+
<item android:drawable="@color/backgroundColorPress" android:state_focused="true"/>
6+
<item android:drawable="@color/backgroundColor"/>
7+
8+
</selector>

demo/src/main/res/layout/gridview.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
android:verticalSpacing="10dp"
66
android:horizontalSpacing="10dp"
77
android:numColumns="2"
8-
android:listSelector="@drawable/hover_background"
8+
android:listSelector="@drawable/item"
99
android:layout_width="match_parent"
1010
android:layout_height="match_parent"/>
1111

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,58 @@
11
<?xml version="1.0" encoding="utf-8" ?>
2-
3-
<com.daimajia.swipe.SwipeLayout
4-
android:id="@+id/swipe"
5-
xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
63
android:layout_width="match_parent"
7-
android:layout_height="800dp"
8-
>
9-
10-
<LinearLayout
11-
android:background="#FF5534"
12-
android:tag="Bottom3"
13-
android:weightSum="10"
14-
android:gravity="center"
4+
android:background="@drawable/item"
5+
android:layout_height="match_parent">
6+
<com.daimajia.swipe.SwipeLayout
7+
android:id="@+id/swipe"
158
android:layout_width="match_parent"
16-
android:layout_height="80dp">
17-
<ImageView
18-
android:id="@+id/trash"
19-
android:src="@drawable/trash"
20-
android:layout_weight="1"
21-
android:layout_width="27dp"
22-
android:layout_height="30dp" />
23-
<TextView
24-
android:text="Delete Item?"
25-
android:textSize="17sp"
26-
android:textColor="#fff"
27-
android:layout_weight="5"
28-
android:layout_width="0dp"
29-
android:layout_height="wrap_content" />
30-
<Button
31-
android:id="@+id/delete"
32-
android:textColor="#FF5534"
33-
android:background="#ffffff"
34-
android:text="Yes,Delete"
35-
android:layout_weight="4"
36-
android:layout_width="0dp"
37-
android:layout_height="40dp" />
38-
</LinearLayout>
9+
android:layout_height="wrap_content"
10+
>
3911

40-
<LinearLayout
41-
android:padding="10dp"
42-
android:background="#ffffff"
43-
android:layout_width="match_parent"
44-
android:layout_height="match_parent">
45-
<TextView
46-
android:id="@+id/position"
47-
android:layout_width="wrap_content"
48-
android:layout_height="wrap_content" />
49-
<TextView
50-
android:tag="Hover"
51-
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
12+
<LinearLayout
13+
android:background="#FF5534"
14+
android:tag="Bottom3"
15+
android:weightSum="10"
16+
android:gravity="center"
17+
android:layout_width="match_parent"
18+
android:layout_height="80dp">
19+
<ImageView
20+
android:id="@+id/trash"
21+
android:src="@drawable/trash"
22+
android:layout_weight="1"
23+
android:layout_width="27dp"
24+
android:layout_height="30dp" />
25+
<TextView
26+
android:text="Delete Item?"
27+
android:textSize="17sp"
28+
android:textColor="#fff"
29+
android:layout_weight="5"
30+
android:layout_width="0dp"
31+
android:layout_height="wrap_content" />
32+
<Button
33+
android:id="@+id/delete"
34+
android:textColor="#FF5534"
35+
android:background="#ffffff"
36+
android:text="Yes,Delete"
37+
android:layout_weight="4"
38+
android:layout_width="0dp"
39+
android:layout_height="40dp" />
40+
</LinearLayout>
41+
42+
<LinearLayout
43+
android:padding="10dp"
44+
android:background="@drawable/item"
5245
android:layout_width="match_parent"
53-
android:layout_height="match_parent" />
54-
</LinearLayout>
55-
</com.daimajia.swipe.SwipeLayout>
46+
android:layout_height="match_parent">
47+
<TextView
48+
android:id="@+id/position"
49+
android:layout_width="wrap_content"
50+
android:layout_height="wrap_content" />
51+
<TextView
52+
android:tag="Hover"
53+
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
54+
android:layout_width="match_parent"
55+
android:layout_height="match_parent" />
56+
</LinearLayout>
57+
</com.daimajia.swipe.SwipeLayout>
58+
</LinearLayout>

demo/src/main/res/layout/sample1.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:background="@drawable/item"
45
android:layout_width="match_parent" android:layout_height="80dp">
56
<LinearLayout
67
android:tag="Bottom1"
@@ -30,7 +31,7 @@
3031

3132
<LinearLayout
3233
android:padding="10dp"
33-
android:background="#ffffff"
34+
android:background="@drawable/item"
3435
android:layout_width="match_parent"
3536
android:layout_height="match_parent">
3637
<TextView
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="backgroundColor">#E8E8E0</color>
4+
<color name="backgroundColorPress">#DBDBD3</color>
5+
</resources>

library/src/main/java/com/daimajia/swipe/SwipeLayout.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -654,13 +654,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
654654
}else{
655655
break;
656656
}
657-
break;
658657
case MotionEvent.ACTION_UP:
659658
case MotionEvent.ACTION_CANCEL:
660659
mTouchConsumedByChild = false;
661660
}
662661

663-
if(mTouchConsumedByChild) return false;
662+
if(mTouchConsumedByChild) return false;
664663
return mDragHelper.shouldInterceptTouchEvent(ev);
665664
}
666665

@@ -718,12 +717,23 @@ public boolean onTouchEvent(MotionEvent event) {
718717
int action = event.getActionMasked();
719718
ViewParent parent = getParent();
720719
gestureDetector.onTouchEvent(event);
720+
Status status = getOpenStatus();
721+
ViewGroup touching = null;
722+
if(status == Status.Close){
723+
touching = getSurfaceView();
724+
}else if(status == Status.Open){
725+
touching = getBottomView();
726+
}
721727
switch (action){
722728
case MotionEvent.ACTION_DOWN:
723729
mDragHelper.processTouchEvent(event);
724730
parent.requestDisallowInterceptTouchEvent(true);
725731
sX = event.getRawX();
726732
sY = event.getRawY();
733+
734+
if(touching != null)
735+
touching.setPressed(true);
736+
727737
return true;
728738
case MotionEvent.ACTION_MOVE:{
729739
if(sX == -1 || sY == -1){
@@ -737,18 +747,22 @@ public boolean onTouchEvent(MotionEvent event) {
737747
sY = event.getRawY();
738748
return true;
739749
}
750+
751+
if(touching != null)
752+
touching.setPressed(false);
753+
740754
float distanceX = event.getRawX() - sX;
741755
float distanceY = event.getRawY() - sY;
742756
float angle = Math.abs(distanceY / distanceX);
743757
angle = (float)Math.toDegrees(Math.atan(angle));
744-
Status status = getOpenStatus();
758+
759+
boolean doNothing = false;
745760
if(mDragEdge == DragEdge.Right){
746761
boolean suitable = (status == Status.Open && distanceX > 0) || (status == Status.Close && distanceX < 0);
747762
suitable = suitable || (status == Status.Middle);
748763

749764
if(angle > 30 || !suitable){
750-
parent.requestDisallowInterceptTouchEvent(false);
751-
return false;
765+
doNothing = true;
752766
}
753767
}
754768

@@ -757,8 +771,7 @@ public boolean onTouchEvent(MotionEvent event) {
757771
suitable = suitable || status == Status.Middle;
758772

759773
if(angle > 30 || ! suitable){
760-
parent.requestDisallowInterceptTouchEvent(false);
761-
return false;
774+
doNothing = true;
762775
}
763776
}
764777

@@ -767,8 +780,7 @@ public boolean onTouchEvent(MotionEvent event) {
767780
suitable = suitable || status == Status.Middle;
768781

769782
if(angle < 60 || ! suitable){
770-
parent.requestDisallowInterceptTouchEvent(false);
771-
return false;
783+
doNothing = true;
772784
}
773785
}
774786

@@ -777,20 +789,27 @@ public boolean onTouchEvent(MotionEvent event) {
777789
suitable = suitable || status == Status.Middle;
778790

779791
if(angle < 60 || ! suitable){
780-
parent.requestDisallowInterceptTouchEvent(false);
781-
return false;
792+
doNothing = true;
782793
}
783794
}
784795

785-
parent.requestDisallowInterceptTouchEvent(true);
786-
mDragHelper.processTouchEvent(event);
796+
if(doNothing){
797+
parent.requestDisallowInterceptTouchEvent(false);
798+
return false;
799+
}else{
800+
parent.requestDisallowInterceptTouchEvent(true);
801+
mDragHelper.processTouchEvent(event);
802+
}
787803
break;
788804
}
789805
case MotionEvent.ACTION_UP:
790806
case MotionEvent.ACTION_CANCEL:
791807
{
792808
sX = -1;
793809
sY = -1;
810+
if(touching != null){
811+
touching.setPressed(false);
812+
}
794813
}
795814
default:
796815
parent.requestDisallowInterceptTouchEvent(true);

0 commit comments

Comments
 (0)