Skip to content

Commit d1df452

Browse files
committed
Merge pull request #8 from StephaneBg/master
Add SimpleSwipeListener
2 parents b8457a5 + 4078489 commit d1df452

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

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

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
import android.view.View;
1010
import android.widget.Toast;
1111

12+
import com.daimajia.swipe.SimpleSwipeListener;
1213
import com.daimajia.swipe.SwipeLayout;
1314
import com.nineoldandroids.view.ViewHelper;
1415

1516
public class MyActivity extends Activity {
1617

17-
private SwipeLayout sample1, sample2,sample3;
18+
private SwipeLayout sample1, sample2, sample3;
1819

1920
@Override
2021
protected void onCreate(Bundle savedInstanceState) {
@@ -26,7 +27,7 @@ protected void onCreate(Bundle savedInstanceState) {
2627

2728
//sample1
2829

29-
sample1 = (SwipeLayout)findViewById(R.id.sample1);
30+
sample1 = (SwipeLayout) findViewById(R.id.sample1);
3031
sample1.setShowMode(SwipeLayout.ShowMode.LayDown);
3132
sample1.setDragEdge(SwipeLayout.DragEdge.Left);
3233
sample1.addRevealListener(R.id.delete, new SwipeLayout.OnRevealListener() {
@@ -38,7 +39,7 @@ public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int
3839

3940
//sample2
4041

41-
sample2 = (SwipeLayout)findViewById(R.id.sample2);
42+
sample2 = (SwipeLayout) findViewById(R.id.sample2);
4243
sample2.setShowMode(SwipeLayout.ShowMode.LayDown);
4344
// sample2.setShowMode(SwipeLayout.ShowMode.PullOut);
4445
sample2.findViewById(R.id.star).setOnClickListener(new View.OnClickListener() {
@@ -65,34 +66,19 @@ public void onClick(View v) {
6566
sample2.findViewById(R.id.click).setOnClickListener(new View.OnClickListener() {
6667
@Override
6768
public void onClick(View v) {
68-
Toast.makeText(MyActivity.this, "Yo",Toast.LENGTH_SHORT).show();
69+
Toast.makeText(MyActivity.this, "Yo", Toast.LENGTH_SHORT).show();
6970
}
7071
});
71-
sample1.addSwipeListener(new SwipeLayout.SwipeListener() {
72-
@Override
73-
public void onClose(SwipeLayout layout) {
74-
75-
}
76-
77-
@Override
78-
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
79-
80-
}
81-
72+
sample1.addSwipeListener(new SimpleSwipeListener() {
8273
@Override
8374
public void onOpen(SwipeLayout layout) {
84-
85-
}
86-
87-
@Override
88-
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
89-
75+
Toast.makeText(MyActivity.this, "Opened", Toast.LENGTH_SHORT).show();
9076
}
9177
});
9278

9379
//sample3
9480

95-
sample3 = (SwipeLayout)findViewById(R.id.sample3);
81+
sample3 = (SwipeLayout) findViewById(R.id.sample3);
9682
sample3.setDragEdge(SwipeLayout.DragEdge.Top);
9783
sample3.addRevealListener(R.id.bottom_wrapper_child1, new SwipeLayout.OnRevealListener() {
9884
@Override
@@ -102,7 +88,7 @@ public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int
10288
ViewHelper.setTranslationY(star, d * fraction);
10389
ViewHelper.setScaleX(star, fraction + 0.6f);
10490
ViewHelper.setScaleY(star, fraction + 0.6f);
105-
int c = (Integer)evaluate(fraction, Color.parseColor("#dddddd"), Color.parseColor("#4C535B"));
91+
int c = (Integer) evaluate(fraction, Color.parseColor("#dddddd"), Color.parseColor("#4C535B"));
10692
child.setBackgroundColor(c);
10793
}
10894
});
@@ -131,7 +117,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
131117
if (id == R.id.action_listview) {
132118
startActivity(new Intent(this, ListViewExample.class));
133119
return true;
134-
}else if(id == R.id.action_gridview){
120+
} else if (id == R.id.action_gridview) {
135121
startActivity(new Intent(this, GridViewExample.class));
136122
return true;
137123
}
@@ -154,9 +140,9 @@ public Object evaluate(float fraction, Object startValue, Object endValue) {
154140
int endG = (endInt >> 8) & 0xff;
155141
int endB = endInt & 0xff;
156142

157-
return (int)((startA + (int)(fraction * (endA - startA))) << 24) |
158-
(int)((startR + (int)(fraction * (endR - startR))) << 16) |
159-
(int)((startG + (int)(fraction * (endG - startG))) << 8) |
160-
(int)((startB + (int)(fraction * (endB - startB))));
143+
return (int) ((startA + (int) (fraction * (endA - startA))) << 24) |
144+
(int) ((startR + (int) (fraction * (endR - startR))) << 16) |
145+
(int) ((startG + (int) (fraction * (endG - startG))) << 8) |
146+
(int) ((startB + (int) (fraction * (endB - startB))));
161147
}
162148
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.daimajia.swipe;
2+
3+
/**
4+
* Created by sbaiget on 29/08/2014.
5+
*/
6+
public class SimpleSwipeListener implements SwipeLayout.SwipeListener {
7+
8+
9+
@Override
10+
public void onClose(SwipeLayout layout) {
11+
}
12+
13+
@Override
14+
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
15+
}
16+
17+
@Override
18+
public void onOpen(SwipeLayout layout) {
19+
}
20+
21+
@Override
22+
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
23+
}
24+
}

0 commit comments

Comments
 (0)