Java Code Examples for android.support.v7.widget.helper.ItemTouchHelper#ACTION_STATE_DRAG

The following examples show how to use android.support.v7.widget.helper.ItemTouchHelper#ACTION_STATE_DRAG . 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: DragAndDropItemCallback.java    From SimpleRecyclerView 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) {
    super.onSelectedChanged(viewHolder, actionState);
    return;
  }

  if (dragAndDropCallback != null) {
    dragAndDropCallback.onCellDragStarted(simpleRecyclerView, viewHolder.itemView, draggingItem, draggingItemPosition);
  }

  if (options.isDefaultEffectEnabled()) {
    viewHolder.itemView.setSelected(true);
    viewHolder.itemView.setAlpha(0.95f);
    if (Build.VERSION.SDK_INT >= 21 && animator == null) {
      animator = AnimatorInflater.loadStateListAnimator(viewHolder.itemView.getContext(), R.animator.raise);
      viewHolder.itemView.setStateListAnimator(animator);
    }
  }

  super.onSelectedChanged(viewHolder, actionState);
}
 
Example 2
Source File: TouchHelperCallback.java    From MyBlogDemo with Apache License 2.0 6 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 width = (float) viewHolder.itemView.getWidth();
        float alpha = 1.0f - Math.abs(dX) / width;
        viewHolder.itemView.setAlpha(alpha);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
        if (isCurrentlyActive) {
            viewHolder.itemView.setScaleX(1.2f);
            viewHolder.itemView.setScaleY(1.2f);
        } else {
            viewHolder.itemView.setScaleX(1);
            viewHolder.itemView.setScaleY(1);
        }
    }
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY,
            actionState, isCurrentlyActive);
}
 
Example 3
Source File: ItemDragAndSwipeCallback.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG
            && !isViewCreateByAdapter(viewHolder)) {
        mAdapter.onItemDragStart(viewHolder);
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        mAdapter.onItemSwipeStart(viewHolder);
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example 4
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 5
Source File: ItemDragAndSwipeCallback.java    From demo4Fish with MIT License 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG
            && !isViewCreateByAdapter(viewHolder)) {
        mAdapter.onItemDragStart(viewHolder);
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        mAdapter.onItemSwipeStart(viewHolder);
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example 6
Source File: ItemDragAndSwipeCallback.java    From GoogleVR with Apache License 2.0 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
        mAdapter.onItemDragStart(viewHolder);
        mActionState = actionState;
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        mAdapter.onItemSwipeStart(viewHolder);
        mActionState = actionState;
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example 7
Source File: ItemDragAndSwipeCallback.java    From GoogleVR with Apache License 2.0 5 votes vote down vote up
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    super.clearView(recyclerView, viewHolder);

    if (mActionState == ItemTouchHelper.ACTION_STATE_DRAG) {
        mAdapter.onItemDragEnd(viewHolder);
    } else if (mActionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        mAdapter.onItemSwipeClear(viewHolder);
    }
    mActionState = ItemTouchHelper.ACTION_STATE_IDLE;
}
 
Example 8
Source File: ItemDragAndSwipeCallback.java    From JD-Test with Apache License 2.0 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG
            && !isViewCreateByAdapter(viewHolder)) {
        mAdapter.onItemDragStart(viewHolder);
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        mAdapter.onItemSwipeStart(viewHolder);
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example 9
Source File: ItemDragAndSwipeCallback.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG
            && !isViewCreateByAdapter(viewHolder)) {
        mAdapter.onItemDragStart(viewHolder);
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        mAdapter.onItemSwipeStart(viewHolder);
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example 10
Source File: SimpleItemTouchHelperCallback.java    From PracticalRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    super.onSelectedChanged(viewHolder, actionState);
    final boolean enabled = !(actionState == ItemTouchHelper.ACTION_STATE_DRAG ||
            actionState == ItemTouchHelper.ACTION_STATE_SWIPE);
    mAdapter.resolveSwipeConflicts(enabled);
}
 
Example 11
Source File: ItemDragAndSwipeCallback.java    From NIM_Android_UIKit with MIT License 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG
            && !isViewCreateByAdapter(viewHolder)) {
        mAdapter.onItemDragStart(viewHolder);
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        mAdapter.onItemSwipeStart(viewHolder);
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example 12
Source File: BaseRecycleItemTouchHelper.java    From Collection-Android with MIT License 3 votes vote down vote up
/**
 * Item被选中时候回调
 *
 * @param viewHolder
 * @param actionState
 *          当前Item的状态
 *          ItemTouchHelper.ACTION_STATE_IDLE   闲置状态
 *          ItemTouchHelper.ACTION_STATE_SWIPE  滑动中状态
 *          ItemTouchHelper#ACTION_STATE_DRAG   拖拽中状态
 */
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    super.onSelectedChanged(viewHolder, actionState);
    if(actionState==ItemTouchHelper.ACTION_STATE_DRAG){//点击可拖拽时的的背景色
        helperCallback.onItemSelected();
    }
}