Java Code Examples for android.support.v7.widget.helper.ItemTouchHelper#ACTION_STATE_SWIPE
The following examples show how to use
android.support.v7.widget.helper.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: ItemDragAndSwipeCallback.java From JD-Test with Apache License 2.0 | 6 votes |
@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 2
Source File: ItemDragAndSwipeCallback.java From GoogleVR with Apache License 2.0 | 6 votes |
@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) { 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 3
Source File: SimpleItemTouchHelperCallback.java From RecyclerViewUndoSwipe with Apache License 2.0 | 5 votes |
@Override public void onChildDraw(final 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; Bitmap icon; if (dX > 0) { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_delete_white_24dp); // Set color for right swipe p.setColor(ContextCompat.getColor(context, R.color.red500)); // Draw Rect with varying right side, equal to displacement dX c.drawRect((float) itemView.getLeft() + Utils.dpToPx(0), (float) itemView.getTop(), dX + Utils.dpToPx(0), (float) itemView.getBottom(), p); // Set the image icon for right swipe c.drawBitmap(icon, (float) itemView.getLeft() + Utils.dpToPx(16), (float) itemView.getTop() + ((float) itemView.getBottom() - (float) itemView.getTop() - icon.getHeight()) / 2, p); icon.recycle(); } } }
Example 4
Source File: SimpleItemTouchHelperCallback.java From mangosta-android with Apache License 2.0 | 5 votes |
@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 5
Source File: ItemDragAndSwipeCallback.java From GoogleVR with Apache License 2.0 | 5 votes |
@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 6
Source File: ItemDragAndSwipeCallback.java From GoogleVR with Apache License 2.0 | 5 votes |
@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: MyItemTouchCallback.java From Fairy with Apache License 2.0 | 5 votes |
@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) { //滑动时改变 Item 的透明度,以实现滑动过程中实现渐变效果 final float alpha = 1 - 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 8
Source File: MyItemTouchHelperCallback.java From MaterialDesignDemo with MIT License | 5 votes |
@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); if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { float value = 1 - Math.abs(dX) / viewHolder.itemView.getWidth(); viewHolder.itemView.setAlpha(value); viewHolder.itemView.setScaleY(value); } }
Example 9
Source File: SimpleItemTouchHelperCallback.java From AvatarTinderView with Apache License 2.0 | 5 votes |
@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 10
Source File: ItemDragAndSwipeCallback.java From demo4Fish with MIT License | 5 votes |
@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 11
Source File: TabListTouchHelperCallback.java From photosearcher with Apache License 2.0 | 5 votes |
@Override public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { getDefaultUIUtil().onDrawOver(c, recyclerView, ((IItemTouchHelperViewHolder) viewHolder).getSwipableView(), dX, dY, actionState, isCurrentlyActive); } else { super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } }
Example 12
Source File: SimpleItemTouchHelperCallback.java From homeassist with Apache License 2.0 | 5 votes |
@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 13
Source File: SimpleItemTouchHelperCallback.java From fingen with Apache License 2.0 | 5 votes |
@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 14
Source File: BindDragCallBack.java From LazyRecyclerAdapter with MIT License | 5 votes |
@Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { int position = viewHolder.getAdapterPosition() - mAdapter.absFirstPosition(); if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { if (position >= 0 && position <= (mAdapter.getDataList().size() - 1) && !(viewHolder instanceof BindSuperAdapter.WrapAdapter.SimpleViewHolder)) { if (mSwipeLength != -1) { dX = SwipeLimited(dX); } super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } } else { dY = DragLimited(viewHolder, dY); super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } }
Example 15
Source File: ConversationListFragment.java From Silence with GNU General Public License v3.0 | 5 votes |
@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) { View itemView = viewHolder.itemView; Paint p = new Paint(); if (dX > 0) { Bitmap icon; if (archive) icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_unarchive_white_36dp); else icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_archive_white_36dp); p.setColor(getResources().getColor(R.color.green_500)); c.drawRect((float) itemView.getLeft(), (float) itemView.getTop(), dX, (float) itemView.getBottom(), p); c.drawBitmap(icon, (float) itemView.getLeft() + getResources().getDimension(R.dimen.conversation_list_fragment_archive_padding), (float) itemView.getTop() + ((float) itemView.getBottom() - (float) itemView.getTop() - icon.getHeight())/2, p); } if (Build.VERSION.SDK_INT >= 11) { float alpha = 1.0f - 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 16
Source File: SimpleItemTouchHelperCallback.java From PracticalRecyclerView with Apache License 2.0 | 5 votes |
@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 17
Source File: SimpleItemTouchHelperCallback.java From friendly-plans with GNU General Public License v3.0 | 5 votes |
@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 18
Source File: SimpleItemTouchHelperCallback.java From clear-todolist with GNU General Public License v3.0 | 5 votes |
@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 19
Source File: SimpleItemTouchHelperCallback.java From YTPlayer with GNU General Public License v3.0 | 5 votes |
@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 20
Source File: SimpleItemTouchHelperCallback.java From Focus with GNU General Public License v3.0 | 4 votes |
@Override public void onChildDraw(final 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; ALog.d("dx" + dX + "originDx" + origin_dx); int width = itemView.getWidth(); Bitmap icon; if (dX > 0) { origin_dx = dX; int position = viewHolder.getAdapterPosition(); if (position > -1 && mDatas != null && position < mDatas.size()){//处理越界错误 if (mDatas.get(position).isRead()){ icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_operation_uncheck); }else { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_operation_check); } // Set color for right swipe p.setColor(ContextCompat.getColor(context, R.color.blue)); // Draw Rect with varying right side, equal to displacement dX c.drawRect((float) itemView.getLeft() + UIUtil.dpToPx(0), (float) itemView.getTop(), dX + UIUtil.dpToPx(0), (float) itemView.getBottom(), p); // Set the image icon for right swipe c.drawBitmap(icon, (float) itemView.getLeft() + UIUtil.dpToPx(16), (float) itemView.getTop() + ((float) itemView.getBottom() - (float) itemView.getTop() - icon.getHeight()) / 2, p); icon.recycle(); } } if (dX == 0 && origin_dx >0 && origin_dx < width){ //说明滑动了一部分又关闭了,这个时候也要标记已读 origin_dx = 0; // mAdapter.onItemDismiss(viewHolder.getAdapterPosition()); } } }