|
6 | 6 | import android.support.v4.view.ViewCompat; |
7 | 7 | import android.support.v4.widget.ViewDragHelper; |
8 | 8 | import android.util.AttributeSet; |
9 | | -import android.util.Log; |
10 | 9 | import android.view.GestureDetector; |
11 | 10 | import android.view.MotionEvent; |
12 | 11 | import android.view.View; |
@@ -50,6 +49,9 @@ public class SwipeLayout extends FrameLayout { |
50 | 49 | private float mTopEdgeSwipeOffset; |
51 | 50 | private float mBottomEdgeSwipeOffset; |
52 | 51 |
|
| 52 | + private Map<DragEdge, Integer> mBottomViewIdMap = new HashMap<DragEdge, Integer>(); |
| 53 | + private boolean mBottomViewIdsSet = false; |
| 54 | + |
53 | 55 | private List<SwipeListener> mSwipeListeners = new ArrayList<SwipeListener>(); |
54 | 56 | private List<SwipeDenier> mSwipeDeniers = new ArrayList<SwipeDenier>(); |
55 | 57 | private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<View, ArrayList<OnRevealListener>>(); |
@@ -1099,12 +1101,70 @@ public ViewGroup getSurfaceView() { |
1099 | 1101 |
|
1100 | 1102 | public List<ViewGroup> getBottomViews() { |
1101 | 1103 | 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 | + } |
1104 | 1125 | } |
1105 | 1126 | return lvg; |
1106 | 1127 | } |
1107 | 1128 |
|
| 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 | + } |
1108 | 1168 | public enum Status { |
1109 | 1169 | Middle, |
1110 | 1170 | Open, |
@@ -1423,7 +1483,7 @@ private float getCurrentOffset() { |
1423 | 1483 | else if (mDragEdges.get(currentDirectionIndex) == DragEdge.Right) |
1424 | 1484 | return mRightEdgeSwipeOffset; |
1425 | 1485 | else if (mDragEdges.get(currentDirectionIndex) == DragEdge.Top) return mTopEdgeSwipeOffset; |
1426 | | - else return mLeftEdgeSwipeOffset; |
| 1486 | + else return mBottomEdgeSwipeOffset; |
1427 | 1487 | } |
1428 | 1488 |
|
1429 | 1489 | private void updateBottomViews() { |
|
0 commit comments