Java Code Examples for android.support.v7.widget.RecyclerView#RecycledViewPool

The following examples show how to use android.support.v7.widget.RecyclerView#RecycledViewPool . 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: PractiseFragment.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
private void initVLayout() {
    mAdapters = new LinkedList<>();
    //初始化
    //创建VirtualLayoutManager对象
    layoutManager = new VirtualLayoutManager(activity);
    recyclerView.setLayoutManager(layoutManager);

    //设置回收复用池大小,(如果一屏内相同类型的 View 个数比较多,需要设置一个合适的大小,防止来回滚动时重新创建 View)
    RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
    recyclerView.setRecycledViewPool(viewPool);
    viewPool.setMaxRecycledViews(0, 20);

    //设置适配器
    delegateAdapter = new DelegateAdapter(layoutManager, true);
    recyclerView.setAdapter(delegateAdapter);

    //自定义各种不同适配器
    initAllTypeView();
    //设置适配器
    //delegateAdapter.setAdapters(mAdapters);
}
 
Example 2
Source File: InnovationFragment.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
private void initYCRefreshView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(activity));
    final RecycleViewItemLine line = new RecycleViewItemLine(activity, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new InnovationAdapter(activity);
    recyclerView.setAdapter(adapter);
    addHeader();
    recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            SwipeRefreshLayout swipeToRefresh = recyclerView.getSwipeToRefresh();
            if(swipeToRefresh.isRefreshing()){
                recyclerView.setRefreshing(false);
            }
        }
    });

    //设置回收复用池大小,(如果一屏内相同类型的 View 个数比较多,需要设置一个合适的大小,防止来回滚动时重新创建 View)
    RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
    recyclerView.getRecyclerView().setRecycledViewPool(viewPool);
    viewPool.setMaxRecycledViews(0, 20);
}
 
Example 3
Source File: BannerView.java    From Tangram-Android with MIT License 5 votes vote down vote up
private void recyclerView(List<BinderViewHolder> cache) {
    if (!cache.isEmpty()) {
        RecyclerView.RecycledViewPool pool = cell.serviceManager.getService(RecyclerView.RecycledViewPool.class);
        for (int i = 0, size = cache.size(); i < size; i++) {
            BinderViewHolder viewHolder = cache.get(i);
            viewHolder.unbind();
            removeView(viewHolder.itemView);
            pool.putRecycledView(viewHolder);
        }
        cache.clear();
    }
}
 
Example 4
Source File: LinearScrollView.java    From Tangram-Android with MIT License 5 votes vote down vote up
private View getViewFromRecycler(@NonNull BaseCell cell) {
    GroupBasicAdapter adapter = cell.serviceManager.getService(GroupBasicAdapter.class);
    RecyclerView.RecycledViewPool pool = cell.serviceManager.getService(RecyclerView.RecycledViewPool.class);
    int itemViewType = adapter.getItemType(cell);
    BinderViewHolder holder = (BinderViewHolder) pool.getRecycledView(itemViewType);
    if (holder == null) {
        holder = (BinderViewHolder) adapter.createViewHolder(this, itemViewType);
    }
    holder.bind(cell);
    mViewHolders.add(holder);
    return holder.itemView;
}
 
Example 5
Source File: BannerView.java    From Tangram-Android with MIT License 5 votes vote down vote up
private View getFooterViewFromRecycler(@NonNull BaseCell cell) {
    GroupBasicAdapter adapter = cell.serviceManager.getService(GroupBasicAdapter.class);
    RecyclerView.RecycledViewPool pool = cell.serviceManager.getService(RecyclerView.RecycledViewPool.class);
    int itemViewType = adapter.getItemType(cell);
    BinderViewHolder holder = (BinderViewHolder) pool.getRecycledView(itemViewType);
    if (holder == null) {
        holder = (BinderViewHolder) adapter.createViewHolder(this, itemViewType);
    }
    holder.bind(cell);
    mFooterViewHolders.add(holder);
    return holder.itemView;
}
 
Example 6
Source File: BannerView.java    From Tangram-Android with MIT License 5 votes vote down vote up
private View getHeaderViewFromRecycler(@NonNull BaseCell cell) {
    GroupBasicAdapter adapter = cell.serviceManager.getService(GroupBasicAdapter.class);
    RecyclerView.RecycledViewPool pool = cell.serviceManager.getService(RecyclerView.RecycledViewPool.class);
    int itemViewType = adapter.getItemType(cell);
    BinderViewHolder holder = (BinderViewHolder) pool.getRecycledView(itemViewType);
    if (holder == null) {
        holder = (BinderViewHolder) adapter.createViewHolder(this, itemViewType);
    }
    holder.bind(cell);
    mHeaderViewHolders.add(holder);
    return holder.itemView;
}
 
Example 7
Source File: BannerView.java    From Tangram-Android with MIT License 5 votes vote down vote up
private View getHeaderViewFromRecycler(@NonNull BaseCell cell) {
    GroupBasicAdapter adapter = cell.serviceManager.getService(GroupBasicAdapter.class);
    RecyclerView.RecycledViewPool pool = cell.serviceManager.getService(RecyclerView.RecycledViewPool.class);
    int itemViewType = adapter.getItemType(cell);
    BinderViewHolder holder = (BinderViewHolder) pool.getRecycledView(itemViewType);
    if (holder == null) {
        holder = (BinderViewHolder) adapter.createViewHolder(this, itemViewType);
    }
    holder.bind(cell);
    mHeaderViewHolders.add(holder);
    return holder.itemView;
}
 
Example 8
Source File: BannerView.java    From Tangram-Android with MIT License 5 votes vote down vote up
private View getFooterViewFromRecycler(@NonNull BaseCell cell) {
    GroupBasicAdapter adapter = cell.serviceManager.getService(GroupBasicAdapter.class);
    RecyclerView.RecycledViewPool pool = cell.serviceManager.getService(RecyclerView.RecycledViewPool.class);
    int itemViewType = adapter.getItemType(cell);
    BinderViewHolder holder = (BinderViewHolder) pool.getRecycledView(itemViewType);
    if (holder == null) {
        holder = (BinderViewHolder) adapter.createViewHolder(this, itemViewType);
    }
    holder.bind(cell);
    mFooterViewHolders.add(holder);
    return holder.itemView;
}
 
Example 9
Source File: VirtualLayoutManagerTest.java    From vlayout with MIT License 5 votes vote down vote up
public void setRecyclerView(final RecyclerView recyclerView, boolean assignDummyPool)
        throws Throwable {
    mRecyclerView = recyclerView;
    if (assignDummyPool) {
        RecyclerView.RecycledViewPool pool = new RecyclerView.RecycledViewPool() {
            @Override
            public RecyclerView.ViewHolder getRecycledView(int viewType) {
                RecyclerView.ViewHolder viewHolder = super.getRecycledView(viewType);
                if (viewHolder == null) {
                    return null;
                }

                ViewHolderHelper.addViewHolderFlag(viewHolder, 1); //  RecyclerView.ViewHolder.FLAG_BOUND
                ViewHolderHelper.setField(viewHolder, "mPosition", 200);
                ViewHolderHelper.setField(viewHolder, "mOldPosition", 300);
                ViewHolderHelper.setField(viewHolder, "mPreLayoutPosition", 500);
                return viewHolder;
            }

            @Override
            public void putRecycledView(RecyclerView.ViewHolder scrap) {
                super.putRecycledView(scrap);
            }
        };
        mRecyclerView.setRecycledViewPool(pool);
    }

    // mAdapterHelper = recyclerView.mAdapterHelper;
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            ((ViewGroup) getActivity().findViewById(android.R.id.content)).addView(recyclerView);
        }
    });
}
 
Example 10
Source File: BannerCell.java    From Tangram-Android with MIT License 5 votes vote down vote up
public void initAdapter() {
    if (mBannerAdapter == null) {
        if (serviceManager != null) {
            GroupBasicAdapter adapter = serviceManager.getService(GroupBasicAdapter.class);
            RecyclerView.RecycledViewPool pool = serviceManager.getService(RecyclerView.RecycledViewPool.class);
            mBannerAdapter = new BannerAdapter(adapter, pool);
        }
    }
    if (mBannerWrapper == null) {
        mBannerWrapper = new UltraViewPagerAdapter(mBannerAdapter);
    }
}
 
Example 11
Source File: AllAppsRecyclerView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the number of apps per row in this recycler view.
 */
public void setNumAppsPerRow(DeviceProfile grid, int numAppsPerRow) {
    mNumAppsPerRow = numAppsPerRow;

    RecyclerView.RecycledViewPool pool = getRecycledViewPool();
    int approxRows = (int) Math.ceil(grid.availableHeightPx / grid.allAppsIconSizePx);
    pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_EMPTY_SEARCH, 1);
    pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_SEARCH_DIVIDER, 1);
    pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_SEARCH_MARKET_DIVIDER, 1);
    pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_SEARCH_MARKET, 1);
    pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_ICON, approxRows * mNumAppsPerRow);
}
 
Example 12
Source File: AllAppsRecyclerView.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the number of apps per row in this recycler view.
 */
public void setNumAppsPerRow(DeviceProfile grid, int numAppsPerRow) {
    mNumAppsPerRow = numAppsPerRow;

    RecyclerView.RecycledViewPool pool = getRecycledViewPool();
    int approxRows = (int) Math.ceil(grid.availableHeightPx / grid.allAppsIconSizePx);
    pool.setMaxRecycledViews(AllAppsGridAdapter.EMPTY_SEARCH_VIEW_TYPE, 1);
    pool.setMaxRecycledViews(AllAppsGridAdapter.SEARCH_MARKET_DIVIDER_VIEW_TYPE, 1);
    pool.setMaxRecycledViews(AllAppsGridAdapter.SEARCH_MARKET_VIEW_TYPE, 1);
    pool.setMaxRecycledViews(AllAppsGridAdapter.ICON_VIEW_TYPE, approxRows * mNumAppsPerRow);
    pool.setMaxRecycledViews(AllAppsGridAdapter.PREDICTION_ICON_VIEW_TYPE, mNumAppsPerRow);
    pool.setMaxRecycledViews(AllAppsGridAdapter.SECTION_BREAK_VIEW_TYPE, approxRows);
    pool.setMaxRecycledViews(AllAppsGridAdapter.CUSTOM_PREDICTED_APPS_HEADER_VIEW_TYPE, 1);
    pool.setMaxRecycledViews(AllAppsGridAdapter.CUSTOM_PREDICTED_APPS_FOOTER_VIEW_TYPE, 1);
}
 
Example 13
Source File: BannerCell.java    From Tangram-Android with MIT License 4 votes vote down vote up
public BannerAdapter(GroupBasicAdapter adapter, RecyclerView.RecycledViewPool pool) {
    super(adapter, pool);
    this.adapter = adapter;
}
 
Example 14
Source File: InnerRecycledViewPool.java    From vlayout with MIT License 4 votes vote down vote up
public InnerRecycledViewPool() {
    this(new RecyclerView.RecycledViewPool());
}
 
Example 15
Source File: RecyclerViewv7DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void recycledViewPool(RecyclerView.RecycledViewPool arg) {
  return BaseDSL.attr("recycledViewPool", arg);
}
 
Example 16
Source File: BannerCell.java    From Tangram-Android with MIT License 4 votes vote down vote up
public BannerAdapter(GroupBasicAdapter adapter, RecyclerView.RecycledViewPool pool) {
    super(adapter, pool);
    this.adapter = adapter;
}
 
Example 17
Source File: LinearScrollCell.java    From Tangram-Android with MIT License 4 votes vote down vote up
public RecyclerView.RecycledViewPool getRecycledViewPool() {
    if (serviceManager != null) {
        return serviceManager.getService(RecyclerView.RecycledViewPool.class);
    }
    return null;
}
 
Example 18
Source File: OnePlusNLayoutActivity.java    From vlayout with MIT License 4 votes vote down vote up
public PagerAdapter(SubAdapter adapter, RecyclerView.RecycledViewPool pool) {
    super(adapter, pool);
}
 
Example 19
Source File: LinearScrollCell.java    From Tangram-Android with MIT License 4 votes vote down vote up
public RecyclerView.RecycledViewPool getRecycledViewPool() {
    if (serviceManager != null) {
        return serviceManager.getService(RecyclerView.RecycledViewPool.class);
    }
    return null;
}
 
Example 20
Source File: InnerRecycledViewPool.java    From vlayout with MIT License 2 votes vote down vote up
/**
 * Wrap an existing pool
 *
 * @param pool
 */
public InnerRecycledViewPool(RecyclerView.RecycledViewPool pool) {
    this.mInnerPool = pool;
}