/**
  * Moves the view
  *
  * @param deltaX delta
  */
 public void move(float deltaX) {
   swipeRecyclerView.onMove(downPosition, deltaX);
   float posX = ViewHelper.getX(frontView);
   if (opened.get(downPosition)) {
     posX += openedRight.get(downPosition) ? -viewWidth + rightOffset : viewWidth - leftOffset;
   }
   if (posX > 0 && !swipingRight) {
     if (SwipeRecyclerView.DEBUG) {
       Log.d(SwipeRecyclerView.TAG, "change to right");
     }
     swipingRight = !swipingRight;
     swipeCurrentAction = swipeActionRight;
     if (swipeCurrentAction == SwipeRecyclerView.SWIPE_ACTION_CHOICE) {
       backView.setVisibility(View.GONE);
     } else {
       backView.setVisibility(View.VISIBLE);
     }
   }
   if (posX < 0 && swipingRight) {
     if (SwipeRecyclerView.DEBUG) {
       Log.d(SwipeRecyclerView.TAG, "change to left");
     }
     swipingRight = !swipingRight;
     swipeCurrentAction = swipeActionLeft;
     if (swipeCurrentAction == SwipeRecyclerView.SWIPE_ACTION_CHOICE) {
       backView.setVisibility(View.GONE);
     } else {
       backView.setVisibility(View.VISIBLE);
     }
   }
   if (swipeCurrentAction == SwipeRecyclerView.SWIPE_ACTION_DISMISS) {
     setTranslationX(parentView, deltaX);
     setAlpha(parentView, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / viewWidth)));
   } else if (swipeCurrentAction == SwipeRecyclerView.SWIPE_ACTION_CHOICE) {
     if ((swipingRight && deltaX > 0 && posX < DISPLACE_CHOICE)
         || (!swipingRight && deltaX < 0 && posX > -DISPLACE_CHOICE)
         || (swipingRight && deltaX < DISPLACE_CHOICE)
         || (!swipingRight && deltaX > -DISPLACE_CHOICE)) {
       setTranslationX(frontView, deltaX);
     }
   } else {
     setTranslationX(frontView, deltaX);
   }
 }
Пример #2
0
 public static float centerX(View view) {
   return ViewHelper.getX(view) + view.getWidth() / 2;
 }