adding support for the user to pass the ids of bottom views
This commit is contained in:
parent
6fcf27d4ce
commit
f8350fce20
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
<LinearLayout
|
||||
android:tag="Bottom4"
|
||||
android:id="@+id/bottom_wrapper_2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
|
|
|||
|
|
@ -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<DragEdge, Integer> mBottomViewIdMap = new HashMap<DragEdge, Integer>();
|
||||
private boolean mBottomViewIdsSet = false;
|
||||
|
||||
private List<SwipeListener> mSwipeListeners = new ArrayList<SwipeListener>();
|
||||
private List<SwipeDenier> mSwipeDeniers = new ArrayList<SwipeDenier>();
|
||||
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<View, ArrayList<OnRevealListener>>();
|
||||
|
|
@ -1099,12 +1101,70 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
public List<ViewGroup> getBottomViews() {
|
||||
List<ViewGroup> lvg = new ArrayList<ViewGroup>();
|
||||
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() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue