Search in sources :

Example 1 with ListViewAdapter

use of me.dkzwm.widget.srl.sample.adapter.ListViewAdapter in project SmoothRefreshLayout by dkzwm.

the class TestScaleEffectActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_scale_effect);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_scale_effect);
    ListView listView = findViewById(R.id.listView_test_scale_effect);
    ListViewAdapter adapter = new ListViewAdapter(this, getLayoutInflater());
    List<String> list = DataUtil.createList(0, 40);
    adapter.updateData(list);
    listView.setAdapter(adapter);
    SmoothRefreshLayout refreshLayout = findViewById(R.id.smoothRefreshLayout_test_scale_effect);
    refreshLayout.setDisableLoadMore(false);
    refreshLayout.setMode(Constants.MODE_SCALE);
    refreshLayout.setDurationToClose(550);
    Interpolator interpolator = new Interpolator() {

        @Override
        public float getInterpolation(float input) {
            return (float) (--input * input * ((1.7 + 1f) * input + 1.7) + 1f);
        }
    };
    refreshLayout.setSpringInterpolator(interpolator);
}
Also used : ListView(android.widget.ListView) ListViewAdapter(me.dkzwm.widget.srl.sample.adapter.ListViewAdapter) Interpolator(android.view.animation.Interpolator) SmoothRefreshLayout(me.dkzwm.widget.srl.SmoothRefreshLayout)

Example 2 with ListViewAdapter

use of me.dkzwm.widget.srl.sample.adapter.ListViewAdapter in project SmoothRefreshLayout by dkzwm.

the class WithGridViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_gridview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.with_gridView);
    mGridView = findViewById(R.id.gridView_with_grid);
    mAdapter = new ListViewAdapter(this, getLayoutInflater());
    mGridView.setAdapter(mAdapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_gridView);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.materialStyle();
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

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

                @Override
                public void run() {
                    if (isRefresh) {
                        mCount = 0;
                        List<String> list = DataUtil.createList(mCount, 15);
                        mCount += 15;
                        mAdapter.updateData(list);
                        mRefreshLayout.refreshComplete();
                    } else {
                        List<String> list = DataUtil.createList(mCount, 15);
                        mCount += 15;
                        mAdapter.appendData(list);
                        mRefreshLayout.setDurationToCloseFooter(0);
                        mGridView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

                            @Override
                            public boolean onPreDraw() {
                                mGridView.getViewTreeObserver().removeOnPreDrawListener(this);
                                mRefreshLayout.refreshComplete();
                                mRefreshLayout.setDurationToCloseFooter(500);
                                return false;
                            }
                        });
                    }
                }
            }, 2000);
        }
    });
    mRefreshLayout.autoRefresh(false);
}
Also used : RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) ListViewAdapter(me.dkzwm.widget.srl.sample.adapter.ListViewAdapter) ViewTreeObserver(android.view.ViewTreeObserver)

Example 3 with ListViewAdapter

use of me.dkzwm.widget.srl.sample.adapter.ListViewAdapter in project SmoothRefreshLayout by dkzwm.

the class WithListViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_listview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.with_listView);
    mListView = findViewById(R.id.listView_with_list);
    mAdapter = new ListViewAdapter(this, getLayoutInflater());
    mListView.setAdapter(mAdapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_listView);
    mClassicHeader = findViewById(R.id.classicHeader_with_listView);
    mClassicHeader.setLastUpdateTimeKey("header_last_update_time");
    mClassicFooter = findViewById(R.id.classicFooter_with_listView);
    mClassicFooter.setLastUpdateTimeKey("footer_last_update_time");
    mClassicHeader.setTitleTextColor(Color.WHITE);
    mClassicHeader.setLastUpdateTextColor(Color.GRAY);
    mRefreshLayout.setEnableKeepRefreshView(true);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setEnableAutoLoadMore(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshBegin(final boolean isRefresh) {
            if (!isRefresh) {
                Toast.makeText(WithListViewActivity.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);
                        mRefreshLayout.setEnableNoMoreData(false);
                    } else {
                        if (mCount > 50) {
                            mRefreshLayout.setEnableNoMoreData(true);
                        } else {
                            List<String> list = DataUtil.createList(mCount, 20);
                            mCount += 20;
                            mAdapter.appendData(list);
                        }
                    }
                    mRefreshLayout.refreshComplete(1200);
                }
            }, 5000);
        }

        @Override
        public void onRefreshComplete(boolean isSuccessful) {
            Toast.makeText(WithListViewActivity.this, R.string.sr_refresh_complete, Toast.LENGTH_SHORT).show();
            if (mRefreshLayout.getState() != Constants.STATE_CONTENT)
                mRefreshLayout.setState(Constants.STATE_CONTENT, false);
        }
    });
    mRefreshLayout.setRatioToKeep(1);
    mRefreshLayout.setRatioToRefresh(1);
    mRefreshLayout.autoRefresh(false);
    findViewById(R.id.button_with_listView_change_empty_state).setOnClickListener(this);
    findViewById(R.id.button_with_listView_change_content_state).setOnClickListener(this);
    findViewById(R.id.button_with_listView_change_error_state).setOnClickListener(this);
    findViewById(R.id.button_with_listView_change_custom_state).setOnClickListener(this);
    findViewById(R.id.button_with_listView_disable_refresh).setOnClickListener(this);
    findViewById(R.id.button_with_listView_enable_refresh).setOnClickListener(this);
    findViewById(R.id.button_with_listView_disable_loadMore).setOnClickListener(this);
    findViewById(R.id.button_with_listView_enable_loadMore).setOnClickListener(this);
}
Also used : RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) ListViewAdapter(me.dkzwm.widget.srl.sample.adapter.ListViewAdapter)

Aggregations

ListViewAdapter (me.dkzwm.widget.srl.sample.adapter.ListViewAdapter)3 RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)2 ViewTreeObserver (android.view.ViewTreeObserver)1 Interpolator (android.view.animation.Interpolator)1 ListView (android.widget.ListView)1 SmoothRefreshLayout (me.dkzwm.widget.srl.SmoothRefreshLayout)1