Java Code Examples for androidx.recyclerview.widget.RecyclerView#getChildAdapterPosition()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#getChildAdapterPosition() .
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: GridSpacingItemDecoration.java From UltimateRecyclerView with Apache License 2.0 | 6 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); // item position int column = position % spanCount; // item column if (includeEdge) { outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing) outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing) if (position < spanCount) { // top edge outRect.top = spacing; } outRect.bottom = spacing; // item bottom } else { outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing) outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing) if (position >= spanCount) { outRect.top = spacing; // item top } } }
Example 2
Source File: HeaderShadowDecoration.java From UltimateRecyclerView with Apache License 2.0 | 6 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (parent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(parent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(parent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(parent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(parent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } }
Example 3
Source File: FilterUsersActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) { int width = parent.getWidth(); int top; int childCount = parent.getChildCount() - (single ? 0 : 1); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); View nextChild = i < childCount - 1 ? parent.getChildAt(i + 1) : null; int position = parent.getChildAdapterPosition(child); if (position < skipRows || child instanceof GraySectionCell || nextChild instanceof GraySectionCell) { continue; } top = child.getBottom(); canvas.drawLine(LocaleController.isRTL ? 0 : AndroidUtilities.dp(72), top, width - (LocaleController.isRTL ? AndroidUtilities.dp(72) : 0), top, Theme.dividerPaint); } }
Example 4
Source File: GridSpacingItemDecoration.java From PictureSelector with Apache License 2.0 | 6 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); int column = position % spanCount; if (includeEdge) { outRect.left = spacing - column * spacing / spanCount; outRect.right = (column + 1) * spacing / spanCount; if (position < spanCount) { outRect.top = spacing; } outRect.bottom = spacing; } else { outRect.left = column * spacing / spanCount; outRect.right = spacing - (column + 1) * spacing / spanCount; if (position < spanCount) { outRect.top = spacing; } outRect.bottom = spacing; } }
Example 5
Source File: GridItemDecoration.java From Pixiv-Shaft with MIT License | 6 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); // item position int column = position % spanCount; // item column if (includeEdge) { outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing) outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing) if (position < spanCount) { // top edge outRect.top = spacing; } outRect.bottom = spacing; // item bottom } else { outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing) outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing) if (position >= spanCount) { outRect.top = spacing; // item top } } }
Example 6
Source File: PreferenceFragment.java From MaterialPreference with Apache License 2.0 | 6 votes |
public final boolean shouldDrawDividerBelow(View view, RecyclerView parent) { if (!(parent.getAdapter() instanceof PreferenceGroupAdapter)) { return false; } PreferenceGroupAdapter adapter = (PreferenceGroupAdapter) parent.getAdapter(); int index = parent.getChildAdapterPosition(view); if (index == RecyclerView.NO_POSITION) { return false; } Preference preference = adapter.getItem(index); switch (preference.getDividerBelowVisibility()) { case DividerVisibility.ENFORCED: return true; case DividerVisibility.FORBIDDEN: return false; case DividerVisibility.UNSPECIFIED: default: if (index == adapter.getItemCount() - 1) { return isAllowDividerAfterLastItem(); } return shouldDrawDividerBelow(view, parent, adapter, index, preference); } }
Example 7
Source File: PaddingDecoration.java From Jockey with Apache License 2.0 | 5 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int indexInAdapter = parent.getChildAdapterPosition(view); if (indexInAdapter == 0) { outRect.top += mVerticalPadding; } if (indexInAdapter == parent.getAdapter().getItemCount() - 1) { outRect.bottom += mVerticalPadding; } }
Example 8
Source File: OmegaRecyclerView.java From OmegaRecyclerView with MIT License | 5 votes |
protected int getAdapterPosition(RecyclerView parent, View view) { int childPosition = parent.getChildAdapterPosition(view); if (parent instanceof OmegaRecyclerView) { RecyclerView.Adapter adapter = parent.getAdapter(); if (adapter instanceof HeaderFooterWrapperAdapter) { return ((HeaderFooterWrapperAdapter) adapter).applyChildPositionToRealPosition(childPosition); } } return childPosition; }
Example 9
Source File: HorizontalHeaderItemDecoration.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { super.onDraw(c, parent, state); boolean foundFirstChild = false; float viewVerticalCenter = 0f; float left = 0f; float limit = -(layout.getMeasuredWidth() / 2f); float initialPosition = ((headerSize / 2f) - (layout.getMeasuredWidth() / 2f) - (margin / 2f)) * PARALLAX_RATIO; for (int i = 0; i < parent.getChildCount(); i++) { View view = parent.getChildAt(i); if (viewVerticalCenter == 0f) { viewVerticalCenter = view.getTop() + (view.getMeasuredHeight() / 2f) - (layout.getMeasuredWidth() / 2f); } if (parent.getChildAdapterPosition(view) == 0) { left = view.getLeft() - (headerSize / 2f) - (layout.getMeasuredWidth() / 2f) - (margin / 2f); left *= PARALLAX_RATIO; if (left < limit) { left = limit; } foundFirstChild = true; break; } } if (!foundFirstChild) { left = limit; } // With API <= 23, there's a bug where if alpha is set to 0, TextViews' alpha is not set correctly int movementPercentage = Math.max((int) (getPercentage(limit, initialPosition, left) * 255), 1); c.save(); c.saveLayerAlpha(new RectF(0, 0, headerSize - 2, c.getHeight()), movementPercentage, Canvas.ALL_SAVE_FLAG); c.translate(left, viewVerticalCenter - VERTICAL_OFFSET); layout.draw(c); c.restore(); }
Example 10
Source File: StickyHeaderDecoration.java From header-decor with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void onDrawOver(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { final int count = parent.getChildCount(); long previousHeaderId = -1; for (int layoutPos = 0; layoutPos < count; layoutPos++) { final View child = parent.getChildAt(layoutPos); final int adapterPos = parent.getChildAdapterPosition(child); if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) { long headerId = adapter.getHeaderId(adapterPos); if (headerId != previousHeaderId) { previousHeaderId = headerId; View header = getHeader(parent, adapterPos).itemView; canvas.save(); final int left = child.getLeft(); final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos); canvas.translate(left, top); header.setTranslationX(left); header.setTranslationY(top); header.draw(canvas); canvas.restore(); } } } }
Example 11
Source File: StickyHeaderDecoration.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
protected int getHeaderTop(RecyclerView parent, View child, View header, int adapterPos, int layoutPos) { int headerHeight = getHeaderHeightForLayout(header); int top = getChildY(parent, child) - headerHeight; if (sticky && layoutPos == 0) { final int count = parent.getChildCount(); final long currentId = adapter.getHeaderId(adapterPos); // find next view with header and compute the offscreen push if needed for (int i = 1; i < count; i++) { int adapterPosHere = parent.getChildAdapterPosition(parent.getChildAt(translatedChildPosition(parent, i))); if (adapterPosHere != RecyclerView.NO_POSITION) { long nextId = adapter.getHeaderId(adapterPosHere); if (nextId != currentId) { final View next = parent.getChildAt(translatedChildPosition(parent, i)); final int offset = getChildY(parent, next) - (headerHeight + getHeader(parent, adapter, adapterPosHere).itemView.getHeight()); if (offset < 0) { return offset; } else { break; } } } } if (sticky) top = Math.max(0, top); } return top; }
Example 12
Source File: StickyHeaderDecoration.java From GetApk with MIT License | 5 votes |
private boolean isStickyView(RecyclerView parent, View v) { if (v == null) { return false; } int position = parent.getChildAdapterPosition(v); if (position == RecyclerView.NO_POSITION) { return false; } return isStickyViewType(parent, position, mAdapter.getItemViewType(position)); }
Example 13
Source File: BottomOffsetDecoration.java From green_android with GNU General Public License v3.0 | 5 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); int dataSize = state.getItemCount(); int position = parent.getChildAdapterPosition(view); if (dataSize > 0 && position == dataSize - 1) { outRect.set(0, 0, 0, mBottomOffset); } else { outRect.set(0, 0, 0, 0); } }
Example 14
Source File: HeaderPositionCalculator.java From toktok-android with GNU General Public License v3.0 | 5 votes |
public void initHeaderBounds(@NonNull Rect bounds, @NonNull RecyclerView recyclerView, @NonNull View header, @NonNull View firstView, boolean firstHeader) { int orientation = mOrientationProvider.getOrientation(recyclerView); initDefaultHeaderOffset(bounds, recyclerView, header, firstView, orientation); if (firstHeader && isStickyHeaderBeingPushedOffscreen(recyclerView, header)) { View viewAfterNextHeader = getFirstViewUnobscuredByHeader(recyclerView, header); int firstViewUnderHeaderPosition = recyclerView.getChildAdapterPosition(viewAfterNextHeader); View secondHeader = mHeaderProvider.getHeader(recyclerView, firstViewUnderHeaderPosition); translateHeaderWithNextHeader(recyclerView, mOrientationProvider.getOrientation(recyclerView), bounds, header, viewAfterNextHeader, secondHeader); } }
Example 15
Source File: GridItemDecoration.java From odyssey with GNU General Public License v3.0 | 5 votes |
@Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { final int position = parent.getChildAdapterPosition(view); // get the current number of columns for the grid final int spanCount = ((GridLayoutManager) parent.getLayoutManager()).getSpanCount(); final int left = isFirstInRow(position, spanCount) ? 0 : mHalfSpacingOffsetPX; final int top = isInFirstRow(position, spanCount) ? 0 : mSpacingOffsetPX; final int right = isLastInRow(position, spanCount) ? 0 : mHalfSpacingOffsetPX; // the offset for the bottom should always be 0 because the top margin of the next row will apply. outRect.set(left, top, right, 0); }
Example 16
Source File: NoteAdapter.java From kolabnotes-android with GNU Lesser General Public License v3.0 | 5 votes |
public void restoreElevation(RecyclerView recyclerView){ for(int i=0; i < recyclerView.getChildCount(); i++){ final View childAt = recyclerView.getChildAt(i); Utils.setElevation(childAt,5); if(i == recyclerView.getChildAdapterPosition(childAt)){ Utils.setElevation(childAt,30); } } }
Example 17
Source File: StickyRecyclerHeadersDecoration.java From toktok-android with GNU General Public License v3.0 | 5 votes |
@Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); int itemPosition = parent.getChildAdapterPosition(view); if (itemPosition == RecyclerView.NO_POSITION) { return; } if (mHeaderPositionCalculator.hasNewHeader(itemPosition, mOrientationProvider.isReverseLayout(parent))) { View header = getHeaderView(parent, itemPosition); setItemOffsetsForHeader(outRect, header, mOrientationProvider.getOrientation(parent)); } }
Example 18
Source File: GridSpaceDecoration.java From NewFastFrame with Apache License 2.0 | 5 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); // item position if (parent instanceof SuperRecyclerView) { SuperRecyclerView superRecyclerView = (SuperRecyclerView) parent; if (superRecyclerView.getHeaderContainer().getChildCount() > position) { return; } position -= superRecyclerView.getHeaderContainer().getChildCount(); } int column = position % spanCount; // item column outRect.top = verticalSize; if (column == spanCount - 1) { if (includeEdge) { outRect.right = horizontalSize; } outRect.left = horizontalSize / 2; } else if (column == 0) { if (includeEdge) { outRect.left = horizontalSize; } outRect.right = horizontalSize / 2; } else { outRect.left = horizontalSize / 2; outRect.right = horizontalSize / 2; } }
Example 19
Source File: SpacesBottomItemDecoration.java From LoopBar with MIT License | 4 votes |
@Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { if (parent.getChildAdapterPosition(view) == parent.getAdapter().getItemCount() - 1) outRect.bottom = getSpace(); }
Example 20
Source File: SpacesLeftItemDecoration.java From LoopBar with MIT License | 4 votes |
@Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { if (parent.getChildAdapterPosition(view) == 0) outRect.left = getSpace(); }