From f8350fce20b0a55feeedbe157767c86aa28143f1 Mon Sep 17 00:00:00 2001 From: HarshEvilGeek Date: Wed, 11 Feb 2015 14:51:05 +0530 Subject: [PATCH] adding support for the user to pass the ids of bottom views --- .../com/daimajia/swipedemo/MyActivity.java | 2 + demo/src/main/res/layout/sample1.xml | 1 + .../java/com/daimajia/swipe/SwipeLayout.java | 68 +++++++++++++++++-- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/demo/src/main/java/com/daimajia/swipedemo/MyActivity.java b/demo/src/main/java/com/daimajia/swipedemo/MyActivity.java index 03ce69d..f006a86 100644 --- a/demo/src/main/java/com/daimajia/swipedemo/MyActivity.java +++ b/demo/src/main/java/com/daimajia/swipedemo/MyActivity.java @@ -29,6 +29,8 @@ public class MyActivity extends Activity { sample1 = (SwipeLayout) findViewById(R.id.sample1); sample1.setShowMode(SwipeLayout.ShowMode.LayDown); sample1.setDragEdges(SwipeLayout.DragEdge.Left, SwipeLayout.DragEdge.Right); + // 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.addRevealListener(R.id.delete, new SwipeLayout.OnRevealListener() { @Override public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) { diff --git a/demo/src/main/res/layout/sample1.xml b/demo/src/main/res/layout/sample1.xml index cb3a6fd..cc989aa 100644 --- a/demo/src/main/res/layout/sample1.xml +++ b/demo/src/main/res/layout/sample1.xml @@ -35,6 +35,7 @@ diff --git a/library/src/main/java/com/daimajia/swipe/SwipeLayout.java b/library/src/main/java/com/daimajia/swipe/SwipeLayout.java index 15377fa..f8199be 100644 --- a/library/src/main/java/com/daimajia/swipe/SwipeLayout.java +++ b/library/src/main/java/com/daimajia/swipe/SwipeLayout.java @@ -6,7 +6,6 @@ import android.graphics.Rect; import android.support.v4.view.ViewCompat; import android.support.v4.widget.ViewDragHelper; import android.util.AttributeSet; -import android.util.Log; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; @@ -50,6 +49,9 @@ public class SwipeLayout extends FrameLayout { private float mTopEdgeSwipeOffset; private float mBottomEdgeSwipeOffset; + private Map mBottomViewIdMap = new HashMap(); + private boolean mBottomViewIdsSet = false; + private List mSwipeListeners = new ArrayList(); private List mSwipeDeniers = new ArrayList(); private Map> mRevealListeners = new HashMap>(); @@ -1099,12 +1101,70 @@ public class SwipeLayout extends FrameLayout { public List getBottomViews() { List lvg = new ArrayList(); - for (int i = 0; i < (getChildCount() - 1); i++) { - lvg.add((ViewGroup) getChildAt(i)); + // If the user has provided a map for views to + if (mBottomViewIdsSet) { + if (mDragEdges.contains(DragEdge.Left)) { + lvg.add(mLeftIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Left)))); + } + if (mDragEdges.contains(DragEdge.Right)) { + lvg.add(mRightIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Right)))); + } + if (mDragEdges.contains(DragEdge.Top)) { + lvg.add(mTopIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Top)))); + } + if (mDragEdges.contains(DragEdge.Bottom)) { + lvg.add(mBottomIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Bottom)))); + } + } + // Default behaviour is to simply use the first n-1 children in the order they're listed in the layout + // and return them in + else { + for (int i = 0; i < (getChildCount() - 1); i++) { + lvg.add((ViewGroup) getChildAt(i)); + } } return lvg; } + // Pass the id of the view if set, otherwise pass -1 + public void setBottomViewIds (int left, int right, int top, int bottom) { + if (mDragEdges.contains(DragEdge.Left)) { + if (left == -1) { + mBottomViewIdsSet = false; + } + else { + mBottomViewIdMap.put(DragEdge.Left, left); + mBottomViewIdsSet = true; + } + } + if (mDragEdges.contains(DragEdge.Right)) { + if (right == -1) { + mBottomViewIdsSet = false; + } + else { + mBottomViewIdMap.put(DragEdge.Right, right); + mBottomViewIdsSet = true; + } + } + if (mDragEdges.contains(DragEdge.Top)) { + if (top == -1) { + mBottomViewIdsSet = false; + } + else { + mBottomViewIdMap.put(DragEdge.Top, top); + mBottomViewIdsSet = true; + } + } + if (mDragEdges.contains(DragEdge.Bottom)) { + if (bottom == -1) { + mBottomViewIdsSet = false; + } + else { + mBottomViewIdMap.put(DragEdge.Bottom, bottom); + mBottomViewIdsSet = true; + } + } + } public enum Status { Middle, Open, @@ -1423,7 +1483,7 @@ public class SwipeLayout extends FrameLayout { else if (mDragEdges.get(currentDirectionIndex) == DragEdge.Right) return mRightEdgeSwipeOffset; else if (mDragEdges.get(currentDirectionIndex) == DragEdge.Top) return mTopEdgeSwipeOffset; - else return mLeftEdgeSwipeOffset; + else return mBottomEdgeSwipeOffset; } private void updateBottomViews() {