demo to show that three edge swipe works

This commit is contained in:
HarshEvilGeek 2015-02-12 16:02:19 +05:30
parent 1fd2ec7d2f
commit 93c06bfa01
3 changed files with 39 additions and 21 deletions

View File

@ -28,9 +28,9 @@ public class MyActivity extends Activity {
sample1 = (SwipeLayout) findViewById(R.id.sample1);
sample1.setShowMode(SwipeLayout.ShowMode.LayDown);
sample1.setDragEdges(SwipeLayout.DragEdge.Left, SwipeLayout.DragEdge.Right);
sample1.setDragEdges(SwipeLayout.DragEdge.Left, SwipeLayout.DragEdge.Right, SwipeLayout.DragEdge.Top);
// 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)
sample1.setBottomViewIds(R.id.bottom_wrapper, R.id.bottom_wrapper_2, -1, -1);
sample1.setBottomViewIds(R.id.bottom_wrapper, R.id.bottom_wrapper_2, R.id.starbott, -1);
sample1.addRevealListener(R.id.delete, new SwipeLayout.OnRevealListener() {
@Override
public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) {

View File

@ -67,6 +67,26 @@
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:tag="Bottom3"
android:id="@+id/starbott"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/bottom_wrapper_child1"
android:background="#BDBEC2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/star"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/star"
android:layout_width="20dp"
android:layout_height="20dp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:padding="10dp"
android:background="#ffffff"

View File

@ -836,7 +836,7 @@ public class SwipeLayout extends FrameLayout {
if (touching != null) touching.setPressed(true);
return true;
case MotionEvent.ACTION_MOVE:{
case MotionEvent.ACTION_MOVE: {
float distanceX = event.getRawX() - sX;
float distanceY = event.getRawY() - sY;
float angle = Math.abs(distanceY / distanceX);
@ -846,13 +846,13 @@ public class SwipeLayout extends FrameLayout {
if (angle < 45) {
if (mLeftIndex != -1 && distanceX > 0 && isLeftSwipeEnabled()) {
mCurrentDirectionIndex = mLeftIndex;
} else if (mRightIndex != -1 && isRightSwipeEnabled()) {
} else if (mRightIndex != -1 && distanceX < 0 && isRightSwipeEnabled()) {
mCurrentDirectionIndex = mRightIndex;
}
} else {
if (mTopIndex != -1 && distanceY < 0 && isTopSwipeEnabled()) {
if (mTopIndex != -1 && distanceY > 0 && isTopSwipeEnabled()) {
mCurrentDirectionIndex = mTopIndex;
} else if (mBottomIndex != -1 && isBottomSwipeEnabled()) {
} else if (mBottomIndex != -1 && distanceY < 0 && isBottomSwipeEnabled()) {
mCurrentDirectionIndex = mBottomIndex;
}
}
@ -1159,12 +1159,11 @@ public class SwipeLayout extends FrameLayout {
}
// Pass the id of the view if set, otherwise pass -1
public void setBottomViewIds (int left, int right, int top, int bottom) {
public void setBottomViewIds(int left, int right, int top, int bottom) {
if (mDragEdges.contains(DragEdge.Left)) {
if (left == -1) {
mBottomViewIdsSet = false;
}
else {
} else {
mBottomViewIdMap.put(DragEdge.Left, left);
mBottomViewIdsSet = true;
}
@ -1172,8 +1171,7 @@ public class SwipeLayout extends FrameLayout {
if (mDragEdges.contains(DragEdge.Right)) {
if (right == -1) {
mBottomViewIdsSet = false;
}
else {
} else {
mBottomViewIdMap.put(DragEdge.Right, right);
mBottomViewIdsSet = true;
}
@ -1181,8 +1179,7 @@ public class SwipeLayout extends FrameLayout {
if (mDragEdges.contains(DragEdge.Top)) {
if (top == -1) {
mBottomViewIdsSet = false;
}
else {
} else {
mBottomViewIdMap.put(DragEdge.Top, top);
mBottomViewIdsSet = true;
}
@ -1190,13 +1187,13 @@ public class SwipeLayout extends FrameLayout {
if (mDragEdges.contains(DragEdge.Bottom)) {
if (bottom == -1) {
mBottomViewIdsSet = false;
}
else {
} else {
mBottomViewIdMap.put(DragEdge.Bottom, bottom);
mBottomViewIdsSet = true;
}
}
}
public enum Status {
Middle,
Open,
@ -1305,7 +1302,8 @@ public class SwipeLayout extends FrameLayout {
int l = getPaddingLeft(), t = getPaddingTop();
if (xvel < 0 && mDragEdges.get(mCurrentDirectionIndex) == DragEdge.Right) l -= mDragDistance;
if (xvel < 0 && mDragEdges.get(mCurrentDirectionIndex) == DragEdge.Right)
l -= mDragDistance;
if (xvel > 0 && mDragEdges.get(mCurrentDirectionIndex) == DragEdge.Left) l += mDragDistance;
if (yvel > 0 && mDragEdges.get(mCurrentDirectionIndex) == DragEdge.Top) t += mDragDistance;
@ -1362,7 +1360,7 @@ public class SwipeLayout extends FrameLayout {
case Bottom:
mCurrentDirectionIndex = mBottomIndex;
}
open (true, true);
open(true, true);
}
public void open(boolean smooth, DragEdge edge) {
@ -1376,9 +1374,9 @@ public class SwipeLayout extends FrameLayout {
case Bottom:
mCurrentDirectionIndex = mBottomIndex;
}
open (smooth, true);
open(smooth, true);
}
public void open(boolean smooth, boolean notify, DragEdge edge) {
switch (edge) {
case Left:
@ -1390,9 +1388,9 @@ public class SwipeLayout extends FrameLayout {
case Bottom:
mCurrentDirectionIndex = mBottomIndex;
}
open (smooth, notify);
open(smooth, notify);
}
/**
* smoothly close surface.
*/