Java Code Examples for androidx.recyclerview.widget.ItemTouchHelper#ACTION_STATE_SWIPE

The following examples show how to use androidx.recyclerview.widget.ItemTouchHelper#ACTION_STATE_SWIPE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DragAndSwipeCallback.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG
            && !isViewCreateByAdapter(viewHolder)) {
        if (mDraggableModule != null) {
            mDraggableModule.onItemDragStart(viewHolder);
        }
        viewHolder.itemView.setTag(R.id.dokit_baseQuickAdapter_dragging_support, true);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        if (mDraggableModule != null) {
            mDraggableModule.onItemSwipeStart(viewHolder);
        }
        viewHolder.itemView.setTag(R.id.dokit_baseQuickAdapter_swiping_support, true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example 2
Source File: DragAndSwipeCallback.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public void onChildDrawOver(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder,
                            float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        View itemView = viewHolder.itemView;

        c.save();
        if (dX > 0) {
            c.clipRect(itemView.getLeft(), itemView.getTop(),
                    itemView.getLeft() + dX, itemView.getBottom());
            c.translate(itemView.getLeft(), itemView.getTop());
        } else {
            c.clipRect(itemView.getRight() + dX, itemView.getTop(),
                    itemView.getRight(), itemView.getBottom());
            c.translate(itemView.getRight() + dX, itemView.getTop());
        }
        if (mDraggableModule != null) {
            mDraggableModule.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
        }
        c.restore();

    }
}
 
Example 3
Source File: DragAndSwipeCallback.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public void onChildDrawOver(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder,
                            float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        View itemView = viewHolder.itemView;

        c.save();
        if (dX > 0) {
            c.clipRect(itemView.getLeft(), itemView.getTop(),
                    itemView.getLeft() + dX, itemView.getBottom());
            c.translate(itemView.getLeft(), itemView.getTop());
        } else {
            c.clipRect(itemView.getRight() + dX, itemView.getTop(),
                    itemView.getRight(), itemView.getBottom());
            c.translate(itemView.getRight() + dX, itemView.getTop());
        }
        if (mDraggableModule != null) {
            mDraggableModule.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
        }
        c.restore();

    }
}
 
Example 4
Source File: DragAndSwipeCallback.java    From BaseRecyclerViewAdapterHelper with MIT License 6 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG
            && !isViewCreateByAdapter(viewHolder)) {
        if (mDraggableModule != null) {
            mDraggableModule.onItemDragStart(viewHolder);
        }
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        if (mDraggableModule != null) {
            mDraggableModule.onItemSwipeStart(viewHolder);
        }
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example 5
Source File: ItemTouchHelperCallback.java    From FlexibleAdapter with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    // Notify the callback about the new event
    mAdapterCallback.onActionStateChanged(viewHolder, actionState);
    // We only want the active item to change
    if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
        if (viewHolder instanceof ViewHolderCallback) {
            // Let the ViewHolder to know that this item is swiping or dragging
            ViewHolderCallback viewHolderCallback = (ViewHolderCallback) viewHolder;
            viewHolderCallback.onActionStateChanged(viewHolder.getAdapterPosition(), actionState);
            if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
                getDefaultUIUtil().onSelected(viewHolderCallback.getFrontView());
            }
        }
    } else {
        super.onSelectedChanged(viewHolder, actionState);
    }
}
 
Example 6
Source File: LocationTouchCallback.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onChildDraw(@NonNull Canvas c,
                        @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder,
                        float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    switch (actionState) {
        case ItemTouchHelper.ACTION_STATE_SWIPE:
            ((LocationHolder) viewHolder).drawSwipe(activity, dX);
            break;

        case ItemTouchHelper.ACTION_STATE_DRAG:
            ((LocationHolder) viewHolder).drawDrag(activity, dY != 0);
            break;

        case ItemTouchHelper.ACTION_STATE_IDLE:
            break;
    }
}
 
Example 7
Source File: ItemDragAndSwipeCallback.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
@Override
public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                            float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        View itemView = viewHolder.itemView;

        c.save();
        if (dX > 0) {
            c.clipRect(itemView.getLeft(), itemView.getTop(),
                    itemView.getLeft() + dX, itemView.getBottom());
            c.translate(itemView.getLeft(), itemView.getTop());
        } else {
            c.clipRect(itemView.getRight() + dX, itemView.getTop(),
                    itemView.getRight(), itemView.getBottom());
            c.translate(itemView.getRight() + dX, itemView.getTop());
        }

        mAdapter.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
        c.restore();

    }
}
 
Example 8
Source File: SimpleItemTouchCallback.java    From YouTube-In-Background with MIT License 6 votes vote down vote up
@Override
public void onChildDraw(
        @NonNull Canvas c,
        @NonNull RecyclerView recyclerView,
        @NonNull RecyclerView.ViewHolder viewHolder,
        float dX,
        float dY,
        int actionState,
        boolean isCurrentlyActive)
{
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        // Fade out the view as it is swiped out of the parent's bounds
        final float alpha = ALPHA_FULL - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
        viewHolder.itemView.setAlpha(alpha);
        viewHolder.itemView.setTranslationX(dX);
    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}
 
Example 9
Source File: DragAndSwipeCallback.java    From BaseRecyclerViewAdapterHelper with MIT License 6 votes vote down vote up
@Override
public void onChildDrawOver(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder,
                            float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        View itemView = viewHolder.itemView;

        c.save();
        if (dX > 0) {
            c.clipRect(itemView.getLeft(), itemView.getTop(),
                    itemView.getLeft() + dX, itemView.getBottom());
            c.translate(itemView.getLeft(), itemView.getTop());
        } else {
            c.clipRect(itemView.getRight() + dX, itemView.getTop(),
                    itemView.getRight(), itemView.getBottom());
            c.translate(itemView.getRight() + dX, itemView.getTop());
        }
        if (mDraggableModule != null) {
            mDraggableModule.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
        }
        c.restore();

    }
}
 
Example 10
Source File: EpoxyModelTouchCallback.java    From epoxy with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSelectedChanged(@Nullable EpoxyViewHolder viewHolder, int actionState) {
  super.onSelectedChanged(viewHolder, actionState);

  if (viewHolder != null) {
    EpoxyModel<?> model = viewHolder.getModel();
    if (!isTouchableModel(model)) {
      throw new IllegalStateException(
          "A model was selected that is not a valid target: " + model.getClass());
    }

    markRecyclerViewHasSelection((RecyclerView) viewHolder.itemView.getParent());

    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
      holderBeingSwiped = viewHolder;
      //noinspection unchecked
      onSwipeStarted((T) model, viewHolder.itemView, viewHolder.getAdapterPosition());
    } else if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
      holderBeingDragged = viewHolder;
      //noinspection unchecked
      onDragStarted((T) model, viewHolder.itemView, viewHolder.getAdapterPosition());
    }
  } else if (holderBeingDragged != null) {
    //noinspection unchecked
    onDragReleased((T) holderBeingDragged.getModel(), holderBeingDragged.itemView);
    holderBeingDragged = null;
  } else if (holderBeingSwiped != null) {
    //noinspection unchecked
    onSwipeReleased((T) holderBeingSwiped.getModel(), holderBeingSwiped.itemView);
    holderBeingSwiped = null;
  }
}
 
Example 11
Source File: ConversationItemSwipeCallback.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onChildDraw(
        @NonNull Canvas c,
        @NonNull RecyclerView recyclerView,
        @NonNull RecyclerView.ViewHolder viewHolder,
        float dx, float dy, int actionState, boolean isCurrentlyActive)
{
  if (cannotSwipeViewHolder(viewHolder)) return;

  float   sign              = getSignFromDirection(viewHolder.itemView);
  boolean isCorrectSwipeDir = sameSign(dx, sign);

  if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && isCorrectSwipeDir) {
    ConversationSwipeAnimationHelper.update((ConversationItem) viewHolder.itemView, Math.abs(dx), sign);
    handleSwipeFeedback((ConversationItem) viewHolder.itemView, Math.abs(dx));
    if (canTriggerSwipe) {
      setTouchListener(recyclerView, viewHolder, Math.abs(dx));
    }
  } else if (actionState == ItemTouchHelper.ACTION_STATE_IDLE || dx == 0) {
    ConversationSwipeAnimationHelper.update((ConversationItem) viewHolder.itemView, 0, 1);
  }

  if (dx == 0) {
    shouldTriggerSwipeFeedback = true;
    canTriggerSwipe            = true;
  }
}
 
Example 12
Source File: SimpleItemTouchHelperCallback.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    // Fade out the view as it is swiped out of the parent's bounds
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        View itemView = viewHolder.itemView;
        final float alpha = ALPHA_FULL - Math.abs(dX) / (float) itemView.getWidth();
        itemView.setAlpha(alpha);
    }
}
 
Example 13
Source File: ItemTouchHelperCallback.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                        float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE &&
            viewHolder instanceof ViewHolderCallback) {

        // Update visibility for RearViews - Convert to custom VH
        ViewHolderCallback viewHolderCallback = (ViewHolderCallback) viewHolder;
        View frontView = viewHolderCallback.getFrontView();

        // Orientation independent
        float dragAmount = dX;
        if (dY != 0) {
            dragAmount = dY;
        }

        // Manage opening - Is Left or Right View?
        int swipingDirection = 0;//0 is to reset the frontView
        if (dragAmount > 0) {
            swipingDirection = ItemTouchHelper.RIGHT;//DOWN
        } else if (dragAmount < 0) {
            swipingDirection = ItemTouchHelper.LEFT;//TOP
        }

        setLayoutVisibility(viewHolderCallback, swipingDirection);
        // Translate the FrontView
        getDefaultUIUtil().onDraw(c, recyclerView, frontView, dX, dY, actionState, isCurrentlyActive);

    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}
 
Example 14
Source File: SimpleItemTouchHelperCallback.java    From andOTP with MIT License 5 votes vote down vote up
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        // Fade out the view as it is swiped out of the parent's bounds
        final float alpha = ALPHA_FULL - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
        viewHolder.itemView.setAlpha(alpha);
        viewHolder.itemView.setTranslationX(dX);
    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}
 
Example 15
Source File: ContactFragment.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        final ContactsAdapter.ContactViewHolder holder = (ContactsAdapter.ContactViewHolder) viewHolder;
        final float actionWidth = holder.getActionWidth();
        final float translationX = dX < -actionWidth ? -actionWidth : dX;
        final float menuTranslationX = translationX / 2 + actionWidth / 2;
        holder.getView(R.id.content).setTranslationX(translationX);
        holder.getView(R.id.menu).setTranslationX(menuTranslationX);
    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}
 
Example 16
Source File: TouchHelperCallback.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
@Override
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        // Fade out the view as it is swiped out of the parent's bounds
        final float alpha = ALPHA_FULL - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
        viewHolder.itemView.setAlpha(alpha);
        viewHolder.itemView.setTranslationX(dX);
    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}
 
Example 17
Source File: SimpleItemTouchHelperCallback.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        // Fade out the view as it is swiped out of the parent's bounds
        final float alpha = ALPHA_FULL - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
        viewHolder.itemView.setAlpha(alpha);
        viewHolder.itemView.setTranslationX(dX);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
        if (isCurrentlyActive) {
            viewHolder.itemView.setAlpha(0.5f);
            viewHolder.itemView.setScaleX(moveScaleFactor);
            viewHolder.itemView.setScaleY(moveScaleFactor);
        } else {
            viewHolder.itemView.setAlpha(1f);
            viewHolder.itemView.setScaleX(1f);
            viewHolder.itemView.setScaleY(1f);
        }
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }

    // 从拖动到释放的过程
    if (null != mOnSelectChangedListener && !isCurrentlyActive && lastActive) {
        mOnSelectChangedListener.onSelectedChanged(viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
    lastActive = isCurrentlyActive;
}
 
Example 18
Source File: EventTouchHelperCallback.java    From Deadline with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        if (Math.abs(dX) <= getSlideLimitation(viewHolder)) {
            viewHolder.itemView.scrollTo(-(int) dX, 0);
        }

    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}
 
Example 19
Source File: SwipeAndDragHelper.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onChildDraw(Canvas c,
                        RecyclerView recyclerView,
                        RecyclerView.ViewHolder viewHolder,
                        float dX,
                        float dY,
                        int actionState,
                        boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        float alpha = 1 - (Math.abs(dX) / recyclerView.getWidth());
        viewHolder.itemView.setAlpha(alpha);
    }
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
 
Example 20
Source File: ExpandableItem.java    From FlexibleAdapter with Apache License 2.0 4 votes vote down vote up
@Override
public void onItemReleased(int position) {
    swiped = (mActionState == ItemTouchHelper.ACTION_STATE_SWIPE);
    super.onItemReleased(position);
}