Java 类android.support.v7.widget.RecyclerView.Adapter 实例源码

项目:Nird2    文件:BriarRecyclerView.java   
public void setAdapter(Adapter adapter) {
    if (recyclerView == null) initViews();

    Adapter oldAdapter = recyclerView.getAdapter();
    if (oldAdapter != null) {
        oldAdapter.unregisterAdapterDataObserver(emptyObserver);
    }

    recyclerView.setAdapter(adapter);

    if (adapter != null) {
        adapter.registerAdapterDataObserver(emptyObserver);

        if (adapter.getItemCount() > 0) {
            // only show data if adapter has data already
            // otherwise progress bar is shown
            emptyObserver.onChanged();
        }
    }
}
项目:Nird2    文件:BriarRecyclerView.java   
public void startPeriodicUpdate() {
    if (recyclerView == null || recyclerView.getAdapter() == null) {
        throw new IllegalStateException("Need to call setAdapter() first!");
    }
    refresher = new Runnable() {
        @Override
        public void run() {
            LOG.info("Updating Content...");
            Adapter adapter = recyclerView.getAdapter();
            adapter.notifyItemRangeChanged(0, adapter.getItemCount());
            handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
        }
    };
    LOG.info("Adding Handler Callback");
    handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
}
项目:Nird2    文件:BriarRecyclerView.java   
public void setAdapter(Adapter adapter) {
    if (recyclerView == null) initViews();

    Adapter oldAdapter = recyclerView.getAdapter();
    if (oldAdapter != null) {
        oldAdapter.unregisterAdapterDataObserver(emptyObserver);
    }

    recyclerView.setAdapter(adapter);

    if (adapter != null) {
        adapter.registerAdapterDataObserver(emptyObserver);

        if (adapter.getItemCount() > 0) {
            // only show data if adapter has data already
            // otherwise progress bar is shown
            emptyObserver.onChanged();
        }
    }
}
项目:Nird2    文件:BriarRecyclerView.java   
public void startPeriodicUpdate() {
    if (recyclerView == null || recyclerView.getAdapter() == null) {
        throw new IllegalStateException("Need to call setAdapter() first!");
    }
    refresher = new Runnable() {
        @Override
        public void run() {
            LOG.info("Updating Content...");
            Adapter adapter = recyclerView.getAdapter();
            adapter.notifyItemRangeChanged(0, adapter.getItemCount());
            handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
        }
    };
    LOG.info("Adding Handler Callback");
    handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
}
项目:Hotspot-master-devp    文件:PullToRefreshRecyclerView.java   
/**
 * @Description: 判断第一个条目是否完全可见
 *
 * @return boolean:
 * @version 1.0
 * @date 2015-9-23
 * @Author zhou.wenkai
 */
private boolean isFirstItemVisible() {
    final Adapter<?> adapter = getRefreshableView().getAdapter();

    // 如果未设置Adapter或者Adapter没有数据可以下拉刷新
    if (null == adapter || adapter.getItemCount() == 0) {
        if (DEBUG) {
            Log.d(LOG_TAG, "isFirstItemVisible. Empty View.");
        }
        return true;

    } else {
        // 第一个条目完全展示,可以刷新
        if (getFirstVisiblePosition() == 0) {
            return mRefreshableView.getChildAt(0).getTop() >= mRefreshableView
                    .getTop();
        }
    }

    return false;
}
项目:Hotspot-master-devp    文件:PullToRefreshRecyclerView.java   
/**
 * @Description: 判断最后一个条目是否完全可见
 *
 * @return boolean:
 * @version 1.0
 * @date 2015-9-23
 * @Author zhou.wenkai
 */
private boolean isLastItemVisible() {
    final Adapter<?> adapter = getRefreshableView().getAdapter();

    // 如果未设置Adapter或者Adapter没有数据可以上拉刷新
    if (null == adapter || adapter.getItemCount() == 0) {
        if (DEBUG) {
            Log.d(LOG_TAG, "isLastItemVisible. Empty View.");
        }
        return true;

    } else {
        // 最后一个条目View完全展示,可以刷新
        int lastVisiblePosition = getLastVisiblePosition();
        if(lastVisiblePosition >= mRefreshableView.getAdapter().getItemCount()-1) {
            return mRefreshableView.getChildAt(
                    mRefreshableView.getChildCount() - 1).getBottom() <= mRefreshableView
                    .getBottom();
        }
    }

    return false;
}
项目:Blockbuster    文件:ItemSelectionSupport.java   
/**
 * Defines the choice behavior for the List. By default, Lists do not have any choice behavior
 * ({@link ChoiceMode#NONE}). By setting the choiceMode to {@link ChoiceMode#SINGLE}, the
 * List allows up to one item to  be in a chosen state. By setting the choiceMode to
 * {@link ChoiceMode#MULTIPLE}, the list allows any number of items to be chosen.
 *
 * @param choiceMode One of {@link ChoiceMode#NONE}, {@link ChoiceMode#SINGLE}, or
 * {@link ChoiceMode#MULTIPLE}
 */
public void setChoiceMode(ChoiceMode choiceMode) {
    if (mChoiceMode == choiceMode) {
        return;
    }

    mChoiceMode = choiceMode;

    if (mChoiceMode != ChoiceMode.NONE) {
        if (mCheckedStates == null) {
            mCheckedStates = new CheckedStates();
        }

        final Adapter adapter = mRecyclerView.getAdapter();
        if (mCheckedIdStates == null && adapter != null && adapter.hasStableIds()) {
            mCheckedIdStates = new CheckedIdStates();
        }
    }
}
项目:ticdesign    文件:FocusableLinearLayoutManager.java   
@Override
public boolean validAdapter(Adapter adapter) {
    if (adapter != null) {
        RecyclerView.ViewHolder viewHolder = adapter.createViewHolder(mTicklableRecyclerView,
                adapter.getItemViewType(0));
        if (!(viewHolder instanceof ViewHolder)) {
            String msg = "adapter's ViewHolder should be instance of FocusableLinearLayoutManager.ViewHolder";
            if (DesignConfig.DEBUG) {
                throw new IllegalArgumentException(msg);
            } else {
                Log.w(TAG, msg);
                return false;
            }
        }
    }
    return true;
}
项目:Blockbuster    文件:ItemSelectionSupport.java   
/**
 * Defines the choice behavior for the List. By default, Lists do not have any choice behavior
 * ({@link ChoiceMode#NONE}). By setting the choiceMode to {@link ChoiceMode#SINGLE}, the
 * List allows up to one item to  be in a chosen state. By setting the choiceMode to
 * {@link ChoiceMode#MULTIPLE}, the list allows any number of items to be chosen.
 *
 * @param choiceMode One of {@link ChoiceMode#NONE}, {@link ChoiceMode#SINGLE}, or
 * {@link ChoiceMode#MULTIPLE}
 */
public void setChoiceMode(ChoiceMode choiceMode) {
    if (mChoiceMode == choiceMode) {
        return;
    }

    mChoiceMode = choiceMode;

    if (mChoiceMode != ChoiceMode.NONE) {
        if (mCheckedStates == null) {
            mCheckedStates = new CheckedStates();
        }

        final Adapter adapter = mRecyclerView.getAdapter();
        if (mCheckedIdStates == null && adapter != null && adapter.hasStableIds()) {
            mCheckedIdStates = new CheckedIdStates();
        }
    }
}
项目:FMTech    文件:PlayRecyclerView.java   
private void setupEmptyViewObserver(RecyclerView.Adapter paramAdapter)
{
  if (paramAdapter != null)
  {
    if (this.mObserver != null)
    {
      paramAdapter.unregisterAdapterDataObserver(this.mObserver);
      this.mObserver = null;
    }
    this.mObserver = new RecyclerView.AdapterDataObserver()
    {
      public final void onChanged()
      {
        PlayRecyclerView.this.updateEmptyStatus();
      }
    };
    paramAdapter.registerAdapterDataObserver(this.mObserver);
  }
}
项目:awesomerecyclerview    文件:ItemSelectionSupport.java   
/**
 * Defines the choice behavior for the List. By default, Lists do not have any choice behavior
 * ({@link ChoiceMode#NONE}). By setting the choiceMode to {@link ChoiceMode#SINGLE}, the
 * List allows up to one item to  be in a chosen state. By setting the choiceMode to
 * {@link ChoiceMode#MULTIPLE}, the list allows any number of items to be chosen.
 *
 * @param choiceMode One of {@link ChoiceMode#NONE}, {@link ChoiceMode#SINGLE}, or
 * {@link ChoiceMode#MULTIPLE}
 */
public void setChoiceMode(ChoiceMode choiceMode) {
    if (mChoiceMode == choiceMode) {
        return;
    }

    mChoiceMode = choiceMode;

    if (mChoiceMode != ChoiceMode.NONE) {
        if (mCheckedStates == null) {
            mCheckedStates = new CheckedStates();
        }

        final Adapter adapter = mRecyclerView.getAdapter();
        if (mCheckedIdStates == null && adapter != null && adapter.hasStableIds()) {
            mCheckedIdStates = new CheckedIdStates();
        }
    }
}
项目:365browser    文件:SelectableListLayout.java   
/**
 * Initializes the RecyclerView.
 *
 * @param adapter The adapter that provides a binding from an app-specific data set to views
 *                that are displayed within the RecyclerView.
 * @return The RecyclerView itself.
 */
public RecyclerView initializeRecyclerView(Adapter<RecyclerView.ViewHolder> adapter) {
    mAdapter = adapter;
    mAdapter.registerAdapterDataObserver(mAdapterObserver);

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.addOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            setToolbarShadowVisibility();
        }
    });

    mItemAnimator = mRecyclerView.getItemAnimator();

    return mRecyclerView;
}
项目:Refugiate    文件:ItemSelectionSupport.java   
/**
 * Defines the choice behavior for the List. By default, Lists do not have any choice behavior
 * ({@link ChoiceMode#NONE}). By setting the choiceMode to {@link ChoiceMode#SINGLE}, the
 * List allows up to one item to  be in a chosen state. By setting the choiceMode to
 * {@link ChoiceMode#MULTIPLE}, the list allows any number of items to be chosen.
 *
 * @param choiceMode One of {@link ChoiceMode#NONE}, {@link ChoiceMode#SINGLE}, or
 * {@link ChoiceMode#MULTIPLE}
 */
public void setChoiceMode(ChoiceMode choiceMode) {
    if (mChoiceMode == choiceMode) {
        return;
    }

    mChoiceMode = choiceMode;

    if (mChoiceMode != ChoiceMode.NONE) {
        if (mCheckedStates == null) {
            mCheckedStates = new CheckedStates();
        }

        final Adapter adapter = mRecyclerView.getAdapter();
        if (mCheckedIdStates == null && adapter != null && adapter.hasStableIds()) {
            mCheckedIdStates = new CheckedIdStates();
        }
    }
}
项目:UltimateAndroid    文件:ItemSelectionSupport.java   
/**
 * Defines the choice behavior for the List. By default, Lists do not have any choice behavior
 * ({@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#NONE}). By setting the choiceMode to {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#SINGLE}, the
 * List allows up to one item to  be in a chosen state. By setting the choiceMode to
 * {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#MULTIPLE}, the list allows any number of items to be chosen.
 *
 * @param choiceMode One of {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#NONE}, {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#SINGLE}, or
 * {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#MULTIPLE}
 */
public void setChoiceMode(ChoiceMode choiceMode) {
    if (mChoiceMode == choiceMode) {
        return;
    }

    mChoiceMode = choiceMode;

    if (mChoiceMode != ChoiceMode.NONE) {
        if (mCheckedStates == null) {
            mCheckedStates = new CheckedStates();
        }

        final Adapter adapter = mRecyclerView.getAdapter();
        if (mCheckedIdStates == null && adapter != null && adapter.hasStableIds()) {
            mCheckedIdStates = new CheckedIdStates();
        }
    }
}
项目:Nird2    文件:BriarRecyclerView.java   
public void showData() {
    if (recyclerView == null) initViews();
    Adapter adapter = recyclerView.getAdapter();
    if (adapter != null) {
        if (adapter.getItemCount() == 0) {
            emptyView.setVisibility(VISIBLE);
            recyclerView.setVisibility(INVISIBLE);
        } else {
            // use GONE here so empty view doesn't use space on small lists
            emptyView.setVisibility(GONE);
            recyclerView.setVisibility(VISIBLE);
        }
        progressBar.setVisibility(GONE);
    }
}
项目:Nird2    文件:BriarRecyclerView.java   
public void showData() {
    if (recyclerView == null) initViews();
    Adapter adapter = recyclerView.getAdapter();
    if (adapter != null) {
        if (adapter.getItemCount() == 0) {
            emptyView.setVisibility(VISIBLE);
            recyclerView.setVisibility(INVISIBLE);
        } else {
            // use GONE here so empty view doesn't use space on small lists
            emptyView.setVisibility(GONE);
            recyclerView.setVisibility(VISIBLE);
        }
        progressBar.setVisibility(GONE);
    }
}
项目:chromium-for-android-56-debug-video    文件:SelectableListLayout.java   
/**
 * Initializes the RecyclerView.
 *
 * @param adapter The adapter that provides a binding from an app-specific data set to views
 *                that are displayed within the RecyclerView.
 */
public void initializeRecyclerView(Adapter<RecyclerView.ViewHolder> adapter) {
    mAdapter = adapter;
    mAdapter.registerAdapterDataObserver(mAdapterObserver);

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
项目: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;
        }
    });
}
项目:Blockbuster    文件:TwoWayLayoutManager.java   
@Override
public void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter) {
    super.onAdapterChanged(oldAdapter, newAdapter);

    final ItemSelectionSupport itemSelectionSupport = ItemSelectionSupport.from(mRecyclerView);
    if (oldAdapter != null && itemSelectionSupport != null) {
        itemSelectionSupport.clearChoices();
    }
}
项目:joy-library    文件:RecyclerAdapter.java   
public RecyclerAdapter(Adapter<ViewHolder> adapter, LayoutManager lm) {

        mHeaderArrays = new SparseArray<>();
        mFooterArrays = new SparseArray<>();

        setWrappedAdapter(adapter);
        mLayoutManager = lm;

        if (lm instanceof GridLayoutManager) {

            GridLayoutManager glm = (GridLayoutManager) lm;
            glm.setSpanSizeLookup(new SpanSizeLookup(this, glm.getSpanCount()));
        }
    }
项目:joy-library    文件:RecyclerAdapter.java   
private void setWrappedAdapter(Adapter<ViewHolder> adapter) {

        if (adapter == null)
            return;

        if (mAdapter != null) {

            notifyItemRangeRemoved(getHeadersCount(), getWrappedItemCount());
            mAdapter.unregisterAdapterDataObserver(mDataObserver);
        }

        mAdapter = adapter;
        mAdapter.registerAdapterDataObserver(mDataObserver);
        notifyItemRangeInserted(getHeadersCount(), getWrappedItemCount());
    }
项目:joy-library    文件:BaseHttpRvFragment2.java   
@Override
public final void addHeaderView(View v) {

    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter == null)
        throw new IllegalStateException(
                "Cannot add header view to recycler -- setAdapter has not been called.");

    ((RecyclerAdapter) adapter).addHeaderView(v);
}
项目:joy-library    文件:BaseHttpRvFragment2.java   
@Override
public final void addFooterView(View v) {

    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter == null)
        throw new IllegalStateException(
                "Cannot add footer view to recycler -- setAdapter has not been called.");

    ((RecyclerAdapter) adapter).addFooterView(v);
}
项目:joy-library    文件:BaseHttpRvFragment2.java   
@Override
public final ExRvAdapter getAdapter() {

    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter instanceof RecyclerAdapter)
        return (ExRvAdapter) ((RecyclerAdapter) adapter).getWrappedAdapter();
    else
        return (ExRvAdapter) adapter;
}
项目:joy-library    文件:BaseHttpRvFragment.java   
protected void addHeaderView(View v) {

        Adapter adapter = mRecyclerView.getAdapter();
        if (adapter == null)
            throw new IllegalStateException(
                    "Cannot add header view to recycler -- setAdapter has not been called.");

        ((RecyclerAdapter) adapter).addHeaderView(v);
    }
项目:joy-library    文件:BaseHttpRvFragment.java   
protected void addFooterView(View v) {

        Adapter adapter = mRecyclerView.getAdapter();
        if (adapter == null)
            throw new IllegalStateException(
                    "Cannot add footer view to recycler -- setAdapter has not been called.");

        ((RecyclerAdapter) adapter).addFooterView(v);
    }
项目:joy-library    文件:BaseHttpRvFragment.java   
protected ExRvAdapter getAdapter() {

        Adapter adapter = mRecyclerView.getAdapter();
        if (adapter instanceof RecyclerAdapter)
            return (ExRvAdapter) ((RecyclerAdapter) adapter).getWrappedAdapter();
        else
            return (ExRvAdapter) adapter;
    }
项目:joy-library    文件:BaseHttpRvActivity.java   
protected void addHeaderView(View v) {

        Adapter adapter = mRecyclerView.getAdapter();
        if (adapter == null)
            throw new IllegalStateException(
                    "Cannot add header view to recycler -- setAdapter has not been called.");

        ((RecyclerAdapter) adapter).addHeaderView(v);
    }
项目:joy-library    文件:BaseHttpRvActivity.java   
protected void addFooterView(View v) {

        Adapter adapter = mRecyclerView.getAdapter();
        if (adapter == null)
            throw new IllegalStateException(
                    "Cannot add footer view to recycler -- setAdapter has not been called.");

        ((RecyclerAdapter) adapter).addFooterView(v);
    }
项目:joy-library    文件:BaseHttpRvActivity.java   
protected ExRvAdapter getAdapter() {

        Adapter adapter = mRecyclerView.getAdapter();
        if (adapter instanceof RecyclerAdapter)
            return (ExRvAdapter) ((RecyclerAdapter) adapter).getWrappedAdapter();
        else
            return (ExRvAdapter) adapter;
    }
项目:joy-library    文件:BaseHttpRvActivity2.java   
@Override
public final void addHeaderView(View v) {

    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter == null)
        throw new IllegalStateException(
                "Cannot add header view to recycler -- setAdapter has not been called.");

    ((RecyclerAdapter) adapter).addHeaderView(v);
}
项目:joy-library    文件:BaseHttpRvActivity2.java   
@Override
public final void addFooterView(View v) {

    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter == null)
        throw new IllegalStateException(
                "Cannot add footer view to recycler -- setAdapter has not been called.");

    ((RecyclerAdapter) adapter).addFooterView(v);
}
项目:joy-library    文件:BaseHttpRvActivity2.java   
@Override
public final ExRvAdapter getAdapter() {

    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter instanceof RecyclerAdapter)
        return (ExRvAdapter) ((RecyclerAdapter) adapter).getWrappedAdapter();
    else
        return (ExRvAdapter) adapter;
}
项目:core-ui    文件:BaseHttpRvFragment.java   
@Override
public final void addHeaderView(View v) {
    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter == null)
        throw new IllegalStateException(
                "Cannot add header view to recycler -- setAdapter has not been called.");
    ((RecyclerAdapter) adapter).addHeaderView(v);
}
项目:core-ui    文件:BaseHttpRvFragment.java   
@Override
public final void addFooterView(View v) {
    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter == null)
        throw new IllegalStateException(
                "Cannot add footer view to recycler -- setAdapter has not been called.");
    ((RecyclerAdapter) adapter).addFooterView(v);
}
项目:core-ui    文件:BaseHttpRvFragment.java   
@Override
public final ExRvAdapter getAdapter() {
    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter instanceof RecyclerAdapter) {
        return (ExRvAdapter) ((RecyclerAdapter) adapter).getWrappedAdapter();
    } else {
        return (ExRvAdapter) adapter;
    }
}
项目:core-ui    文件:RecyclerAdapter.java   
public RecyclerAdapter(Adapter<ViewHolder> adapter, LayoutManager lm) {
    mHeaderArrays = new SparseArray<>();
    mFooterArrays = new SparseArray<>();

    setWrappedAdapter(adapter);
    mLayoutManager = lm;

    if (lm instanceof GridLayoutManager) {
        GridLayoutManager glm = (GridLayoutManager) lm;
        glm.setSpanSizeLookup(new SpanSizeLookup(this, glm.getSpanCount()));
    }
}
项目:core-ui    文件:RecyclerAdapter.java   
private void setWrappedAdapter(Adapter<ViewHolder> adapter) {
    if (adapter == null) {
        return;
    }
    if (mAdapter != null) {
        notifyItemRangeRemoved(getHeadersCount(), getWrappedItemCount());
        mAdapter.unregisterAdapterDataObserver(mDataObserver);
    }
    mAdapter = adapter;
    mAdapter.registerAdapterDataObserver(mDataObserver);
    notifyItemRangeInserted(getHeadersCount(), getWrappedItemCount());
}
项目:core-ui    文件:BaseHttpRvActivity.java   
@Override
public final void addHeaderView(View v) {
    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter == null)
        throw new IllegalStateException(
                "Cannot add header view to recycler -- setAdapter has not been called.");
    ((RecyclerAdapter) adapter).addHeaderView(v);
}
项目:core-ui    文件:BaseHttpRvActivity.java   
@Override
public final void addFooterView(View v) {
    Adapter adapter = mRecyclerView.getAdapter();
    if (adapter == null)
        throw new IllegalStateException(
                "Cannot add footer view to recycler -- setAdapter has not been called.");
    ((RecyclerAdapter) adapter).addFooterView(v);
}