Ejemplo n.º 1
0
 /**
  * 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();
   }
 }
Ejemplo n.º 2
0
 /** 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);
   }
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /** 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));
 }
Ejemplo n.º 5
0
 /**
  * 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();
 }
Ejemplo n.º 6
0
 /**
  * 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();
 }
Ejemplo n.º 7
0
 /** Configure the dragView margin bottom applied when the dragView is minimized. */
 public void setTopViewMarginBottom(int topFragmentMarginBottom) {
   transformer.setMarginBottom(topFragmentMarginBottom);
 }
Ejemplo n.º 8
0
 /**
  * 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);
 }
Ejemplo n.º 9
0
 /**
  * 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();
 }
Ejemplo n.º 10
0
 /**
  * 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();
 }
Ejemplo n.º 11
0
 /** Modify dragged view scale based on the dragged view vertical position and the scale factor. */
 void changeDragViewScale() {
   transformer.updateScale(getVerticalDragOffset());
 }
Ejemplo n.º 12
0
 /**
  * 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());
 }
Ejemplo n.º 13
0
 /**
  * Configure the dragged view height.
  *
  * @param topFragmentHeight in pixels
  */
 public void setTopViewHeight(int topFragmentHeight) {
   transformer.setViewHeight(topFragmentHeight);
 }
Ejemplo n.º 14
0
 /** @return configured dragged view margin right configured. */
 private int getDragViewMarginRight() {
   return transformer.getMarginRight();
 }
Ejemplo n.º 15
0
 /**
  * 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();
 }
Ejemplo n.º 16
0
 /** @return configured dragged view margin bottom. */
 private int getDragViewMarginBottom() {
   return transformer.getMarginBottom();
 }
Ejemplo n.º 17
0
 /**
  * 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();
 }
Ejemplo n.º 18
0
 public int getDraggedViewHeightPlusMarginTop() {
   return transformer.getMinHeightPlusMargin();
 }
Ejemplo n.º 19
0
 /**
  * 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();
 }
Ejemplo n.º 20
0
 /**
  * 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);
 }
Ejemplo n.º 21
0
 /**
  * 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);
 }