Java 类android.support.v7.widget.GridLayoutManager.SpanSizeLookup 实例源码

项目:easy-header-footer-adapter    文件:EasyHeaderFooterAdapter.java   
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));
            }
        });
    }
}
项目:WrapperAdapter    文件:KeepFullSpanHelper.java   
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);
    }

}
项目:letv    文件:ChannelWallActivity.java   
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);
}
项目:boohee_v5.6    文件:RcvAdapterWrapper.java   
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;
        }
    });
}
项目:WrapperAdapter    文件:KeepFullSpanHelper.java   
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);
        }
    }
}
项目:sprockets-android    文件:InsetDecoration.java   
@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);
    }
}
项目:sprockets-android    文件:LayoutManagers.java   
/**
 * 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;
}
项目:WrapperAdapter    文件:KeepFullSpanHelper.java   
InnerSpanSizeLookup(SpanSizeLookup originSpanSizeLookup, GridLayoutManager gridLayoutManager) {
    mOriginSpanSizeLookup = originSpanSizeLookup;
    mGridLayoutManager = gridLayoutManager;
    mSpanCount = mGridLayoutManager.getSpanCount();
}
项目:FMTech    文件:CategoryTab.java   
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);
  }
}