private void recycleFromStart(RecyclerView.Recycler recycler, int line, LayoutManagerHelper helper) { final OrientationHelper orientationHelper = helper.getMainOrientationHelper(); boolean changed = true; while (helper.getChildCount() > 0 && changed) { View child = helper.getChildAt(0); if (child != null && orientationHelper.getDecoratedEnd(child) < line) { LayoutParams lp = (LayoutParams) child.getLayoutParams(); int position = lp.getViewPosition(); Span span = findSpan(position, child, true); if (span != null) { span.popStart(orientationHelper); helper.removeChildView(child); recycler.recycleView(child); } else { changed = false; } } else { return;// done } } }
private void recycleFromEnd(RecyclerView.Recycler recycler, int line, LayoutManagerHelper helper) { final OrientationHelper orientationHelper = helper.getMainOrientationHelper(); final int childCount = helper.getChildCount(); int i; for (i = childCount - 1; i >= 0; i--) { View child = helper.getChildAt(i); if (child != null && orientationHelper.getDecoratedStart(child) > line) { LayoutParams lp = (LayoutParams) child.getLayoutParams(); int position = lp.getViewPosition(); Span span = findSpan(position, child, false); if (span != null) { span.popEnd(orientationHelper); helper.removeChildView(child); recycler.recycleView(child); } } else { return;// done } } }
private void recycleFromStart(RecyclerView.Recycler recycler, int line, LayoutManagerHelper helper) { final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper(); boolean changed = true; while (helper.getChildCount() > 0 && changed) { View child = helper.getChildAt(0); if (child != null && orientationHelper.getDecoratedEnd(child) < line) { LayoutParams lp = (LayoutParams) child.getLayoutParams(); int position = lp.getViewPosition(); Span span = findSpan(position, child, true); if (span != null) { span.popStart(orientationHelper); helper.removeChildView(child); recycler.recycleView(child); } else { changed = false; } } else { return;// done } } }
private void recycleFromEnd(RecyclerView.Recycler recycler, int line, LayoutManagerHelper helper) { final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper(); final int childCount = helper.getChildCount(); int i; for (i = childCount - 1; i >= 0; i--) { View child = helper.getChildAt(i); if (child != null && orientationHelper.getDecoratedStart(child) > line) { LayoutParams lp = (LayoutParams) child.getLayoutParams(); int position = lp.getViewPosition(); Span span = findSpan(position, child, false); if (span != null) { span.popEnd(orientationHelper); helper.removeChildView(child); recycler.recycleView(child); } } else { return;// done } } }
public View nextViewInLimitedList(View ignore) { int size = this.mScrapList.size(); View closest = null; int closestDistance = Integer.MAX_VALUE; for (int i = 0; i < size; i++) { View view = ((ViewHolder) this.mScrapList.get(i)).itemView; LayoutParams lp = (LayoutParams) view.getLayoutParams(); if (!(view == ignore || lp.isItemRemoved())) { int distance = (lp.getViewLayoutPosition() - this.mCurrentPosition) * this.mItemDirection; if (distance >= 0 && distance < closestDistance) { closest = view; closestDistance = distance; if (distance == 0) { break; } } } } return closest; }
public View nextViewInLimitedList(View ignore) { int size = this.mScrapList.size(); View closest = null; int closestDistance = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED; for (int i = 0; i < size; i++) { View view = ((ViewHolder) this.mScrapList.get(i)).itemView; LayoutParams lp = (LayoutParams) view.getLayoutParams(); if (!(view == ignore || lp.isItemRemoved())) { int distance = (lp.getViewLayoutPosition() - this.mCurrentPosition) * this.mItemDirection; if (distance >= 0 && distance < closestDistance) { closest = view; closestDistance = distance; if (distance == 0) { break; } } } } return closest; }
private View makeAndAddView(int position, Direction direction, Recycler recycler) { final View child = recycler.getViewForPosition(position); final boolean isItemRemoved = ((LayoutParams) child.getLayoutParams()).isItemRemoved(); if (!isItemRemoved) { addView(child, (direction == Direction.END ? -1 : 0)); } setupChild(child, direction); if (!isItemRemoved) { updateLayoutEdgesFromNewChild(child); } return child; }
@Override protected void layoutChild(View child, Direction direction) { getLaneForChild(mTempLaneInfo, child, direction); mLanes.getChildFrame(mChildFrame, getDecoratedMeasuredWidth(child), getDecoratedMeasuredHeight(child), mTempLaneInfo, direction); final ItemEntry entry = cacheChildFrame(child, mChildFrame); layoutDecorated(child, mChildFrame.left, mChildFrame.top, mChildFrame.right, mChildFrame.bottom); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (!lp.isItemRemoved()) { pushChildFrame(entry, mChildFrame, mTempLaneInfo.startLane, getLaneSpanForChild(child), direction); } }
/** * @param header * @param index * @param orientation */ public int addHeaderView(View header, int index, int orientation) { if (mHeaderLayout == null) { mHeaderLayout = new LinearLayout(header.getContext()); if (orientation == LinearLayout.VERTICAL) { mHeaderLayout.setOrientation(LinearLayout.VERTICAL); mHeaderLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT)); } else { mHeaderLayout.setOrientation(LinearLayout.HORIZONTAL); mHeaderLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT)); } } final int childCount = mHeaderLayout.getChildCount(); if (index < 0 || index > childCount) { index = childCount; } mHeaderLayout.addView(header, index); if (mHeaderLayout.getChildCount() == 1) { int position = getHeaderViewPosition(); if (position != -1) { notifyItemInserted(position); } } return index; }
/** * Add footer view to mFooterLayout and set footer view position in mFooterLayout. * When index = -1 or index >= child count in mFooterLayout, * the effect of this method is the same as that of {@link #addFooterView(View)}. * * @param footer * @param index the position in mFooterLayout of this footer. * When index = -1 or index >= child count in mFooterLayout, * the effect of this method is the same as that of {@link #addFooterView(View)}. */ public int addFooterView(View footer, int index, int orientation) { if (mFooterLayout == null) { mFooterLayout = new LinearLayout(footer.getContext()); if (orientation == LinearLayout.VERTICAL) { mFooterLayout.setOrientation(LinearLayout.VERTICAL); mFooterLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT)); } else { mFooterLayout.setOrientation(LinearLayout.HORIZONTAL); mFooterLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT)); } } final int childCount = mFooterLayout.getChildCount(); if (index < 0 || index > childCount) { index = childCount; } mFooterLayout.addView(footer, index); if (mFooterLayout.getChildCount() == 1) { int position = getFooterViewPosition(); if (position != -1) { notifyItemInserted(position); } } return index; }
public void setEmptyView(View emptyView) { boolean insert = false; if (mEmptyLayout == null) { mEmptyLayout = new FrameLayout(emptyView.getContext()); final LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); final ViewGroup.LayoutParams lp = emptyView.getLayoutParams(); if (lp != null) { layoutParams.width = lp.width; layoutParams.height = lp.height; } mEmptyLayout.setLayoutParams(layoutParams); insert = true; } mEmptyLayout.removeAllViews(); mEmptyLayout.addView(emptyView); mIsUseEmpty = true; if (insert) { if (getEmptyViewCount() == 1) { int position = 0; if (mHeadAndEmptyEnable && getHeaderLayoutCount() != 0) { position++; } notifyItemInserted(position); } } }
/** * @param header * @param index * @param orientation */ public void addHeaderView(View header, int index, int orientation) { if (mHeaderLayout == null) { if (mCopyHeaderLayout == null) { mHeaderLayout = new LinearLayout(header.getContext()); if (orientation == LinearLayout.VERTICAL) { mHeaderLayout.setOrientation(LinearLayout.VERTICAL); mHeaderLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT)); } else { mHeaderLayout.setOrientation(LinearLayout.HORIZONTAL); mHeaderLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT)); } mCopyHeaderLayout = mHeaderLayout; } else { mHeaderLayout = mCopyHeaderLayout; } } index = index >= mHeaderLayout.getChildCount() ? -1 : index; mHeaderLayout.addView(header, index); this.notifyDataSetChanged(); }
/** * Add footer view to mFooterLayout and set footer view position in mFooterLayout. * When index = -1 or index >= child count in mFooterLayout, * the effect of this method is the same as that of {@link #addFooterView(View)}. * * @param footer * @param index the position in mFooterLayout of this footer. * When index = -1 or index >= child count in mFooterLayout, * the effect of this method is the same as that of {@link #addFooterView(View)}. */ public void addFooterView(View footer, int index) { mNextLoadEnable = false; if (mFooterLayout == null) { if (mCopyFooterLayout == null) { mFooterLayout = new LinearLayout(footer.getContext()); mFooterLayout.setOrientation(LinearLayout.VERTICAL); mFooterLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT)); mCopyFooterLayout = mFooterLayout; } else { mFooterLayout = mCopyFooterLayout; } } index = index >= mFooterLayout.getChildCount() ? -1 : index; mFooterLayout.addView(footer, index); this.notifyItemChanged(getItemCount()); }
/** * @param header * @param index * @param orientation */ public void addHeaderView(View header, int index, int orientation) { if (mHeaderLayout == null) { mHeaderLayout = new LinearLayout(header.getContext()); if (orientation == LinearLayout.VERTICAL) { mHeaderLayout.setOrientation(LinearLayout.VERTICAL); mHeaderLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT)); } else { mHeaderLayout.setOrientation(LinearLayout.HORIZONTAL); mHeaderLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT)); } } index = index >= mHeaderLayout.getChildCount() ? -1 : index; mHeaderLayout.addView(header, index); if (mHeaderLayout.getChildCount() == 1) { int position = getHeaderViewPosition(); if (position != -1) { notifyItemInserted(position); } } }
/** * Add footer view to mFooterLayout and set footer view position in mFooterLayout. * When index = -1 or index >= child count in mFooterLayout, * the effect of this method is the same as that of {@link #addFooterView(View)}. * * @param footer * @param index the position in mFooterLayout of this footer. * When index = -1 or index >= child count in mFooterLayout, * the effect of this method is the same as that of {@link #addFooterView(View)}. */ public void addFooterView(View footer, int index) { if (mFooterLayout == null) { mFooterLayout = new LinearLayout(footer.getContext()); mFooterLayout.setOrientation(LinearLayout.VERTICAL); mFooterLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT)); } index = index >= mFooterLayout.getChildCount() ? -1 : index; mFooterLayout.addView(footer, index); if (mFooterLayout.getChildCount() == 1) { int position = getFooterViewPosition(); if (position != -1) { notifyItemInserted(position); } } }
public void setEmptyView(View emptyView) { boolean insert = false; if (mEmptyView == null) { mEmptyView = new FrameLayout(emptyView.getContext()); mEmptyView.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT)); insert = true; } mEmptyView.removeAllViews(); mEmptyView.addView(emptyView); mIsUseEmpty = true; if (insert) { if (getEmptyViewCount() == 1) { int position = 0; if (mHeadAndEmptyEnable && getHeaderLayoutCount() != 0) { position++; } notifyItemInserted(position); } } }
public void setEmptyView(View emptyView) { boolean insert = false; if (mEmptyView == null) { mEmptyView = new FrameLayout(emptyView.getContext()); mEmptyView.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT)); insert = true; } mEmptyView.removeAllViews(); mEmptyView.addView(emptyView); mIsUseEmpty = true; if (insert) { if (getEmptyViewCount() == 1) { notifyItemInserted(0); } } }
void prependToSpan(View view, OrientationHelper helper) { LayoutParams lp = getLayoutParams(view); mViews.add(0, view); mCachedStart = INVALID_LINE; if (mViews.size() == 1) { mCachedEnd = INVALID_LINE; } if (lp.isItemRemoved() || lp.isItemChanged()) { mDeletedSize += helper.getDecoratedMeasurement(view); } }
void appendToSpan(View view, OrientationHelper helper) { LayoutParams lp = getLayoutParams(view); mViews.add(view); mCachedEnd = INVALID_LINE; if (mViews.size() == 1) { mCachedStart = INVALID_LINE; } if (lp.isItemRemoved() || lp.isItemChanged()) { mDeletedSize += helper.getDecoratedMeasurement(view); } }
void popEnd(OrientationHelper helper) { final int size = mViews.size(); View end = mViews.remove(size - 1); final LayoutParams lp = getLayoutParams(end); if (lp.isItemRemoved() || lp.isItemChanged()) { mDeletedSize -= helper.getDecoratedMeasurement(end); } if (size == 1) { mCachedStart = INVALID_LINE; } mCachedEnd = INVALID_LINE; }
void popStart(OrientationHelper helper) { View start = mViews.remove(0); final LayoutParams lp = getLayoutParams(start); if (mViews.size() == 0) { mCachedEnd = INVALID_LINE; } if (lp.isItemRemoved() || lp.isItemChanged()) { mDeletedSize -= helper.getDecoratedMeasurement(start); } mCachedStart = INVALID_LINE; }
void prependToSpan(View view, OrientationHelperEx helper) { LayoutParams lp = getLayoutParams(view); mViews.add(0, view); mCachedStart = INVALID_LINE; if (mViews.size() == 1) { mCachedEnd = INVALID_LINE; } if (lp.isItemRemoved() || lp.isItemChanged()) { mDeletedSize += helper.getDecoratedMeasurement(view); } }
void appendToSpan(View view, OrientationHelperEx helper) { LayoutParams lp = getLayoutParams(view); mViews.add(view); mCachedEnd = INVALID_LINE; if (mViews.size() == 1) { mCachedStart = INVALID_LINE; } if (lp.isItemRemoved() || lp.isItemChanged()) { mDeletedSize += helper.getDecoratedMeasurement(view); } }
void popEnd(OrientationHelperEx helper) { final int size = mViews.size(); View end = mViews.remove(size - 1); final LayoutParams lp = getLayoutParams(end); if (lp.isItemRemoved() || lp.isItemChanged()) { mDeletedSize -= helper.getDecoratedMeasurement(end); } if (size == 1) { mCachedStart = INVALID_LINE; } mCachedEnd = INVALID_LINE; }
void popStart(OrientationHelperEx helper) { View start = mViews.remove(0); final LayoutParams lp = getLayoutParams(start); if (mViews.size() == 0) { mCachedEnd = INVALID_LINE; } if (lp.isItemRemoved() || lp.isItemChanged()) { mDeletedSize -= helper.getDecoratedMeasurement(start); } mCachedStart = INVALID_LINE; }
public int calculateDyToMakeVisible(View view, int snapPreference) { LayoutManager layoutManager = getLayoutManager(); if (layoutManager == null || !layoutManager.canScrollVertically()) { return 0; } LayoutParams params = (LayoutParams) view.getLayoutParams(); return calculateDtToFit(layoutManager.getDecoratedTop(view) - params.topMargin, layoutManager.getDecoratedBottom(view) + params.bottomMargin, layoutManager.getPaddingTop(), layoutManager.getHeight() - layoutManager.getPaddingBottom(), snapPreference); }
public int calculateDxToMakeVisible(View view, int snapPreference) { LayoutManager layoutManager = getLayoutManager(); if (layoutManager == null || !layoutManager.canScrollHorizontally()) { return 0; } LayoutParams params = (LayoutParams) view.getLayoutParams(); return calculateDtToFit(layoutManager.getDecoratedLeft(view) - params.leftMargin, layoutManager.getDecoratedRight(view) + params.rightMargin, layoutManager.getPaddingLeft(), layoutManager.getWidth() - layoutManager.getPaddingRight(), snapPreference); }
private View nextViewFromScrapList() { int size = this.mScrapList.size(); for (int i = 0; i < size; i++) { View view = ((ViewHolder) this.mScrapList.get(i)).itemView; LayoutParams lp = (LayoutParams) view.getLayoutParams(); if (!lp.isItemRemoved() && this.mCurrentPosition == lp.getViewLayoutPosition()) { assignPositionFromScrapList(view); return view; } } return null; }
public void assignPositionFromScrapList(View ignore) { View closest = nextViewInLimitedList(ignore); if (closest == null) { this.mCurrentPosition = -1; } else { this.mCurrentPosition = ((LayoutParams) closest.getLayoutParams()).getViewLayoutPosition(); } }