Search in sources :

Example 61 with StaggeredGridLayoutManager

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();
}
Also used : ViewGroup(android.view.ViewGroup) SpaceDecoration(com.jude.easyrecyclerview.decoration.SpaceDecoration) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) ColorPointHintView(com.jude.rollviewpager.hintview.ColorPointHintView) RecyclerView(android.support.v7.widget.RecyclerView) EasyRecyclerView(com.jude.easyrecyclerview.EasyRecyclerView) RollPagerView(com.jude.rollviewpager.RollPagerView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) BannerAdapter(com.jude.dome.header.BannerAdapter) ColorPointHintView(com.jude.rollviewpager.hintview.ColorPointHintView) RollPagerView(com.jude.rollviewpager.RollPagerView)

Example 62 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.

the class MyRecyclerView method onScrolled.

@Override
public void onScrolled(int dx, int dy) {
    super.onScrolled(dx, dy);
    RecyclerView.LayoutManager layoutManager = getLayoutManager();
    if (layoutManagerType == null) {
        if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } 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();
            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 63 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.

the class ImageFragment method initData.

@Override
protected void initData() {
    if (!isPrepared || !isVisible || isLoad) {
        return;
    }
    recyclerView.setLoadingData(this);
    recyclerView.setHasFixedSize(true);
    imageListPresenter = new ImagePresenterImpl(this);
    swipeRefreshLayout.setOnRefreshListener(this);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    adapter = new ImageAdapter(new LinkedList<BaseModel>());
    adapter.setOnItemClickListener(this);
    recyclerView.setAdapter(adapter);
    swipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            onRefresh();
        }
    });
    setLoad();
}
Also used : ImageAdapter(com.jsoupsimple.image.imagelist.widget.adapter.ImageAdapter) ImagePresenterImpl(com.jsoupsimple.image.imagelist.presenter.ImagePresenterImpl) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinkedList(java.util.LinkedList)

Example 64 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.

the class MRecyclerView method onScrolled.

@Override
public void onScrolled(int dx, int dy) {
    super.onScrolled(dx, dy);
    RecyclerView.LayoutManager layoutManager = getLayoutManager();
    if (layoutManagerType == null) {
        if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } 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();
            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 65 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.

the class RecyclerOnScrollListener 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 = LAYOUT_MANAGER_TYPE.LINEAR;
        } 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();
            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 : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

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