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));
}
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);
}
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;
}
});
}
}
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;
}
});
}
}
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);
}
});
}
Aggregations