コード例 #1
0
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
      super.onScrolled(recyclerView, dx, dy);

      int childCount = recyclerView.getChildCount();
      int width = recyclerView.getChildAt(0).getWidth();
      int padding = (recyclerView.getWidth() - width) / 2;

      for (int i = 0; i < childCount; i++) {
        View view = recyclerView.getChildAt(i);

        float ratio = 0;

        if (view.getLeft() <= padding) {
          if (view.getLeft() >= padding - view.getWidth()) {
            ratio = (padding - view.getLeft()) * 1f / view.getWidth();
          } else {
            ratio = 1;
          }
          view.setScaleY(1 - ratio * 0.5f);
          view.setScaleX(1 - ratio * 0.5f);

        } else {

          if (view.getLeft() <= recyclerView.getWidth() - padding) {
            ratio = (recyclerView.getWidth() - padding - view.getLeft()) * 1f / view.getWidth();
          }
          view.setScaleY(0.5f + ratio * 0.5f);
          view.setScaleX(0.5f + ratio * 0.5f);
        }
      }
    }
  @Override
  public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    boolean needsInvalidate = false;

    if (mTopGlow != null && !mTopGlow.isFinished()) {
      final int restore = c.save();
      if (getClipToPadding(parent)) {
        c.translate(parent.getPaddingLeft(), parent.getPaddingTop());
      }
      //noinspection ConstantConditions
      needsInvalidate |= mTopGlow.draw(c);
      c.restoreToCount(restore);
    }

    if (mBottomGlow != null && !mBottomGlow.isFinished()) {
      final int restore = c.save();
      c.rotate(180);
      if (getClipToPadding(parent)) {
        c.translate(
            -parent.getWidth() + parent.getPaddingRight(),
            -parent.getHeight() + parent.getPaddingBottom());
      } else {
        c.translate(-parent.getWidth(), -parent.getHeight());
      }
      needsInvalidate |= mBottomGlow.draw(c);
      c.restoreToCount(restore);
    }

    if (needsInvalidate) {
      ViewCompat.postInvalidateOnAnimation(parent);
    }
  }
コード例 #3
0
ファイル: SwipeableRVTL.java プロジェクト: keng42/Keep
 /** 处理触摸事件 */
 private boolean handleTouchEvent(MotionEvent motionEvent) {
   if (mViewWidth < 2) {
     mViewWidth = mRecyclerView.getWidth();
   }
   switch (motionEvent.getActionMasked()) {
     case MotionEvent.ACTION_DOWN:
       {
         actionDown(motionEvent);
         break;
       }
     case MotionEvent.ACTION_CANCEL:
       {
         actionCancel();
         break;
       }
     case MotionEvent.ACTION_UP:
       {
         actionUp(motionEvent);
         break;
       }
     case MotionEvent.ACTION_MOVE:
       {
         return actionMove(motionEvent);
       }
   }
   return false;
 }
コード例 #4
0
  @Override
  public View getHeader(RecyclerView parent, int position) {
    long headerId = mAdapter.getHeaderId(position);

    View header = mHeaderViews.get(headerId);
    if (header == null) {
      // TODO - recycle views
      RecyclerView.ViewHolder viewHolder = mAdapter.onCreateHeaderViewHolder(parent);
      mAdapter.onBindHeaderViewHolder(viewHolder, position);
      header = viewHolder.itemView;
      if (header.getLayoutParams() == null) {
        header.setLayoutParams(
            new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
      }

      int widthSpec;
      int heightSpec;

      if (mOrientationProvider.getOrientation(parent) == LinearLayoutManager.VERTICAL) {
        widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY);
        heightSpec =
            View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED);
      } else {
        widthSpec =
            View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.UNSPECIFIED);
        heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.EXACTLY);
      }

      int childWidth =
          ViewGroup.getChildMeasureSpec(
              widthSpec,
              parent.getPaddingLeft() + parent.getPaddingRight(),
              header.getLayoutParams().width);
      int childHeight =
          ViewGroup.getChildMeasureSpec(
              heightSpec,
              parent.getPaddingTop() + parent.getPaddingBottom(),
              header.getLayoutParams().height);
      header.measure(childWidth, childHeight);
      header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
      mHeaderViews.put(headerId, header);
    }
    return header;
  }
コード例 #5
0
  @Override
  public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (mDivider == null) {
      super.onDrawOver(c, parent, state);
      return;
    }

    // Initialization needed to avoid compiler warning
    int left = 0, right = 0, top = 0, bottom = 0, size;
    int orientation = mOrientation != -1 ? mOrientation : getOrientation(parent);
    int childCount = parent.getChildCount();

    if (orientation == LinearLayoutManager.VERTICAL) {
      size = mDivider.getIntrinsicHeight();
      left = parent.getPaddingLeft();
      right = parent.getWidth() - parent.getPaddingRight();
    } else { // horizontal
      size = mDivider.getIntrinsicWidth();
      top = parent.getPaddingTop();
      bottom = parent.getHeight() - parent.getPaddingBottom();
    }

    for (int i = mShowFirstDivider ? 0 : 1; i < childCount; i++) {
      View child = parent.getChildAt(i);
      RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

      if (orientation == LinearLayoutManager.VERTICAL) {
        top = child.getTop() - params.topMargin - size;
        bottom = top + size;
      } else { // horizontal
        left = child.getLeft() - params.leftMargin;
        right = left + size;
      }
      mDivider.setBounds(left, top, right, bottom);
      mDivider.draw(c);
    }

    // show last divider
    if (mShowLastDivider && childCount > 0) {
      View child = parent.getChildAt(childCount - 1);
      if (parent.getChildAdapterPosition(child) == (state.getItemCount() - 1)) {
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        if (orientation == LinearLayoutManager.VERTICAL) {
          top = child.getBottom() + params.bottomMargin;
          bottom = top + size;
        } else { // horizontal
          left = child.getRight() + params.rightMargin;
          right = left + size;
        }
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
      }
    }
  }
コード例 #6
0
 /**
  * 绘制水平方向的分割线
  *
  * @param c
  * @param parent
  */
 private void drawHDeraction(Canvas c, RecyclerView parent) {
   int left = parent.getPaddingLeft();
   int right = parent.getWidth() - parent.getPaddingRight();
   int childCount = parent.getChildCount();
   for (int i = 0; i < childCount; i++) {
     View child = parent.getChildAt(i);
     RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
     int top = child.getBottom() + layoutParams.bottomMargin;
     int bottom = top + mDivider.getIntrinsicHeight();
     mDivider.setBounds(left, top, right, bottom);
     mDivider.draw(c);
   }
 }
コード例 #7
0
 public void drawVertical(Canvas c, RecyclerView parent) {
   final int left = parent.getPaddingLeft();
   final int right = parent.getWidth() - parent.getPaddingRight();
   final int childCount = parent.getChildCount();
   for (int i = 0; i < childCount; i++) {
     final View child = parent.getChildAt(i);
     final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
     final int top = child.getBottom() + params.bottomMargin;
     final int bottom = top + mDivider.getIntrinsicHeight();
     mDivider.setBounds(left, top, right, bottom);
     mDivider.draw(c);
   }
 }
コード例 #8
0
  private void drawVertical(Canvas canvas, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();
    final int childCount = parent.getChildCount();

    for (int i = 1; i < childCount; i++) {
      final View child = parent.getChildAt(i);
      final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
      final int size = mDivider.getIntrinsicHeight();
      final int top = child.getTop() - params.topMargin;
      final int bottom = top + size;
      mDivider.setBounds(left, top, right, bottom);
      mDivider.draw(canvas);
    }
  }
コード例 #9
0
ファイル: ViewUtils.java プロジェクト: x930073498/MultiView
 public static boolean isChildInCenterX(RecyclerView recyclerView, View view) {
   int childCount = recyclerView.getChildCount();
   int[] lvLocationOnScreen = new int[2];
   int[] vLocationOnScreen = new int[2];
   recyclerView.getLocationOnScreen(lvLocationOnScreen);
   int middleX =
       (int) (lvLocationOnScreen[0] + recyclerView.getWidth() * recyclerView.getScaleX() / 2);
   if (childCount > 0) {
     view.getLocationOnScreen(vLocationOnScreen);
     if (vLocationOnScreen[0] <= middleX
         && vLocationOnScreen[0] + view.getWidth() * view.getScaleX() >= middleX) {
       return true;
     }
   }
   return false;
 }
コード例 #10
0
  @Override
  public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
      View child = parent.getChildAt(i);

      RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
      int top = child.getBottom() + params.bottomMargin;
      int bottom = top + 1;

      c.drawRect(left, top, right, bottom, mPaint);
    }
  }
コード例 #11
0
  public void drawVertical(@NonNull Canvas c, @NonNull RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();
    final int childCount = parent.getChildCount();

    IntStream.range(0, childCount)
        .forEach(
            i -> {
              final View child = parent.getChildAt(i);
              final RecyclerView.LayoutParams params =
                  (RecyclerView.LayoutParams) child.getLayoutParams();
              final int top = child.getBottom() + params.bottomMargin;
              final int bottom = top + mDivider.getIntrinsicHeight();
              mDivider.setBounds(left, top, right, bottom);
              mDivider.draw(c);
            });
  }
コード例 #12
0
  @Override
  public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, state);

    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
      final View child = parent.getChildAt(i);
      RecyclerView v = new RecyclerView(parent.getContext());
      final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
      final int top = child.getBottom() + params.bottomMargin;
      final int bottom = top + mDivider.getIntrinsicHeight();
      mDivider.setBounds(left, top, right, bottom);
      mDivider.draw(c);
    }
  }
コード例 #13
0
  @Override
  public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
      View child = parent.getChildAt(i);

      RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

      int top = child.getBottom() + params.bottomMargin;
      int bottom = top + lineaDivisoria.getIntrinsicHeight();

      lineaDivisoria.setBounds(left, top, right, bottom);
      lineaDivisoria.draw(c);
    }
  }
コード例 #14
0
  @Override
  public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();
    int top = parent.getPaddingTop();
    int bottom = parent.getHeight() - parent.getPaddingBottom();

    int orientation = getOrientation(parent);
    int childCount = parent.getChildCount();

    for (int i = showFirstDivider ? 0 : 1; i < childCount; i++) {
      View child = parent.getChildAt(i);
      RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

      if (orientation == LinearLayoutManager.VERTICAL) {
        top = child.getTop() - params.topMargin;
        bottom = top - (size / 2);

        canvas.drawLine(left, bottom, right, bottom, paint);
      } else {
        left = child.getLeft() - params.leftMargin;
        right = left - (size / 2);

        canvas.drawLine(right, top, right, bottom, paint);
      }
    }

    if (showLastDivider && childCount > 0) {
      View child = parent.getChildAt(childCount - 1);
      RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

      if (orientation == LinearLayoutManager.VERTICAL) {
        top = child.getBottom() + params.bottomMargin;
        bottom = top + size;

        canvas.drawLine(left, bottom, right, bottom, paint);
      } else {
        left = child.getRight() + params.rightMargin;
        right = left + (size / 2);

        canvas.drawLine(right, top, right, bottom, paint);
      }
    }
  }
コード例 #15
0
 void handleDragScroll(RecyclerView rv, DragInfo dragInfo) {
   if (rv.getLayoutManager().canScrollHorizontally()) {
     if (rv.canScrollHorizontally(-1) && dragInfo.shouldScrollLeft()) {
       rv.scrollBy(-SCROLL_AMOUNT, 0);
       dragManager.clearNextMove();
     } else if (rv.canScrollHorizontally(1) && dragInfo.shouldScrollRight(rv.getWidth())) {
       rv.scrollBy(SCROLL_AMOUNT, 0);
       dragManager.clearNextMove();
     }
   } else if (rv.getLayoutManager().canScrollVertically()) {
     if (rv.canScrollVertically(-1) && dragInfo.shouldScrollUp()) {
       rv.scrollBy(0, -SCROLL_AMOUNT);
       dragManager.clearNextMove();
     } else if (rv.canScrollVertically(1) && dragInfo.shouldScrollDown(rv.getHeight())) {
       rv.scrollBy(0, SCROLL_AMOUNT);
       dragManager.clearNextMove();
     }
   }
 }
コード例 #16
0
  public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
      final View child = parent.getChildAt(i);
      // 有脚部时,最后一条不画
      if (hasFooter
          && parent.getChildLayoutPosition(child) == parent.getLayoutManager().getItemCount() - 1) {
        continue;
      }
      final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
      final int top = child.getBottom() + params.bottomMargin;
      final int bottom = top + mDivider.getIntrinsicHeight();
      mDivider.setBounds(left, top, right, bottom);
      mDivider.draw(c);
    }
  }
コード例 #17
0
  @Override
  public boolean onInterceptTouchEvent(final RecyclerView view, MotionEvent motionEvent) {
    if (mPaused) {
      return false;
    }
    // offset because the view is translated during swipe
    motionEvent.offsetLocation(mTranslationX, 0);

    if (mViewWidth < 2) {
      mViewWidth = view.getWidth();
    }

    switch (motionEvent.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        return down(motionEvent);
      case MotionEvent.ACTION_MOVE:
        return move(motionEvent);
    }
    return false;
  }
  @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
  private boolean handleTouchEvent(MotionEvent motionEvent) {
    if (mViewWidth < 2) {
      mViewWidth = mRecyclerView.getWidth();
    }

    switch (motionEvent.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        {
          if (mPaused) {
            break;
          }

          // Find the child view that was touched (perform a hit test)
          Rect rect = new Rect();
          int childCount = mRecyclerView.getChildCount();
          int[] listViewCoords = new int[2];
          mRecyclerView.getLocationOnScreen(listViewCoords);
          int x = (int) motionEvent.getRawX() - listViewCoords[0];
          int y = (int) motionEvent.getRawY() - listViewCoords[1];
          View child;
          for (int i = 0; i < childCount; i++) {
            child = mRecyclerView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
              mDownView = child;
              break;
            }
          }

          if (mDownView != null
              && mAnimatingPosition != mRecyclerView.getChildPosition(mDownView)) {
            mAlpha = mDownView.getAlpha();
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mRecyclerView.getChildPosition(mDownView);
            if (mSwipeListener.canSwipe(mDownPosition)) {
              mVelocityTracker = VelocityTracker.obtain();
              mVelocityTracker.addMovement(motionEvent);
            } else {
              mDownView = null;
            }
          }
          break;
        }

      case MotionEvent.ACTION_CANCEL:
        {
          if (mVelocityTracker == null) {
            break;
          }

          if (mDownView != null && mSwiping) {
            // cancel
            mDownView
                .animate()
                .translationX(0)
                .alpha(mAlpha)
                .setDuration(mAnimationTime)
                .setListener(null);
          }
          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownY = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          mSwiping = false;
          break;
        }

      case MotionEvent.ACTION_UP:
        {
          if (mVelocityTracker == null) {
            break;
          }

          mFinalDelta = motionEvent.getRawX() - mDownX;
          mVelocityTracker.addMovement(motionEvent);
          mVelocityTracker.computeCurrentVelocity(1000);
          float velocityX = mVelocityTracker.getXVelocity();
          float absVelocityX = Math.abs(velocityX);
          float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
          boolean dismiss = false;
          boolean dismissRight = false;
          if (Math.abs(mFinalDelta) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = mFinalDelta > 0;
          } else if (mMinFlingVelocity <= absVelocityX
              && absVelocityX <= mMaxFlingVelocity
              && absVelocityY < absVelocityX
              && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (mFinalDelta < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
          }
          if (dismiss
              && mDownPosition != mAnimatingPosition
              && mDownPosition != ListView.INVALID_POSITION) {
            // dismiss
            final View downView = mDownView; // mDownView gets null'd before animation ends
            final int downPosition = mDownPosition;
            ++mDismissAnimationRefCount;
            mAnimatingPosition = mDownPosition;
            mDownView
                .animate()
                .translationX(dismissRight ? mViewWidth : -mViewWidth)
                .alpha(0)
                .setDuration(mAnimationTime)
                .setListener(
                    new AnimatorListenerAdapter() {
                      @Override
                      public void onAnimationEnd(Animator animation) {
                        performDismiss(downView, downPosition);
                      }
                    });
          } else {
            // cancel
            mDownView
                .animate()
                .translationX(0)
                .alpha(mAlpha)
                .setDuration(mAnimationTime)
                .setListener(null);
          }
          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownY = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          mSwiping = false;
          break;
        }

      case MotionEvent.ACTION_MOVE:
        {
          if (mVelocityTracker == null || mPaused) {
            break;
          }

          mVelocityTracker.addMovement(motionEvent);
          float deltaX = motionEvent.getRawX() - mDownX;
          float deltaY = motionEvent.getRawY() - mDownY;
          if (!mSwiping && Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
          }

          if (mSwiping) {
            mDownView.setTranslationX(deltaX - mSwipingSlop);
            mDownView.setAlpha(
                Math.max(0f, Math.min(mAlpha, mAlpha * (1f - Math.abs(deltaX) / mViewWidth))));
            return true;
          }
          break;
        }
    }

    return false;
  }
コード例 #19
0
  private void updateTranslationOffset() {
    final RecyclerView rv = mRecyclerView;
    final int childCount = rv.getChildCount();

    if (childCount > 0) {
      mTranslationLeftLimit = 0;
      mTranslationRightLimit = rv.getWidth() - mDraggingItemInfo.width;

      mTranslationTopLimit = 0;
      mTranslationBottomLimit = rv.getHeight() - mDraggingItemInfo.height;

      switch (mLayoutOrientation) {
        case CustomRecyclerViewUtils.ORIENTATION_VERTICAL:
          {
            mTranslationLeftLimit += rv.getPaddingLeft();
            mTranslationRightLimit -= rv.getPaddingRight();
            break;
          }
        case CustomRecyclerViewUtils.ORIENTATION_HORIZONTAL:
          {
            mTranslationTopLimit += rv.getPaddingTop();
            mTranslationBottomLimit -= rv.getPaddingBottom();
            break;
          }
      }

      mTranslationRightLimit = Math.max(mTranslationLeftLimit, mTranslationRightLimit);
      mTranslationBottomLimit = Math.max(mTranslationTopLimit, mTranslationBottomLimit);

      if (!mIsScrolling) {
        final int firstVisiblePosition =
            CustomRecyclerViewUtils.findFirstVisibleItemPosition(rv, true);
        final int lastVisiblePosition =
            CustomRecyclerViewUtils.findLastVisibleItemPosition(rv, true);
        final View firstChild =
            findRangeFirstItem(rv, mRange, firstVisiblePosition, lastVisiblePosition);
        final View lastChild =
            findRangeLastItem(rv, mRange, firstVisiblePosition, lastVisiblePosition);

        switch (mLayoutOrientation) {
          case CustomRecyclerViewUtils.ORIENTATION_VERTICAL:
            {
              if (firstChild != null) {
                mTranslationTopLimit = Math.min(mTranslationBottomLimit, firstChild.getTop());
              }

              if (lastChild != null) {
                mTranslationBottomLimit = Math.min(mTranslationBottomLimit, lastChild.getTop());
              }
              break;
            }
          case CustomRecyclerViewUtils.ORIENTATION_HORIZONTAL:
            {
              if (firstChild != null) {
                mTranslationLeftLimit = Math.min(mTranslationLeftLimit, firstChild.getLeft());
              }

              if (lastChild != null) {
                mTranslationRightLimit = Math.min(mTranslationRightLimit, lastChild.getLeft());
              }
              break;
            }
        }
      }
    } else {
      mTranslationRightLimit = mTranslationLeftLimit = rv.getPaddingLeft();
      mTranslationBottomLimit = mTranslationTopLimit = rv.getPaddingTop();
    }

    mTranslationX = mTouchPositionX - mDraggingItemInfo.grabbedPositionX;
    mTranslationY = mTouchPositionY - mDraggingItemInfo.grabbedPositionY;

    mTranslationX = clip(mTranslationX, mTranslationLeftLimit, mTranslationRightLimit);
    mTranslationY = clip(mTranslationY, mTranslationTopLimit, mTranslationBottomLimit);
  }
コード例 #20
0
  private boolean handleTouchEvent(MotionEvent motionEvent) {
    if (mViewWidth < 2) {
      mViewWidth = mRecyclerView.getWidth();
    }

    switch (motionEvent.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        {
          if (mPaused) {
            break;
          }

          // Find the child view that was touched (perform a hit test)
          Rect rect = new Rect();
          int childCount = mRecyclerView.getChildCount();
          int[] listViewCoords = new int[2];
          mRecyclerView.getLocationOnScreen(listViewCoords);
          int x = (int) motionEvent.getRawX() - listViewCoords[0];
          int y = (int) motionEvent.getRawY() - listViewCoords[1];
          View child;
          for (int i = 0; i < childCount; i++) {
            child = mRecyclerView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
              mDownView = child;
              break;
            }
          }

          if (mDownView != null) {
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mRecyclerView.getChildAdapterPosition(mDownView);
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(motionEvent);
            mFgView = mDownView.findViewById(mFgID);
          }
          break;
        }

      case MotionEvent.ACTION_CANCEL:
        {
          if (mVelocityTracker == null) {
            break;
          }

          if (mDownView != null && mSwiping) {
            // cancel
            mFgView.animate().translationX(0).setDuration(ANIMATION_FAST).setListener(null);
          }
          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownY = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          mSwiping = false;
          mBgView = null;
          break;
        }

      case MotionEvent.ACTION_UP:
        {
          if (mVelocityTracker == null) {
            break;
          }

          mFinalDelta = motionEvent.getRawX() - mDownX;
          mVelocityTracker.addMovement(motionEvent);
          mVelocityTracker.computeCurrentVelocity(1000);
          float velocityX = mVelocityTracker.getXVelocity();
          float absVelocityX = Math.abs(velocityX);
          float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
          boolean dismiss = false;
          boolean dismissRight = false;
          if (Math.abs(mFinalDelta) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = mFinalDelta > 0;
          } else if (mMinFlingVelocity <= absVelocityX
              && absVelocityX <= mMaxFlingVelocity
              && absVelocityY < absVelocityX
              && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (mFinalDelta < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
          }
          if (dismiss
              && mDownPosition != ListView.INVALID_POSITION
              && mSwipeListener.canSwipe(mDownPosition)) {
            // dismiss
            ++mDismissAnimationRefCount;
            mBgView.animate().alpha(1).setDuration(ANIMATION_FAST);
            mFgView
                .animate()
                .translationX(dismissRight ? mViewWidth : -mViewWidth)
                .setDuration(ANIMATION_FAST)
                .setListener(
                    new AnimatorListenerAdapter() {
                      @Override
                      public void onAnimationEnd(Animator animation) {
                        mFgView.animate().translationX(0); // Esto hace que regrese a su posision :)
                      }
                    });
          } else {
            // cancel
            mFgView.animate().translationX(0).setDuration(ANIMATION_FAST).setListener(null);
          }
          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownY = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          mSwiping = false;
          mBgView = null;
          break;
        }

      case MotionEvent.ACTION_MOVE:
        {
          if (mVelocityTracker == null || mPaused) {
            break;
          }

          mVelocityTracker.addMovement(motionEvent);
          float deltaX = motionEvent.getRawX() - mDownX;
          float deltaY = motionEvent.getRawY() - mDownY;
          if (!mSwiping && Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
          }

          if (mSwiping) {
            if (mBgView == null) {
              mBgView = mDownView.findViewById(mBgID);
              mBgView.setVisibility(View.VISIBLE);
              listener.holaView((deltaX - mSwipingSlop) > 0, mBgView);
            }
            mFgView.setTranslationX(deltaX - mSwipingSlop);
            return true;
          }
          break;
        }
    }

    return false;
  }