use of androidx.recyclerview.widget.GridLayoutManager in project SwipeRecyclerView by yanzhenjie.
the class DefaultActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_refresh_loadmore);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
mRefreshLayout = findViewById(R.id.refresh_layout);
// 刷新监听。
mRefreshLayout.setOnRefreshListener(mRefreshListener);
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
// RecyclerView Item点击监听。
mRecyclerView.setOnItemClickListener(mItemClickListener);
// 使用默认的加载更多的View。
mRecyclerView.useDefaultLoadMore();
// 加载更多的监听。
mRecyclerView.setLoadMoreListener(mLoadMoreListener);
mAdapter = new MainAdapter(this);
mRecyclerView.setAdapter(mAdapter);
// 请求服务器加载数据。
loadData();
}
use of androidx.recyclerview.widget.GridLayoutManager in project epoxy by airbnb.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EpoxyRecyclerView recyclerView = (EpoxyRecyclerView) findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
recyclerView.setController(controller);
if (savedInstanceState != null) {
carousels = savedInstanceState.getParcelableArrayList(CAROUSEL_DATA_KEY);
}
initTouch(recyclerView);
updateController();
}
use of androidx.recyclerview.widget.GridLayoutManager in project epoxy by airbnb.
the class EpoxyItemSpacingDecorator method calculatePositionDetails.
private void calculatePositionDetails(RecyclerView parent, int position, LayoutManager layout) {
int itemCount = parent.getAdapter().getItemCount();
firstItem = position == 0;
lastItem = position == itemCount - 1;
horizontallyScrolling = layout.canScrollHorizontally();
verticallyScrolling = layout.canScrollVertically();
grid = layout instanceof GridLayoutManager;
if (grid) {
GridLayoutManager grid = (GridLayoutManager) layout;
final SpanSizeLookup spanSizeLookup = grid.getSpanSizeLookup();
int spanSize = spanSizeLookup.getSpanSize(position);
int spanCount = grid.getSpanCount();
int spanIndex = spanSizeLookup.getSpanIndex(position, spanCount);
isFirstItemInRow = spanIndex == 0;
fillsLastSpan = spanIndex + spanSize == spanCount;
isInFirstRow = isInFirstRow(position, spanSizeLookup, spanCount);
isInLastRow = !isInFirstRow && isInLastRow(position, itemCount, spanSizeLookup, spanCount);
}
}
use of androidx.recyclerview.widget.GridLayoutManager in project Signal-Android by WhisperSystems.
the class PaymentsRecoveryPhraseFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
Toolbar toolbar = view.findViewById(R.id.payments_recovery_phrase_fragment_toolbar);
RecyclerView recyclerView = view.findViewById(R.id.payments_recovery_phrase_fragment_recycler);
TextView message = view.findViewById(R.id.payments_recovery_phrase_fragment_message);
View next = view.findViewById(R.id.payments_recovery_phrase_fragment_next);
View edit = view.findViewById(R.id.payments_recovery_phrase_fragment_edit);
View copy = view.findViewById(R.id.payments_recovery_phrase_fragment_copy);
GridLayoutManager gridLayoutManager = new GridLayoutManager(requireContext(), SPAN_COUNT);
PaymentsRecoveryPhraseFragmentArgs args = PaymentsRecoveryPhraseFragmentArgs.fromBundle(requireArguments());
final List<String> words;
if (args.getWords() != null) {
words = Arrays.asList(args.getWords());
setUpForConfirmation(message, next, edit, copy, words);
} else {
Mnemonic mnemonic = SignalStore.paymentsValues().getPaymentsMnemonic();
words = mnemonic.getWords();
setUpForDisplay(message, next, edit, copy, words, args);
}
List<MnemonicPart> parts = Stream.of(words).mapIndexed(MnemonicPart::new).sorted(new MnemonicPartComparator(words.size(), SPAN_COUNT)).toList();
MnemonicPartAdapter adapter = new MnemonicPartAdapter();
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(adapter);
recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
toolbar.setNavigationOnClickListener(v -> {
if (args.getFinishOnConfirm()) {
requireActivity().finish();
} else {
toolbar.setNavigationOnClickListener(t -> Navigation.findNavController(view).popBackStack(R.id.paymentsHome, false));
}
});
adapter.submitList(parts);
}
use of androidx.recyclerview.widget.GridLayoutManager in project boilerplate by koush.
the class GridRecyclerView method setNumColumns.
private void setNumColumns(Context context, int numColumns) {
if (gridLayoutManager == null) {
gridLayoutManager = new GridLayoutManager(context, numColumns);
typeToSpan = new Hashtable<Integer, Integer>();
gridLayoutManager.setSpanSizeLookup(spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
int viewType = getAdapter().getItemViewType(position);
Integer span = typeToSpan.get(viewType);
if (span != null)
return span;
ViewHolder vh = getAdapter().createViewHolder(GridRecyclerView.this, viewType);
int foundSpan;
if (vh instanceof SpanningViewHolder)
foundSpan = ((SpanningViewHolder) vh).getSpanSize(gridLayoutManager.getSpanCount());
else
foundSpan = 1;
typeToSpan.put(viewType, foundSpan);
return foundSpan;
}
});
setLayoutManager(gridLayoutManager);
} else {
gridLayoutManager.setSpanCount(numColumns);
}
typeToSpan.clear();
spanSizeLookup.invalidateSpanIndexCache();
requestLayout();
}
Aggregations