/** * Open a specific layout. * @param id unique id which identifies the data object which is bind to the layout. */ public void openLayout(string id) { lock (stateChangeLock) { mapStates.put(id, SwipeRevealLayout.STATE_OPEN); SwipeRevealLayout layout = null; if (mapLayouts.TryGetValue(id, out layout) && layout != null) { layout.open(true); } else if (openOnlyOne) { closeOthers(id, mapLayouts.get(id)); } } }
/** * Help to save and restore open/close state of the swipeLayout. Call this method * when you bind your view holder with the data object. * * @param swipeLayout swipeLayout of the current view. * @param id a string that uniquely defines the data object of the current view. */ public void bind(SwipeRevealLayout swipeLayout, string id) { base.ExecuteMethod("bind", delegate() { if (swipeLayout.shouldRequestLayout()) { swipeLayout.RequestLayout(); } mapLayouts.removeAllWithValue(swipeLayout); mapLayouts.put(id, swipeLayout); swipeLayout.abort(); swipeLayout.setDragStateChangeListener(new CustomListener(this, swipeLayout, id)); // first time binding. if (!mapStates.ContainsKey(id)) { mapStates.put(id, SwipeRevealLayout.STATE_CLOSE); swipeLayout.close(false); } // not the first time, then close or open depends on the current state. else { int state = mapStates.get(id); if (state == SwipeRevealLayout.STATE_CLOSE || state == SwipeRevealLayout.STATE_CLOSING || state == SwipeRevealLayout.STATE_DRAGGING) { swipeLayout.close(false); } else { swipeLayout.open(false); } } // set lock swipe swipeLayout.setLockDrag(lockedSwipeSet.ContainsKey(id)); }); }
public override void OnViewReleased(View releasedChild, float xvel, float yvel) { bool velRightExceeded = _layout.pxToDp((int)xvel) >= _layout.mMinFlingVelocity; bool velLeftExceeded = _layout.pxToDp((int)xvel) <= -_layout.mMinFlingVelocity; bool velUpExceeded = _layout.pxToDp((int)yvel) <= -_layout.mMinFlingVelocity; bool velDownExceeded = _layout.pxToDp((int)yvel) >= _layout.mMinFlingVelocity; int pivotHorizontal = _layout.getHalfwayPivotHorizontal(); int pivotVertical = _layout.getHalfwayPivotVertical(); switch (_layout.mDragEdge) { case DRAG_EDGE_RIGHT: if (velRightExceeded) { _layout.close(true); } else if (velLeftExceeded) { _layout.open(true); } else { if (_layout.mMainView.Right < pivotHorizontal) { _layout.open(true); } else { _layout.close(true); } } break; case DRAG_EDGE_LEFT: if (velRightExceeded) { _layout.open(true); } else if (velLeftExceeded) { _layout.close(true); } else { if (_layout.mMainView.Left < pivotHorizontal) { _layout.close(true); } else { _layout.open(true); } } break; case DRAG_EDGE_TOP: if (velUpExceeded) { _layout.close(true); } else if (velDownExceeded) { _layout.open(true); } else { if (_layout.mMainView.Top < pivotVertical) { _layout.close(true); } else { _layout.open(true); } } break; case DRAG_EDGE_BOTTOM: if (velUpExceeded) { _layout.open(true); } else if (velDownExceeded) { _layout.close(true); } else { if (_layout.mMainView.Bottom < pivotVertical) { _layout.open(true); } else { _layout.close(true); } } break; } }