/** * Close the custom view applying an animation to close the view to the left side of the screen. */ public void closeToLeft() { if (viewDragHelper.smoothSlideViewTo( dragView, -transformer.getOriginalWidth(), getHeight() - transformer.getMinHeightPlusMargin())) { ViewCompat.postInvalidateOnAnimation(this); notifyCloseToLeftListener(); } }
/** Override method to configure the dragged view and secondView layout properly. */ @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { if (isInEditMode()) super.onLayout(changed, left, top, right, bottom); else if (isDragViewAtTop()) { dragView.layout(left, top, right, transformer.getOriginalHeight()); secondView.layout(left, transformer.getOriginalHeight(), right, bottom); ViewHelper.setY(dragView, top); ViewHelper.setY(secondView, transformer.getOriginalHeight()); } else { secondView.layout(left, transformer.getOriginalHeight(), right, bottom); } }
/** * Realize an smooth slide to an slide offset passed as argument. This method is the base of * maximize, minimize and close methods. * * @param slideOffset to apply * @return true if the view is slided. */ private boolean smoothSlideTo(float slideOffset) { final int topBound = getPaddingTop(); int x = (int) (slideOffset * (getWidth() - transformer.getMinWidthPlusMarginRight())); int y = (int) (topBound + slideOffset * getVerticalDragRange()); if (viewDragHelper.smoothSlideViewTo(dragView, x, y)) { ViewCompat.postInvalidateOnAnimation(this); return true; } return false; }
/** Initialize Transformer with a scalable or change width/height implementation. */ private void initializeTransformer(TypedArray attributes) { topViewResize = attributes.getBoolean(R.styleable.draggable_view_top_view_resize, DEFAULT_TOP_VIEW_RESIZE); TransformerFactory transformerFactory = new TransformerFactory(); transformer = transformerFactory.getTransformer(topViewResize, dragView, this); transformer.setViewHeight( attributes.getDimensionPixelSize( R.styleable.draggable_view_top_view_height, DEFAULT_TOP_VIEW_HEIGHT)); transformer.setXScaleFactor( attributes.getFloat( R.styleable.draggable_view_top_view_x_scale_factor, DEFAULT_SCALE_FACTOR)); transformer.setYScaleFactor( attributes.getFloat( R.styleable.draggable_view_top_view_y_scale_factor, DEFAULT_SCALE_FACTOR)); transformer.setMarginRight( attributes.getDimensionPixelSize( R.styleable.draggable_view_top_view_margin_right, DEFAULT_TOP_VIEW_MARGIN)); transformer.setMarginBottom( attributes.getDimensionPixelSize( R.styleable.draggable_view_top_view_margin_bottom, DEFAULT_TOP_VIEW_MARGIN)); }
/** * Check if dragged view is at the bottom of the custom view. * * @return true if dragged view bottom position is equals to custom view height. */ boolean isDragViewAtBottom() { return transformer.isViewAtBottom(); }
/** * Check if dragged view is at the right of the custom view. * * @return true if dragged view right position is equals to custom view width. */ boolean isDragViewAtRight() { return transformer.isViewAtRight(); }
/** Configure the dragView margin bottom applied when the dragView is minimized. */ public void setTopViewMarginBottom(int topFragmentMarginBottom) { transformer.setMarginBottom(topFragmentMarginBottom); }
/** * Configure the horizontal scale factor applied when the view is dragged to the bottom of the * custom view. */ public void setXTopViewScaleFactor(float xScaleFactor) { transformer.setXScaleFactor(xScaleFactor); }
/** * Calculate the vertical drag range between the custom view and dragged view. * * @return the difference between the custom view height and the dragged view height. */ private float getVerticalDragRange() { return getHeight() - transformer.getMinHeightPlusMargin(); }
/** * Check if dragged view is above the middle of the custom view. * * @return true if dragged view is above the middle of the custom view or false if is below. */ boolean isDragViewAboveTheMiddle() { return transformer.isAboveTheMiddle(); }
/** Modify dragged view scale based on the dragged view vertical position and the scale factor. */ void changeDragViewScale() { transformer.updateScale(getVerticalDragOffset()); }
/** * Modify dragged view pivot based on the dragged view vertical position to simulate a horizontal * displacement while the view is dragged. */ void changeDragViewPosition() { transformer.updatePosition(getVerticalDragOffset()); }
/** * Configure the dragged view height. * * @param topFragmentHeight in pixels */ public void setTopViewHeight(int topFragmentHeight) { transformer.setViewHeight(topFragmentHeight); }
/** @return configured dragged view margin right configured. */ private int getDragViewMarginRight() { return transformer.getMarginRight(); }
/** * Check if dragged view is next to the left bound. * * @return true if dragged view right position is behind the right half of the custom view. */ boolean isNextToLeftBound() { return transformer.isNextToLeftBound(); }
/** @return configured dragged view margin bottom. */ private int getDragViewMarginBottom() { return transformer.getMarginBottom(); }
/** * Check if dragged view is next to the right bound. * * @return true if dragged view left position is behind the left quarter of the custom view. */ boolean isNextToRightBound() { return transformer.isNextToRightBound(); }
public int getDraggedViewHeightPlusMarginTop() { return transformer.getMinHeightPlusMargin(); }
/** * Check if dragged view is at the top of the custom view. * * @return true if dragged view top position is equals to zero. */ boolean isDragViewAtTop() { return transformer.isViewAtTop(); }
/** * Configure the vertical scale factor applied when the view is dragged to the bottom of the * custom view. */ public void setYTopViewScaleFactor(float yScaleFactor) { transformer.setYScaleFactor(yScaleFactor); }
/** * Configure the dragged view margin right applied when the dragged view is minimized. * * @param topFragmentMarginRight in pixels. */ public void setTopViewMarginRight(int topFragmentMarginRight) { transformer.setMarginRight(topFragmentMarginRight); }