use of me.dkzwm.widget.srl.util.AutoRefreshUtil in project SmoothRefreshLayout by dkzwm.
the class WithWebViewActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_with_webview);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle(R.string.with_webView);
mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_webView);
MaterialHeader header = new MaterialHeader(this);
header.setPadding(0, PixelUtl.dp2px(this, 20), 0, PixelUtl.dp2px(this, 20));
mRefreshLayout.setHeaderView(header);
mRefreshLayout.setEnablePinRefreshViewWhileLoading(true);
mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
@Override
public void onRefreshing() {
mWebView.loadUrl("https://github.com/dkzwm");
}
});
mWebView = findViewById(R.id.webView_with_webView);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
mRefreshLayout.refreshComplete();
}
});
mRefreshLayout.autoRefresh(false);
mAutoRefreshUtil = new AutoRefreshUtil(mWebView);
mRefreshLayout.addLifecycleObserver(mAutoRefreshUtil);
}
use of me.dkzwm.widget.srl.util.AutoRefreshUtil in project SmoothRefreshLayout by dkzwm.
the class TestScrollToAutoRefreshActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_scroll_to_auto_refresh);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle(R.string.test_scroll_to_auto_refresh);
RecyclerView recyclerView = findViewById(R.id.recyclerView_test_scroll_to_auto_refresh);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
mAdapter = new RecyclerViewAdapter(this, getLayoutInflater());
recyclerView.setAdapter(mAdapter);
mLottieHeader = new CustomLottieHeader(this);
mLottieHeader.setAnimation(NAME_OF_ANIMATION_JSON[mIndex]);
mLottieHeader.setScale(.15f);
mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_scroll_to_auto_refresh);
mRefreshLayout.setDisableLoadMore(false);
mRefreshLayout.setHeaderView(mLottieHeader);
mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
@Override
public void onRefreshing() {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
List<String> list = DataUtil.createList(mCount, 20);
mCount = list.size();
mAdapter.updateData(list);
mRefreshLayout.refreshComplete();
}
}, 2000);
}
@Override
public void onLoadingMore() {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
List<String> list = DataUtil.createList(mCount, 20);
mCount += list.size();
mAdapter.appendData(list);
mRefreshLayout.refreshComplete();
}
}, 2000);
}
});
mRefreshLayout.addOnStatusChangedListener(new SmoothRefreshLayout.OnStatusChangedListener() {
@Override
public void onStatusChanged(byte old, byte now) {
if (now == SmoothRefreshLayout.SR_STATUS_INIT && old == SmoothRefreshLayout.SR_STATUS_COMPLETE) {
if (mIndex >= NAME_OF_ANIMATION_JSON.length - 1) {
mIndex = 0;
} else {
mIndex++;
}
mLottieHeader.setAnimation(NAME_OF_ANIMATION_JSON[mIndex]);
}
}
});
mRefreshLayout.setSpringInterpolator(new OvershootInterpolator(3));
mRefreshLayout.autoRefresh(false);
mAutoRefreshUtil = new AutoRefreshUtil(recyclerView);
mRefreshLayout.addLifecycleObserver(mAutoRefreshUtil);
findViewById(R.id.button_test_scroll_to_auto_refresh_left).setOnClickListener(this);
findViewById(R.id.button_test_scroll_to_auto_refresh_right).setOnClickListener(this);
}
Aggregations