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

The following examples show how to use androidx.recyclerview.widget.RecyclerView#findChildViewUnder() . 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: RowHeaderRecyclerViewItemClickListener.java    From TableView with MIT License 6 votes vote down vote up
@Override
protected boolean clickAction(@NonNull RecyclerView view, @NonNull MotionEvent e) {
    // Get interacted view from x,y coordinate.
    View childView = view.findChildViewUnder(e.getX(), e.getY());

    if (childView != null) {
        // Find the view holder
        AbstractViewHolder holder = (AbstractViewHolder) mRecyclerView.getChildViewHolder
                (childView);

        int row = holder.getAdapterPosition();

        // Control to ignore selection color
        if (!mTableView.isIgnoreSelectionColors()) {
            mSelectionHandler.setSelectedRowPosition(holder, row);
        }

        // Call ITableView listener for item click
        getTableViewListener().onRowHeaderClicked(holder, row);
        return true;
    }
    return false;
}
 
Example 2
Source File: StickyHeaderDecoration.java    From GetApk with MIT License 6 votes vote down vote up
@Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
        createPinnedHeader(parent);

        if (mStickyView != null) {
            View v = parent.findChildViewUnder(c.getWidth() / 2, mStickyView.getHeight() + 0.5f);
//            View firstVisibleItemView = parent.getLayoutManager().getChildAt(0);
//            int firstVisiblePosition = ((RecyclerView.LayoutParams) firstVisibleItemView.getLayoutParams()).getViewAdapterPosition();
            if (isStickyView(parent, v)) {
                mStickyHeaderTop = v.getTop() - mStickyView.getHeight();
            } else {
                mStickyHeaderTop = 0;
            }
            mClipBounds = c.getClipBounds();
            mClipBounds.top = mStickyHeaderTop;
            mClipBounds.bottom = mStickyHeaderTop + mStickyView.getHeight();
        }
    }
 
Example 3
Source File: ColumnHeaderRecyclerViewItemClickListener.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected boolean clickAction(RecyclerView view, MotionEvent e) {
    // Get interacted view from x,y coordinate.
    View childView = view.findChildViewUnder(e.getX(), e.getY());

    if (childView != null) {
        // Find the view holder
        AbstractViewHolder holder = (AbstractViewHolder) mRecyclerView.getChildViewHolder
                (childView);

        int column = holder.getAdapterPosition();

        // Control to ignore selection color
        if (!mTableView.isIgnoreSelectionColors()) {
            mSelectionHandler.setSelectedColumnPosition(holder, column);
        }

        if (getTableViewListener() != null) {
            // Call ITableView listener for item click
            getTableViewListener().onColumnHeaderClicked(holder, column);
        }

        return true;
    }
    return false;
}
 
Example 4
Source File: RowHeaderRecyclerViewItemClickListener.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected boolean clickAction(RecyclerView view, MotionEvent e) {
    // Get interacted view from x,y coordinate.
    View childView = view.findChildViewUnder(e.getX(), e.getY());

    if (childView != null) {
        // Find the view holder
        AbstractViewHolder holder = (AbstractViewHolder) mRecyclerView.getChildViewHolder
                (childView);

        int row = holder.getAdapterPosition();

        // Control to ignore selection color
        if (!mTableView.isIgnoreSelectionColors()) {
            mSelectionHandler.setSelectedRowPosition(holder, row);
        }

        if (getTableViewListener() != null) {
            // Call ITableView listener for item click
            getTableViewListener().onRowHeaderClicked(holder, row);
        }
        return true;
    }
    return false;
}
 
Example 5
Source File: CustomRecyclerView.java    From msdkui-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(final RecyclerView view, final MotionEvent e) {
    final View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClicked(view.getChildAdapterPosition(childView), childView);
        return true;
    }
    return false;
}
 
Example 6
Source File: DoubleHeaderFragment.java    From header-decor with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(@NonNull RecyclerView recyclerView,
        @NonNull MotionEvent event) {
    // really bad click detection just for demonstration purposes
    // it will not allow the list to scroll if the swipe motion starts
    // on top of a header
    return recyclerView.findChildViewUnder(event.getX(), event.getY()) == null;
}
 
Example 7
Source File: RecyclerCollectionEventsController.java    From litho with Apache License 2.0 5 votes vote down vote up
private int getSmoothScrollTarget(boolean forward, int defaultTarget) {
  switch (mSnapMode) {
    case SNAP_NONE:
      return defaultTarget;
    case SNAP_TO_START:
      return Math.max(
          0,
          forward
              ? mFirstCompletelyVisibleItemPosition + 1
              : mFirstCompletelyVisibleItemPosition - 1);
    case SNAP_TO_END: // SNAP_TO_END not yet implemented
      return Math.max(
          0,
          forward
              ? mLastCompletelyVisibleItemPosition + 1
              : mLastCompletelyVisibleItemPosition - 1);
    case SNAP_TO_CENTER:
    case SNAP_TO_CENTER_CHILD:
      final RecyclerView recyclerView = getRecyclerView();
      if (recyclerView == null) {
        return defaultTarget;
      }
      final int centerPositionX = recyclerView.getWidth() / 2;
      final int centerPositionY = recyclerView.getHeight() / 2;
      final View centerView = recyclerView.findChildViewUnder(centerPositionX, centerPositionY);
      if (centerView == null) {
        return defaultTarget;
      }
      final int centerViewPosition = recyclerView.getChildAdapterPosition(centerView);
      return Math.max(0, forward ? centerViewPosition + 1 : centerViewPosition - 1);
    default:
      return defaultTarget;
  }
}
 
Example 8
Source File: RecyclerItemClickListener.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
        return true;
    }
    return false;
}
 
Example 9
Source File: RecyclerItemClickListener.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, view.getChildPosition(childView));
        return true;
    }
    return false;
}
 
Example 10
Source File: StickyHeaderFragment.java    From header-decor with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(@NonNull RecyclerView recyclerView,
        @NonNull MotionEvent event) {
    // really bad click detection just for demonstration purposes
    // it will not allow the list to scroll if the swipe motion starts
    // on top of a header
    View v = recyclerView.findChildViewUnder(event.getX(), event.getY());
    return v == null;
}
 
Example 11
Source File: RecyclerItemClickListener.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());

    if(childView != null && onItemClickListener != null && gestureDetector.onTouchEvent(e)){
        onItemClickListener.onItemClick(childView, view.getChildPosition(childView));
    }

    return false;
}
 
Example 12
Source File: RecyclerItemClickListener.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
        return true;
    }
    return false;
}
 
Example 13
Source File: InlineDoubleHeaderFragment.java    From header-decor with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(@NonNull RecyclerView recyclerView,
        @NonNull MotionEvent event) {
    // really bad click detection just for demonstration purposes
    // it will not allow the list to scroll if the swipe motion starts
    // on top of a header
    return recyclerView.findChildViewUnder(event.getX(), event.getY()) == null;
}
 
Example 14
Source File: OnItemSelectedListener.java    From animation-samples with Apache License 2.0 5 votes vote down vote up
@Override
public final boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
    if (gestureDetector.onTouchEvent(e)) {
        View touchedView = rv.findChildViewUnder(e.getX(), e.getY());
        onItemSelected(rv.findContainingViewHolder(touchedView),
                rv.getChildAdapterPosition(touchedView));
    }
    return false;
}
 
Example 15
Source File: OdysseyRecyclerView.java    From odyssey with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(@NonNull RecyclerView view, @NonNull MotionEvent motionEvent) {
    final View childView = view.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
    if (childView != null && mGestureDetector.onTouchEvent(motionEvent)) {
        childView.playSoundEffect(SoundEffectConstants.CLICK);
        mOnItemClickListener.onItemClick(view.getChildAdapterPosition(childView));
        return true;
    }
    return false;
}
 
Example 16
Source File: RecyclerItemClickListener.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
    }
    return false;
}
 
Example 17
Source File: FavoritesCardItemView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
    View childView = rv.findChildViewUnder(e.getX(), e.getY());
    if(e.getAction() == MotionEvent.ACTION_DOWN) {
        touchX = e.getX();
        return false;
    }
    if (childView != null && e.getAction() == MotionEvent.ACTION_UP && Math.abs(touchX-e.getX()) < 15) {
        onItemClick(rv.getChildAdapterPosition(childView));
        return true;
    }
    return false;
}
 
Example 18
Source File: RecyclerItemClickListener.java    From Word-By-Word-Quran-Android with MIT License 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
  View childView = view.findChildViewUnder(e.getX(), e.getY());

  if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
    mListener.onItemClick(childView, view.getChildLayoutPosition(childView));
  }

  return false;
}
 
Example 19
Source File: ReorderDecoration.java    From RecyclerExt with Apache License 2.0 5 votes vote down vote up
/**
 * This will determine two things.
 * 1. If we need to handle the touch event
 * 2. If reordering needs to start due to dragHandle being clicked
 */
@Override
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent event) {
    if (dragState == DragState.DRAGGING) {
        return true;
    }

    if (dragHandleId == INVALID_RESOURCE_ID) {
        return false;
    }

    View itemView = recyclerView.findChildViewUnder(event.getX(), event.getY());
    if (itemView == null) {
        return false;
    }

    View handleView = itemView.findViewById(dragHandleId);
    if (handleView == null || handleView.getVisibility() != View.VISIBLE) {
        return false;
    }


    int[] handlePosition = new int[2];
    handleView.getLocationOnScreen(handlePosition);

    //Determine if the MotionEvent is inside the handle
    if ((event.getRawX() >= handlePosition[0] && event.getRawX() <= handlePosition[0] + handleView.getWidth()) &&
            (event.getRawY() >= handlePosition[1] && event.getRawY() <= handlePosition[1] + handleView.getHeight())) {
        startReorder(itemView, event);
        return true;
    }

    return false;
}
 
Example 20
Source File: RecyclerViewItemClickListener.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
    }

    return false;
}