Java Code Examples for android.support.v4.widget.SwipeRefreshLayout#post()
The following examples show how to use
android.support.v4.widget.SwipeRefreshLayout#post() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LatestPostsFragment.java From materialup with MIT License | 6 votes |
private void setupSwipeRefreshLayout() { mSwipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { getContent(); } }); mSwipeRefreshLayout.post(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(true); } }); }
Example 2
Source File: PopularPostsFragment.java From materialup with MIT License | 6 votes |
private void setupSwipeRefreshLayout() { mSwipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { getContent(); } }); mSwipeRefreshLayout.post(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(true); } }); }
Example 3
Source File: WebViewPresenterImpl.java From AdBlockedWebView-Android with MIT License | 6 votes |
@Override public void onProgressChanged(final SwipeRefreshLayout swipeRefreshLayout, int progress) { if (swipeRefreshLayout.isRefreshing() && progress == 100) { swipeRefreshLayout.post(new Runnable() { @Override public void run() { mView.setRefreshing(false); } }); } if (!swipeRefreshLayout.isRefreshing() && progress != 100) { swipeRefreshLayout.post(new Runnable() { @Override public void run() { mView.setRefreshing(true); } }); } if (progress == 100) { progress = 0; } mView.setProgressBar(progress); }
Example 4
Source File: NotesFragment.java From androidtestdebug with MIT License | 6 votes |
@Override public void setProgressIndicator(final boolean active) { if (getView() == null) { return; } final SwipeRefreshLayout srl = (SwipeRefreshLayout) getView().findViewById(R.id.refresh_layout); // Make sure setRefreshing() is called after the layout is done with everything else. srl.post(new Runnable() { @Override public void run() { srl.setRefreshing(active); } }); }
Example 5
Source File: CategorySelectionFragment.java From CoolSignIn with Apache License 2.0 | 6 votes |
@Override public void onViewCreated(View view, Bundle savedInstanceState) { final User user = ((CategorySelectionActivity)getActivity()).getUser(); swipeRefreshLayout = (SwipeRefreshLayout)view.findViewById(R.id.swipe_refresh_layout); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { AsyncHttpHelper.refrash(user.getPhone(), user.getPass(), CategorySelectionFragment.this); } }); setUpQuizGrid((RecyclerView) view.findViewById(R.id.categories)); swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); } }); AsyncHttpHelper.refrash(user.getPhone(), user.getPass(), CategorySelectionFragment.this); super.onViewCreated(view, savedInstanceState); }
Example 6
Source File: CollectionFragment.java From Bangumi-Android with MIT License | 6 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); adapter = new CardRecyclerAdapter(getActivity(), data); adapter.setViewType(CardRecyclerAdapter.VIEW_TYPE_WITH_PROGRESS); RecyclerView mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_wrapper).findViewById(R.id.recycler); mRecyclerView.addItemDecoration(new MarginDecoration(getActivity())); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(adapter); mSwipeRefresh = (SwipeRefreshLayout) getView().findViewById(R.id.recycler_wrapper); mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { getCollections(); } }); mSwipeRefresh.post(new Runnable() { @Override public void run() { getCollections(); } }); }
Example 7
Source File: CalendarPageFragment.java From Bangumi-Android with MIT License | 6 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); adapter = new CardRecyclerAdapter(ctx, data); RecyclerView mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler); mRecyclerView.addItemDecoration(new MarginDecoration(getActivity())); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(adapter); mSwipeRefresh = (SwipeRefreshLayout) getView().findViewById(R.id.swipe_refresh); mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mSwipeRefresh.setRefreshing(false); } }); mSwipeRefresh.post(new Runnable() { @Override public void run() { mSwipeRefresh.setRefreshing(true); } }); }
Example 8
Source File: NotesFragment.java From androidtestdebug with MIT License | 6 votes |
@Override public void setProgressIndicator(final boolean active) { if (getView() == null) { return; } final SwipeRefreshLayout srl = (SwipeRefreshLayout) getView().findViewById(R.id.refresh_layout); // Make sure setRefreshing() is called after the layout is done with everything else. srl.post(new Runnable() { @Override public void run() { srl.setRefreshing(active); } }); }
Example 9
Source File: StaffDeskActivity.java From RestaurantApp with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(R.style.AppThemeStaffLogin); super.onCreate(savedInstanceState); setContentView(R.layout.activity_staff_desk); deskListGlobal = new ArrayList<>(); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); } } ); Request request = new Request(this, url, com.android.volley.Request.Method.GET); request.requestVolleyDeskList(this); gridView = (GridView) findViewById(R.id.gvDesk); gridView.setOnItemClickListener(this); getSupportActionBar().setDisplayOptions(android.support.v7.app.ActionBar.DISPLAY_SHOW_CUSTOM); getSupportActionBar().setCustomView(R.layout.custom_actionbar); tvActionBar = (TextView)getSupportActionBar().getCustomView().findViewById(R.id.tvActionBar); ibLogout = (ImageButton) getSupportActionBar().getCustomView().findViewById(R.id.ibLogout); ibLogout.setVisibility(View.VISIBLE); ibLogout.setOnClickListener(this); tvActionBar.setText(getResources().getString(R.string.staffDeskHeader)); //startService(new Intent(StaffDeskActivity.this, StaffService.class)); }
Example 10
Source File: TasksFragment.java From AndroidProjects with MIT License | 5 votes |
@Override public void setLoadingIndicator(final boolean active) { if (getView() == null) { return; } final SwipeRefreshLayout srl = (SwipeRefreshLayout) getView().findViewById(R.id.refresh_layout); // 确保setRefreshing()布局后完成了一切。 srl.post(new Runnable() { @Override public void run() { srl.setRefreshing(active); } }); }
Example 11
Source File: ComputerNewsFragment.java From MyHearts with Apache License 2.0 | 5 votes |
private void initView(View view) { mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh); mRefreshLayout.setColorSchemeColors(Color.YELLOW, Color.RED, Color.BLUE, Color.GREEN); //能够模拟进入就刷新 mRefreshLayout.post(() -> mRefreshLayout.setRefreshing(true)); mRefreshLayout.setOnRefreshListener(this); mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); LinearLayoutManager manager = new LinearLayoutManager(getContext()); mRecyclerView.setLayoutManager(manager); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); int lastVisiableItemPosition = manager.findLastVisibleItemPosition(); if (lastVisiableItemPosition + 1 == mNewsAdapter.getItemCount()) { if (!isLoading) { isLoading = true; new Handler().postDelayed(() -> { getMoreData(); isLoading = false; mNewsAdapter.notifyItemRemoved(mNewsAdapter.getItemCount()); }, 3000); } } } }); //mNewsAdapter = new NewsAdapter(getContext(),mDatasEntities); // mRecyclerView.setAdapter(mNewsAdapter); }
Example 12
Source File: AndroidUtils.java From go-bees with GNU General Public License v3.0 | 5 votes |
/** * Displays or hide loading indicator. * * @param view current view. * @param active true or false. */ public static void setLoadingIndicator(View view, final boolean active) { if (view == null) { return; } final SwipeRefreshLayout srl = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout); // Make sure setRefreshing() is called after the layout is done with everything else srl.post(new Runnable() { @Override public void run() { srl.setRefreshing(active); } }); }
Example 13
Source File: ModLog.java From Slide with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false); RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content)); final PreCachingLayoutManager mLayoutManager; mLayoutManager = new PreCachingLayoutManager(getActivity()); rv.setLayoutManager(mLayoutManager); v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE); final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("mod", getActivity())); //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned. //So, we estimate the height of the header in dp mSwipeRefreshLayout.setProgressViewOffset(false, Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM); mSwipeRefreshLayout.post(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(true); } }); posts = new ModLogPosts(); adapter = new ModLogAdapter(getActivity(), posts, rv); rv.setAdapter(adapter); rv.setOnScrollListener(new ToolbarScrollHideHandler(((ModQueue) getActivity()).mToolbar, (getActivity()).findViewById(R.id.header))); posts.bindAdapter(adapter, mSwipeRefreshLayout); mSwipeRefreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { posts.loadMore(adapter); } } ); return v; }
Example 14
Source File: MainActivity.java From cashuwallet with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); navigationView.getMenu().performIdentifierAction(R.id.nav_wallet, 0); sync = MainApplication.app().getSync(); List<Multiwallet> multiwallets = sync.findMultiwallets(0); Collections.sort(multiwallets, (Multiwallet m1, Multiwallet m2) -> m1.getCoin().getName().compareTo(m2.getCoin().getName())); adapter = new Adapter(multiwallets); RecyclerView recyclerView = findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL)); recyclerView.setAdapter(adapter); SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.swipe_refresh_layout); swipeRefreshLayout.setOnRefreshListener(() -> { if (!MainApplication.app().networkAvailable()) { Snackbar.make(recyclerView, R.string.network_not_available, Snackbar.LENGTH_LONG).show(); swipeRefreshLayout.setRefreshing(false); return; } adapter.refresh(); swipeRefreshLayout.setRefreshing(false); }); swipeRefreshLayout.post(() -> adapter.refresh()); if (MainApplication.app().requiresReconnect()) { new AlertDialog.Builder(this) .setTitle(R.string.new_version_installed) .setCancelable(true) .setMessage(R.string.info_newcoins_reset) .setPositiveButton(R.string.ok, null) .show(); } }
Example 15
Source File: MainActivity.java From MyWeather with Apache License 2.0 | 4 votes |
private void initWidget() { contentMian = (ScrollView) findViewById(R.id.content_main); contentMian.setVisibility(View.INVISIBLE); mCurrentAreaTv = (TextView) findViewById(R.id.tv_topCity); mCurrentAreaTv.setText("正在刷新"); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh); swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); } }); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(false); } }); mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar.setTitle(""); setSupportActionBar(mToolbar); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawLayout); mFirstShowRl = findViewById(R.id.first_show_rl); TypedArray actionbarSizeTypedArray = this.obtainStyledAttributes(new int[]{android.R.attr.actionBarSize}); int h = (int) actionbarSizeTypedArray.getDimension(0, 0); mFirstShowRl.getLayoutParams().height = ScreenUtil.getScreenHeight(this) - h - ScreenUtil.getStatusBarHeight(this); setDrawerLayout(); setRealWeather(); setForeCast(); setWind(); setAqi(); setSunRiseView(); setZhiShu(); }
Example 16
Source File: CircleFriendsActivity.java From MyHearts with Apache License 2.0 | 4 votes |
@Override public void initView() { eventid = getIntent().getStringExtra("eventid"); mCommentCount = Integer.parseInt(getIntent().getStringExtra("commentCount")); totalPage = mCommentCount / 30 + 1; this.mLlrote = (LinearLayout) findViewById(R.id.ll_rote); this.mRecomment = (LinearLayout) findViewById(R.id.re_comment); this.mRecyclerview = (RecyclerView) findViewById(R.id.recycler_view); mRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh); mRefreshLayout.setColorSchemeColors(Color.YELLOW, Color.RED, Color.BLUE, Color.GREEN); mRefreshLayout.post(() -> mRefreshLayout.setRefreshing(true)); mRefreshLayout.setOnRefreshListener(this); FullyLinearLayoutManager manager = new FullyLinearLayoutManager(this) { @Override public boolean canScrollVertically() { return false; } }; mRecyclerview.setLayoutManager(manager); mRecyclerview.setItemAnimator(new SlideInOutTopItemAnimator(mRecyclerview)); mCommentAdapter = new CircleFriendsCommentAdapter(this, mCircleFriendsComments); mRecyclerview.setAdapter(mCommentAdapter); // //滑动到底部自动加载更多(如果后面还有数据的话) // mRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() { // @Override // public void onScrollStateChanged(RecyclerView recyclerView, int newState) { // super.onScrollStateChanged(recyclerView, newState); // // int lastVisiableItemPosition = manager.findLastVisibleItemPosition(); // int itemNum = manager.getItemCount(); // if (lastVisiableItemPosition + 1 == manager.getItemCount()) { // if (!isLoading) { // isLoading = true; // CustomPrograss.show(CircleFriendsActivity.this, // getResources().getString(R.string.loading), false, null); // new Handler().postDelayed(() -> { // getMoreData(); // isLoading = false; // CustomPrograss.disMiss(); // // mMemberAdapter.notifyItemRemoved(mMemberAdapter.getItemCount()); // }, 3000); // } // } // } // }); this.mTvviewcount = (TextView) findViewById(R.id.tv_view_count); this.mIvcomment = (ImageView) findViewById(R.id.iv_comment); this.mTvcommentcount = (TextView) findViewById(R.id.tv_comment_count); this.mIvtype = (ImageView) findViewById(R.id.iv_type); this.mNineGrid = (NineGridView) findViewById(R.id.nineGrid); this.mTvcontent = (TextView) findViewById(R.id.tv_content); this.mImagegender = (ImageView) findViewById(R.id.image_gender); this.mTvtime = (TextView) findViewById(R.id.tv_time); this.mTvname = (TextView) findViewById(R.id.tv_name); this.mIvtour = (ImageView) findViewById(R.id.iv_tour); this.mIcBack = (ImageView) findViewById(R.id.ic_back); this.mIcReport = (ImageView) findViewById(R.id.ic_report); mScrollView = (MyScrollview) findViewById(R.id.scrollView); mScrollView.setVisibility(View.INVISIBLE); mScrollView.setOnZdyScrollViewListener(() -> { //加载更多数据 CustomPrograss.show(CircleFriendsActivity.this, getResources().getString(R.string.loading), false, null); new Handler().postDelayed(() -> getMoreData(),1000); }); }
Example 17
Source File: BaseListFragment.java From FlowGeek with GNU General Public License v2.0 | 4 votes |
@Override public void onViewCreated(final View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh); mListView = (RecyclerView) view.findViewById(R.id.list_view); mErrorLayout = (ErrorLayout) view.findViewById(R.id.error_frame); if (getRefreshable()){ mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setColorSchemeResources( R.color.swipe_refresh_first, R.color.swipe_refresh_second, R.color.swipe_refresh_third, R.color.swipe_refresh_four ); mSwipeRefreshLayout.setProgressBackgroundColorSchemeResource( UIHelper.getAttrResourceFromTheme(R.attr.refresh_progress_background, getActivity().getTheme()) ); } mErrorLayout.setOnActiveClickListener(this); mListView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); mListView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(getActivity()) .color(setDividerColor()) .size(setDividerSize()) .build()); if (mAdapter!=null){ mListView.setAdapter(mAdapter); }else{ mAdapter = onSetupAdapter(); mListView.setAdapter(mAdapter); mAdapter.setOnLoadingListener(this); mErrorLayout.setState(ErrorLayout.LOADING); } if (savedInstanceState != null){ if (mState == STATE_REFRESHING && getRefreshable() && savedInstanceState.getInt(BUNDLE_STATE_REFRESH, STATE_NONE) == STATE_REFRESHING){ mSwipeRefreshLayout.post(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(true); } }); } if (mState == STATE_CACHE_LOADING && getRefreshable() && savedInstanceState.getInt(BUNDLE_STATE_REFRESH, STATE_NONE) == STATE_CACHE_LOADING){ mErrorLayout.setState(ErrorLayout.LOADING); } } }
Example 18
Source File: HistoryView.java From Slide with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false); final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content)); final PreCachingLayoutManager mLayoutManager; mLayoutManager = new PreCachingLayoutManager(getContext()); rv.setLayoutManager(mLayoutManager); rv.setItemViewCacheSize(2); v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE); final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("default", getActivity())); //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned. //So, we estimate the height of the header in dp mSwipeRefreshLayout.setProgressViewOffset(false, Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM); mSwipeRefreshLayout.post(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(true); } }); posts = new HistoryPosts(); adapter = new ContributionAdapter(getActivity(), posts, rv); rv.setAdapter(adapter); posts.bindAdapter(adapter, mSwipeRefreshLayout); //TODO catch errors mSwipeRefreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { posts.loadMore(adapter, true); //TODO catch errors } } ); rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); visibleItemCount = rv.getLayoutManager().getChildCount(); totalItemCount = rv.getLayoutManager().getItemCount(); if (rv.getLayoutManager() instanceof PreCachingLayoutManager) { pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition(); } else { int[] firstVisibleItems = null; firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems); if (firstVisibleItems != null && firstVisibleItems.length > 0) { pastVisiblesItems = firstVisibleItems[0]; } } if (!posts.loading) { if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) { posts.loading = true; posts.loadMore(adapter, false); } } } }); return v; }
Example 19
Source File: ReadLaterView.java From Slide with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false); final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content)); final PreCachingLayoutManager mLayoutManager; mLayoutManager = new PreCachingLayoutManager(getContext()); rv.setLayoutManager(mLayoutManager); v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE); final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("default", getActivity())); //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned. //So, we estimate the height of the header in dp mSwipeRefreshLayout.setProgressViewOffset(false, Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM); mSwipeRefreshLayout.post(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(true); } }); posts = new HistoryPosts("readLater"); adapter = new ContributionAdapter(getActivity(), posts, rv); rv.setAdapter(adapter); posts.bindAdapter(adapter, mSwipeRefreshLayout); //TODO catch errors mSwipeRefreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { posts.loadMore(adapter, true); //TODO catch errors } } ); rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); visibleItemCount = rv.getLayoutManager().getChildCount(); totalItemCount = rv.getLayoutManager().getItemCount(); if (rv.getLayoutManager() instanceof PreCachingLayoutManager) { pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition(); } else { int[] firstVisibleItems = null; firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems); if (firstVisibleItems != null && firstVisibleItems.length > 0) { pastVisiblesItems = firstVisibleItems[0]; } } if (!posts.loading) { if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) { posts.loading = true; posts.loadMore(adapter, false); } } } }); return v; }
Example 20
Source File: WeatherActivity.java From FoodOrdering with Apache License 2.0 | 4 votes |
private void initWidget() { contentMian = (ScrollView) findViewById(R.id.content_main); contentMian.setVisibility(View.INVISIBLE); mCurrentAreaTv = (TextView) findViewById(R.id.tv_topCity); mCurrentAreaTv.setText("正在刷新"); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh); swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); } }); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(false); } }); mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar.setTitle(""); setSupportActionBar(mToolbar); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawLayout); mFirstShowRl = findViewById(R.id.first_show_rl); TypedArray actionbarSizeTypedArray = this.obtainStyledAttributes(new int[]{android.R.attr.actionBarSize}); int h = (int) actionbarSizeTypedArray.getDimension(0, 0); mFirstShowRl.getLayoutParams().height = ScreenUtil.getScreenHeight(this) - h - ScreenUtil.getStatusBarHeight(this); // setDrawerLayout();//加载侧滑栏菜单 setRealWeather(); setForeCast(); setWind(); setAqi(); setSunRiseView(); setZhiShu(); }