Search in sources :

Example 6 with GridLayout

use of android.support.v7.widget.GridLayout in project Collar by CodeZsx.

the class EndlessRecyclerViewOnScrollListener method onScrolled.

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager != null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LINEARLAYOUT;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = GRIDLAYOUT;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = STAGGEREDGRIDLAYOUT;
        } else {
            throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    switch(layoutManagerType) {
        case LINEARLAYOUT:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GRIDLAYOUT:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case STAGGEREDGRIDLAYOUT:
            StaggeredGridLayoutManager staggeredGridLayoutManager = ((StaggeredGridLayoutManager) layoutManager);
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = lastPositions[0];
            for (int value : lastPositions) {
                lastVisibleItemPosition = value > lastVisibleItemPosition ? value : lastVisibleItemPosition;
            }
            break;
    }
}
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 7 with GridLayout

use of android.support.v7.widget.GridLayout in project boon by Wing-Li.

the class OnRecycleViewScrollListener method onScrolled.

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LayoutManagerType.LinearLayout;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LayoutManagerType.GridLayout;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LayoutManagerType.StaggeredGridLayout;
        } else {
            throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    switch(layoutManagerType) {
        case LinearLayout:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GridLayout:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case StaggeredGridLayout:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            break;
    }
}
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)

Aggregations

View (android.view.View)5 GridLayout (android.support.v7.widget.GridLayout)4 ColorStateList (android.content.res.ColorStateList)3 Drawable (android.graphics.drawable.Drawable)3 RippleDrawable (android.graphics.drawable.RippleDrawable)3 StateListDrawable (android.graphics.drawable.StateListDrawable)3 FrameLayout (android.widget.FrameLayout)3 GradientDrawable (android.graphics.drawable.GradientDrawable)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)2 LayoutInflater (android.view.LayoutInflater)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1