Java Code Examples for androidx.recyclerview.widget.RecyclerView#setOnTouchListener()

The following examples show how to use androidx.recyclerview.widget.RecyclerView#setOnTouchListener() . 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: ConversationItemSwipeCallback.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
private void setTouchListener(@NonNull RecyclerView recyclerView,
                              @NonNull RecyclerView.ViewHolder viewHolder,
                              float dx)
{
  recyclerView.setOnTouchListener((v, event) -> {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        shouldTriggerSwipeFeedback = true;
        break;
      case MotionEvent.ACTION_UP:
        handleTouchActionUp(recyclerView, viewHolder, dx);
      case MotionEvent.ACTION_CANCEL:
        swipeBack = true;
        shouldTriggerSwipeFeedback = false;
        resetProgressIfAnimationsDisabled(viewHolder);
        break;
    }
    return false;
  });
}
 
Example 2
Source File: ConversationItemSwipeCallback.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleTouchActionUp(@NonNull RecyclerView recyclerView,
                                 @NonNull RecyclerView.ViewHolder viewHolder,
                                 float dx)
{
  if (dx > SWIPE_SUCCESS_DX) {
    canTriggerSwipe = false;
    onSwiped(viewHolder);
    if (shouldTriggerSwipeFeedback) {
      vibrate(viewHolder.itemView.getContext());
    }
    recyclerView.setOnTouchListener(null);
  }
  recyclerView.cancelPendingInputEvents();
}
 
Example 3
Source File: AccessLogActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_accesslog_date_list, container, false);

    mListAdapter = new DateListAdapter(inflater);
    mListAdapter.setOnItemClickListener((v, position) ->
            gotoAccessLogListFragment(mListAdapter.getItem(position)));
    mListAdapter.setOnItemRemoveListener((data) -> {
        AccessLogProvider provider = getAccessLogProvider();
        if (provider != null) {
            provider.remove(data);
        }
    });

    RecyclerView recyclerView = root.findViewById(R.id.recycler_view_accesslog_date_list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setAdapter(mListAdapter);
    recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
    recyclerView.setOnTouchListener((v, event) -> {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mListAdapter.dismissSnackbar();
                break;
        }
        return false;
    });

    ItemTouchHelper helper = new ItemTouchHelper(new SwipeToDeleteCallback(getContext()) {
        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            mListAdapter.onItemRemove(viewHolder, recyclerView);
        }
    });
    helper.attachToRecyclerView(recyclerView);

    setHasOptionsMenu(true);

    return root;
}
 
Example 4
Source File: SwipeController.java    From geopackage-mapcache-android with MIT License 5 votes vote down vote up
private void setTouchListener(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                              float dX, float dY, int actionState, boolean isCurrentlyActive) {

    recyclerView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            swipeBack = event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP;
            return false;
        }
    });
}
 
Example 5
Source File: AccessLogActivity.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_accesslog_list, container, false);

    mListAdapter = new AccessLogListAdapter(inflater);
    mListAdapter.setOnItemClickListener((view, position) ->
            gotoAccessLogFragment(mListAdapter.getItem(position)));
    mListAdapter.setOnItemRemoveListener((data) -> {
        AccessLogProvider provider = getAccessLogProvider();
        if (provider != null) {
            provider.remove(data);
        }
    });

    mCondition = root.findViewById(R.id.fragment_search_edit_text);

    RecyclerView recyclerView = root.findViewById(R.id.list_view_accesslog_list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setAdapter(mListAdapter);
    recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
    recyclerView.setOnTouchListener((v, event) -> {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mListAdapter.dismissSnackbar();
                break;
        }
        return false;
    });

    ItemTouchHelper helper = new ItemTouchHelper(new SwipeToDeleteCallback(getContext()) {
        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            mListAdapter.onItemRemove(viewHolder, recyclerView);
        }
    });
    helper.attachToRecyclerView(recyclerView);

    root.findViewById(R.id.fragment_search_btn).setOnClickListener((v) -> {
        searchAccessLogs(mCondition.getText().toString());
        InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    });

    setHasOptionsMenu(true);

    return root;
}