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

The following examples show how to use androidx.recyclerview.widget.RecyclerView#getChildViewHolder() . 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: DashboardRecyclerItemClickListener.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) {
        if(mGestureDetector.onTouchEvent(e)) {
            mListener.onItemClick(view.getChildViewHolder(childView), view.getChildAdapterPosition(childView));
        }
        else if(e.getAction() == MotionEvent.ACTION_DOWN) {
            startDragX = (int) e.getRawX();
            startDragY = (int) e.getRawY();
            startDragItem = view.getChildViewHolder(childView);
        } else if (e.getAction() == MotionEvent.ACTION_UP) {
            int xCoord = (int) e.getRawX();
            int yCoord = (int) e.getRawY();
            RecyclerView.ViewHolder selectedView = view.getChildViewHolder(childView);
            if(Math.abs(startDragY-yCoord) > Math.abs(startDragX - xCoord)) {
                return false;
            }
            if(xCoord - startDragX > 10) {
                Log.d("**Russ", "flipright");
                mListener.onDragRight(startDragItem, view.getChildAdapterPosition(childView));
            } else if(startDragX - xCoord > 10) {
                Log.d("**Russ", "flipleft");
                mListener.onDragLeft(startDragItem, view.getChildAdapterPosition(childView));
            }
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: FeatureAdapterItemDecoration.java    From FeatureAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
  final RecyclerView.ViewHolder holder = parent.getChildViewHolder(view);
  final int viewType = holder.getItemViewType();
  final FeatureItemDecoration decoration = viewTypeDecorationMap.get(viewType);
  if (decoration != null) {
    decoration.getItemOffsetsImpl(outRect, view, holder, parent, state);
  }
}
 
Example 3
Source File: FeatureAdapterItemDecoration.java    From FeatureAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
  if (parent.getLayoutManager() == null) {
    return;
  }
  for (int i = 0; i < parent.getChildCount(); i++) {
    final View view = parent.getChildAt(i);
    final RecyclerView.ViewHolder holder = parent.getChildViewHolder(view);
    final int viewType = holder.getItemViewType();
    final FeatureItemDecoration decoration = viewTypeDecorationMap.get(viewType);
    if (decoration != null) {
      decoration.onDrawViewImpl(canvas, view, holder, parent, state);
    }
  }
}
 
Example 4
Source File: NotificationRulesAdapter.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean hasDivider(RecyclerView parent, View view) {
    RecyclerView.ViewHolder holder = parent.getChildViewHolder(view);
    int viewType = holder.getItemViewType();
    return viewType != TYPE_HEADER && viewType != TYPE_TIP && !(viewType == TYPE_USER_RULE
            && ((RuleHolder) holder).mIsDragged);
}
 
Example 5
Source File: DCCTransferListAdapter.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
public void updateActiveProgress(RecyclerView recyclerView) {
    int cnt = recyclerView.getChildCount();
    for (int i = 0; i < cnt; i++) {
        View view = recyclerView.getChildAt(i);
        RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(view);
        if (holder instanceof ActiveTransferHolder)
            ((ActiveTransferHolder) holder).updateProgress();
    }
}
 
Example 6
Source File: EpoxyVisibilityTracker.java    From epoxy with Apache License 2.0 5 votes vote down vote up
/**
 * Don't call this method directly, it is called from
 * {@link EpoxyVisibilityTracker#processVisibilityEvents}
 *
 * @param child               the view to process for visibility event
 * @param detachEvent         true if the child was just detached
 * @param eventOriginForDebug a debug strings used for logs
 */
private void processChild(@NonNull View child, boolean detachEvent, String eventOriginForDebug) {
  final RecyclerView recyclerView = attachedRecyclerView;
  if (recyclerView != null) {
    // Preemptive check for child's parent validity to prevent `IllegalArgumentException` in
    // `getChildViewHolder`.
    final boolean isParentValid = child.getParent() == null || child.getParent() == recyclerView;
    final ViewHolder holder = isParentValid ? recyclerView.getChildViewHolder(child) : null;
    if (holder instanceof EpoxyViewHolder) {
      boolean changed = processVisibilityEvents(
          recyclerView,
          (EpoxyViewHolder) holder,
          detachEvent,
          eventOriginForDebug
      );
      if (changed) {
        if (child instanceof RecyclerView) {
          EpoxyVisibilityTracker tracker = nestedTrackers.get(child);
          if (tracker != null) {
            // If view visibility changed and there was a tracker on it then notify it.
            tracker.processChangeEvent("parent");
          }
        }
      }
    }
  }
}
 
Example 7
Source File: DefaultAdapter.java    From MVPArms with Apache License 2.0 5 votes vote down vote up
/**
 * 遍历所有 {@link BaseHolder}, 释放他们需要释放的资源
 *
 * @param recyclerView {@link RecyclerView}
 */
public static void releaseAllHolder(RecyclerView recyclerView) {
    if (recyclerView == null) {
        return;
    }
    for (int i = recyclerView.getChildCount() - 1; i >= 0; i--) {
        final View view = recyclerView.getChildAt(i);
        RecyclerView.ViewHolder viewHolder = recyclerView.getChildViewHolder(view);
        if (viewHolder instanceof BaseHolder) {
            ((BaseHolder) viewHolder).onRelease();
        }
    }
}
 
Example 8
Source File: AbstractPreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Returns, whether a divider should be drawn above a view, or not.
 *
 * @param view
 *         The view, which should be checked, as an instance of the class {@link View}. The
 *         view may not be null
 * @param recyclerView
 *         The recycler view, the given view belongs to, as an instance of the class {@link
 *         RecyclerView}. The recycler view may not be null
 * @return True, if a divider should be drawn above the given view, false otherwise
 */
private boolean shouldDrawDividerAbove(@NonNull final View view,
                                       @NonNull final RecyclerView recyclerView) {
    RecyclerView.ViewHolder viewHolder = recyclerView.getChildViewHolder(view);
    int position = viewHolder.getAdapterPosition();

    if (position > 0) {
        @SuppressLint("RestrictedApi") Preference preference = adapter.getItem(position);
        return preference instanceof PreferenceGroup;
    }

    return false;
}
 
Example 9
Source File: FlexibleItemDecoration.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
protected void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int itemCount = parent.getChildCount();
    for (int i = 0; i < itemCount - mDividerOnLastItem; i++) {
        final View child = parent.getChildAt(i);
        RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);
        if (shouldDrawDivider(viewHolder)) {
            parent.getDecoratedBoundsWithMargins(child, mBounds);
            final int bottom = mBounds.bottom + Math.round(child.getTranslationY());
            final int top = bottom - mDivider.getIntrinsicHeight();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
    }
    canvas.restore();
}
 
Example 10
Source File: FlexibleItemDecoration.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
protected void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int top;
    final int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int itemCount = parent.getChildCount();
    for (int i = 0; i < itemCount - mDividerOnLastItem; i++) {
        final View child = parent.getChildAt(i);
        RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);
        if (shouldDrawDivider(viewHolder)) {
            parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
            final int right = mBounds.right + Math.round(child.getTranslationX());
            final int left = right - mDivider.getIntrinsicWidth();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
    }
    canvas.restore();
}
 
Example 11
Source File: IRCLinkActivity.java    From revolution-irc with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean hasDivider(RecyclerView parent, View view) {
    RecyclerView.ViewHolder holder = parent.getChildViewHolder(view);
    int viewType = holder.getItemViewType();
    return viewType != TYPE_HEADER && viewType != TYPE_TEXT;
}