Search in sources :

Example 46 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project TwinklingRefreshLayout by lcodecorex.

the class ScrollingUtil 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) {
                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;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) GridView(android.widget.GridView) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) View(android.view.View) ListView(android.widget.ListView) WebView(android.webkit.WebView)

Example 47 with StaggeredGridLayoutManager

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));
}
Also used : Context(android.content.Context) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) OverallItem(eu.davidea.samples.flexibleadapter.items.OverallItem) ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) ScrollableLayoutItem(eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem)

Example 48 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project FlexibleAdapter by davideas.

the class FragmentOverall method onPrepareOptionsMenu.

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem gridMenuItem = menu.findItem(R.id.action_list_type);
    if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        gridMenuItem.setIcon(R.drawable.ic_view_agenda_white_24dp);
        gridMenuItem.setTitle(R.string.linear_layout);
    } else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
        gridMenuItem.setIcon(R.drawable.ic_dashboard_white_24dp);
        gridMenuItem.setTitle(R.string.staggered_layout);
    } else {
        gridMenuItem.setIcon(R.drawable.ic_view_grid_white_24dp);
        gridMenuItem.setTitle(R.string.grid_layout);
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) SmoothScrollGridLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) MenuItem(android.view.MenuItem) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Example 49 with StaggeredGridLayoutManager

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;
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 50 with StaggeredGridLayoutManager

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;
}
Also used : BGAStickyNavLayout(cn.bingoogolapple.refreshlayout.BGAStickyNavLayout) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) View(android.view.View) WebView(android.webkit.WebView)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)78 RecyclerView (android.support.v7.widget.RecyclerView)52 View (android.view.View)37 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)32 GridLayoutManager (android.support.v7.widget.GridLayoutManager)26 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)9 Handler (android.os.Handler)7 Toolbar (android.support.v7.widget.Toolbar)7 TextView (android.widget.TextView)7 Nullable (android.support.annotation.Nullable)5 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)5 ViewGroup (android.view.ViewGroup)5 AbsListView (android.widget.AbsListView)5 ScrollView (android.widget.ScrollView)5 BindView (butterknife.BindView)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 Bundle (android.os.Bundle)3 FloatingActionButton (android.support.design.widget.FloatingActionButton)3