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);
}
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;
}
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);
}
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();
}
}
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);
}
Aggregations