use of android.support.v4.widget.SwipeRefreshLayout in project FastDev4Android by jiangqqlmj.
the class RecyclerRefreshActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recycler_refresh_layout);
top_bar_linear_back = (LinearLayout) this.findViewById(R.id.top_bar_linear_back);
top_bar_linear_back.setOnClickListener(new CustomOnClickListener());
top_bar_title = (TextView) this.findViewById(R.id.top_bar_title);
top_bar_title.setText("RecyclerView下拉刷新,下拉加载更多...");
demo_swiperefreshlayout = (SwipeRefreshLayout) this.findViewById(R.id.demo_swiperefreshlayout);
demo_recycler = (RecyclerView) this.findViewById(R.id.demo_recycler);
// 设置刷新时动画的颜色,可以设置4个
demo_swiperefreshlayout.setProgressBackgroundColorSchemeResource(android.R.color.white);
demo_swiperefreshlayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
demo_swiperefreshlayout.setProgressViewOffset(false, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));
linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(OrientationHelper.VERTICAL);
demo_recycler.setLayoutManager(linearLayoutManager);
// 添加分隔线
demo_recycler.addItemDecoration(new AdvanceDecoration(this, OrientationHelper.VERTICAL));
demo_recycler.setAdapter(adapter = new RefreshRecyclerAdapter(this));
demo_swiperefreshlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Log.d("zttjiangqq", "invoke onRefresh...");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
List<String> newDatas = new ArrayList<String>();
for (int i = 0; i < 5; i++) {
int index = i + 1;
newDatas.add("new item" + index);
}
adapter.addItem(newDatas);
demo_swiperefreshlayout.setRefreshing(false);
Toast.makeText(RecyclerRefreshActivity.this, "更新了五条数据...", Toast.LENGTH_SHORT).show();
}
}, 1500);
}
});
// RecyclerView滑动监听
demo_recycler.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItem + 1 == adapter.getItemCount()) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
List<String> newDatas = new ArrayList<String>();
for (int i = 0; i < 5; i++) {
int index = i + 1;
newDatas.add("more item" + index);
}
adapter.addMoreItem(newDatas);
}
}, 1000);
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
}
});
}
use of android.support.v4.widget.SwipeRefreshLayout in project LeafPic by HoraApps.
the class MainActivity method initUI.
private void initUI() {
/**
** TOOLBAR ***
*/
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
/**
** RECYCLER VIEW ***
*/
rvAlbums = (RecyclerView) findViewById(R.id.grid_albums);
rvMedia = ((RecyclerView) findViewById(R.id.grid_photos));
rvAlbums.setHasFixedSize(true);
rvAlbums.setItemAnimator(new DefaultItemAnimator());
rvMedia.setHasFixedSize(true);
rvMedia.setItemAnimator(new DefaultItemAnimator());
albumsAdapter = new AlbumsAdapter(getAlbums().dispAlbums, MainActivity.this);
albumsAdapter.setOnClickListener(albumOnClickListener);
albumsAdapter.setOnLongClickListener(albumOnLongCLickListener);
rvAlbums.setAdapter(albumsAdapter);
mediaAdapter = new MediaAdapter(getAlbum().getMedia(), MainActivity.this);
mediaAdapter.setOnClickListener(photosOnClickListener);
mediaAdapter.setOnLongClickListener(photosOnLongClickListener);
rvMedia.setAdapter(mediaAdapter);
int spanCount = SP.getInt("n_columns_folders", 2);
rvAlbumsDecoration = new GridSpacingItemDecoration(spanCount, Measure.pxToDp(3, getApplicationContext()), true);
rvAlbums.addItemDecoration(rvAlbumsDecoration);
rvAlbums.setLayoutManager(new GridLayoutManager(this, spanCount));
spanCount = SP.getInt("n_columns_media", 3);
rvMediaDecoration = new GridSpacingItemDecoration(spanCount, Measure.pxToDp(3, getApplicationContext()), true);
rvMedia.setLayoutManager(new GridLayoutManager(getApplicationContext(), spanCount));
rvMedia.addItemDecoration(rvMediaDecoration);
/**
** SWIPE TO REFRESH ***
*/
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setColorSchemeColors(getAccentColor());
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(getBackgroundColor());
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (albumsMode) {
getAlbums().clearSelectedAlbums();
new PrepareAlbumTask().execute();
} else {
getAlbum().clearSelectedPhotos();
new PreparePhotosTask().execute();
}
}
});
/**
** DRAWER ***
*/
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.addDrawerListener(new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
public void onDrawerClosed(View view) {
// Put your code here
// materialMenu.animateIconState(MaterialMenuDrawable.IconState.BURGER);
}
public void onDrawerOpened(View drawerView) {
// Put your code here
// materialMenu.animateIconState(MaterialMenuDrawable.IconState.ARROW);
}
});
/**
** FAB **
*/
fabCamera = (FloatingActionButton) findViewById(R.id.fab_camera);
fabCamera.setImageDrawable(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_camera_alt).color(Color.WHITE));
fabCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA));
}
});
// region TESTING
fabCamera.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// NOTE: this is used to acquire write permission on sd with api 21
// TODO call this one when unable to write on sd
requestSdCardPermissions();
return false;
}
});
// endregion
setRecentApp(getString(R.string.app_name));
setupUI();
}
use of android.support.v4.widget.SwipeRefreshLayout in project MVCHelper by LuckyJayce.
the class SwipeRefreshActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swiperefresh);
// PullToRefreshListView refreshListView = (PullToRefreshListView)
// findViewById(R.id.pullToRefreshListView);
ListView listView = (ListView) findViewById(R.id.listView);
SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
mvcHelper = new MVCSwipeRefreshHelper<>(swipeRefreshLayout);
// 设置数据源
mvcHelper.setDataSource(new BooksDataSource());
// 设置适配器
mvcHelper.setAdapter(new BooksAdapter(this));
// 加载数据
mvcHelper.refresh();
listView.setOnItemClickListener(onItemClickListener);
}
use of android.support.v4.widget.SwipeRefreshLayout in project MVCHelper by LuckyJayce.
the class Volley_OKHttp_GridViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_girdview);
// PullToRefreshListView refreshListView = (PullToRefreshListView)
// findViewById(R.id.pullToRefreshListView);
SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
// GridViewWithHeaderAndFooter gridViewWithHeaderAndFooter =
// (GridViewWithHeaderAndFooter) findViewById(R.id.girdView);
mvcHelper = new MVCSwipeRefreshHelper<List<Book>>(swipeRefreshLayout);
/**
* 设置数据源
*/
// 用okhttp 普通请求的例子
// mvcHelper.setDataSource(new BooksOkHttpNormal_DataSource());
// 用mvcelper-okhttp 异步执行的例子
mvcHelper.setDataSource(new BooksOkHttp_AsyncDataSource());
// 用mvcelper-okhttp 同步执行的例子
// mvcHelper.setDataSource(new BooksOkHttp_SyncDataSource());
// 用volley 例子
// mvcHelper.setDataSource(new BooksVolleyDataSource());
// 设置AsyncHttpClient 作为网络请求的数据源
// listViewHelper.setDataSource(new BooksOkHttpNormal_DataSource());
// 设置适配器
mvcHelper.setAdapter(new BooksAdapter(this), new GridViewHandler());
// 加载数据
mvcHelper.refresh();
}
use of android.support.v4.widget.SwipeRefreshLayout in project android-oss by kickstarter.
the class CommentsActivity method onCreate.
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.comments_layout);
ButterKnife.bind(this);
adapter = new CommentsAdapter(this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerViewPaginator = new RecyclerViewPaginator(recyclerView, viewModel.inputs::nextPage);
swipeRefresher = new SwipeRefresher(this, swipeRefreshLayout, viewModel.inputs::refresh, viewModel.outputs::isFetchingComments);
final Observable<TextView> commentBodyEditText = alertDialog.map(a -> ButterKnife.findById(a, R.id.comment_body));
final Observable<TextView> postCommentButton = alertDialog.map(a -> ButterKnife.findById(a, R.id.post_button));
final Observable<TextView> cancelButton = alertDialog.map(a -> ButterKnife.findById(a, R.id.cancel_button));
cancelButton.switchMap(RxView::clicks).observeOn(AndroidSchedulers.mainThread()).compose(bindToLifecycle()).subscribe(__ -> viewModel.inputs.commentDialogDismissed());
postCommentButton.switchMap(RxView::clicks).compose(bindToLifecycle()).subscribe(__ -> viewModel.inputs.postCommentClicked());
commentBodyEditText.switchMap(t -> RxTextView.textChanges(t).skip(1)).map(CharSequence::toString).compose(bindToLifecycle()).subscribe(viewModel.inputs::commentBodyChanged);
viewModel.outputs.currentCommentBody().compose(Transformers.takePairWhen(commentBodyEditText)).observeOn(AndroidSchedulers.mainThread()).compose(bindToLifecycle()).subscribe(ce -> ce.second.append(ce.first));
viewModel.outputs.commentsData().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(adapter::takeData);
viewModel.outputs.enablePostButton().compose(Transformers.combineLatestPair(postCommentButton)).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(bb -> setPostButtonEnabled(bb.second, bb.first));
viewModel.outputs.showCommentButton().map(show -> show ? View.VISIBLE : View.GONE).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(commentButtonTextView::setVisibility);
viewModel.outputs.showCommentDialog().filter(projectAndShow -> projectAndShow != null).map(projectAndShow -> projectAndShow.first).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showCommentDialog);
alertDialog.compose(Transformers.takeWhen(viewModel.outputs.dismissCommentDialog())).observeOn(AndroidSchedulers.mainThread()).compose(bindToLifecycle()).subscribe(this::dismissCommentDialog);
lifecycle().compose(Transformers.combineLatestPair(alertDialog)).filter(ad -> ad.first == ActivityEvent.DESTROY).map(ad -> ad.second).observeOn(AndroidSchedulers.mainThread()).take(1).subscribe(this::dismissCommentDialog);
toastMessages().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(ViewUtils.showToast(this));
}
Aggregations