Search in sources :

Example 6 with RefreshingListenerAdapter

use of me.dkzwm.widget.srl.RefreshingListenerAdapter 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)

Example 7 with RefreshingListenerAdapter

use of me.dkzwm.widget.srl.RefreshingListenerAdapter in project SmoothRefreshLayout by dkzwm.

the class TestMaterialStyleActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_refresh);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_material_style);
    mTextView = findViewById(R.id.textView_test_refresh_desc);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_refresh);
    mRefreshLayout.materialStyle();
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

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

                @Override
                public void run() {
                    mRefreshLayout.refreshComplete();
                    String times = getString(R.string.number_of_refresh) + mCount;
                    mTextView.setText(times);
                }
            }, 2000);
        }
    });
    mRefreshLayout.autoRefresh(false);
}
Also used : RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter)

Example 8 with RefreshingListenerAdapter

use of me.dkzwm.widget.srl.RefreshingListenerAdapter in project SmoothRefreshLayout by dkzwm.

the class TestMultiDirectionViewsActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_multi_direction_views);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_multi_direction_views);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_multi_direction_views);
    ClassicHeader header = new ClassicHeader(this);
    mRefreshLayout.setHeaderView(header);
    mRefreshLayout.setEnableKeepRefreshView(true);
    mRefreshLayout.setDisableWhenAnotherDirectionMove(true);
    mRefreshLayout.setEnableCheckInsideAnotherDirectionView(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

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

                @Override
                public void run() {
                    mViewPager.setCurrentItem(0, true);
                    mRefreshLayout.refreshComplete();
                }
            }, 2000);
        }
    });
    mViewPager = findViewById(R.id.viewPager_test_multi_direction_views_pager);
    List<PageFragment> fragments = new ArrayList<>();
    for (int i = 0; i < sColors.length; i++) {
        fragments.add(PageFragment.newInstance(i, sColors[i]));
    }
    mAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragments);
    mViewPager.setAdapter(mAdapter);
    mRefreshLayout.autoRefresh(false);
    mTextView = findViewById(R.id.textView_load_detail_footer_details);
    mScrollView = findViewById(R.id.scrollView_test_multi_direction_views);
    mInnerRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_multi_direction_views_inner);
    mInnerRefreshLayout.setDisableRefresh(true);
    mInnerRefreshLayout.setDisableLoadMore(false);
    mInnerRefreshLayout.setLoadingMinTime(0);
    mInnerRefreshLayout.setEnableOverScroll(false);
    CustomLoadDetailFooter footer = new CustomLoadDetailFooter(this);
    mInnerRefreshLayout.setFooterView(footer);
    mInnerRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshBegin(boolean isRefresh) {
            mInnerRefreshLayout.setDurationToClose(500);
            mInnerRefreshLayout.refreshComplete();
            mInnerRefreshLayout.setDurationToClose(500);
            mScrollView.smoothScrollTo(0, mTextView.getTop());
        }
    });
}
Also used : ClassicHeader(me.dkzwm.widget.srl.extra.header.ClassicHeader) RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) ArrayList(java.util.ArrayList) PageFragment(me.dkzwm.widget.srl.sample.ui.fragment.PageFragment) ViewPagerAdapter(me.dkzwm.widget.srl.sample.adapter.ViewPagerAdapter) CustomLoadDetailFooter(me.dkzwm.widget.srl.sample.footer.CustomLoadDetailFooter)

Example 9 with RefreshingListenerAdapter

use of me.dkzwm.widget.srl.RefreshingListenerAdapter in project SmoothRefreshLayout by dkzwm.

the class TestNestedHorizontalViewsActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_nested_horizontal_views);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_nested_horizontal_views);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_nested_horizontal_views);
    ClassicHeader header = new ClassicHeader(this);
    mRefreshLayout.setHeaderView(header);
    mRefreshLayout.setEnableKeepRefreshView(true);
    mRefreshLayout.setDisableWhenAnotherDirectionMove(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

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

                @Override
                public void run() {
                    mViewPager.setCurrentItem(0, true);
                    mRefreshLayout.refreshComplete();
                    Toast.makeText(TestNestedHorizontalViewsActivity.this, R.string.sr_refresh_complete, Toast.LENGTH_SHORT).show();
                }
            }, 4000);
        }
    });
    mViewPager = findViewById(R.id.viewPager_test_nested_horizontal_views_pager);
    List<PageFragment> fragments = new ArrayList<>();
    for (int i = 0; i < sColors.length; i++) {
        fragments.add(PageFragment.newInstance(i, sColors[i]));
    }
    mAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragments);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setPageTransformer(true, new DrawerTransformer());
    mRefreshLayout.setEnableCheckInsideAnotherDirectionView(true);
    mRefreshLayout.autoRefresh(false);
}
Also used : ClassicHeader(me.dkzwm.widget.srl.extra.header.ClassicHeader) RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) ArrayList(java.util.ArrayList) PageFragment(me.dkzwm.widget.srl.sample.ui.fragment.PageFragment) ViewPagerAdapter(me.dkzwm.widget.srl.sample.adapter.ViewPagerAdapter) DrawerTransformer(com.ToxicBakery.viewpager.transforms.DrawerTransformer)

Example 10 with RefreshingListenerAdapter

use of me.dkzwm.widget.srl.RefreshingListenerAdapter in project SmoothRefreshLayout by dkzwm.

the class WithTextViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_textview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.with_textView);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_textView);
    mTextView = findViewById(R.id.textView_with_textView_desc);
    mRefreshLayout.setEnableKeepRefreshView(true);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setDisablePerformLoadMore(true);
    mRefreshLayout.setEnableHideFooterView(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

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

                @Override
                public void run() {
                    mRefreshLayout.setState(Constants.STATE_CONTENT, true);
                    mRefreshLayout.refreshComplete();
                    String times = getString(R.string.number_of_refresh) + mCount;
                    mTextView.setText(times);
                }
            }, 2000);
        }
    });
    mRefreshLayout.autoRefresh(true);
    mRefreshLayout.setIndicatorOffsetCalculator(new IIndicator.IOffsetCalculator() {

        @Override
        public float calculate(@MovingStatus int status, int currentPos, float offset) {
            if (status == Constants.MOVING_HEADER) {
                if (offset < 0) {
                    // 如果希望拖动缩回时类似QQ一样有阻尼效果,那么请注释掉这个判断语句
                    return offset;
                }
                return (float) Math.pow(Math.pow(currentPos / 2, 1.28d) + offset, 1 / 1.28d) * 2 - currentPos;
            } else if (status == Constants.MOVING_FOOTER) {
                if (offset > 0) {
                    // 如果希望拖动缩回时类似QQ一样有阻尼效果,那么请注释掉这个判断语句
                    return offset;
                }
                return -((float) Math.pow(Math.pow(currentPos / 2, 1.28d) - offset, 1 / 1.28d) * 2 - currentPos);
            } else {
                if (offset > 0) {
                    return (float) Math.pow(offset, 1 / 1.28d) * 2;
                } else if (offset < 0) {
                    return -(float) Math.pow(-offset, 1 / 1.28d) * 2;
                } else {
                    return offset;
                }
            }
        }
    });
    findViewById(R.id.button_with_textView_change_empty_state).setOnClickListener(this);
    findViewById(R.id.button_with_textView_change_content_state).setOnClickListener(this);
    findViewById(R.id.button_with_textView_change_error_state).setOnClickListener(this);
}
Also used : RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) IIndicator(me.dkzwm.widget.srl.indicator.IIndicator)

Aggregations

RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 ClassicHeader (me.dkzwm.widget.srl.extra.header.ClassicHeader)4 MaterialHeader (me.dkzwm.widget.srl.extra.header.MaterialHeader)4 RecyclerViewAdapter (me.dkzwm.widget.srl.sample.adapter.RecyclerViewAdapter)4 RecyclerView (android.support.v7.widget.RecyclerView)3 View (android.view.View)3 SmoothRefreshLayout (me.dkzwm.widget.srl.SmoothRefreshLayout)3 IIndicator (me.dkzwm.widget.srl.indicator.IIndicator)3 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 ArrayList (java.util.ArrayList)2 MaterialFooter (me.dkzwm.widget.srl.extra.footer.MaterialFooter)2 ListViewAdapter (me.dkzwm.widget.srl.sample.adapter.ListViewAdapter)2 ViewPagerAdapter (me.dkzwm.widget.srl.sample.adapter.ViewPagerAdapter)2 PageFragment (me.dkzwm.widget.srl.sample.ui.fragment.PageFragment)2 Nullable (android.support.annotation.Nullable)1 ViewTreeObserver (android.view.ViewTreeObserver)1 TextView (android.widget.TextView)1 DrawerTransformer (com.ToxicBakery.viewpager.transforms.DrawerTransformer)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1