androidx.recyclerview.widget.RecyclerView.ItemDecoration Java Examples

The following examples show how to use androidx.recyclerview.widget.RecyclerView.ItemDecoration. 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: DefaultBandHost.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
DefaultBandHost(
        @NonNull RecyclerView recyclerView,
        @DrawableRes int bandOverlayId,
        @NonNull ItemKeyProvider<K> keyProvider,
        @NonNull SelectionPredicate<K> selectionPredicate) {

    checkArgument(recyclerView != null);

    mRecyclerView = recyclerView;
    mBand = ContextCompat.getDrawable(mRecyclerView.getContext(), bandOverlayId);

    checkArgument(mBand != null);
    checkArgument(keyProvider != null);
    checkArgument(selectionPredicate != null);

    mKeyProvider = keyProvider;
    mSelectionPredicate = selectionPredicate;

    mRecyclerView.addItemDecoration(
            new ItemDecoration() {
                @Override
                public void onDrawOver(
                        Canvas canvas,
                        RecyclerView unusedParent,
                        RecyclerView.State unusedState) {
                    DefaultBandHost.this.onDrawBand(canvas);
                }
            });
}
 
Example #2
Source File: QueueFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void setupRecyclerView() {
    Drawable shadow = ContextCompat.getDrawable(getContext(), R.drawable.list_drag_shadow);

    ItemDecoration background = new DragBackgroundDecoration(R.id.song_drag_root);
    ItemDecoration divider = new DragDividerDecoration(getContext(), true, R.id.instance_blank);
    ItemDecoration dragShadow = new DragDropDecoration((NinePatchDrawable) shadow);

    mRecyclerView.addItemDecoration(background);
    mRecyclerView.addItemDecoration(divider);
    mRecyclerView.addItemDecoration(dragShadow);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

    boolean portrait = getResources().getConfiguration().orientation != ORIENTATION_LANDSCAPE;
    boolean tablet = getResources().getConfiguration().smallestScreenWidthDp >= 600;
    if (portrait || !tablet) {
        // Add an inner shadow at the top of the list
        mRecyclerView.addItemDecoration(new InsetDecoration(
                ContextCompat.getDrawable(getContext(), R.drawable.inset_top_shadow),
                (int) getResources().getDimension(R.dimen.inset_top_shadow_height),
                Gravity.TOP));
    } else {
        // Add an inner shadow at the bottom of the list
        mRecyclerView.addItemDecoration(new InsetDecoration(
                ContextCompat.getDrawable(getContext(), R.drawable.inset_bottom_shadow),
                getResources().getDimensionPixelSize(R.dimen.inset_bottom_shadow_height),
                Gravity.BOTTOM));
    }
}
 
Example #3
Source File: PlaylistViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Bindable
public ItemDecoration[] getItemDecorations() {
    NinePatchDrawable dragShadow = (NinePatchDrawable) ContextCompat.getDrawable(
            getContext(), R.drawable.list_drag_shadow);

    return new ItemDecoration[] {
            new DragBackgroundDecoration(R.id.song_drag_root),
            new DragDividerDecoration(R.id.song_drag_root, getContext(), R.id.empty_layout),
            new DragDropDecoration(dragShadow)
    };
}
 
Example #4
Source File: ArtistViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Bindable
public ItemDecoration[] getItemDecorations() {
    return new ItemDecoration[] {
            new BackgroundDecoration(R.id.loading_frame, R.id.artist_bio_card, R.id.relatedCard),
            new DividerDecoration(getContext(), R.id.artist_bio_card, R.id.album_view,
                    R.id.subheader_frame, R.id.relatedCard, R.id.empty_layout),
            new GridSpacingDecoration(
                    (int) getResources().getDimension(R.dimen.grid_margin),
                    mAlbumColumnCount, mAlbumSection.getTypeId()),
            new GridSpacingDecoration(
                    (int) getResources().getDimension(R.dimen.card_margin),
                    mRelatedColumnCount, mRelatedArtistSection.getTypeId())
    };
}
 
Example #5
Source File: GenreViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Bindable
public ItemDecoration[] getItemDecorations() {
    return new ItemDecoration[] {
            new BackgroundDecoration(),
            new DividerDecoration(getContext(), R.id.empty_layout)
    };
}
 
Example #6
Source File: ExpandingPickerComponentSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnCreateLayout
static Component onCreateLayout(
    final ComponentContext c,
    @State DynamicValue<Float> expandedAmount,
    @State DynamicValue<Float> contractButtonRotation,
    @State DynamicValue<Float> contractButtonScale,
    @State DynamicValue<Float> contractButtonAlpha,
    @State DynamicValue<Float> expandButtonScale,
    @State DynamicValue<Float> expandButtonAlpha,
    @State DynamicValue<Float> menuButtonAlpha) {
  final SectionContext s = new SectionContext(c);
  return Row.create(c)
      .paddingDip(YogaEdge.ALL, 20)
      .clickHandler(ExpandingPickerComponent.onClickEvent(c))
      .child(
          Row.create(c)
              .widthPercent(100)
              .child(
                  TileComponent.create(c)
                      .scaleX(expandButtonScale)
                      .scaleY(expandButtonScale)
                      .alpha(expandButtonAlpha)
                      .bgColor(Color.RED)
                      .text("Aa"))
              .child(
                  TileComponent.create(c)
                      .positionType(YogaPositionType.ABSOLUTE)
                      .rotation(contractButtonRotation)
                      .scaleX(contractButtonScale)
                      .scaleY(contractButtonScale)
                      .alpha(contractButtonAlpha)
                      .bgColor(Color.LTGRAY)
                      .text("<"))
              .child(
                  RecyclerCollectionComponent.create(s)
                      .flexGrow(1)
                      .itemDecoration(
                          new ItemDecoration() {
                            @Override
                            public void getItemOffsets(
                                Rect outRect,
                                View view,
                                RecyclerView parent,
                                RecyclerView.State state) {
                              outRect.left = c.getResourceResolver().dipsToPixels(5);
                            }
                          })
                      .recyclerConfiguration(
                          ListRecyclerConfiguration.create()
                              .orientation(LinearLayoutManager.HORIZONTAL)
                              .build())
                      .section(MenuItemsSection.create(s).expandedAmount(expandedAmount).build())
                      .build())
              .child(
                  TileComponent.create(c).alpha(menuButtonAlpha).bgColor(Color.LTGRAY).text("#")))
      .build();
}
 
Example #7
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);
        }
      }
    }
  };
}
 
Example #8
Source File: RecyclerViewBindingAdapters.java    From Jockey with Apache License 2.0 4 votes vote down vote up
@BindingAdapter("itemDecorations")
public static void setItemDecorations(RecyclerView recyclerView, ItemDecoration... decor) {
    for (ItemDecoration decoration : decor) {
        recyclerView.addItemDecoration(decoration);
    }
}