use of android.support.v7.widget.StaggeredGridLayoutManager in project PhotoPicker by donglua.
the class PhotoPickerFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.__picker_fragment_photo_picker, container, false);
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.rv_photos);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(column, OrientationHelper.VERTICAL);
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(photoGridAdapter);
recyclerView.setItemAnimator(new DefaultItemAnimator());
final Button btSwitchDirectory = (Button) rootView.findViewById(R.id.button);
listPopupWindow = new ListPopupWindow(getActivity());
listPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
listPopupWindow.setAnchorView(btSwitchDirectory);
listPopupWindow.setAdapter(listAdapter);
listPopupWindow.setModal(true);
listPopupWindow.setDropDownGravity(Gravity.BOTTOM);
listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
listPopupWindow.dismiss();
PhotoDirectory directory = directories.get(position);
btSwitchDirectory.setText(directory.getName());
photoGridAdapter.setCurrentDirectoryIndex(position);
photoGridAdapter.notifyDataSetChanged();
}
});
photoGridAdapter.setOnPhotoClickListener(new OnPhotoClickListener() {
@Override
public void onClick(View v, int position, boolean showCamera) {
final int index = showCamera ? position - 1 : position;
List<String> photos = photoGridAdapter.getCurrentPhotoPaths();
ImagePagerFragment imagePagerFragment = ImagePagerFragment.newInstance(photos, index);
((PhotoPickerActivity) getActivity()).addImagePagerFragment(imagePagerFragment);
}
});
photoGridAdapter.setOnCameraClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (!PermissionsUtils.checkCameraPermission(PhotoPickerFragment.this))
return;
if (!PermissionsUtils.checkWriteStoragePermission(PhotoPickerFragment.this))
return;
openCamera();
}
});
btSwitchDirectory.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (listPopupWindow.isShowing()) {
listPopupWindow.dismiss();
} else if (!getActivity().isFinishing()) {
adjustHeight();
listPopupWindow.show();
}
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
// Log.d(">>> Picker >>>", "dy = " + dy);
if (Math.abs(dy) > SCROLL_THRESHOLD) {
mGlideRequestManager.pauseRequests();
} else {
resumeRequestsIfNotDestroyed();
}
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
resumeRequestsIfNotDestroyed();
}
}
});
return rootView;
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project SuperRecyclerView by Malinskiy.
the class SuperRecyclerView method caseStaggeredGrid.
private int caseStaggeredGrid(RecyclerView.LayoutManager layoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
if (lastScrollPositions == null)
lastScrollPositions = new int[staggeredGridLayoutManager.getSpanCount()];
staggeredGridLayoutManager.findLastVisibleItemPositions(lastScrollPositions);
return findMax(lastScrollPositions);
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project InstaMaterial by frogermcs.
the class UserProfileActivity method setupUserProfileGrid.
private void setupUserProfileGrid() {
final StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
rvUserProfile.setLayoutManager(layoutManager);
rvUserProfile.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
userPhotosAdapter.setLockedAnimations(true);
}
});
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project XRecyclerView by jianghejie.
the class XRecyclerView method onScrollStateChanged.
/**
* ======================================================= end =======================================================
*/
@Override
public void onScrollStateChanged(int state) {
super.onScrollStateChanged(state);
if (state == RecyclerView.SCROLL_STATE_IDLE && mLoadingListener != null && !isLoadingData && loadingMoreEnabled) {
LayoutManager layoutManager = getLayoutManager();
int lastVisibleItemPosition;
if (layoutManager instanceof GridLayoutManager) {
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(into);
lastVisibleItemPosition = findMax(into);
} else {
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
}
int adjAdapterItemCount = layoutManager.getItemCount() + getHeaders_includingRefreshCount();
// Log.e("aaaaa","adjAdapterItemCount "+adjAdapterItemCount +" getItemCount "+layoutManager.getItemCount());
int status = STATE_DONE;
if (mRefreshHeader != null)
status = mRefreshHeader.getState();
if (layoutManager.getChildCount() > 0 && lastVisibleItemPosition >= adjAdapterItemCount - limitNumberToCallLoadMore && adjAdapterItemCount >= layoutManager.getChildCount() && !isNoMore && status < ArrowRefreshHeader.STATE_REFRESHING) {
isLoadingData = true;
if (mFootView instanceof LoadingMoreFooter) {
((LoadingMoreFooter) mFootView).setState(LoadingMoreFooter.STATE_LOADING);
} else {
if (footerViewCallBack != null) {
footerViewCallBack.onLoadingMore(mFootView);
}
}
mLoadingListener.onLoadMore();
}
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project EasyRecyclerView by Jude95.
the class StaggeredGridActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recyclerview);
recyclerView = (EasyRecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL));
recyclerView.setAdapter(adapter = new ImageAdapter(this));
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 4);
gridLayoutManager.setSpanSizeLookup(adapter.obtainGridSpanSizeLookUp(4));
recyclerView.setLayoutManager(gridLayoutManager);
adapter.addHeader(new RecyclerArrayAdapter.ItemView() {
@Override
public View onCreateView(ViewGroup parent) {
RollPagerView header = new RollPagerView(StaggeredGridActivity.this);
header.setHintView(new ColorPointHintView(StaggeredGridActivity.this, Color.YELLOW, Color.GRAY));
header.setHintPadding(0, 0, 0, (int) Utils.convertDpToPixel(8, StaggeredGridActivity.this));
header.setPlayDelay(2000);
header.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) Utils.convertDpToPixel(200, StaggeredGridActivity.this)));
header.setAdapter(new BannerAdapter(StaggeredGridActivity.this));
return header;
}
@Override
public void onBindView(View headerView) {
}
});
SpaceDecoration itemDecoration = new SpaceDecoration((int) Utils.convertDpToPixel(8, this));
itemDecoration.setPaddingEdgeSide(true);
itemDecoration.setPaddingStart(true);
itemDecoration.setPaddingHeaderFooter(true);
recyclerView.addItemDecoration(itemDecoration);
adapter.setMore(R.layout.view_more, new RecyclerArrayAdapter.OnMoreListener() {
@Override
public void onMoreShow() {
addData();
}
@Override
public void onMoreClick() {
}
});
adapter.setNoMore(R.layout.view_nomore);
recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
adapter.clear();
adapter.addAll(DataProvider.getPictures(0));
}
}, 1000);
}
});
addData();
}
Aggregations