Skip to content

Commit 93c06bf

Browse files
committed
demo to show that three edge swipe works
1 parent 1fd2ec7 commit 93c06bf

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ protected void onCreate(Bundle savedInstanceState) {
2828

2929
sample1 = (SwipeLayout) findViewById(R.id.sample1);
3030
sample1.setShowMode(SwipeLayout.ShowMode.LayDown);
31-
sample1.setDragEdges(SwipeLayout.DragEdge.Left, SwipeLayout.DragEdge.Right);
31+
sample1.setDragEdges(SwipeLayout.DragEdge.Left, SwipeLayout.DragEdge.Right, SwipeLayout.DragEdge.Top);
3232
// When using multiple drag edges it's a good idea to pass the ids of the views that you're using for the left, right, top bottom views (-1 if you're not using a particular view)
33-
sample1.setBottomViewIds(R.id.bottom_wrapper, R.id.bottom_wrapper_2, -1, -1);
33+
sample1.setBottomViewIds(R.id.bottom_wrapper, R.id.bottom_wrapper_2, R.id.starbott, -1);
3434
sample1.addRevealListener(R.id.delete, new SwipeLayout.OnRevealListener() {
3535
@Override
3636
public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@
6767
android:layout_height="match_parent" />
6868
</LinearLayout>
6969

70+
<LinearLayout
71+
android:tag="Bottom3"
72+
android:id="@+id/starbott"
73+
android:layout_width="match_parent"
74+
android:layout_height="match_parent">
75+
<RelativeLayout
76+
android:id="@+id/bottom_wrapper_child1"
77+
android:background="#BDBEC2"
78+
android:layout_width="match_parent"
79+
android:layout_height="match_parent">
80+
<ImageView
81+
android:id="@+id/star"
82+
android:layout_alignParentTop="true"
83+
android:layout_centerHorizontal="true"
84+
android:src="@drawable/star"
85+
android:layout_width="20dp"
86+
android:layout_height="20dp" />
87+
</RelativeLayout>
88+
</LinearLayout>
89+
7090
<LinearLayout
7191
android:padding="10dp"
7292
android:background="#ffffff"

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ public boolean onTouchEvent(MotionEvent event) {
836836

837837
if (touching != null) touching.setPressed(true);
838838
return true;
839-
case MotionEvent.ACTION_MOVE:{
839+
case MotionEvent.ACTION_MOVE: {
840840
float distanceX = event.getRawX() - sX;
841841
float distanceY = event.getRawY() - sY;
842842
float angle = Math.abs(distanceY / distanceX);
@@ -846,13 +846,13 @@ public boolean onTouchEvent(MotionEvent event) {
846846
if (angle < 45) {
847847
if (mLeftIndex != -1 && distanceX > 0 && isLeftSwipeEnabled()) {
848848
mCurrentDirectionIndex = mLeftIndex;
849-
} else if (mRightIndex != -1 && isRightSwipeEnabled()) {
849+
} else if (mRightIndex != -1 && distanceX < 0 && isRightSwipeEnabled()) {
850850
mCurrentDirectionIndex = mRightIndex;
851851
}
852852
} else {
853-
if (mTopIndex != -1 && distanceY < 0 && isTopSwipeEnabled()) {
853+
if (mTopIndex != -1 && distanceY > 0 && isTopSwipeEnabled()) {
854854
mCurrentDirectionIndex = mTopIndex;
855-
} else if (mBottomIndex != -1 && isBottomSwipeEnabled()) {
855+
} else if (mBottomIndex != -1 && distanceY < 0 && isBottomSwipeEnabled()) {
856856
mCurrentDirectionIndex = mBottomIndex;
857857
}
858858
}
@@ -1159,44 +1159,41 @@ public List<ViewGroup> getBottomViews() {
11591159
}
11601160

11611161
// Pass the id of the view if set, otherwise pass -1
1162-
public void setBottomViewIds (int left, int right, int top, int bottom) {
1162+
public void setBottomViewIds(int left, int right, int top, int bottom) {
11631163
if (mDragEdges.contains(DragEdge.Left)) {
11641164
if (left == -1) {
11651165
mBottomViewIdsSet = false;
1166-
}
1167-
else {
1166+
} else {
11681167
mBottomViewIdMap.put(DragEdge.Left, left);
11691168
mBottomViewIdsSet = true;
11701169
}
11711170
}
11721171
if (mDragEdges.contains(DragEdge.Right)) {
11731172
if (right == -1) {
11741173
mBottomViewIdsSet = false;
1175-
}
1176-
else {
1174+
} else {
11771175
mBottomViewIdMap.put(DragEdge.Right, right);
11781176
mBottomViewIdsSet = true;
11791177
}
11801178
}
11811179
if (mDragEdges.contains(DragEdge.Top)) {
11821180
if (top == -1) {
11831181
mBottomViewIdsSet = false;
1184-
}
1185-
else {
1182+
} else {
11861183
mBottomViewIdMap.put(DragEdge.Top, top);
11871184
mBottomViewIdsSet = true;
11881185
}
11891186
}
11901187
if (mDragEdges.contains(DragEdge.Bottom)) {
11911188
if (bottom == -1) {
11921189
mBottomViewIdsSet = false;
1193-
}
1194-
else {
1190+
} else {
11951191
mBottomViewIdMap.put(DragEdge.Bottom, bottom);
11961192
mBottomViewIdsSet = true;
11971193
}
11981194
}
11991195
}
1196+
12001197
public enum Status {
12011198
Middle,
12021199
Open,
@@ -1305,7 +1302,8 @@ private void processBottomLayDownMode(float xvel, float yvel) {
13051302

13061303
int l = getPaddingLeft(), t = getPaddingTop();
13071304

1308-
if (xvel < 0 && mDragEdges.get(mCurrentDirectionIndex) == DragEdge.Right) l -= mDragDistance;
1305+
if (xvel < 0 && mDragEdges.get(mCurrentDirectionIndex) == DragEdge.Right)
1306+
l -= mDragDistance;
13091307
if (xvel > 0 && mDragEdges.get(mCurrentDirectionIndex) == DragEdge.Left) l += mDragDistance;
13101308

13111309
if (yvel > 0 && mDragEdges.get(mCurrentDirectionIndex) == DragEdge.Top) t += mDragDistance;
@@ -1362,7 +1360,7 @@ public void open(DragEdge edge) {
13621360
case Bottom:
13631361
mCurrentDirectionIndex = mBottomIndex;
13641362
}
1365-
open (true, true);
1363+
open(true, true);
13661364
}
13671365

13681366
public void open(boolean smooth, DragEdge edge) {
@@ -1376,9 +1374,9 @@ public void open(boolean smooth, DragEdge edge) {
13761374
case Bottom:
13771375
mCurrentDirectionIndex = mBottomIndex;
13781376
}
1379-
open (smooth, true);
1377+
open(smooth, true);
13801378
}
1381-
1379+
13821380
public void open(boolean smooth, boolean notify, DragEdge edge) {
13831381
switch (edge) {
13841382
case Left:
@@ -1390,9 +1388,9 @@ public void open(boolean smooth, boolean notify, DragEdge edge) {
13901388
case Bottom:
13911389
mCurrentDirectionIndex = mBottomIndex;
13921390
}
1393-
open (smooth, notify);
1391+
open(smooth, notify);
13941392
}
1395-
1393+
13961394
/**
13971395
* smoothly close surface.
13981396
*/

0 commit comments

Comments
 (0)