Skip to content

Commit f8350fc

Browse files
committed
adding support for the user to pass the ids of bottom views
1 parent 6fcf27d commit f8350fc

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ protected void onCreate(Bundle savedInstanceState) {
2929
sample1 = (SwipeLayout) findViewById(R.id.sample1);
3030
sample1.setShowMode(SwipeLayout.ShowMode.LayDown);
3131
sample1.setDragEdges(SwipeLayout.DragEdge.Left, SwipeLayout.DragEdge.Right);
32+
// 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);
3234
sample1.addRevealListener(R.id.delete, new SwipeLayout.OnRevealListener() {
3335
@Override
3436
public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
<LinearLayout
3737
android:tag="Bottom4"
38+
android:id="@+id/bottom_wrapper_2"
3839
android:layout_width="wrap_content"
3940
android:layout_height="match_parent">
4041

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

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.support.v4.view.ViewCompat;
77
import android.support.v4.widget.ViewDragHelper;
88
import android.util.AttributeSet;
9-
import android.util.Log;
109
import android.view.GestureDetector;
1110
import android.view.MotionEvent;
1211
import android.view.View;
@@ -50,6 +49,9 @@ public class SwipeLayout extends FrameLayout {
5049
private float mTopEdgeSwipeOffset;
5150
private float mBottomEdgeSwipeOffset;
5251

52+
private Map<DragEdge, Integer> mBottomViewIdMap = new HashMap<DragEdge, Integer>();
53+
private boolean mBottomViewIdsSet = false;
54+
5355
private List<SwipeListener> mSwipeListeners = new ArrayList<SwipeListener>();
5456
private List<SwipeDenier> mSwipeDeniers = new ArrayList<SwipeDenier>();
5557
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<View, ArrayList<OnRevealListener>>();
@@ -1099,12 +1101,70 @@ public ViewGroup getSurfaceView() {
10991101

11001102
public List<ViewGroup> getBottomViews() {
11011103
List<ViewGroup> lvg = new ArrayList<ViewGroup>();
1102-
for (int i = 0; i < (getChildCount() - 1); i++) {
1103-
lvg.add((ViewGroup) getChildAt(i));
1104+
// If the user has provided a map for views to
1105+
if (mBottomViewIdsSet) {
1106+
if (mDragEdges.contains(DragEdge.Left)) {
1107+
lvg.add(mLeftIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Left))));
1108+
}
1109+
if (mDragEdges.contains(DragEdge.Right)) {
1110+
lvg.add(mRightIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Right))));
1111+
}
1112+
if (mDragEdges.contains(DragEdge.Top)) {
1113+
lvg.add(mTopIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Top))));
1114+
}
1115+
if (mDragEdges.contains(DragEdge.Bottom)) {
1116+
lvg.add(mBottomIndex, ((ViewGroup) findViewById(mBottomViewIdMap.get(DragEdge.Bottom))));
1117+
}
1118+
}
1119+
// Default behaviour is to simply use the first n-1 children in the order they're listed in the layout
1120+
// and return them in
1121+
else {
1122+
for (int i = 0; i < (getChildCount() - 1); i++) {
1123+
lvg.add((ViewGroup) getChildAt(i));
1124+
}
11041125
}
11051126
return lvg;
11061127
}
11071128

1129+
// Pass the id of the view if set, otherwise pass -1
1130+
public void setBottomViewIds (int left, int right, int top, int bottom) {
1131+
if (mDragEdges.contains(DragEdge.Left)) {
1132+
if (left == -1) {
1133+
mBottomViewIdsSet = false;
1134+
}
1135+
else {
1136+
mBottomViewIdMap.put(DragEdge.Left, left);
1137+
mBottomViewIdsSet = true;
1138+
}
1139+
}
1140+
if (mDragEdges.contains(DragEdge.Right)) {
1141+
if (right == -1) {
1142+
mBottomViewIdsSet = false;
1143+
}
1144+
else {
1145+
mBottomViewIdMap.put(DragEdge.Right, right);
1146+
mBottomViewIdsSet = true;
1147+
}
1148+
}
1149+
if (mDragEdges.contains(DragEdge.Top)) {
1150+
if (top == -1) {
1151+
mBottomViewIdsSet = false;
1152+
}
1153+
else {
1154+
mBottomViewIdMap.put(DragEdge.Top, top);
1155+
mBottomViewIdsSet = true;
1156+
}
1157+
}
1158+
if (mDragEdges.contains(DragEdge.Bottom)) {
1159+
if (bottom == -1) {
1160+
mBottomViewIdsSet = false;
1161+
}
1162+
else {
1163+
mBottomViewIdMap.put(DragEdge.Bottom, bottom);
1164+
mBottomViewIdsSet = true;
1165+
}
1166+
}
1167+
}
11081168
public enum Status {
11091169
Middle,
11101170
Open,
@@ -1423,7 +1483,7 @@ private float getCurrentOffset() {
14231483
else if (mDragEdges.get(currentDirectionIndex) == DragEdge.Right)
14241484
return mRightEdgeSwipeOffset;
14251485
else if (mDragEdges.get(currentDirectionIndex) == DragEdge.Top) return mTopEdgeSwipeOffset;
1426-
else return mLeftEdgeSwipeOffset;
1486+
else return mBottomEdgeSwipeOffset;
14271487
}
14281488

14291489
private void updateBottomViews() {

0 commit comments

Comments
 (0)