private void initLayoutManager(final RecyclerView.LayoutManager layoutManager) { this.layoutManager = layoutManager; if (layoutManager instanceof GridLayoutManager) { final GridLayoutManager castedLayoutManager = (GridLayoutManager) layoutManager; final SpanSizeLookup existingLookup = castedLayoutManager.getSpanSizeLookup(); castedLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (isHeader(position) || isFooter(position)) { return castedLayoutManager.getSpanCount(); } return existingLookup.getSpanSize(getRealPosition(position)); } }); } }
void setFullSpanForGird(GridLayoutManager gridLayoutManager) { SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup(); if (mOriginSpanSizeLookup == spanSizeLookup) {//first in if (mInnerSpanSizeLookup == null) { mInnerSpanSizeLookup = new InnerSpanSizeLookup(mOriginSpanSizeLookup, gridLayoutManager); } gridLayoutManager.setSpanSizeLookup(mInnerSpanSizeLookup); return; } if (mInnerSpanSizeLookup != spanSizeLookup) {//spanSizeLookup is new mOriginSpanSizeLookup = spanSizeLookup; mInnerSpanSizeLookup = new InnerSpanSizeLookup(mOriginSpanSizeLookup, gridLayoutManager); gridLayoutManager.setSpanSizeLookup(mInnerSpanSizeLookup); } }
private void init() { GridLayoutManager manager = new GridLayoutManager(this, 4); this.mRecyclerView.setLayoutManager(manager); ItemTouchHelper helper = new ItemTouchHelper(new ItemDragHelperCallback()); helper.attachToRecyclerView(this.mRecyclerView); this.mAdapter = new ChannelFragmentAdapter(this, helper, this.mChannelListBean, this.mRecyclerView); this.mAdapter.setFrom(this.mFromMineCustom); manager.setSpanSizeLookup(new SpanSizeLookup(this) { final /* synthetic */ ChannelWallActivity this$0; { if (HotFix.PREVENT_VERIFY) { System.out.println(VerifyLoad.class); } this.this$0 = this$0; } public int getSpanSize(int position) { int viewType = this.this$0.mAdapter.getItemViewType(position); if (viewType == 2 || viewType == 1) { return 1; } return 4; } }); this.mRecyclerView.setAdapter(this.mAdapter); }
static void setSpanSizeLookup(final Adapter adapter, final GridLayoutManager layoutManager) { layoutManager.setSpanSizeLookup(new SpanSizeLookup() { public int getSpanSize(int position) { int type = adapter.getItemViewType(position); if (type == RcvAdapterWrapper.TYPE_HEADER || type == RcvAdapterWrapper.TYPE_FOOTER) { return layoutManager.getSpanCount(); } return 1; } }); }
void cleanFullSpanIfNeed(RecyclerView recyclerView) { RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { SpanSizeLookup spanSizeLookup = ((GridLayoutManager) layoutManager).getSpanSizeLookup(); if (spanSizeLookup == mInnerSpanSizeLookup) { ((GridLayoutManager) layoutManager).setSpanSizeLookup(mOriginSpanSizeLookup); } } }
@Override public void getItemOffsets(Rect rect, View view, RecyclerView parent, State state) { int pos = parent.getChildLayoutPosition(view); if (pos == NO_POSITION) { return; } int items = state.getItemCount(); int spans = LayoutManagers.getSpanCount(parent); SpanSizeLookup lookup = LayoutManagers.getSpanSizeLookup(parent); /* vertical orientation terminology, mentally swap "row" and "col[umn]" for horizontal */ int row = lookup.getSpanGroupIndex(pos, spans); int col = lookup.getSpanIndex(pos, spans); int nextCol = col + lookup.getSpanSize(pos); boolean row1 = row == 0; boolean rowN = pos == items - 1 || row == lookup.getSpanGroupIndex(items - 1, spans); boolean col1 = col == 0; boolean col2 = col == 1; boolean col2N = nextCol == spans - 1; boolean colN = nextCol == spans; rect.top = row1 ? 0 : mHalf; rect.bottom = rowN ? 0 : mHalf; if (spans <= 2) { rect.left = col1 ? 0 : mHalf; rect.right = colN ? 0 : mHalf; } else { // inset first and last columns more to keep all items same size rect.left = col1 ? 0 : col2 ? mThird : colN ? mTwoThirds : mHalf; rect.right = col1 && !colN ? mTwoThirds : col2N ? mThird : colN ? 0 : mHalf; } if (LayoutManagers.getOrientation(parent) == HORIZONTAL) { // rotate //noinspection SuspiciousNameCombination rect.set(rect.top, rect.left, rect.bottom, rect.right); } }
/** * If the RecyclerView uses a {@link GridLayoutManager}, get its SpanSizeLookup. Otherwise get a * {@link DefaultSpanSizeLookup DefaultSpanSizeLookup}. */ public static SpanSizeLookup getSpanSizeLookup(RecyclerView view) { LayoutManager layout = view.getLayoutManager(); if (layout instanceof GridLayoutManager) { return ((GridLayoutManager) layout).getSpanSizeLookup(); } if (sDefSpanSizeLookup == null) { sDefSpanSizeLookup = new DefaultSpanSizeLookup(); } return sDefSpanSizeLookup; }
InnerSpanSizeLookup(SpanSizeLookup originSpanSizeLookup, GridLayoutManager gridLayoutManager) { mOriginSpanSizeLookup = originSpanSizeLookup; mGridLayoutManager = gridLayoutManager; mSpanCount = mGridLayoutManager.getSpanCount(); }
public final View getView(int paramInt) { if (this.mCategoryView == null) { this.mCategoryView = ((ViewGroup)this.mLayoutInflater.inflate(2130968662, null)); this.mRecyclerView = ((PlayRecyclerView)this.mCategoryView.findViewById(2131755329)); this.mRecyclerView.setVisibility(0); if (!FinskyApp.get().getExperiments().isH20StoreEnabled()) { break label272; } final CategoryAdapterV2 localCategoryAdapterV2 = new CategoryAdapterV2(this.mContext, this.mCategories, this.mNavigationManager, paramInt, this.mToc, this.mBitmapLoader, this.mQuickLinksV2, this.mQuickLinksV2Title, this.mCategoriesTitle, this.mTabMode, this.mParentNode); this.mCategoryAdapter = localCategoryAdapterV2; if (this.mRestoredInstanceState.containsKey("CategoryTab.AdapterInstanceState")) { ObjectMap localObjectMap = (ObjectMap)this.mRestoredInstanceState.get("CategoryTab.AdapterInstanceState"); if (localObjectMap != null) { localCategoryAdapterV2.mQuickLinksInstanceState = ((Bundle)localObjectMap.get("CategoryAdapterV2.QuickLinksViewState")); } } GridLayoutManager localGridLayoutManager = new GridLayoutManager(this.mContext); this.mRecyclerView.setLayoutManager(localGridLayoutManager); localGridLayoutManager.mSpanSizeLookup = new GridLayoutManager.SpanSizeLookup() { public final int getSpanSize(int paramAnonymousInt) { if (localCategoryAdapterV2.displayViewInTwoColumns(paramAnonymousInt)) { return 1; } return 2; } }; this.mRecyclerView.addItemDecoration(new GridMarginItemDecoration(localCategoryAdapterV2)); this.mRecyclerView.addItemDecoration(new CardLookDecoration(this.mContext)); } for (;;) { this.mRecyclerView.setAdapter(this.mCategoryAdapter); if (this.mRestoredInstanceState.containsKey("CategoryTab.RecyclerViewState")) { this.mRecyclerView.restoreInstanceState((Parcelable)this.mRestoredInstanceState.get("CategoryTab.RecyclerViewState")); } return this.mCategoryView; label272: this.mRecyclerView.setLayoutManager(new LinearLayoutManager()); this.mCategoryAdapter = new CategoryAdapter(this.mContext, this.mCategories, this.mNavigationManager, paramInt, this.mToc, this.mBitmapLoader, this.mQuickLinks, this.mTabTitle, this.mTabMode, this.mParentNode); } }