use of androidx.recyclerview.widget.GridLayoutManager in project Applozic-Android-SDK by AppLozic.
the class AlScrollListener method onScrolled.
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
visibleItemCount = recyclerView.getChildCount();
if (manager instanceof GridLayoutManager) {
GridLayoutManager gridLayoutManager = (GridLayoutManager) manager;
firstVisibleItem = gridLayoutManager.findFirstVisibleItemPosition();
totalItemCount = gridLayoutManager.getItemCount();
} else if (manager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) manager;
firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition();
totalItemCount = linearLayoutManager.getItemCount();
}
if (infiniteScrollingEnabled) {
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
}
}
if ((totalItemCount - visibleItemCount) == 0) {
return;
}
if (!loading && (totalItemCount - visibleItemCount <= firstVisibleItem + visibleThreshold)) {
// End has been reached
// do something
onLoadMore();
loading = true;
}
}
if (firstVisibleItem == 0) {
if (!controlsVisible) {
onScrollUp();
controlsVisible = true;
}
return;
}
if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
onScrollDown();
controlsVisible = false;
scrolledDistance = 0;
} else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) {
onScrollUp();
controlsVisible = true;
scrolledDistance = 0;
}
if ((controlsVisible && dy > 0) || (!controlsVisible && dy < 0)) {
scrolledDistance += dy;
}
}
use of androidx.recyclerview.widget.GridLayoutManager in project SmoothRefreshLayout by dkzwm.
the class TestHorizontalRecyclerViewActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_with_horizontal_recyclerview);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle(R.string.test_horizontal_recyclerView);
mRecyclerView = findViewById(R.id.recyclerView_with_horizontal_recyclerView);
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3, LinearLayoutManager.HORIZONTAL, false));
mRecyclerView.setHasFixedSize(true);
mAdapter = new HorizontalRecyclerViewAdapter(this, getLayoutInflater());
mRecyclerView.setAdapter(mAdapter);
mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_horizontal_recyclerView);
MaterialHeader header = new MaterialHeader(this);
header.setColorSchemeColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
header.setPadding(PixelUtl.dp2px(this, 25), 0, PixelUtl.dp2px(this, 25), 0);
mRefreshLayout.setHeaderView(header);
MaterialFooter footer = new MaterialFooter(this);
footer.setProgressBarColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
mRefreshLayout.setFooterView(footer);
mRefreshLayout.setDisableLoadMore(false);
mRefreshLayout.setEnableAutoLoadMore(true);
mRefreshLayout.setEnablePinContentView(true);
mRefreshLayout.setEnablePinRefreshViewWhileLoading(true);
mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
@Override
public void onRefreshing() {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
List<String> list = DataUtil.createList(mCount, 20);
mCount = list.size();
mAdapter.updateData(list);
mRefreshLayout.refreshComplete();
}
}, 3000);
}
@Override
public void onLoadingMore() {
Toast.makeText(TestHorizontalRecyclerViewActivity.this, R.string.has_been_triggered_to_load_more, Toast.LENGTH_SHORT).show();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
List<String> list = DataUtil.createList(mCount, 20);
mCount += list.size();
mAdapter.appendData(list);
mRefreshLayout.refreshComplete();
}
}, 3000);
}
});
mRefreshLayout.setDurationToClose(800);
mRefreshLayout.autoRefresh(false);
}
use of androidx.recyclerview.widget.GridLayoutManager in project SmoothRefreshLayout by dkzwm.
the class TestRecyclerViewInNestedScrollViewInSrlActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_recyclerview_in_nestedscrollview_in_srl);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.arrow_back_white_72x72);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
mRecyclerView = findViewById(R.id.recyclerView_test_recyclerView_in_nestedScrollView);
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
mAdapter = new RecyclerViewAdapter(this, getLayoutInflater());
mRecyclerView.setAdapter(mAdapter);
mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_recyclerView_in_nestedScrollView);
mRefreshLayout.setDisableLoadMore(false);
mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
@Override
public void onRefreshing() {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
List<String> list = DataUtil.createList(mCount, 60);
mCount = list.size();
mAdapter.updateData(list);
mRefreshLayout.refreshComplete(500);
}
}, 2000);
}
@Override
public void onLoadingMore() {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
List<String> list = DataUtil.createList(mCount, 15);
mCount += list.size();
mAdapter.appendData(list);
mRefreshLayout.refreshComplete(500);
}
}, 2000);
}
});
mRefreshLayout.autoRefresh();
}
use of androidx.recyclerview.widget.GridLayoutManager in project CloudReader by youlookwhat.
the class TreeFragment method initRefreshView.
private void initRefreshView() {
RefreshHelper.setSwipeRefreshView(bindingView.srlWan);
bindingView.srlWan.setOnRefreshListener(() -> bindingView.srlWan.postDelayed(this::getTree, 150));
LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
bindingView.xrvWan.setLayoutManager(layoutManager);
mTreeAdapter = new TreeAdapter(activity);
bindingView.xrvWan.setAdapter(mTreeAdapter);
HeaderItemTreeBinding oneBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.header_item_tree, null, false);
bindingView.xrvWan.addHeaderView(oneBinding.getRoot());
oneBinding.tvPosition.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mTreeAdapter.isSelect()) {
GridLayoutManager layoutManager = new GridLayoutManager(activity, 2);
bindingView.xrvWan.setLayoutManager(layoutManager);
oneBinding.tvPosition.setText("选择类别");
mTreeAdapter.setSelect(true);
mTreeAdapter.notifyDataSetChanged();
bindingView.xrvWan.addItemDecoration(new SpacesItemDecoration(activity).setNoShowDivider(1, 0).setDrawable(R.drawable.shape_line));
} else {
LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
bindingView.xrvWan.setLayoutManager(layoutManager);
oneBinding.tvPosition.setText("发现页内容订制");
mTreeAdapter.setSelect(false);
mTreeAdapter.notifyDataSetChanged();
if (bindingView.xrvWan.getItemDecorationCount() > 0) {
bindingView.xrvWan.removeItemDecorationAt(0);
}
}
}
});
bindingView.xrvWan.setOnItemClickListener(new OnItemFilterClickListener() {
@Override
public void onSingleClick(View v, int position) {
if (mTreeAdapter.isSelect()) {
if (mTreeAdapter.getSelectedPosition() == position) {
ToastUtil.showToastLong("当前已经是\"" + mTreeAdapter.getData().get(position).getName() + "\"");
return;
}
LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
bindingView.xrvWan.setLayoutManager(layoutManager);
oneBinding.tvPosition.setText("发现页内容订制");
mTreeAdapter.setSelect(false);
mTreeAdapter.notifyDataSetChanged();
if (bindingView.xrvWan.getItemDecorationCount() > 0) {
bindingView.xrvWan.removeItemDecorationAt(0);
}
layoutManager.scrollToPositionWithOffset(position + bindingView.xrvWan.getCustomTopItemViewCount(), 0);
RxBus.getDefault().post(RxCodeConstants.FIND_CUSTOM, position);
}
}
});
}
use of androidx.recyclerview.widget.GridLayoutManager in project fresco by facebook.
the class DraweeRecyclerViewFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
final RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
final int imageSize = (right - left) / SPAN_COUNT;
mResizeOptions = new ResizeOptions(imageSize, imageSize);
}
});
GridLayoutManager layoutManager = new GridLayoutManager(getContext(), SPAN_COUNT);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
final SimpleAdapter adapter = new SimpleAdapter(new ArrayList<Uri>());
recyclerView.setAdapter(adapter);
final Spinner imageSource = view.findViewById(R.id.spinner_image_source);
ImageSourceSpinner.INSTANCE.setup(imageSource, sampleUris(), new Function1<List<Uri>, Unit>() {
@Override
public Unit invoke(List<Uri> uris) {
adapter.setData(uris);
return null;
}
});
}
Aggregations