Search in sources :

Example 1 with MaterialFooter

use of me.dkzwm.widget.srl.extra.footer.MaterialFooter in project SmoothRefreshLayout by dkzwm.

the class TestHorizontalRecyclerViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_horizontal_recyclerview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_horizontal_recyclerView);
    mRecyclerView = findViewById(R.id.recyclerView_with_horizontal_recyclerView);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3, LinearLayoutManager.HORIZONTAL, false));
    mRecyclerView.setHasFixedSize(true);
    mAdapter = new HorizontalRecyclerViewAdapter(this, getLayoutInflater());
    mRecyclerView.setAdapter(mAdapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_horizontal_recyclerView);
    MaterialHeader header = new MaterialHeader(this);
    header.setColorSchemeColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
    header.setPadding(PixelUtl.dp2px(this, 25), 0, PixelUtl.dp2px(this, 25), 0);
    mRefreshLayout.setHeaderView(header);
    MaterialFooter footer = new MaterialFooter(this);
    footer.setProgressBarColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
    mRefreshLayout.setFooterView(footer);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setEnableAutoLoadMore(true);
    mRefreshLayout.setEnablePinContentView(true);
    mRefreshLayout.setEnablePinRefreshViewWhileLoading(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshBegin(final boolean isRefresh) {
            if (!isRefresh) {
                Toast.makeText(TestHorizontalRecyclerViewActivity.this, R.string.has_been_triggered_to_load_more, Toast.LENGTH_SHORT).show();
            }
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (isRefresh) {
                        mCount = 0;
                        List<String> list = DataUtil.createList(mCount, 20);
                        mCount += 20;
                        mAdapter.updateData(list);
                    } else {
                        List<String> list = DataUtil.createList(mCount, 20);
                        mCount += 20;
                        mAdapter.appendData(list);
                    }
                    mRefreshLayout.refreshComplete();
                }
            }, 3000);
        }

        @Override
        public void onRefreshComplete(boolean isSuccessful) {
            Toast.makeText(TestHorizontalRecyclerViewActivity.this, R.string.sr_refresh_complete, Toast.LENGTH_SHORT).show();
        }
    });
    mRefreshLayout.setDurationToClose(800);
    mRefreshLayout.autoRefresh(false);
}
Also used : MaterialHeader(me.dkzwm.widget.srl.extra.header.MaterialHeader) MaterialFooter(me.dkzwm.widget.srl.extra.footer.MaterialFooter) RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) GridLayoutManager(android.support.v7.widget.GridLayoutManager) HorizontalRecyclerViewAdapter(me.dkzwm.widget.srl.sample.adapter.HorizontalRecyclerViewAdapter)

Example 2 with MaterialFooter

use of me.dkzwm.widget.srl.extra.footer.MaterialFooter in project SmoothRefreshLayout by dkzwm.

the class TestHorizontalRefreshActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_horizontal_refresh);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_horizontal_refresh);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_horizontal_refresh);
    MaterialHeader header = new MaterialHeader(this);
    header.setColorSchemeColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
    header.setPadding(PixelUtl.dp2px(this, 25), 0, PixelUtl.dp2px(this, 25), 0);
    mRefreshLayout.setHeaderView(header);
    MaterialFooter footer = new MaterialFooter(this);
    footer.setProgressBarColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
    mRefreshLayout.setFooterView(footer);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setDisablePerformLoadMore(false);
    mRefreshLayout.setEnableKeepRefreshView(true);
    mRefreshLayout.setDisableWhenAnotherDirectionMove(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshBegin(boolean isRefresh) {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mRefreshLayout.refreshComplete();
                    Toast.makeText(TestHorizontalRefreshActivity.this, R.string.sr_refresh_complete, Toast.LENGTH_SHORT).show();
                }
            }, 4000);
        }
    });
    mRefreshLayout.setRatioToKeep(1);
    mRefreshLayout.setRatioToRefresh(1);
    mRefreshLayout.autoRefresh(false);
}
Also used : MaterialHeader(me.dkzwm.widget.srl.extra.header.MaterialHeader) MaterialFooter(me.dkzwm.widget.srl.extra.footer.MaterialFooter) RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter)

Aggregations

RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)2 MaterialFooter (me.dkzwm.widget.srl.extra.footer.MaterialFooter)2 MaterialHeader (me.dkzwm.widget.srl.extra.header.MaterialHeader)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 HorizontalRecyclerViewAdapter (me.dkzwm.widget.srl.sample.adapter.HorizontalRecyclerViewAdapter)1