use of android.support.v7.widget.StaggeredGridLayoutManager in project VirtualApp by asLody.
the class SmartRecyclerAdapter method onCreateViewHolder.
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = null;
if (viewType == TYPE_HEADER) {
itemView = headerView;
} else if (viewType == TYPE_FOOTER) {
itemView = footerView;
}
if (itemView != null) {
//set StaggeredGridLayoutManager header & footer view
if (layoutManager instanceof StaggeredGridLayoutManager) {
ViewGroup.LayoutParams targetParams = itemView.getLayoutParams();
StaggeredGridLayoutManager.LayoutParams StaggerLayoutParams;
if (targetParams != null) {
StaggerLayoutParams = new StaggeredGridLayoutManager.LayoutParams(targetParams.width, targetParams.height);
} else {
StaggerLayoutParams = new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
StaggerLayoutParams.setFullSpan(true);
itemView.setLayoutParams(StaggerLayoutParams);
}
return new RecyclerView.ViewHolder(itemView) {
};
}
return super.onCreateViewHolder(parent, viewType);
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project BGARefreshLayout-Android by bingoogolapple.
the class BGARefreshScrollingUtil method isRecyclerViewToBottom.
public static boolean isRecyclerViewToBottom(RecyclerView recyclerView) {
if (recyclerView != null) {
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null || manager.getItemCount() == 0) {
return false;
}
if (manager instanceof LinearLayoutManager) {
// 处理item高度超过一屏幕时的情况
View lastVisibleChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
if (lastVisibleChild != null && lastVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) {
if (android.os.Build.VERSION.SDK_INT < 14) {
return !(ViewCompat.canScrollVertically(recyclerView, 1) || recyclerView.getScrollY() < 0);
} else {
return !ViewCompat.canScrollVertically(recyclerView, 1);
}
}
LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
if (layoutManager.findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1) {
BGAStickyNavLayout stickyNavLayout = getStickyNavLayout(recyclerView);
if (stickyNavLayout != null) {
// 处理BGAStickyNavLayout中findLastCompletelyVisibleItemPosition失效问题
View lastCompletelyVisibleChild = layoutManager.getChildAt(layoutManager.findLastCompletelyVisibleItemPosition());
if (lastCompletelyVisibleChild == null) {
return true;
} else {
// 0表示x,1表示y
int[] location = new int[2];
lastCompletelyVisibleChild.getLocationOnScreen(location);
int lastChildBottomOnScreen = location[1] + lastCompletelyVisibleChild.getMeasuredHeight();
stickyNavLayout.getLocationOnScreen(location);
int stickyNavLayoutBottomOnScreen = location[1] + stickyNavLayout.getMeasuredHeight();
return lastChildBottomOnScreen <= stickyNavLayoutBottomOnScreen;
}
} else {
return true;
}
}
} else if (manager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;
int[] out = layoutManager.findLastCompletelyVisibleItemPositions(null);
int lastPosition = layoutManager.getItemCount() - 1;
for (int position : out) {
if (position == lastPosition) {
return true;
}
}
}
}
return false;
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project BGARefreshLayout-Android by bingoogolapple.
the class BGARefreshScrollingUtil method isRecyclerViewToTop.
public static boolean isRecyclerViewToTop(RecyclerView recyclerView) {
if (recyclerView != null) {
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null) {
return true;
}
if (manager.getItemCount() == 0) {
return true;
}
if (manager instanceof LinearLayoutManager) {
LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
int firstChildTop = 0;
if (recyclerView.getChildCount() > 0) {
// 处理item高度超过一屏幕时的情况
View firstVisibleChild = recyclerView.getChildAt(0);
if (firstVisibleChild != null && firstVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) {
if (android.os.Build.VERSION.SDK_INT < 14) {
return !(ViewCompat.canScrollVertically(recyclerView, -1) || recyclerView.getScrollY() > 0);
} else {
return !ViewCompat.canScrollVertically(recyclerView, -1);
}
}
// 如果RecyclerView的子控件数量不为0,获取第一个子控件的top
// 解决item的topMargin不为0时不能触发下拉刷新
View firstChild = recyclerView.getChildAt(0);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) firstChild.getLayoutParams();
firstChildTop = firstChild.getTop() - layoutParams.topMargin - getRecyclerViewItemTopInset(layoutParams) - recyclerView.getPaddingTop();
}
if (layoutManager.findFirstCompletelyVisibleItemPosition() < 1 && firstChildTop == 0) {
return true;
}
} else if (manager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;
int[] out = layoutManager.findFirstCompletelyVisibleItemPositions(null);
if (out[0] < 1) {
return true;
}
}
}
return false;
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project UltimateRecyclerView by cymcsg.
the class UltimateRecyclerView method scroll_load_more_detection.
private void scroll_load_more_detection(RecyclerView recyclerView) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManagerType == null) {
if (layoutManager instanceof GridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
} else if (layoutManager instanceof LinearLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
} else {
throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
}
}
mTotalItemCount = layoutManager.getItemCount();
mVisibleItemCount = layoutManager.getChildCount();
switch(layoutManagerType) {
case LINEAR:
mFirstVisibleItem = mRecyclerViewHelper.findFirstVisibleItemPosition();
lastVisibleItemPosition = mRecyclerViewHelper.findLastVisibleItemPosition();
break;
case GRID:
if (layoutManager instanceof GridLayoutManager) {
GridLayoutManager ly = (GridLayoutManager) layoutManager;
lastVisibleItemPosition = ly.findLastVisibleItemPosition();
mFirstVisibleItem = ly.findFirstVisibleItemPosition();
}
break;
case STAGGERED_GRID:
if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager sy = (StaggeredGridLayoutManager) layoutManager;
if (mlastPositionsStaggeredGridLayout == null)
mlastPositionsStaggeredGridLayout = new int[sy.getSpanCount()];
sy.findLastVisibleItemPositions(mlastPositionsStaggeredGridLayout);
lastVisibleItemPosition = findMax(mlastPositionsStaggeredGridLayout);
sy.findFirstVisibleItemPositions(mlastPositionsStaggeredGridLayout);
mFirstVisibleItem = findMin(mlastPositionsStaggeredGridLayout);
}
break;
}
if (automaticLoadMoreEnabled) {
if (mTotalItemCount > previousTotal) {
automaticLoadMoreEnabled = false;
previousTotal = mTotalItemCount;
}
}
boolean bottomEdgeHit = (mTotalItemCount - mVisibleItemCount) <= mFirstVisibleItem;
if (bottomEdgeHit) {
if (mIsLoadMoreWidgetEnabled) {
/**auto activate load more**/
if (!automaticLoadMoreEnabled) {
onLoadMoreListener.loadMore(mRecyclerView.getAdapter().getItemCount(), lastVisibleItemPosition);
automaticLoadMoreEnabled = true;
}
}
mAdapter.internalExecuteLoadingView();
previousTotal = mTotalItemCount;
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project FlexibleAdapter by davideas.
the class OverallAdapter method onBindViewHolder.
/**
* METHOD A - NEW! Via Model objects. In this case you don't need to implement this method!
* METHOD B - You override and implement this method as you prefer (don't call super).
*
* Using Method B, some methods need to be called by the user, see bottom of this method!
*/
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List payload) {
int viewType = getItemViewType(position);
Context context = holder.itemView.getContext();
if (viewType == R.layout.recycler_scrollable_usecase_item) {
ScrollableUseCaseItem item = (ScrollableUseCaseItem) getItem(position);
ScrollableUseCaseItem.UCViewHolder vHolder = (ScrollableUseCaseItem.UCViewHolder) holder;
assert item != null;
DrawableUtils.setBackgroundCompat(holder.itemView, DrawableUtils.getRippleDrawable(DrawableUtils.getColorDrawable(context.getResources().getColor(R.color.material_color_blue_grey_50)), DrawableUtils.getColorControlHighlight(context)));
vHolder.mTitle.setText(Utils.fromHtmlCompat(item.getTitle()));
vHolder.mSubtitle.setText(Utils.fromHtmlCompat(item.getSubtitle()));
//Support for StaggeredGridLayoutManager
if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(true);
Log.d("LayoutItem", "LayoutItem configured fullSpan for StaggeredGridLayout");
}
} else if (viewType == R.layout.recycler_scrollable_layout_item) {
ScrollableLayoutItem item = (ScrollableLayoutItem) getItem(position);
ScrollableLayoutItem.LayoutViewHolder vHolder = (ScrollableLayoutItem.LayoutViewHolder) holder;
assert item != null;
//For marquee
vHolder.mTitle.setSelected(true);
vHolder.mTitle.setText(item.getTitle());
vHolder.mSubtitle.setText(item.getSubtitle());
//Support for StaggeredGridLayoutManager
if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(true);
Log.d("LayoutItem", "LayoutItem configured fullSpan for StaggeredGridLayout");
}
} else if (viewType == R.layout.recycler_overall_item) {
OverallItem item = (OverallItem) getItem(position);
OverallItem.LabelViewHolder vHolder = (OverallItem.LabelViewHolder) holder;
assert item != null;
if (item.getTitle() != null) {
vHolder.mTitle.setText(item.getTitle());
vHolder.mTitle.setEnabled(isEnabled(position));
}
if (item.getDescription() != null) {
vHolder.mSubtitle.setText(Utils.fromHtmlCompat(item.getDescription()));
vHolder.mSubtitle.setEnabled(isEnabled(position));
}
if (item.getIcon() != null) {
vHolder.mIcon.setImageDrawable(item.getIcon());
}
}
// IMPORTANT!!!
// With method B, animateView() needs to be called by the user!
// With method A, the call is handled by the Adapter
animateView(holder, position);
// Same concept for EndlessScrolling and View activation:
// - onLoadMore(position);
// - holder.itemView.setActivated(isSelected(position));
}
Aggregations