androidx.swiperefreshlayout.widget.SwipeRefreshLayout Java Examples

The following examples show how to use androidx.swiperefreshlayout.widget.SwipeRefreshLayout. 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: MobiComQuickConversationFragment.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void onPreExecute() {
    super.onPreExecute();
    isAlreadyLoading = true;
    if (loadMoreMessages) {
        if (!messageList.contains(null)) {
            messageList.add(null);
        }
        if (recyclerAdapter != null) {
            recyclerAdapter.notifyItemInserted(messageList.size() - 1);
        }
    } else {
        if (swipeRefreshLayoutWeakReference != null) {
            final SwipeRefreshLayout swipeRefreshLayout = swipeRefreshLayoutWeakReference.get();
            if (swipeRefreshLayout != null) {
                swipeRefreshLayout.setEnabled(true);
                swipeRefreshLayout.post(new Runnable() {
                    @Override
                    public void run() {
                        swipeRefreshLayout.setRefreshing(true);
                    }
                });
            }
        }
    }
}
 
Example #2
Source File: MaterialScrollBar.java    From MaterialScrollBar with Apache License 2.0 6 votes vote down vote up
void identifySwipeRefreshParents() {
    boolean cycle = true;
    ViewParent parent = getParent();
    if(parent != null) {
        while(cycle) {
            if(parent instanceof SwipeRefreshLayout) {
                swipeRefreshLayout = (SwipeRefreshLayout)parent;
                cycle = false;
            } else {
                if(parent.getParent() == null) {
                    cycle = false;
                } else {
                    parent = parent.getParent();
                }
            }
        }
    }
}
 
Example #3
Source File: ItemFragment.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) {
    if (isNewInstance()) {
        mFragmentView = inflater.inflate(R.layout.fragment_item, container, false);
        mEmptyView = mFragmentView.findViewById(R.id.empty);
        mRecyclerView = (RecyclerView) mFragmentView.findViewById(R.id.recycler_view);
        mRecyclerView.setLayoutManager(new SnappyLinearLayoutManager(getActivity(), true));
        mItemDecoration = new CommentItemDecoration(getActivity());
        mRecyclerView.addItemDecoration(mItemDecoration);
        mSwipeRefreshLayout = (SwipeRefreshLayout) mFragmentView.findViewById(R.id.swipe_layout);
        mSwipeRefreshLayout.setColorSchemeResources(R.color.white);
        mSwipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.redA200);
        mSwipeRefreshLayout.setOnRefreshListener(() -> {
            if (TextUtils.isEmpty(mItemId)) {
                return;
            }
            mCacheMode = ItemManager.MODE_NETWORK;
            if (mAdapter != null) {
                mAdapter.setCacheMode(mCacheMode);
            }
            loadKidData();
        });
    }
    return mFragmentView;
}
 
Example #4
Source File: ArticleListFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    ButterKnife.bind(this, view);
    ((BaseActivity) getActivity()).setupToolbar();
    mArticleAdapter = new ArticleListAdapter(getContext(),getActivity().getSupportFragmentManager());
    mArticleAdapter.setMenuTogglerListener(mMenuTogglerListener);
    mListView.setLayoutManager(new LinearLayoutManager(getContext()));
    mListView.setItemViewCacheSize(20);
    mListView.setAdapter(mArticleAdapter);
    mListView.setEmptyView(view.findViewById(R.id.empty_view));
    if (PhoneConfiguration.getInstance().useSolidColorBackground()) {
        mListView.addItemDecoration(new DividerItemDecoration(view.getContext(), DividerItemDecoration.VERTICAL));
    }

    TextView sayingView = (TextView) mLoadingView.findViewById(R.id.saying);
    sayingView.setText(ActivityUtils.getSaying());

    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            loadPage();
        }
    });
    super.onViewCreated(view, savedInstanceState);
}
 
Example #5
Source File: RecentNotificationFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    mRefreshLayout = view.findViewById(R.id.swipe_refresh);
    mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mNotificationTask.queryRecentReply(RecentNotificationFragment.this);
        }
    });
    mRefreshLayout.setVisibility(View.GONE);

    mLoadingLayout = view.findViewById(R.id.loading_view);
    mEmptyLayout = view.findViewById(R.id.empty_view);

    RecyclerViewEx listView = view.findViewById(R.id.list);
    listView.setLayoutManager(new LinearLayoutManager(getContext()));
    listView.setAdapter(mNotificationAdapter);
    listView.setEmptyView(mEmptyLayout);
    listView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));

    mNotificationTask.queryRecentReply(this);
}
 
Example #6
Source File: FavoriteFragment.java    From memorize with MIT License 6 votes vote down vote up
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_favorite, container, false);
        mRecyclerView = root.findViewById(R.id.fav_recycler_view);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setLayoutManager(new LinearLayoutManager(AppMain.getContext(), LinearLayoutManager.VERTICAL, false));
        SnapHelper snapHelper = new LinearSnapHelper();
        snapHelper.attachToRecyclerView(mRecyclerView);
        mRecyclerView.setAdapter(mAdapter);

        swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.fav_swiper);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                presenter.loadWords(false);
            }
        });
//        animation = AnimationUtils.loadAnimation(AppMain.getContext(), R.anim.card_in);

        return root;
    }
 
Example #7
Source File: FavoriteFragment.java    From memorize with MIT License 6 votes vote down vote up
@Override
public void setLoadingIndicator(final boolean active) {
    if (getView() == null) {
        return;
    }
    final SwipeRefreshLayout refreshLayout =
            (SwipeRefreshLayout) getView().findViewById(R.id.fav_swiper);

    // Make sure setRefreshing() is called after the layout is done with everything else.
    refreshLayout.post(new Runnable() {
        @Override
        public void run() {
            refreshLayout.setRefreshing(active);
        }
    });
}
 
Example #8
Source File: MainActivity.java    From AppsMonitor with MIT License 6 votes vote down vote up
private void initEvents() {
    if (!DataManager.getInstance().hasPermission(getApplicationContext())) {
        mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    Intent intent = new Intent(MainActivity.this, AppService.class);
                    intent.putExtra(AppService.SERVICE_ACTION, AppService.SERVICE_ACTION_CHECK);
                    startService(intent);
                }
            }
        });
    }
    mSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            process();
        }
    });
}
 
Example #9
Source File: NovelReviewReplyListActivity.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onPreExecute() {
    if (isLoading.getAndSet(true)) {
        // is running, do not run again
        runOrNot = false;
    } else {
        // not running, so run it
        SwipeRefreshLayout tempSwipeLayout = swipeRefreshLayoutWeakReference.get();
        if (tempSwipeLayout != null) tempSwipeLayout.setRefreshing(true);

        NovelReviewReplyListActivity tempActivity = novelReviewListActivityWeakReference.get();
        if (tempActivity != null) tempActivity.hideRetryButton();
    }
}
 
Example #10
Source File: PermsUsageStatsActivity.java    From AppOpsX with MIT License 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_usage_stats);

  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  getSupportActionBar().setDisplayHomeAsUpEnabled(true);

  setTitle(R.string.menu_stats);

  mProgressBar = findViewById(R.id.progressBar);

  recyclerView = findViewById(R.id.recyclerView);
  mSwipeRefreshLayout = findViewById(R.id.swiperefreshlayout);
  mSwipeRefreshLayout.setRefreshing(false);
  mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent);
  mSwipeRefreshLayout.setEnabled(false);

  recyclerView.setLayoutManager(new LinearLayoutManager(this));
  recyclerView.addItemDecoration(new CommonDivderDecorator(getApplicationContext()));
  recyclerView.setItemAnimator(new RefactoredDefaultItemAnimator());

  adapter = new UsageStatsAdapter();
  recyclerView.setAdapter(adapter);


  loadData(true);
  mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {
      loadData(false);
    }
  });


}
 
Example #11
Source File: BiAdAdapterSwitcher.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * will implement more functions later
 *
 * @param delay_trigger na
 * @return switchableadapter object
 */

public BiAdAdapterSwitcher onEnableRefresh(final int delay_trigger) {
    listview.setDefaultOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            new Handler().postDelayed(refresh_default, delay_trigger);
        }
    });
    return this;
}
 
Example #12
Source File: FragmentHolderSections.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"ConstantConditions", "NullableProblems"})
private void initializeRecyclerView(Bundle savedInstanceState) {
    // Initialize Adapter and RecyclerView
    // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
    FlexibleAdapter.useTag("HolderSectionsAdapter");
    mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());

    mRecyclerView = getView().findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setHasFixedSize(true); //Size of RV will not change
    // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
    // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());

    // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    FastScroller fastScroller = getView().findViewById(R.id.fast_scroller);
    fastScroller.addOnScrollStateChangeListener((MainActivity) getActivity());
    mAdapter.setFastScroller(fastScroller);

    mAdapter.setDisplayHeadersAtStartUp(true)
            .setStickyHeaders(true)
            .setOnlyEntryAnimation(true);

    SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);

    // Add 1 Scrollable Header
    mAdapter.addScrollableHeader(new ScrollableUseCaseItem(
            getString(R.string.model_holders_use_case_title),
            getString(R.string.model_holders_use_case_description)));
}
 
Example #13
Source File: TestAdMobClassicActivity.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
private void enableRefresh() {
    ultimateRecyclerView.setDefaultOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    simpleRecyclerViewAdapter.removeAll();
                    ultimateRecyclerView.setRefreshing(false);
                }
            }, 1000);
        }
    });

}
 
Example #14
Source File: OpenChannelListFragment.java    From SendBird-Android with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_open_channel_list, container, false);

    setRetainInstance(true);
    setHasOptionsMenu(true);

    ((OpenChannelActivity) getActivity()).setActionBarTitle(getResources().getString(R.string.all_open_channels));

    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_open_channel_list);
    mChannelListAdapter = new OpenChannelListAdapter(getContext());

    // Set color?
    mSwipeRefresh = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_layout_open_channel_list);

    // Swipe down to refresh channel list.
    mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mSwipeRefresh.setRefreshing(true);
            refresh();
        }
    });

    mCreateChannelFab = (FloatingActionButton) rootView.findViewById(R.id.fab_open_channel_list);
    mCreateChannelFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), CreateOpenChannelActivity.class);
            startActivityForResult(intent, INTENT_REQUEST_NEW_OPEN_CHANNEL);
        }
    });

    setUpRecyclerView();
    setUpChannelListAdapter();

    return rootView;
}
 
Example #15
Source File: MainActivity.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
public void refreshTab() {
    mWebView = TabManager.getCurrentTab();
    mWebView.setLayoutParams(new SwipeRefreshLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    swipe = new RelativeLayout(this);
    ViewGroup group = (ViewGroup) mWebView.getParent();
    if (group != null) {
        group.removeAllViews();
    }
    swipe.addView(mWebView);
    for (int i = 0; i < root.getChildCount(); i++) {
        if (root.getChildAt(i) instanceof GridView) {
        } else {
            View view = root.getChildAt(i);
            root.removeView(view);
        }
    }
    root.addView(swipe);
    if (mWebView.getUrl() == null) {
        mSearchView.setText(homepage);
    } else {
        mSearchView.setText(mWebView.getUrl());
    }
    if (mWebView.getFavicon() != null && StaticUtils.isLollipop()) {
        setColor(Palette.from(mWebView.getFavicon()).generate().getVibrantColor(Palette.from(mWebView.getFavicon()).generate().getMutedColor(ContextCompat.getColor(MainActivity.this, R.color.no_fav))));
    }else{
        setColor(ContextCompat.getColor(MainActivity.this, R.color.no_fav));

    }

}
 
Example #16
Source File: FrageMyTopic.java    From Ruisi with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    Bundle bundle = getArguments();//从activity传过来的Bundle
    int uid = 0;
    if (bundle != null) {
        uid = bundle.getInt("uid", 0);
        String username = bundle.getString("username", "我的");
        if (uid == 0) {
            title = "我的帖子";
        } else {
            title = username + "的帖子";
        }
    }
    initToolbar(true, title);
    RecyclerView recyclerView = mRootView.findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);
    SwipeRefreshLayout refreshLayout = mRootView.findViewById(R.id.refresh_layout);
    refreshLayout.setEnabled(false);
    String myUid = App.getUid(getActivity());

    url = "home.php?mod=space&uid=" + (uid > 0 ? uid : myUid) + "&do=thread&view=me&mobile=2";
    datas = new ArrayList<>();
    adapter = new MyPostsListAdapter(getActivity(), datas);

    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.addItemDecoration(new MyListDivider(getActivity(), MyListDivider.VERTICAL));
    recyclerView.addOnScrollListener(new LoadMoreListener(layoutManager, this, 10));
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);
    refresh();
    return mRootView;
}
 
Example #17
Source File: FrageMyStar.java    From Ruisi with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    initToolbar(true, "我的收藏");
    recyclerView = mRootView.findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);
    SwipeRefreshLayout refreshLayout = mRootView.findViewById(R.id.refresh_layout);
    refreshLayout.setEnabled(false);
    String myUid = App.getUid(getActivity());

    //我的收藏
    url = "home.php?mod=space&uid=" + myUid + "&do=favorite&view=me&type=thread&mobile=no";

    datas = new ArrayList<>();
    adapter = new MyStarAdapter(getActivity(), datas);
    adapter.setLongClickListener((v, position) -> {
        int favId = datas.get(position).favId;
        String title = datas.get(position).title;
        new AlertDialog.Builder(getActivity())
                .setTitle("取消收藏")
                .setMessage(title)
                .setPositiveButton("取消收藏", (dialog, which) -> unStarPost(favId, position))
                .setNegativeButton("关闭", null)
                .setCancelable(true)
                .create()
                .show();
    });

    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.addItemDecoration(new MyListDivider(getActivity(), MyListDivider.VERTICAL));
    recyclerView.addOnScrollListener(new LoadMoreListener((LinearLayoutManager) layoutManager, this, 10));
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);
    refresh();
    return mRootView;
}
 
Example #18
Source File: MainActivity.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onFragmentChange(SwipeRefreshLayout swipeRefreshLayout, RecyclerView recyclerView, int mode) {
    mRecyclerView = recyclerView;
    mAdapter = (FlexibleAdapter) recyclerView.getAdapter();
    mSwipeRefreshLayout = swipeRefreshLayout;
    initializeSwipeToRefresh();
    initializeActionModeHelper(mode);
}
 
Example #19
Source File: MainFragment.java    From ui with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View myView = inflater.inflate(R.layout.fragment_main, container, false);

    mSwipeRefreshLayout = (SwipeRefreshLayout) myView.findViewById(R.id.activity_main_swipe_refresh_layout);
    mListView = (ListView) myView.findViewById(R.id.ListView01);
    String[] fakelist = getRandomList();
    mAdapter = new ArrayAdapter<String>(
            getActivity(),
            android.R.layout.simple_list_item_1, fakelist);
    mListView.setAdapter(mAdapter);

    //setup some colors for the refresh circle.
    mSwipeRefreshLayout.setColorSchemeResources(R.color.orange, R.color.green, R.color.blue);
    //now setup the swiperefrestlayout listener where the main work is done.
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            //where we call the refresher parts.  normally some kind of networking async task or web service.
            //this is a bad way to do this, I'm just redoing the adapter, normally, the adapter would update
            //and then use the mAdapter.notifyDataSetChanged();

            /* normally something like this... but I want to slow it down for demo purposes, so
             *   it's commented out.
            String[] fakelist = getRandomList();
            mAdapter = new ArrayAdapter<String>(
                    getActivity(),
                    android.R.layout.simple_list_item_1, fakelist);
            mListView.setAdapter(mAdapter);
            //new turn off the refresh.
            mSwipeRefreshLayout.setRefreshing(false);
            */
            refreshslower();  //this will be slower, for the demo.
        }
    });
    return myView;
}
 
Example #20
Source File: NovelReviewReplyListActivity.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onPostExecute(Void v) {
    // refresh everything when required
    if (!runOrNot) return;

    NovelReviewReplyListActivity tempActivity = novelReviewListActivityWeakReference.get();
    if (metNetworkIssue) {
        // met net work issue, show retry button
        if (tempActivity != null) tempActivity.showRetryButton();
    } else {
        // all good, update list
        if (tempActivity.getAdapter() == null) {
            ReviewReplyItemAdapter reviewReplyItemAdapter = new ReviewReplyItemAdapter(reviewReplyList);
            tempActivity.setAdapter(reviewReplyItemAdapter);
            reviewReplyItemAdapter.setOnItemLongClickListener(tempActivity);
            tempActivity.getRecyclerView().setAdapter(reviewReplyItemAdapter);
        }
        tempActivity.getAdapter().notifyDataSetChanged();

        tempActivity.hideListLoading();
    }

    // stop spinning
    SwipeRefreshLayout tempSwipeLayout = swipeRefreshLayoutWeakReference.get();
    if (tempSwipeLayout != null) tempSwipeLayout.setRefreshing(false);

    // reset loading status
    isLoading.set(false);
}
 
Example #21
Source File: LazyMainActivity.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstance) {
	super.onCreate(savedInstance);

	// Set up the snackbar for when the user experience a no reply from twitch's servers
	snackbar = setupSnackbar();

	mSwipeRefreshLayout.setProgressViewOffset(true, (int) getResources().getDimension(R.dimen.swipe_refresh_start_offset), (int) getResources().getDimension(R.dimen.swipe_refresh_end_offset));
	mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
		@Override
		public void onRefresh() {
			new Runnable() {

				@Override
				public void run() {
					refreshElements();
				}

			}.run();
		}
	});

	//  Set up the specialized OnScrollListener
	mRecyclerView.clearOnScrollListeners();
	mOnScrollListener = new LazyFetchingOnScrollListener<>(
			this, mMainToolbar, mDecorativeToolbar, mToolbarShadow, mCircleIconWrapper, mTitleView, LOG_TAG, this, true
	);
	mScrollListener = mOnScrollListener;
	mRecyclerView.addOnScrollListener(mScrollListener);

	GetVisualElementsTask<T> getElementsTask = new GetVisualElementsTask<>();
	getElementsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, this);
}
 
Example #22
Source File: LoadMoreRefreshUseActivity.java    From BaseRecyclerViewAdapterHelper with MIT License 5 votes vote down vote up
private void initRefreshLayout() {
    mSwipeRefreshLayout.setColorSchemeColors(Color.rgb(47, 223, 189));
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refresh();
        }
    });
}
 
Example #23
Source File: PostFragment.java    From Girls with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.activity_fragment, null);
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.activity_recycke_view);

    //设置adapter
    mRecyclerView.setAdapter(mGirlAdapter);
    //设置Item增加、移除动画
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setHasFixedSize(false);

    //设置布局管理器
    LinearLayoutManager linearLayoutManager =
            new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    mRecyclerView.setLayoutManager(linearLayoutManager);

    mCircularProgressBar = (CircularProgressBar) rootView.findViewById(R.id.circular_progressbar);

    swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setColorSchemeColors(
            R.color.holo_red_light,
            R.color.holo_green_light,
            R.color.holo_blue_bright);

    //swipeRefreshLayout 设置下拉刷新事件
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            getData();
            //成功了 关闭刷新
            swipeRefreshLayout.setRefreshing(false);
        }
    });
    return rootView;
}
 
Example #24
Source File: UIUtils.java    From Kore with Apache License 2.0 5 votes vote down vote up
/**
 * Use this to manually start the swiperefreshlayout refresh animation.
 * Fixes issue with refresh animation not showing when using appcompat library (from version 20?)
 * See https://code.google.com/p/android/issues/detail?id=77712
 * @param layout
 */
public static void showRefreshAnimation(@NonNull final SwipeRefreshLayout layout) {
    layout.post(new Runnable() {
        @Override
        public void run() {
            layout.setRefreshing(true);
        }
    });
}
 
Example #25
Source File: FragmentDataBinding.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"ConstantConditions", "NullableProblems"})
private void initializeRecyclerView(Bundle savedInstanceState) {
    // Initialize Adapter and RecyclerView
    FlexibleAdapter.useTag("DataBindingAdapter");
    mAdapter = new BindingFlexibleAdapter<>(getActivity(), true);
    mAdapter.setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling);
    mRecyclerView = getView().findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setHasFixedSize(true); //Size of RV will not change
    // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
    // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
    mRecyclerView.setItemAnimator(new GarageDoorItemAnimator());

    // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    FastScroller fastScroller = getView().findViewById(R.id.fast_scroller);
    mAdapter.setFastScroller(fastScroller);

    // New empty views handling, to set after FastScroller
    EmptyViewHelper.create(mAdapter,
            getView().findViewById(R.id.empty_view),
            getView().findViewById(R.id.filter_view));

    mAdapter.setLongPressDragEnabled(true)
            .setHandleDragEnabled(true)
            .setSwipeEnabled(true)
            .setDisplayHeadersAtStartUp(true)
            .setStickyHeaders(true);

    SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);

    mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem(
            getString(R.string.databinding_use_case_title),
            getString(R.string.databinding_use_case_description)), 500L, false);
}
 
Example #26
Source File: FragmentAnimators.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"ConstantConditions", "NullableProblems"})
private void initializeRecyclerView(Bundle savedInstanceState) {
    FlexibleAdapter.useTag("AnimatorsAdapter");
    mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
    mAdapter.expandItemsAtStartUp()
            .setAutoCollapseOnExpand(false)
            .setAutoScrollOnExpand(true)
            .setOnlyEntryAnimation(false)
            .setAnimationEntryStep(true) //In Overall, watch the effect at initial loading when Grid Layout is set
            .setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling)
            .setAnimationOnReverseScrolling(true)
            .setAnimationInterpolator(new DecelerateInterpolator())
            .setAnimationDuration(300L);
    mRecyclerView = getView().findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
    mRecyclerView.setAdapter(mAdapter);
    //mRecyclerView.setHasFixedSize(true); //Size of RV will not change

    // NOTE: Custom item animators inherit 'canReuseUpdatedViewHolder()' from Default Item
    // Animator. It will return true if a Payload is provided. FlexibleAdapter is actually
    // sending Payloads onItemChange notifications.
    mRecyclerView.setItemAnimator(new FlexibleItemAnimator());
    initializeSpinnerItemAnimators();
    initializeSpinnerScrollAnimators();

    mAdapter.setSwipeEnabled(true)
            .getItemTouchHelperCallback()
            .setSwipeFlags(ItemTouchHelper.RIGHT); //Enable swipe

    SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(false);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);

    // Add 1 Scrollable Header
    mAdapter.addScrollableHeader(new ScrollableUseCaseItem(
            getString(R.string.animator_use_case_title),
            getString(R.string.animator_use_case_description)));
}
 
Example #27
Source File: TurbolinksSession.java    From turbolinks-android with MIT License 5 votes vote down vote up
/**
 * <p><b>REQUIRED</b> A {@link TurbolinksView} object that's been inflated in a custom layout is
 * required so the library can manage various view-related tasks: attaching/detaching the
 * internal webView, showing/hiding a progress loading view, etc.</p>
 *
 * @param turbolinksView An inflated TurbolinksView from your custom layout.
 * @return The TurbolinksSession to continue the chained calls.
 */
public TurbolinksSession view(TurbolinksView turbolinksView) {
    this.turbolinksView = turbolinksView;
    this.turbolinksView.getRefreshLayout().setCallback(this);
    this.turbolinksView.getRefreshLayout().setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            visitLocationWithAction(location, ACTION_ADVANCE);
        }
    });
    this.webViewAttachedToNewParent = this.turbolinksView.attachWebView(webView, screenshotsEnabled, pullToRefreshEnabled);

    return this;
}
 
Example #28
Source File: FragmentStaggeredLayout.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"ConstantConditions", "NullableProblems"})
private void initializeRecyclerView(Bundle savedInstanceState) {
    // Initialize Adapter and RecyclerView
    // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
    FlexibleAdapter.useTag("StaggeredLayoutAdapter");
    mAdapter = new FlexibleAdapter<>(DatabaseService.getInstance().getDatabaseList(), getActivity());
    mRecyclerView = getView().findViewById(R.id.recycler_view);
    // Customize the speed of the smooth scroll.
    // NOTE: Every time you change this value you MUST recreate the LayoutManager instance
    // and to assign it again to the RecyclerView!
    TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 33f; //Make faster the smooth scroll
    mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager());
    // This value is restored to 100f (default) right here, because it is used in the
    // constructor by Android. If we don't change it now, others LayoutManager will be
    // impacted too by the above modification!
    TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 100f;

    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setHasFixedSize(true); //Size of RV will not change
    // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
    // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity())
            .addItemViewType(R.layout.recycler_staggered_item, 8)
            .withEdge(true));

    mAdapter.setDisplayHeadersAtStartUp(true) //Show Headers at startUp!
            .setNotifyMoveOfFilteredItems(true)
            .setPermanentDelete(true) //Default=true
            .setOnlyEntryAnimation(true);

    SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);

    // Add 1 Scrollable Header
    mAdapter.addScrollableHeader(new ScrollableUseCaseItem(
            getString(R.string.staggered_use_case_title),
            getString(R.string.staggered_use_case_description)));
}
 
Example #29
Source File: MultipleDaysFragment.java    From weather with Apache License 2.0 5 votes vote down vote up
private void initSwipeView() {
  swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
      android.R.color.holo_green_light,
      android.R.color.holo_orange_light,
      android.R.color.holo_red_light);
  swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

    @Override
    public void onRefresh() {
      requestWeather();
    }

  });
}
 
Example #30
Source File: CourseOutlineFragment.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final Bundle bundle;
    {
        if (savedInstanceState != null) {
            bundle = savedInstanceState;
        } else {
            bundle = getArguments();
        }
    }

    final View view = inflater.inflate(R.layout.fragment_course_outline, container, false);
    listView = (ListView) view.findViewById(R.id.outline_list);
    swipeContainer = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
    errorNotification = new FullScreenErrorNotification(swipeContainer);
    loadingIndicator = view.findViewById(R.id.loading_indicator);
    flBulkDownload = view.findViewById(R.id.fl_bulk_download_container);
    swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            // Hide the progress bar as swipe layout has its own progress indicator
            loadingIndicator.setVisibility(View.GONE);
            errorNotification.hideError();
            getCourseComponentFromServer(false);
        }
    });
    UiUtil.setSwipeRefreshLayoutColors(swipeContainer);

    restore(bundle);
    initListView(view);
    fetchCourseComponent();
    // Track CourseOutline for A/A test
    trackAATestCourseOutline();
    getCourseUpgradeFirebaseConfig();
    return view;
}