use of androidx.recyclerview.widget.GridLayoutManager in project Carbon by ZieIony.
the class BottomSheetLayout method updateRecycler.
private void updateRecycler() {
if (menu == null)
return;
recycler.setLayoutManager(style == Style.List ? new LinearLayoutManager(getContext()) : new GridLayoutManager(getContext(), 3));
ArrayList<Serializable> items = new ArrayList<>();
for (int i = 0; i < menu.size(); i++) {
if (menu.getItem(i).isVisible())
items.add(new Item(menu.getItem(i)));
}
if (style == Style.List) {
for (int i = 0; i < recycler.getItemDecorationCount(); i++) recycler.removeItemDecorationAt(0);
ViewItemDecoration dividerItemDecoration = new ViewItemDecoration(getContext(), R.layout.carbon_menustrip_hseparator_item);
dividerItemDecoration.setDrawAfter(position -> position < items.size() - 1 && items.get(position) instanceof NavigationView.Item && items.get(position + 1) instanceof NavigationView.Item && ((NavigationView.Item) items.get(position)).getGroupId() != ((NavigationView.Item) items.get(position + 1)).getGroupId());
recycler.addItemDecoration(dividerItemDecoration);
ViewItemDecoration paddingItemDecoration = new ViewItemDecoration(getContext(), R.layout.carbon_row_padding);
paddingItemDecoration.setDrawAfter(position -> position == items.size() - 1);
recycler.addItemDecoration(paddingItemDecoration);
}
RowListAdapter<Serializable> adapter = new RowListAdapter<>();
adapter.putFactory(Item.class, style == Style.List ? BottomSheetRow::new : BottomSheetCell::new);
adapter.setItems(items);
recycler.setAdapter(adapter);
}
use of androidx.recyclerview.widget.GridLayoutManager in project PhotoView by chrisbanes.
the class ActivityTransitionActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transition);
RecyclerView list = findViewById(R.id.list);
list.setLayoutManager(new GridLayoutManager(this, 2));
ImageAdapter imageAdapter = new ImageAdapter(new ImageAdapter.Listener() {
@Override
public void onImageClicked(View view) {
transition(view);
}
});
list.setAdapter(imageAdapter);
}
use of androidx.recyclerview.widget.GridLayoutManager in project OneSignal-Android-SDK by OneSignal.
the class MainActivityViewModel method setupInAppMessagingLayout.
private void setupInAppMessagingLayout() {
recyclerViewBuilder.setupRecyclerView(inAppMessagingRecyclerView, 4, false, true);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2);
inAppMessagingRecyclerView.setLayoutManager(gridLayoutManager);
inAppMessagingRecyclerViewAdapter = new InAppMessageRecyclerViewAdapter(context, InAppMessage.values());
inAppMessagingRecyclerView.setAdapter(inAppMessagingRecyclerViewAdapter);
}
use of androidx.recyclerview.widget.GridLayoutManager in project AntennaPod by AntennaPod.
the class TagSettingsDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
ArrayList<FeedPreferences> feedPreferencesList = (ArrayList<FeedPreferences>) getArguments().getSerializable(ARG_FEED_PREFERENCES);
Set<String> commonTags = new HashSet<>(feedPreferencesList.get(0).getTags());
for (FeedPreferences preference : feedPreferencesList) {
commonTags.retainAll(preference.getTags());
}
displayedTags = new ArrayList<>(commonTags);
displayedTags.remove(FeedPreferences.TAG_ROOT);
viewBinding = EditTagsDialogBinding.inflate(getLayoutInflater());
viewBinding.tagsRecycler.setLayoutManager(new GridLayoutManager(getContext(), 2));
viewBinding.tagsRecycler.addItemDecoration(new ItemOffsetDecoration(getContext(), 4));
adapter = new TagSelectionAdapter();
adapter.setHasStableIds(true);
viewBinding.tagsRecycler.setAdapter(adapter);
viewBinding.rootFolderCheckbox.setChecked(commonTags.contains(FeedPreferences.TAG_ROOT));
viewBinding.newTagButton.setOnClickListener(v -> addTag(viewBinding.newTagEditText.getText().toString().trim()));
loadTags();
viewBinding.newTagEditText.setThreshold(1);
viewBinding.newTagEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
viewBinding.newTagEditText.showDropDown();
viewBinding.newTagEditText.requestFocus();
return false;
}
});
if (feedPreferencesList.size() > 1) {
viewBinding.commonTagsInfo.setVisibility(View.VISIBLE);
}
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
dialog.setView(viewBinding.getRoot());
dialog.setTitle(R.string.feed_tags_label);
dialog.setPositiveButton(android.R.string.ok, (d, input) -> {
addTag(viewBinding.newTagEditText.getText().toString().trim());
updatePreferencesTags(feedPreferencesList, commonTags);
});
dialog.setNegativeButton(R.string.cancel_label, null);
return dialog.create();
}
use of androidx.recyclerview.widget.GridLayoutManager in project SwipeRecyclerView by yanzhenjie.
the class GridActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scroll);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
mRecyclerView.addItemDecoration(new BorderItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
mRecyclerView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(View itemView, int position) {
// 根据原position判断该item是否是parent item
if (mAdapter.isParentItem(position)) {
// 换取parent position
int parentPosition = mAdapter.parentItemPosition(position);
// 判断parent是否打开了二级菜单
if (mAdapter.isExpanded(parentPosition)) {
mDataList.get(parentPosition).setExpanded(false);
mAdapter.notifyParentChanged(parentPosition);
// 关闭该parent下的二级菜单
mAdapter.collapseParent(parentPosition);
} else {
mDataList.get(parentPosition).setExpanded(true);
mAdapter.notifyParentChanged(parentPosition);
// 打开该parent下的二级菜单
mAdapter.expandParent(parentPosition);
}
} else {
// 换取parent position
int parentPosition = mAdapter.parentItemPosition(position);
// 换取child position
int childPosition = mAdapter.childItemPosition(position);
String message = String.format("我是%1$d爸爸的%2$d儿子", parentPosition, childPosition);
Toast.makeText(GridActivity.this, message, Toast.LENGTH_LONG).show();
}
}
});
mAdapter = new ExpandedAdapter(this);
mRecyclerView.setAdapter(mAdapter);
refresh();
}
Aggregations