/** * Return the value of slide based * on left and width of the element * * @param child return the view on focus * @param left return the left size of DraggerView * @param dx return the scroll on x-axis * @return the offset of slide */ @Override public int clampViewPositionHorizontal(View child, int left, int dx) { int leftBound = 0; int rightBound = 0; switch (draggerView.getDragPosition()) { case RIGHT: if (left > 0) { leftBound = draggerView.getPaddingLeft(); rightBound = (int) draggerListener.dragHorizontalDragRange(); } break; case LEFT: if (left < 0) { leftBound = (int) -draggerListener.dragHorizontalDragRange(); rightBound = draggerView.getPaddingLeft(); } break; default: break; } return Math.min(Math.max(left, leftBound), rightBound); }
/** * 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); } }
/** * 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); }
/** * This is called only the touch on DraggerView is released. * * @param releasedChild return the view on focus * @param xVel return the speed of X animation * @param yVel return the speed of Y animation */ @Override public void onViewReleased(View releasedChild, float xVel, float yVel) { super.onViewReleased(releasedChild, xVel, yVel); if (draggerView.isDragViewAboveTheLimit()) { switch (draggerView.getDragPosition()) { case LEFT: draggerView.closeFromCenterToLeft(); break; case RIGHT: draggerView.closeFromCenterToRight(); break; case TOP: default: draggerView.closeFromCenterToBottom(); break; case BOTTOM: draggerView.closeFromCenterToTop(); break; } } else { draggerView.moveToCenter(); } }