Search in sources :

Example 61 with SwipeRefreshLayout

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();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AdvanceDecoration(com.chinaztt.fda.widget.AdvanceDecoration) RecyclerView(android.support.v7.widget.RecyclerView) RefreshRecyclerAdapter(com.chinaztt.fda.adapter.RefreshRecyclerAdapter)

Example 62 with SwipeRefreshLayout

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();
}
Also used : AlbumsAdapter(org.horaapps.leafpic.adapters.AlbumsAdapter) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) MediaAdapter(org.horaapps.leafpic.adapters.MediaAdapter) Intent(android.content.Intent) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SearchView(android.support.v7.widget.SearchView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) IconicsImageView(com.mikepenz.iconics.view.IconicsImageView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) GridSpacingItemDecoration(org.horaapps.leafpic.views.GridSpacingItemDecoration)

Example 63 with SwipeRefreshLayout

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);
}
Also used : BooksAdapter(com.shizhefei.test.view.adapters.BooksAdapter) ListView(android.widget.ListView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) BooksDataSource(com.shizhefei.test.models.datasource.BooksDataSource)

Example 64 with SwipeRefreshLayout

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();
}
Also used : BooksOkHttp_AsyncDataSource(com.shizhefei.test.models.datasource.okhttp.BooksOkHttp_AsyncDataSource) BooksAdapter(com.shizhefei.test.view.adapters.BooksAdapter) List(java.util.List) GridViewHandler(in.srain.cube.views.GridViewHandler) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 65 with SwipeRefreshLayout

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));
}
Also used : Transformers(com.kickstarter.libs.rx.transformers.Transformers) ViewUtils(com.kickstarter.libs.utils.ViewUtils) ProjectContextViewHolder(com.kickstarter.ui.viewholders.ProjectContextViewHolder) LoginReason(com.kickstarter.ui.data.LoginReason) EmptyCommentsViewHolder(com.kickstarter.ui.viewholders.EmptyCommentsViewHolder) Bundle(android.os.Bundle) ActivityRequestCodes(com.kickstarter.libs.ActivityRequestCodes) ButterKnife(butterknife.ButterKnife) Pair(android.util.Pair) WindowManager(android.view.WindowManager) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) CommentsViewModel(com.kickstarter.viewmodels.CommentsViewModel) OnClick(butterknife.OnClick) Observable(rx.Observable) RecyclerViewPaginator(com.kickstarter.libs.RecyclerViewPaginator) RequiresActivityViewModel(com.kickstarter.libs.qualifiers.RequiresActivityViewModel) RxView(com.jakewharton.rxbinding.view.RxView) CommentsAdapter(com.kickstarter.ui.adapters.CommentsAdapter) R(com.kickstarter.R) ActivityEvent(com.trello.rxlifecycle.ActivityEvent) View(android.view.View) Bind(butterknife.Bind) DialogInterface(android.content.DialogInterface) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SwipeRefresher(com.kickstarter.libs.SwipeRefresher) BaseActivity(com.kickstarter.libs.BaseActivity) Project(com.kickstarter.models.Project) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ObjectUtils(com.kickstarter.libs.utils.ObjectUtils) BindString(butterknife.BindString) RecyclerView(android.support.v7.widget.RecyclerView) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable) IntentKey(com.kickstarter.ui.IntentKey) PublishSubject(rx.subjects.PublishSubject) RxTextView(com.jakewharton.rxbinding.widget.RxTextView) TransitionUtils.slideInFromLeft(com.kickstarter.libs.utils.TransitionUtils.slideInFromLeft) CommentsAdapter(com.kickstarter.ui.adapters.CommentsAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefresher(com.kickstarter.libs.SwipeRefresher) RecyclerViewPaginator(com.kickstarter.libs.RecyclerViewPaginator) TextView(android.widget.TextView) RxTextView(com.jakewharton.rxbinding.widget.RxTextView) RxView(com.jakewharton.rxbinding.view.RxView)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)115 View (android.view.View)65 RecyclerView (android.support.v7.widget.RecyclerView)58 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)43 TextView (android.widget.TextView)30 Bundle (android.os.Bundle)21 Intent (android.content.Intent)20 Handler (android.os.Handler)17 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)16 Toolbar (android.support.v7.widget.Toolbar)16 ArrayList (java.util.ArrayList)16 AdapterView (android.widget.AdapterView)14 ListView (android.widget.ListView)12 ImageView (android.widget.ImageView)11 GridLayoutManager (android.support.v7.widget.GridLayoutManager)10 Context (android.content.Context)9 LayoutInflater (android.view.LayoutInflater)9 ViewGroup (android.view.ViewGroup)9 DialogInterface (android.content.DialogInterface)8 FrameLayout (android.widget.FrameLayout)7