/** * Return the max value of view that can * slide based on #clampViewPositionVertical * * @param child return the view on focus * @return max vertical distance that view on focus can slide */ @Override public int getViewVerticalDragRange(View child) { return (int) draggerListener.dragVerticalDragRange(); }
/** * Return the value of slide based * on top and height of the element * * @param child return the view on focus * @param top return the top size of DraggerView * @param dy return the scroll on y-axis * @return the offset of slide */ @Override public int clampViewPositionVertical(View child, int top, int dy) { int topBound = 0; int bottomBound = 0; switch (draggerView.getDragPosition()) { case TOP: if (top > 0) { topBound = draggerView.getPaddingTop(); bottomBound = (int) draggerListener.dragVerticalDragRange(); } break; case BOTTOM: if (top < 0) { topBound = (int) -draggerListener.dragVerticalDragRange(); bottomBound = draggerView.getPaddingTop(); } break; default: break; } return Math.min(Math.max(top, topBound), bottomBound); }
/** * Verify if view is dragging or idle and * check dragOffset is bigger than dragRange, * if true, finish the activity. * * @param state return the touch state of view */ @Override public void onViewDragStateChanged(int state) { if (state == dragState) { return; } if ((dragState == ViewDragHelper.STATE_DRAGGING || dragState == ViewDragHelper.STATE_SETTLING) && state == ViewDragHelper.STATE_IDLE && (dragOffset == draggerListener.dragHorizontalDragRange() || dragOffset == draggerListener.dragVerticalDragRange())) { draggerListener.finishActivity(); } dragState = state; }
/** * Override method used notify the drag value * based on position and dragRange * * @param left position. * @param top position. * @param dx change in X position from the last call. * @param dy change in Y position from the last call. */ @Override public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) { super.onViewPositionChanged(changedView, left, top, dx, dy); float fractionScreen; switch (draggerView.getDragPosition()) { case TOP: case BOTTOM: dragOffset = Math.abs(top); fractionScreen = (float) dragOffset / draggerListener.dragVerticalDragRange(); break; case LEFT: case RIGHT: default: dragOffset = Math.abs(left); fractionScreen = (float) dragOffset / draggerListener.dragHorizontalDragRange(); break; } if (draggerListener != null) { draggerListener.onViewPositionChanged(fractionScreen >= 1 ? 1 : fractionScreen); } }