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

The following examples show how to use android.support.v7.widget.helper.ItemTouchHelper#RIGHT . 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: 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 2
Source File: SheetSortController.java    From Musicoco with Apache License 2.0 6 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 3
Source File: LanguagesEditorFragment.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);
    setHasOptionsMenu(true);
    setCanLoadMore(false);
    if(LanguagesEditorActivity.LanguageEditorMode.Sort.equals(mPresenter.getMode())){
        ItemTouchHelperCallback callback = new ItemTouchHelperCallback(
                ItemTouchHelper.UP | ItemTouchHelper.DOWN,
                ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, this);
        itemTouchHelper = new ItemTouchHelper(callback);
        itemTouchHelper.attachToRecyclerView(recyclerView);
        if(PrefUtils.isLanguagesEditorTipAble()){
            showOperationTip(R.string.languages_editor_tip);
            PrefUtils.set(PrefUtils.LANGUAGES_EDITOR_TIP_ABLE, false);
        }
    }
    addVerticalDivider();
    initSearchEditText();
}
 
Example 4
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 5
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 6
Source File: BindDragCallBack.java    From LazyRecyclerAdapter with MIT License 5 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    final int dragFlags;
    final int swipeFlags;
    if (recyclerView.getLayoutManager() instanceof GridLayoutManager
            || recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
        swipeFlags = 0;
    } else {
        dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
        swipeFlags = mSwipeFlags;
    }
    return makeMovementFlags(dragFlags, swipeFlags);
}
 
Example 7
Source File: SWRecyclerView.java    From SwipeableRV with Apache License 2.0 5 votes vote down vote up
@Override
public String getSnackBarMessage(int direction) {
    if (direction == ItemTouchHelper.RIGHT) {
        return mLTRSnackBarMessage;
    } else {
        return mRTLSnackBarMessage;
    }
}
 
Example 8
Source File: ItemDragHelperCallback.java    From Toutiao with Apache License 2.0 5 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    int dragFlags;
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager || manager instanceof StaggeredGridLayoutManager) {
        dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
    } else {
        dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
    }
    // 如果想支持滑动(删除)操作, swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END
    int swipeFlags = 0;
    return makeMovementFlags(dragFlags, swipeFlags);
}
 
Example 9
Source File: MyItemTouchHelperCallback.java    From MaterialDesignDemo with MIT License 5 votes vote down vote up
/**
 * 获取动作标识
 * 动作标识分:dragFlags和swipeFlags
 * dragFlags:列表滚动方向的动作标识(如竖直列表就是上和下,水平列表就是左和右)
 * wipeFlags:与列表滚动方向垂直的动作标识(如竖直列表就是左和右,水平列表就是上和下)
 */
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
    int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
    int flags = makeMovementFlags(dragFlags, swipeFlags);
    return flags;
}
 
Example 10
Source File: CardItemTouchHelperCallback.java    From CardSwipeLayout with MIT License 5 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    int dragFlags = 0;
    int swipeFlags = 0;
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof CardLayoutManager) {
        swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
    }
    return makeMovementFlags(dragFlags, swipeFlags);
}
 
Example 11
Source File: SWRecyclerView.java    From SwipeableRV with Apache License 2.0 5 votes vote down vote up
@Override
@ColorInt
public int getUndoActionTextColor(int direction) {
    if (direction == ItemTouchHelper.RIGHT) {
        return mLTRUndoActionTextColor;
    } else {
        return mRTLUndoActionTextColor;
    }
}
 
Example 12
Source File: ItemTouchHelperCallback.java    From PowerfulRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    int dragFlags = ItemTouchHelper.UP   | ItemTouchHelper.DOWN |
            ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
    int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
    return makeMovementFlags(dragFlags, swipeFlags);
}
 
Example 13
Source File: ConversationListFragment.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
public ArchiveListenerCallback() {
  super(0, ItemTouchHelper.RIGHT);
}
 
Example 14
Source File: BookshelfFragment.java    From MaterialHome with Apache License 2.0 4 votes vote down vote up
@Override
    protected void initEvents() {
        mToolbar.setTitle("Bookshelf");
        spanCount = getResources().getInteger(R.integer.gallery_span_count);
        mBookshelfPresenter = new BookshelfPresenterImpl(this);
        mBookshelfs = new ArrayList<>();
        mSwipeRefreshLayout.setColorSchemeResources(R.color.recycler_color1, R.color.recycler_color2,
                R.color.recycler_color3, R.color.recycler_color4);

        //设置布局管理器
        mLayoutManager = new GridLayoutManager(getActivity(), spanCount);
        mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return mbookshelfAdapter.getItemColumnSpan(position);
            }
        });
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(mLayoutManager);

        //设置adapter
        mbookshelfAdapter = new BookShelfAdapter(getActivity(), mBookshelfs, spanCount);
        mbookshelfAdapter.setSortable(isSortable);
        mRecyclerView.setAdapter(mbookshelfAdapter);

        //设置Item增加、移除动画
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.addOnScrollListener(new RecyclerViewScrollDetector());
        final int space = DensityUtils.dp2px(getActivity(), 4);
        mRecyclerView.addItemDecoration(new StaggeredGridDecoration(space, space, space, space, spanCount));
        mSwipeRefreshLayout.setOnRefreshListener(this);
//        mFab.setImageDrawable(AppCompatResources.getDrawable(getActivity(), R.drawable.ic_action_add_white));
        mFab.setOnClickListener(v -> {
            final BookShelfEditorHolder bookShelfHolder = new BookShelfEditorHolder(getActivity(), "", "");
            final int inputSpace = DensityUtils.dp2px(getActivity(), 16);
            final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setCancelable(false)
                    .setView(bookShelfHolder.getContentView(), inputSpace, inputSpace, inputSpace, inputSpace)
                    .setTitle(UIUtils.getContext().getString(R.string.add_bookshelf))
                    .setNegativeButton(R.string.cancel, (dialog, which) -> {
                        dialog.dismiss();
                        KeyBoardUtils.closeKeyBord(bookShelfHolder.et_bookshelf_name, getActivity());
                    })
                    .setPositiveButton(R.string.ok, (dialog, which) -> {
                        if (!bookShelfHolder.check()) {
                            Snackbar.make(BaseActivity.activity.getToolbar(), R.string.bookshelf_name_is_empty, Snackbar.LENGTH_SHORT).show();
                        } else {
                            mBookshelfPresenter.addBookshelf(bookShelfHolder.getName(), bookShelfHolder.getRemark(), TimeUtils.getCurrentTime());
                        }
                        KeyBoardUtils.closeKeyBord(bookShelfHolder.et_bookshelf_name, getActivity());
                    }).create().show();
        });
        touchHelper = new ItemTouchHelper(new SimpleItemTouchHelperCallback(ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT | ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT));
    }
 
Example 15
Source File: DownloadFileItemHelperCallback.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
public DownloadFileItemHelperCallback(SubsonicFragment fragment, boolean mainList) {
	super(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
	this.fragment = fragment;
	this.mainList = mainList;
}
 
Example 16
Source File: NoteTouchCallback.java    From reductor with Apache License 2.0 4 votes vote down vote up
public NoteTouchCallback(Action1<Integer> onDismissed) {
    super(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
    this.onDismissed = onDismissed;
}
 
Example 17
Source File: ItemDragCallback.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
    int swipeFlags = ItemTouchHelper.ACTION_STATE_IDLE;
    return makeMovementFlags(dragFlags, swipeFlags);
}
 
Example 18
Source File: TrackedBeaconsFragment.java    From beaconloc with Apache License 2.0 4 votes vote down vote up
private void setupSwipe() {

        ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new UndoSwipableCallback(
                ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT));
        swipeToDismissTouchHelper.attachToRecyclerView(mListBeacons);
    }
 
Example 19
Source File: SwipeHandler.java    From ApkTrack with GNU General Public License v3.0 4 votes vote down vote up
public SwipeHandler(CoordinatorLayout cl, AppAdapter adapter)
{
    super(0, ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT);
    _coordinator_layout = cl;
    _adapter = adapter;
}
 
Example 20
Source File: NormalAdapter.java    From PowerRecyclerView with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public int[] getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    return new int[]{ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, ItemTouchHelper.ACTION_STATE_IDLE};
}