Skip to content

Commit 742494d

Browse files
committed
improve touch handle and intercept logic :
1.The surface and bottom view could be clickable and longClickable, and it's selector drawables works fine; 2.The swipeLayout can wrap in other gestural layout, the swipe and other layout's gesture work's pretty;
1 parent 9ca31ac commit 742494d

File tree

12 files changed

+295
-242
lines changed

12 files changed

+295
-242
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public boolean onTouch(View v, MotionEvent event) {
6868
@Override
6969
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
7070
Toast.makeText(mContext, "OnItemLongClickListener", Toast.LENGTH_SHORT).show();
71-
return false;
71+
return true;
7272
}
7373
});
7474
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Intent;
55
import android.graphics.Color;
66
import android.os.Bundle;
7+
import android.util.Log;
78
import android.view.Menu;
89
import android.view.MenuItem;
910
import android.view.View;
@@ -20,6 +21,9 @@ public class MyActivity extends Activity {
2021
protected void onCreate(Bundle savedInstanceState) {
2122
super.onCreate(savedInstanceState);
2223
setContentView(R.layout.main);
24+
SwipeLayout godfatherSwipe = (SwipeLayout) findViewById(R.id.godfather);
25+
godfatherSwipe.setDragEdges(SwipeLayout.DragEdge.Left, SwipeLayout.DragEdge.Right, SwipeLayout.DragEdge.Top, SwipeLayout.DragEdge.Bottom);
26+
godfatherSwipe.setBottomViewIds(R.id.bird_left, R.id.bird_right, R.id.bird_top, R.id.bird_bottom);
2327

2428
// SwipeLayout swipeLayout = (SwipeLayout)findViewById(R.id.godfather);
2529
// swipeLayout.setDragEdge(SwipeLayout.DragEdge.Bottom); // Set in XML
@@ -38,6 +42,21 @@ public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int
3842
}
3943
});
4044

45+
sample1.getSurfaceView().setOnClickListener(new View.OnClickListener() {
46+
@Override
47+
public void onClick(View v) {
48+
Toast.makeText(MyActivity.this, "Click on surface", Toast.LENGTH_SHORT).show();
49+
Log.d(MyActivity.class.getName(), "click on surface");
50+
}
51+
});
52+
sample1.getSurfaceView().setOnLongClickListener(new View.OnLongClickListener() {
53+
@Override
54+
public boolean onLongClick(View v) {
55+
Toast.makeText(MyActivity.this, "longClick on surface", Toast.LENGTH_SHORT).show();
56+
Log.d(MyActivity.class.getName(), "longClick on surface");
57+
return true;
58+
}
59+
});
4160
sample1.findViewById(R.id.star2).setOnClickListener(new View.OnClickListener() {
4261
@Override
4362
public void onClick(View v) {
@@ -103,6 +122,12 @@ public void onClick(View v) {
103122
Toast.makeText(MyActivity.this, "Yo", Toast.LENGTH_SHORT).show();
104123
}
105124
});
125+
sample2.getSurfaceView().setOnClickListener(new View.OnClickListener() {
126+
@Override
127+
public void onClick(View v) {
128+
Toast.makeText(MyActivity.this, "Click on surface", Toast.LENGTH_SHORT).show();
129+
}
130+
});
106131

107132
//sample3
108133

@@ -120,12 +145,18 @@ public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int
120145
child.setBackgroundColor(c);
121146
}
122147
});
123-
sample3.findViewById(R.id.star).setOnClickListener(new View.OnClickListener() {
148+
sample3.findViewById(R.id.bottom_wrapper_child1).setOnClickListener(new View.OnClickListener() {
124149
@Override
125150
public void onClick(View v) {
126151
Toast.makeText(MyActivity.this, "Yo!", Toast.LENGTH_SHORT).show();
127152
}
128153
});
154+
sample3.getSurfaceView().setOnClickListener(new View.OnClickListener() {
155+
@Override
156+
public void onClick(View v) {
157+
Toast.makeText(MyActivity.this, "Click on surface", Toast.LENGTH_SHORT).show();
158+
}
159+
});
129160

130161
}
131162

demo/src/main/java/com/daimajia/swipedemo/adapter/ListViewAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public void onDoubleClick(SwipeLayout layout, boolean surface) {
4343
Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show();
4444
}
4545
});
46+
v.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() {
47+
@Override
48+
public void onClick(View view) {
49+
Toast.makeText(mContext, "click delete", Toast.LENGTH_SHORT).show();
50+
}
51+
});
4652
return v;
4753
}
4854

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/dark_gray_press" android:state_pressed="true"/>
5+
<item android:drawable="@color/dark_gray_press" android:state_focused="true"/>
6+
<item android:drawable="@color/dark_gray"/>
7+
8+
</selector>

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

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/red_press" android:state_pressed="true"/>
5+
<item android:drawable="@color/red_press" android:state_focused="true"/>
6+
<item android:drawable="@color/red"/>
7+
8+
</selector>
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="@android:color/darker_gray" android:state_pressed="true"/>
5+
<item android:drawable="@android:color/darker_gray" android:state_focused="true"/>
6+
<item android:drawable="@android:color/white"/>
7+
8+
</selector>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
android:layout_width="0dp"
3737
android:layout_height="40dp"
3838
android:layout_weight="4"
39-
android:background="#ffffff"
39+
android:background="@drawable/white"
4040
android:text="Yes,Delete"
4141
android:textColor="#FF5534" />
4242
</LinearLayout>

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,39 @@
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
xmlns:app="http://schemas.android.com/apk/res-auto"
66
android:id="@+id/godfather"
7-
android:layout_width="match_parent" android:layout_height="match_parent"
8-
app:drag_edge="bottom">
7+
android:layout_width="match_parent" android:layout_height="match_parent">
98
<LinearLayout
9+
android:id="@+id/bird_left"
10+
android:gravity="center"
11+
android:layout_width="100dp"
12+
android:layout_height="match_parent">
13+
<ImageView
14+
android:src="@drawable/bird"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content" />
17+
</LinearLayout>
18+
<LinearLayout
19+
android:id="@+id/bird_right"
20+
android:gravity="center"
21+
android:layout_width="100dp"
22+
android:layout_height="match_parent">
23+
<ImageView
24+
android:src="@drawable/bird"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content" />
27+
</LinearLayout>
28+
<LinearLayout
29+
android:id="@+id/bird_top"
30+
android:gravity="center"
31+
android:layout_width="match_parent"
32+
android:layout_height="100dp">
33+
<ImageView
34+
android:src="@drawable/bird"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content" />
37+
</LinearLayout>
38+
<LinearLayout
39+
android:id="@+id/bird_bottom"
1040
android:gravity="center"
1141
android:layout_width="match_parent"
1242
android:layout_height="match_parent">

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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_selector"
54
android:layout_width="match_parent"
65
android:layout_height="80dp">
76

@@ -19,7 +18,8 @@
1918
android:text="Archive"
2019
android:layout_weight="0.5"
2120
android:gravity="center"
22-
android:background="#FF1300"
21+
android:clickable="true"
22+
android:background="@drawable/red"
2323
android:layout_width="wrap_content"
2424
android:layout_height="match_parent" />
2525

@@ -61,7 +61,7 @@
6161
android:id="@+id/trash2"
6262
android:src="@drawable/trash"
6363
android:layout_width="70dp"
64-
android:background="#FF3B30"
64+
android:background="@drawable/red"
6565
android:paddingLeft="25dp"
6666
android:paddingRight="25dp"
6767
android:layout_height="match_parent" />
@@ -74,7 +74,8 @@
7474
android:layout_height="match_parent">
7575
<RelativeLayout
7676
android:id="@+id/bottom_wrapper_child1"
77-
android:background="#4C535B"
77+
android:background="@drawable/dark_gray"
78+
android:clickable="true"
7879
android:layout_width="match_parent"
7980
android:layout_height="match_parent">
8081
<ImageView
@@ -89,7 +90,7 @@
8990

9091
<LinearLayout
9192
android:padding="10dp"
92-
android:background="#ffffff"
93+
android:background="@drawable/white"
9394
android:layout_width="match_parent"
9495
android:layout_height="match_parent">
9596

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
android:id="@+id/trash"
2727
android:src="@drawable/trash"
2828
android:layout_width="70dp"
29-
android:background="#FF3B30"
29+
android:background="@drawable/red"
3030
android:paddingLeft="25dp"
3131
android:paddingRight="25dp"
3232
android:layout_height="match_parent" />
@@ -35,7 +35,7 @@
3535
<LinearLayout
3636
android:padding="10dp"
3737
android:orientation="vertical"
38-
android:background="#ffffff"
38+
android:background="@drawable/white"
3939
android:layout_width="match_parent"
4040
android:layout_height="match_parent">
4141
<TextView

0 commit comments

Comments
 (0)