use of androidx.recyclerview.widget.RecyclerView in project Rajawali by Rajawali.
the class ExamplesFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_examples, container, false);
RecyclerView recyclerView = view.findViewById(R.id.recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(adapter);
return view;
}
use of androidx.recyclerview.widget.RecyclerView in project SwipeRecyclerView by yanzhenjie.
the class ItemTouchHelperCallback method getMovementFlags.
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder targetViewHolder) {
if (onItemMovementListener != null) {
int dragFlags = onItemMovementListener.onDragFlags(recyclerView, targetViewHolder);
int swipeFlags = onItemMovementListener.onSwipeFlags(recyclerView, targetViewHolder);
return makeMovementFlags(dragFlags, swipeFlags);
} else {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
int swipeFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
return makeMovementFlags(dragFlags, swipeFlags);
} else {
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
return makeMovementFlags(dragFlags, swipeFlags);
}
} else if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
int dragFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
int swipeFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
return makeMovementFlags(dragFlags, swipeFlags);
} else {
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
return makeMovementFlags(dragFlags, swipeFlags);
}
}
}
return makeMovementFlags(0, 0);
}
use of androidx.recyclerview.widget.RecyclerView in project SwipeRecyclerView by yanzhenjie.
the class AdapterWrapper method onAttachedToRecyclerView.
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
mAdapter.onAttachedToRecyclerView(recyclerView);
RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();
if (lm instanceof GridLayoutManager) {
final GridLayoutManager glm = (GridLayoutManager) lm;
final GridLayoutManager.SpanSizeLookup originLookup = glm.getSpanSizeLookup();
glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (isHeaderOrFooter(position))
return glm.getSpanCount();
if (originLookup != null)
return originLookup.getSpanSize(position);
return 1;
}
});
}
}
use of androidx.recyclerview.widget.RecyclerView in project SwipeRecyclerView by yanzhenjie.
the class DefaultItemDecoration method onDraw.
@Override
public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
assert layoutManager != null;
int orientation = getOrientation(layoutManager);
int spanCount = getSpanCount(layoutManager);
int childCount = layoutManager.getChildCount();
if (layoutManager instanceof LinearLayoutManager) {
canvas.save();
for (int i = 0; i < childCount; i++) {
View view = layoutManager.getChildAt(i);
assert view != null;
int position = parent.getChildLayoutPosition(view);
if (orientation == RecyclerView.VERTICAL) {
drawVertical(canvas, view, position, spanCount, childCount);
} else {
drawHorizontal(canvas, view, position, spanCount, childCount);
}
}
canvas.restore();
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
canvas.save();
for (int i = 0; i < childCount; i++) {
View view = layoutManager.getChildAt(i);
mDrawer.drawLeft(view, canvas);
mDrawer.drawTop(view, canvas);
mDrawer.drawRight(view, canvas);
mDrawer.drawBottom(view, canvas);
}
canvas.restore();
}
}
use of androidx.recyclerview.widget.RecyclerView in project epoxy by airbnb.
the class ModelClickListenerTest method mockModelForClicking.
private View mockModelForClicking(EpoxyModel model) {
View mockedView = mock(View.class);
RecyclerView recyclerMock = mock(RecyclerView.class);
EpoxyViewHolder holderMock = mock(EpoxyViewHolder.class);
when(holderMock.getAdapterPosition()).thenReturn(1);
doReturn(recyclerMock).when(mockedView).getParent();
doReturn(holderMock).when(recyclerMock).findContainingViewHolder(mockedView);
doReturn(model).when(holderMock).getModel();
when(mockedView.getParent()).thenReturn(recyclerMock);
when(recyclerMock.findContainingViewHolder(mockedView)).thenReturn(holderMock);
when(holderMock.getAdapterPosition()).thenReturn(1);
when(holderMock.getModel()).thenReturn(model);
View parentView = mock(View.class);
when(holderMock.objectToBind()).thenReturn(parentView);
doReturn(parentView).when(holderMock).objectToBind();
return mockedView;
}
Aggregations