Search in sources :

Example 26 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.

the class WebViewPracticeActivity method onCreate.

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_practice_webview);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    final WebView webView = (WebView) findViewById(R.id.webView);
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    refreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(@NonNull RefreshLayout refreshLayout) {
            webView.loadUrl("https://github.com/scwang90/SmartRefreshLayout");
        }
    });
    refreshLayout.autoRefresh();
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            refreshLayout.finishRefresh();
            view.loadUrl(String.format(Locale.CHINA, "javascript:document.body.style.paddingTop='%fpx'; void 0", DensityUtil.px2dp(webView.getPaddingTop())));
        }
    });
    // 状态栏透明和间距处理
    StatusBarUtil.immersive(this);
    StatusBarUtil.setPaddingSmart(this, webView);
    StatusBarUtil.setPaddingSmart(this, toolbar);
    StatusBarUtil.setMargin(this, findViewById(R.id.header));
    StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurView));
}
Also used : RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) Toolbar(android.support.v7.widget.Toolbar) WebViewClient(android.webkit.WebViewClient) SuppressLint(android.annotation.SuppressLint)

Example 27 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.

the class WeiboPracticeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_practice_weibo);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    // 状态栏透明和间距处理
    StatusBarUtil.immersive(this);
    StatusBarUtil.setPaddingSmart(this, toolbar);
    final View parallax = findViewById(R.id.parallax);
    final View buttonBar = findViewById(R.id.buttonBarLayout);
    final NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.scrollView);
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    findViewById(R.id.attention).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Toast.makeText(view.getContext(), "点击了关注", Toast.LENGTH_SHORT).show();
        }
    });
    findViewById(R.id.leaveword).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Toast.makeText(view.getContext(), "点击了留言", Toast.LENGTH_SHORT).show();
        }
    });
    refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {

        @Override
        public void onRefresh(@NonNull RefreshLayout refreshLayout) {
            refreshLayout.finishRefresh(3000);
        }

        @Override
        public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
            refreshLayout.finishLoadMore(2000);
        }

        @Override
        public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
            mOffset = offset / 2;
            parallax.setTranslationY(mOffset - mScrollY);
            toolbar.setAlpha(1 - Math.min(percent, 1));
        }
    });
    scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

        private int lastScrollY = 0;

        private int h = DensityUtil.dp2px(170);

        private int color = ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary) & 0x00ffffff;

        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if (lastScrollY < h) {
                scrollY = Math.min(h, scrollY);
                mScrollY = scrollY > h ? h : scrollY;
                buttonBar.setAlpha(1f * mScrollY / h);
                toolbar.setBackgroundColor(((255 * mScrollY / h) << 24) | color);
                parallax.setTranslationY(mOffset - mScrollY);
            }
            lastScrollY = scrollY;
        }
    });
    buttonBar.setAlpha(0);
    toolbar.setBackgroundColor(0);
}
Also used : RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) NestedScrollView(android.support.v4.widget.NestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) Toolbar(android.support.v7.widget.Toolbar)

Example 28 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.

the class EmptyLayoutExampleFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(root, savedInstanceState);
    final Toolbar toolbar = (Toolbar) root.findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });
    mRefreshLayout = (RefreshLayout) root.findViewById(refreshLayout);
    mRefreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
    mRefreshLayout.setOnRefreshListener(this);
    mRecyclerView = (RecyclerView) root.findViewById(recyclerView);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
    mLoadingLayout = (LoadingLayout) root.findViewById(R.id.loading);
    mLoadingLayout.showEmpty();
    /*主动演示刷新*/
    if (mIsNeedDemo) {
        mRefreshLayout.getLayout().postDelayed(new Runnable() {

            @Override
            public void run() {
                if (mIsNeedDemo) {
                    mRefreshLayout.autoRefresh();
                }
            }
        }, 3000);
        mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {

            @Override
            public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
                mIsNeedDemo = false;
            }
        });
    }
}
Also used : SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) ClassicsHeader(com.scwang.smartrefresh.layout.header.ClassicsHeader) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) R.id.recyclerView(com.scwang.refreshlayout.R.id.recyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Toolbar(android.support.v7.widget.Toolbar)

Example 29 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.

the class EmptyLayoutExampleFragmentInner method onViewCreated.

@Override
public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(root, savedInstanceState);
    final Toolbar toolbar = (Toolbar) root.findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });
    mRefreshLayout = (RefreshLayout) root.findViewById(refreshLayout);
    mRefreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
    mRefreshLayout.setOnRefreshListener(this);
    mRecyclerView = (RecyclerView) root.findViewById(recyclerView);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
    mEmptyLayout = root.findViewById(R.id.empty);
    ImageView image = (ImageView) root.findViewById(R.id.empty_image);
    image.setImageResource(R.drawable.ic_empty);
    TextView empty = (TextView) root.findViewById(R.id.empty_text);
    empty.setText("暂无数据下拉刷新");
    /*主动演示刷新*/
    if (mIsNeedDemo) {
        mRefreshLayout.getLayout().postDelayed(new Runnable() {

            @Override
            public void run() {
                if (mIsNeedDemo) {
                    mRefreshLayout.autoRefresh();
                }
            }
        }, 3000);
        mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {

            @Override
            public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
                mIsNeedDemo = false;
            }
        });
    }
}
Also used : SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) ClassicsHeader(com.scwang.smartrefresh.layout.header.ClassicsHeader) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) R.id.recyclerView(com.scwang.refreshlayout.R.id.recyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Toolbar(android.support.v7.widget.Toolbar)

Example 30 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.

the class NestedScrollExampleFragmentIntegral method onViewCreated.

@Override
public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(root, savedInstanceState);
    Toolbar toolbar = (Toolbar) root.findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });
    Banner banner = (Banner) root.findViewById(R.id.banner);
    banner.setImageLoader(new BannerImageLoader());
    banner.setImages(Arrays.asList(image_weibo_home_2, gif_header_repast));
    banner.start();
    RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recyclerView);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
    recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter<Item>(buildItems(), simple_list_item_2, NestedScrollExampleFragmentIntegral.this) {

        @Override
        protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
            holder.text(android.R.id.text1, model.name());
            holder.text(android.R.id.text2, model.name);
            holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
        }
    });
    RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
    refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

        @Override
        public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
            refreshLayout.getLayout().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mAdapter.loadMore(buildItems());
                    refreshLayout.finishLoadMore();
                }
            }, 2000);
        }
    });
}
Also used : OnLoadMoreListener(com.scwang.smartrefresh.layout.listener.OnLoadMoreListener) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) Banner(com.youth.banner.Banner) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Item(com.scwang.refreshlayout.fragment.example.NestedScrollExampleFragment.Item) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)40 View (android.view.View)26 Toolbar (android.support.v7.widget.Toolbar)24 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)22 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)20 SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)17 RecyclerView (android.support.v7.widget.RecyclerView)15 OnLoadmoreListener (com.scwang.smartrefresh.layout.listener.OnLoadmoreListener)12 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)11 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)10 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)10 AdapterView (android.widget.AdapterView)10 SimpleMultiPurposeListener (com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener)9 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)7 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)7 TextView (android.widget.TextView)6 ImageView (android.widget.ImageView)5 RefreshState (com.scwang.smartrefresh.layout.constant.RefreshState)5 ClassicsHeader (com.scwang.smartrefresh.layout.header.ClassicsHeader)5 OnLoadMoreListener (com.scwang.smartrefresh.layout.listener.OnLoadMoreListener)5