Search in sources :

Example 21 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.

the class XRecyclerView method onScrollStateChanged.

@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();
        }
        if (layoutManager.getChildCount() > 0 && lastVisibleItemPosition >= layoutManager.getItemCount() - 1 && layoutManager.getItemCount() > layoutManager.getChildCount() && !isnomore && mRefreshHeader.getState() < YunRefreshHeader.STATE_REFRESHING) {
            View footView = mFootViews.get(0);
            isLoadingData = true;
            if (footView instanceof LoadingMoreFooter) {
                ((LoadingMoreFooter) footView).setState(LoadingMoreFooter.STATE_LOADING);
            } else {
                footView.setVisibility(View.VISIBLE);
            }
            if (isNetWorkConnected(getContext())) {
                mLoadingListener.onLoadMore();
            } else {
                postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        mLoadingListener.onLoadMore();
                    }
                }, 1000);
            }
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 22 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project weex-example by KalicyZhou.

the class WXRecyclerViewOnScrollListener method onScrolled.

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    IOnLoadMoreListener l;
    if ((l = listener.get()) != null) {
        l.onBeforeScroll(dx, dy);
    }
    //  int lastVisibleItemPosition = -1;
    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else {
            throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    switch(layoutManagerType) {
        case LINEAR:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            listener.get().notifyAppearStateChange(((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition(), lastVisibleItemPosition, dx, dy);
            break;
        case GRID:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case STAGGERED_GRID:
            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)

Example 23 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project easy by MehdiBenmesa.

the class Utils method scrollTo.

public static void scrollTo(Object scroll, float yOffset) {
    if (scroll instanceof RecyclerView) {
        //RecyclerView.scrollTo : UnsupportedOperationException
        //Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset
        //Have to be instanceOf RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager)
        final RecyclerView.LayoutManager layoutManager = ((RecyclerView) scroll).getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            linearLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            staggeredGridLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        }
    } else if (scroll instanceof NestedScrollView) {
        ((NestedScrollView) scroll).scrollTo(0, (int) yOffset);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 24 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project wh-app-android by WhiteHouse.

the class FeedItemListFragment method onCreateLayoutManager.

@Override
public RecyclerView.LayoutManager onCreateLayoutManager() {
    Resources res = getResources();
    int feedGridCols = res.getInteger(R.integer.feed_grid_columns);
    int photoGridCols = res.getInteger(R.integer.photo_grid_columns);
    switch(mFeedType) {
        case TYPE_PHOTOS:
            return new StaggeredGridLayoutManager(photoGridCols, VERTICAL);
        case TYPE_VIDEOS:
            return new GridLayoutManager(getActivity(), feedGridCols);
        case TYPE_LIVE:
            return new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        case TYPE_ARTICLE:
        default:
            return new StaggeredGridLayoutManager(feedGridCols, VERTICAL);
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) Resources(android.content.res.Resources) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 25 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project Douya by DreaminginCodeZH.

the class BaseBroadcastListFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    CustomTabsHelperFragment.attachTo(this);
    mBroadcastListResource = onAttachBroadcastListResource();
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            onSwipeRefresh();
        }
    });
    mBroadcastList.setHasFixedSize(true);
    mBroadcastList.setItemAnimator(new NoChangeAnimationItemAnimator());
    // Always use StaggeredGridLayoutManager so that instance state can be saved.
    Activity activity = getActivity();
    int columnCount = CardUtils.getColumnCount(activity);
    mBroadcastList.setLayoutManager(new StaggeredGridLayoutManager(columnCount, StaggeredGridLayoutManager.VERTICAL));
    mBroadcastAdapter = new BroadcastAdapter(mBroadcastListResource.get(), this);
    mAdapter = new LoadMoreAdapter(R.layout.load_more_card_item, mBroadcastAdapter);
    mBroadcastList.setAdapter(mAdapter);
    final AppBarHost appBarHost = (AppBarHost) getParentFragment();
    mBroadcastList.addOnScrollListener(new OnVerticalScrollWithPagingTouchSlopListener(activity) {

        @Override
        public void onScrolled(int dy) {
            if (!RecyclerViewUtils.hasFirstChildReachedTop(mBroadcastList)) {
                onShow();
            }
        }

        @Override
        public void onScrolledUp() {
            onShow();
        }

        private void onShow() {
            appBarHost.showAppBar();
            mSendFab.show();
        }

        @Override
        public void onScrolledDown() {
            if (RecyclerViewUtils.hasFirstChildReachedTop(mBroadcastList)) {
                appBarHost.hideAppBar();
                mSendFab.hide();
            }
        }

        @Override
        public void onScrolledToBottom() {
            mBroadcastListResource.load(true);
        }
    });
    updateRefreshing();
    CheatSheetUtils.setup(mSendFab);
    mSendFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onSendBroadcast();
        }
    });
}
Also used : Activity(android.app.Activity) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) FriendlySwipeRefreshLayout(me.zhanghai.android.douya.ui.FriendlySwipeRefreshLayout) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) OnVerticalScrollWithPagingTouchSlopListener(me.zhanghai.android.douya.ui.OnVerticalScrollWithPagingTouchSlopListener) LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator) AppBarHost(me.zhanghai.android.douya.ui.AppBarHost)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)71 RecyclerView (android.support.v7.widget.RecyclerView)47 View (android.view.View)32 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)30 GridLayoutManager (android.support.v7.widget.GridLayoutManager)22 Handler (android.os.Handler)7 TextView (android.widget.TextView)7 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)6 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 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 ArrayList (java.util.ArrayList)4 Bundle (android.os.Bundle)3 Nullable (android.support.annotation.Nullable)3 MenuItem (android.view.MenuItem)3 RefreshListenerAdapter (com.lcodecore.tkrefreshlayout.RefreshListenerAdapter)3