android.support.v7.widget.helper.ItemTouchHelper Java Examples

The following examples show how to use android.support.v7.widget.helper.ItemTouchHelper. 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: SimpleItemTouchHelperCallback.java    From YImagePicker with Apache License 2.0 6 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    // We only want the active item to change
    if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
        if (viewHolder instanceof ItemTouchHelperViewHolder) {
            // Let the view holder know that this item is being moved or dragged
            ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
            itemViewHolder.onItemSelected();
        }
    }
    super.onSelectedChanged(viewHolder, actionState);

    if (null != mOnSelectChangedListener) {
        mOnSelectChangedListener.onSelectedChanged(viewHolder, actionState);
    }
}
 
Example #2
Source File: ItemDragHelper.java    From MultiItem with Apache License 2.0 6 votes vote down vote up
/**
     * 当item位置变换,滚动recycler到正确的位置
     * TODO: 2017/2/21 0021 整理更优雅的写法  还有scrollToPosition(0)是否必要?
     */
    private void scrollToRightPositionWhenItemChanged(RecyclerView recyclerView, View itemView, int itemPos) {
        final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        if (layoutManager instanceof ItemTouchHelper.ViewDropHandler) {
            OrientationHelper helper = OrientationHelper.createVerticalHelper(layoutManager);
            int start = helper.getDecoratedStart(itemView);
            int end = helper.getDecoratedEnd(itemView);
            ((LinearLayoutManager) layoutManager).scrollToPositionWithOffset(
                    itemPos, lastItemPos > itemPos ? start : end - itemViewHeight);
//                System.out.println(lastItemPos + "-" + childPos + "OrientationHelperOrientationHelper:"
//                        + height + "==" + itemViewHeight + "=||=" + start + "===" + end + "||||||" + myStart + "===" + itemTargetView.getHeight() );
        }
        if (lastItemPos == 0 || itemPos == 0) {
            recyclerView.scrollToPosition(0);
        }
    }
 
Example #3
Source File: CardItemTouchHelperCallback.java    From CardSwipeLayout with MIT License 6 votes vote down vote up
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
    // 移除 onTouchListener,否则触摸滑动会乱了
    viewHolder.itemView.setOnTouchListener(null);
    int layoutPosition = viewHolder.getLayoutPosition();
    T remove = dataList.remove(layoutPosition);
    adapter.notifyDataSetChanged();
    if (mListener != null) {
        mListener.onSwiped(viewHolder, remove, direction == ItemTouchHelper.LEFT ? CardConfig.SWIPED_LEFT : CardConfig.SWIPED_RIGHT);
    }
    // 当没有数据时回调 mListener
    if (adapter.getItemCount() == 0) {
        if (mListener != null) {
            mListener.onSwipedClear();
        }
    }
}
 
Example #4
Source File: TypeEditActivity.java    From AccountBook with GNU General Public License v3.0 6 votes vote down vote up
private void initAdapter() {
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
    mAdapter = new TypeEditAdapter(mTypes);
    ItemDragAndSwipeCallback itemDragAndSwipeCallback = new ItemDragAndSwipeCallback(mAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemDragAndSwipeCallback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);

    itemDragAndSwipeCallback.setSwipeMoveFlags(ItemTouchHelper.START | ItemTouchHelper.END);
    mAdapter.enableSwipeItem();
    mAdapter.setOnItemSwipeListener(onItemSwipeListener);
    mAdapter.enableDragItem(itemTouchHelper);
    mAdapter.setOnItemDragListener(onItemDragListener);
    mRecyclerView.setAdapter(mAdapter);

    mRecyclerView.addOnItemTouchListener(new OnSimpleClickListener(){
        @Override
        public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
            Type data = (Type) baseQuickAdapter.getData().get(i);
            // 编辑分类
            Intent intent = new Intent(mContext, AddEditTypeActivity.class);
            intent.putExtra(AppConstants.EXTRA_ACCOUNT_TYPE, mType);
            intent.putExtra(AppConstants.EXTRA_DATA, data);
            startActivityForResult(intent, CODE_EDIT_TYPE);
        }
    });
}
 
Example #5
Source File: ItemMoveCallback.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder,
                              int actionState) {


    if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
        if (viewHolder instanceof NPlayAdapter.MyViewHolder) {
            NPlayAdapter.MyViewHolder myViewHolder=
                    (NPlayAdapter.MyViewHolder) viewHolder;
            mAdapter.onRowSelected(myViewHolder);
        }

    }

    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #6
Source File: ShopCartItemTouchHelperCallback.java    From FastWaiMai with MIT License 6 votes vote down vote up
/**
 * Callback回调监听时先调用的,用来判断当前是什么动作,比如判断方向
 * 作用:哪个方向的拖动
 *
 * @param recyclerView
 * @param viewHolder
 * @return
 */
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
	//方向:up,down,left,right
	//常量
	// ItemTouchHelper.UP    0x0001
	// ItemTouchHelper.DOWN  0x0010
	// ItemTouchHelper.LEFT
	// ItemTouchHelper.RIGHT

	//我要监听的拖拽方向是哪个方向
	int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
	//我要监听的swipe侧滑方向是哪个方向
	int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;


	int flags = makeMovementFlags(dragFlags, swipeFlags);
	return flags;
}
 
Example #7
Source File: TraceFragment.java    From OpenHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
    protected void initFragment(Bundle savedInstanceState) {
        super.initFragment(savedInstanceState);
        setLoadMoreEnable(true);
        ItemTouchHelperCallback callback = new ItemTouchHelperCallback(0,
                ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, this);
        itemTouchHelper = new ItemTouchHelper(callback);
        itemTouchHelper.attachToRecyclerView(recyclerView);
        StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(adapter);
        recyclerView.addItemDecoration(headersDecor);

        StickyRecyclerHeadersTouchListener touchListener =
                new StickyRecyclerHeadersTouchListener(recyclerView, headersDecor);
        touchListener.setOnHeaderClickListener((header, position, headerId) -> {
            //wrong position returned
//            recyclerView.smoothScrollToPosition(mPresenter.getFirstItemByDate((Long) header.getTag()));
        });
        recyclerView.addOnItemTouchListener(touchListener);

    }
 
Example #8
Source File: DefaultItemTouchHelperCallback.java    From SwipeRecyclerView-master 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) {
    // 判断当前是否是swipe方式:侧滑。
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        //1.ItemView--ViewHolder; 2.侧滑条目的透明度程度关联谁?dX(delta增量,范围:当前条目-width~width)。
        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        float alpha = 1;
        if (layoutManager instanceof LinearLayoutManager) {
            int orientation = ((LinearLayoutManager) layoutManager).getOrientation();
            if (orientation == LinearLayoutManager.HORIZONTAL) {
                alpha = 1 - Math.abs(dY) / viewHolder.itemView.getHeight();
            } else if (orientation == LinearLayoutManager.VERTICAL) {
                alpha = 1 - Math.abs(dX) / viewHolder.itemView.getWidth();
            }
        }
        viewHolder.itemView.setAlpha(alpha);//1~0
    }
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
 
Example #9
Source File: ChannelFragmentAdapter.java    From letv with Apache License 2.0 6 votes vote down vote up
public ChannelFragmentAdapter(Context context, ItemTouchHelper helper, ChannelListBean channelListBean, RecyclerView view) {
    this.mInflater = LayoutInflater.from(context);
    this.mContext = context;
    this.mItemTouchHelper = helper;
    this.mRecyclerView = view;
    this.mChannelListBean = channelListBean;
    if (channelListBean != null && !BaseTypeUtils.isListEmpty(channelListBean.listChannel)) {
        for (int i = 0; i < channelListBean.listChannel.size(); i++) {
            if (channelListBean.listChannel.get(i) != null) {
                this.mMyChannelItems.add(channelListBean.listChannel.get(i));
                if (((Channel) channelListBean.listChannel.get(i)).top == 0) {
                    this.mTopSize++;
                }
                if (((Channel) channelListBean.listChannel.get(i)).lock == 1) {
                    this.mLockSize++;
                }
            }
        }
        this.mImageDownloader = ImageDownloader.getInstance();
    }
}
 
Example #10
Source File: ItemTouchHelperCallback.java    From PowerfulRecyclerView 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) {
    boolean clickHeader = ((PowerfulRecyclerAdapter) mAdapter).hasHeaderView() && viewHolder.getAdapterPosition() == 0;
    boolean clickFooter = ((PowerfulRecyclerAdapter) mAdapter).hasFootView() && viewHolder.getAdapterPosition() == ((PowerfulRecyclerAdapter)mAdapter).getItemCount() - 1;
    boolean clickRecyclerFooter = ((PowerfulRecyclerAdapter) mAdapter).getPlugAdapter().getItemViewType(viewHolder.getAdapterPosition() - ((PowerfulRecyclerAdapter) mAdapter).getHeaderViewCount()) == PowerfulRecyclerView.TYPE_RECYCLER_FOOTER;
    if(clickHeader || clickFooter || clickRecyclerFooter){
        return;
    }else{
        if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
            float width = (float) viewHolder.itemView.getWidth();
            float alpha = 1.0f - Math.abs(dX) / width;
            viewHolder.itemView.setAlpha(alpha);
            viewHolder.itemView.setTranslationX(dX);
        } else {
            super.onChildDraw(c, recyclerView, viewHolder, dX, dY,
                    actionState, isCurrentlyActive);
        }
    }
}
 
Example #11
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 #12
Source File: ItemDragAndSwipeCallback.java    From imsdk-android with MIT License 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 #13
Source File: ItemMoveCallback.java    From journaldev with MIT License 6 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder,
                              int actionState) {


    if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
        if (viewHolder instanceof RecyclerViewAdapter.MyViewHolder) {
            RecyclerViewAdapter.MyViewHolder myViewHolder=
                    (RecyclerViewAdapter.MyViewHolder) viewHolder;
            mAdapter.onRowSelected(myViewHolder);
        }

    }

    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #14
Source File: GiveawayListFragment.java    From SteamGifts with MIT License 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) {
    View itemView = viewHolder.itemView;

    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && dX < 0) {
        // draw x mark
        int itemHeight = itemView.getBottom() - itemView.getTop();
        int intrinsicWidth = xMark.getIntrinsicWidth();
        int intrinsicHeight = xMark.getIntrinsicWidth();

        int xMarkLeft = itemView.getRight() - xMarkMargin - intrinsicWidth;
        int xMarkRight = itemView.getRight() - xMarkMargin;
        int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2;
        int xMarkBottom = xMarkTop + intrinsicHeight;
        xMark.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom);

        xMark.draw(c);
    }

    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
 
Example #15
Source File: DemoActivity.java    From SwipeableRV with Apache License 2.0 6 votes vote down vote up
private void initViews() {
    mRecyclerView = (SWRecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.getSwipeMessageBuilder()
                 .withFontPath(getString(R.string.droidSerif))
                 .withSwipeDirection(SwipeMessageBuilder.BOTH)
                 .build();
    LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
    mRecyclerView.setLayoutManager(layoutManager);

    reminders.add("Reminder 1");
    reminders.add("Reminder 2");
    reminders.add("Reminder 3");
    reminders.add("Reminder 4");
    reminders.add("Reminder 5");
    reminders.add("Reminder 6");
    reminders.add("Reminder 7");
    reminders.add("Reminder 8");
    reminders.add("Reminder 9");
    reminders.add("Reminder 10");

    mAdapter = new io.huannguyen.swipeablerv.demo.SampleAdapter(reminders);
    // allow swiping with both directions (left-to-right and right-to-left)
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setupSwipeToDismiss(mAdapter, ItemTouchHelper.LEFT|ItemTouchHelper.RIGHT);
}
 
Example #16
Source File: WifiProvisionFragment.java    From amazon-freertos-ble-android-sdk with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_wifi_provision, container, false);
    mWifiInfoRecyclerView = (RecyclerView) view.findViewById(R.id.wifi_recycler_view);
    mWifiInfoRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mWifiInfoAdapter = new WifiInfoAdapter(mWifiInfoList, this);
    mWifiInfoRecyclerView.setAdapter(mWifiInfoAdapter);

    DragSwipeController dragSwipeController = new DragSwipeController(mWifiInfoAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(dragSwipeController);
    itemTouchHelper.attachToRecyclerView(mWifiInfoRecyclerView);
    mAmazonFreeRTOSManager = AmazonFreeRTOSAgent.getAmazonFreeRTOSManager(getActivity());
    mDevice = mAmazonFreeRTOSManager.getConnectedDevice(mDeviceMacAddr);
    listNetworks();
    return view;
}
 
Example #17
Source File: MainActivity.java    From CircularDeletionSwipe with Apache License 2.0 6 votes vote down vote up
@Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

toolbar = (Toolbar)findViewById(R.id.toolbar);
toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.semi_black));
setSupportActionBar(toolbar);

recycler = (RecyclerView)findViewById(R.id.recyclerView);
recycler.setLayoutManager(new LinearLayoutManager(this));
recycler.setItemAnimator(new DefaultItemAnimator());
recycler.setAdapter(new AdapterRecyclerView(this, getItemList()));

ItemTouchHelper.Callback callback = new DeletionSwipeHelper(0, ItemTouchHelper.START, this, this);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(recycler);
  }
 
Example #18
Source File: CustomPreviewControllerView.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
private void initPreviewList() {
    mPreviewRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false));
    previewAdapter = new MultiPreviewAdapter(selectedList, presenter);
    mPreviewRecyclerView.setAdapter(previewAdapter);
    SimpleItemTouchHelperCallback callback = new SimpleItemTouchHelperCallback(previewAdapter);
    ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(mPreviewRecyclerView);
}
 
Example #19
Source File: TabListTouchHelperCallback.java    From photosearcher with Apache License 2.0 5 votes vote down vote up
@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 #20
Source File: UpdatesViewBinder.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
public UpdatesViewBinder(final AppCompatActivity activity, FrameLayout parent) {
    this.activity = activity;
    View view = activity.getLayoutInflater().inflate(R.layout.main_tab_updates, parent, true);

    adapter = new UpdatesAdapter(activity);
    adapter.registerAdapterDataObserver(adapterChangeListener);

    list = (RecyclerView) view.findViewById(R.id.list);
    list.setHasFixedSize(true);
    list.setLayoutManager(new LinearLayoutManager(activity));
    list.setAdapter(adapter);

    ItemTouchHelper touchHelper = new ItemTouchHelper(new UpdatesItemTouchCallback(adapter));
    touchHelper.attachToRecyclerView(list);

    emptyState = (TextView) view.findViewById(R.id.empty_state);
    emptyImage = (ImageView) view.findViewById(R.id.image);
    emptyUpdatingProgress = view.findViewById(R.id.empty_updating_progress);

    final SwipeRefreshLayout swipeToRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swipe_to_refresh);
    Utils.applySwipeLayoutColors(swipeToRefresh);
    swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            swipeToRefresh.setRefreshing(false);
            UpdateService.updateNow(activity);
        }
    });

}
 
Example #21
Source File: SectionDataManager.java    From sectioned-recycler-view with MIT License 5 votes vote down vote up
/**
 * Restricts dragging for all items and swiping for section headers. Returns swipe flags
 * obtained from corresponding {@link SectionItemSwipeCallback}, if it exists and the
 * swiping is enabled.
 */
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    int swipeFlags = 0;
    if (!isTypeHeader(viewHolder.getItemViewType())) {
        SectionItemSwipeCallback swipeCallback = getSwipeCallback(viewHolder);
        if (swipeCallback != null && swipeCallback.isSwipeEnabled()) {
            ViewHolderWrapper viewHolderWrapper = (ViewHolderWrapper) viewHolder;
            swipeFlags = swipeCallback.getSwipeDirFlags(recyclerView, (BaseSectionAdapter.ItemViewHolder) viewHolderWrapper.viewHolder);
        }
    }
    return ItemTouchHelper.Callback.makeMovementFlags(0, swipeFlags);
}
 
Example #22
Source File: IgnoreSetting.java    From MemoryCleaner with Apache License 2.0 5 votes vote down vote up
@Override
public void initViews(IgnoreListAdapter recyclerAdapter, Context context, ItemTouchHelper itemTouchHelper) {
    mWaveView.setVisibility(View.GONE);
    recyclerView.setLayoutManager(
            new LinearLayoutManager(context, LinearLayoutManager.VERTICAL,
                    false));
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(recyclerAdapter);
    //mSwipeRefreshLayout.setOnRefreshListener(mIgnoreSettingPresenter);
    mSwipeRefreshLayout.setColorSchemeColors(getColorPrimary());
    mRecyclerFastScroller.attachRecyclerView(recyclerView);
    mCollapsingToolbarLayout.setTitle(0 + "个应用");
    itemTouchHelper.attachToRecyclerView(recyclerView);
}
 
Example #23
Source File: WalletFragment.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
SwipeCallback(TokensAdapter adapter) {
    super(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
    mAdapter = adapter;
    if (getActivity() != null) {
        icon = ContextCompat.getDrawable(getActivity(), R.drawable.ic_hide_token);
        if (icon != null) {
            icon.setTint(ContextCompat.getColor(getActivity(), R.color.white));
        }
        background = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.cancel_red));
    }
}
 
Example #24
Source File: CustomNewsActivity.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
private void initRecycle() {
    adapter = new ChannelCustomAdapter(CustomNewsActivity.this);
    adapter.setOnStartDragListener(CustomNewsActivity.this);
    adapter.setOnChangeListener(CustomNewsActivity.this);
    getBinding().content.setAdapter(adapter);
    getBinding().content.setHasFixedSize(true);

    ItemTouchHelper.Callback callback = simpleItemTouch(adapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(getBinding().content);
}
 
Example #25
Source File: ItemTouchHelperCallback.java    From voice-pitch-analyzer with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder)
{
    final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
    final int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
    return makeMovementFlags(dragFlags, swipeFlags);
}
 
Example #26
Source File: QueueActivity.java    From PainlessMusicPlayer 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_IDLE) {
        if (viewHolder instanceof ItemTouchHelperViewHolder) {
            ((ItemTouchHelperViewHolder) viewHolder).onItemSelected();
        }
    }

    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #27
Source File: AssignmentsAdapter.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onItemRemoved(int position, int direction) {
    isPositionChanged = true;
    Assignment mJustDeletedToDoItem = getData().remove(position);
    notifyItemRemoved(position);
    if (onItemRemovedListener != null) {
        if (direction == ItemTouchHelper.END) {
            onItemRemovedListener.onItemRemovedRight(mJustDeletedToDoItem, position);
        } else if (direction == ItemTouchHelper.START) {
            onItemRemovedListener.onItemRemovedLeft(mJustDeletedToDoItem, position);
        }
    }
}
 
Example #28
Source File: SimpleItemTouchHelperCallback.java    From Xrv 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();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            viewHolder.itemView.setAlpha(alpha);
            viewHolder.itemView.setTranslationX(dX);
        }
    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}
 
Example #29
Source File: ItemDragHelperCallBack.java    From FriendBook with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    int dragFlags;
    if (manager instanceof GridLayoutManager || manager instanceof StaggeredGridLayoutManager) {
        //监听上下左右拖动
        dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
    } else {
        dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
    }
    return makeMovementFlags(dragFlags, 0);
}
 
Example #30
Source File: SelectRecycleAdapter.java    From PowerRecyclerView with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public int[] getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    if (viewHolder.getAdapterPosition() % 2 == 0) {
        return new int[] { ItemTouchHelper.UP | ItemTouchHelper.DOWN
            | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, ItemTouchHelper.ACTION_STATE_IDLE };
    }
    return super.getMovementFlags(recyclerView, viewHolder);
}