Search in sources :

Example 36 with RecyclerView

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;
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Nullable(androidx.annotation.Nullable)

Example 37 with RecyclerView

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);
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 38 with RecyclerView

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;
            }
        });
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 39 with RecyclerView

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();
    }
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 40 with RecyclerView

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;
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

RecyclerView (androidx.recyclerview.widget.RecyclerView)352 View (android.view.View)232 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)156 TextView (android.widget.TextView)51 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)39 ImageView (android.widget.ImageView)29 Nullable (androidx.annotation.Nullable)29 Toolbar (androidx.appcompat.widget.Toolbar)25 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)20 Intent (android.content.Intent)19 NonNull (androidx.annotation.NonNull)19 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)19 Bundle (android.os.Bundle)18 ViewGroup (android.view.ViewGroup)16 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)16 Context (android.content.Context)15 Rect (android.graphics.Rect)15 SuppressLint (android.annotation.SuppressLint)12 LayoutInflater (android.view.LayoutInflater)11