Search in sources :

Example 51 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project Gadgetbridge by Freeyourgadget.

the class CommuteActionsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_commute_actions);
    sharedPreferences = GBApplication.getPrefs().getPreferences();
    findViewById(R.id.actionAddFab).setOnClickListener(this);
    // set up the RecyclerView
    RecyclerView recyclerView = findViewById(R.id.actionsListView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    actionsListAdapter = new CommuteActionsListAdapter(this, actionsList);
    actionsListAdapter.setClickListener(this);
    recyclerView.setAdapter(actionsListAdapter);
    refreshActions();
    // set up touch helper for reordering items
    ItemTouchHelper.Callback actionTouchHelperCallback = new ActionTouchHelperCallback(actionsListAdapter);
    actionTouchHelper = new ItemTouchHelper(actionTouchHelperCallback);
    actionTouchHelper.attachToRecyclerView(recyclerView);
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 52 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager 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 53 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager 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 54 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager 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 55 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project SwipeRecyclerView by yanzhenjie.

the class MenuFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(getContext(), R.color.divider_color)));
    mRecyclerView.setOnItemClickListener(mItemClickListener);
    mRecyclerView.setSwipeMenuCreator(mSwipeMenuCreator);
    mRecyclerView.setOnItemMenuClickListener(mItemMenuClickListener);
    MainAdapter menuAdapter = new MainAdapter(getContext());
    mRecyclerView.setAdapter(menuAdapter);
    List<String> dataList = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        dataList.add("我是第" + i + "个。");
    }
    menuAdapter.notifyDataSetChanged(dataList);
}
Also used : MainAdapter(com.yanzhenjie.recyclerview.sample.adapter.MainAdapter) DefaultItemDecoration(com.yanzhenjie.recyclerview.widget.DefaultItemDecoration) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)502 RecyclerView (androidx.recyclerview.widget.RecyclerView)301 View (android.view.View)197 TextView (android.widget.TextView)75 ArrayList (java.util.ArrayList)44 Bundle (android.os.Bundle)43 Nullable (androidx.annotation.Nullable)41 Intent (android.content.Intent)36 ImageView (android.widget.ImageView)34 Toolbar (androidx.appcompat.widget.Toolbar)34 List (java.util.List)33 NonNull (androidx.annotation.NonNull)31 Context (android.content.Context)28 ViewGroup (android.view.ViewGroup)27 AlertDialog (androidx.appcompat.app.AlertDialog)24 Test (org.junit.Test)24 LayoutInflater (android.view.LayoutInflater)23 ContextualCard (com.android.settings.homepage.contextualcards.ContextualCard)20 MenuItem (android.view.MenuItem)18 DividerItemDecoration (androidx.recyclerview.widget.DividerItemDecoration)17