androidx.recyclerview.widget.RecyclerView.State Java Examples

The following examples show how to use androidx.recyclerview.widget.RecyclerView.State. 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: DividerGridItemDecorationUtils.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) {
        super.getItemOffsets(outRect, view, parent, state);
        int itemPosition = parent.getChildLayoutPosition(view);
        int spanCount = getSpanCount(parent);
        int childCount = parent.getAdapter().getItemCount();
//        if (isLastRaw(parent, itemPosition, spanCount, childCount))// 如果是最后一行,则不需要绘制底部
//        {
//            outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
//        }
        if (isLastColumn(parent, itemPosition, spanCount, childCount))// 如果是最后一列,则不需要绘制右边
        {
            outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
        } else {
            outRect.set(0, 0, mDivider.getIntrinsicWidth(),
                    mDivider.getIntrinsicHeight());
        }
    }
 
Example #2
Source File: MainActivity.java    From LollipopContactsRecyclerViewFastScroller with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
    numberOfItems = getArguments().getInt(ITEMS_COUNT);
    View rootView = inflater.inflate(R.layout.fragment_recycler_view, container, false);
    RecyclerView recyclerView = rootView.findViewById(R.id.recyclerview);
    final LargeAdapter adapter = new LargeAdapter(numberOfItems);
    recyclerView.setAdapter(adapter);
    final RecyclerViewFastScroller fastScroller = rootView.findViewById(R.id.fastscroller);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false) {
        @Override
        public void onLayoutCompleted(final State state) {
            super.onLayoutCompleted(state);
            final int firstVisibleItemPosition = findFirstVisibleItemPosition();
            final int lastVisibleItemPosition = findLastVisibleItemPosition();
            int itemsShown = lastVisibleItemPosition - firstVisibleItemPosition + 1;
            //if all items are shown, hide the fast-scroller
            fastScroller.setVisibility(adapter.getItemCount() > itemsShown ? View.VISIBLE : View.GONE);
        }
    });
    fastScroller.setRecyclerView(recyclerView);
    fastScroller.setViewsToUse(R.layout.recycler_view_fast_scroller__fast_scroller, R.id.fastscroller_bubble, R.id.fastscroller_handle);
    //new Handler().postDelayed(new Runnable() {
    //    @Override
    //    public void run() {
    //        adapter.setItemsCount(new Random().nextInt(20));
    //        adapter.notifyDataSetChanged();
    //    }
    //}, 2000L);
    return rootView;
}
 
Example #3
Source File: DividerGridItemDecorationUtils.java    From shinny-futures-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, State state) {
    drawHorizontal(c, parent);
    drawVertical(c, parent);
}
 
Example #4
Source File: MaterialCalendar.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@NonNull
private ItemDecoration createItemDecoration() {
  return new ItemDecoration() {

    private final Calendar startItem = UtcDates.getUtcCalendar();
    private final Calendar endItem = UtcDates.getUtcCalendar();

    @Override
    public void onDraw(
        @NonNull Canvas canvas, @NonNull RecyclerView recyclerView, @NonNull State state) {
      if (!(recyclerView.getAdapter() instanceof YearGridAdapter)
          || !(recyclerView.getLayoutManager() instanceof GridLayoutManager)) {
        return;
      }
      YearGridAdapter adapter = (YearGridAdapter) recyclerView.getAdapter();
      GridLayoutManager layoutManager = (GridLayoutManager) recyclerView.getLayoutManager();

      for (Pair<Long, Long> range : dateSelector.getSelectedRanges()) {
        if (range.first == null || range.second == null) {
          continue;
        }
        startItem.setTimeInMillis(range.first);
        endItem.setTimeInMillis(range.second);

        int firstHighlightPosition = adapter.getPositionForYear(startItem.get(Calendar.YEAR));
        int lastHighlightPosition = adapter.getPositionForYear(endItem.get(Calendar.YEAR));
        View firstView = layoutManager.findViewByPosition(firstHighlightPosition);
        View lastView = layoutManager.findViewByPosition(lastHighlightPosition);

        int firstRow = firstHighlightPosition / layoutManager.getSpanCount();
        int lastRow = lastHighlightPosition / layoutManager.getSpanCount();

        for (int row = firstRow; row <= lastRow; row++) {
          int firstPositionInRow = row * layoutManager.getSpanCount();
          View viewInRow = layoutManager.findViewByPosition(firstPositionInRow);
          if (viewInRow == null) {
            continue;
          }
          int top = viewInRow.getTop() + calendarStyle.year.getTopInset();
          int bottom = viewInRow.getBottom() - calendarStyle.year.getBottomInset();
          int left = row == firstRow ? firstView.getLeft() + firstView.getWidth() / 2 : 0;
          int right =
              row == lastRow
                  ? lastView.getLeft() + lastView.getWidth() / 2
                  : recyclerView.getWidth();
          canvas.drawRect(left, top, right, bottom, calendarStyle.rangeFill);
        }
      }
    }
  };
}