Pull-down refresh is a very common function. Nowadays, many apps provide the same pull-down refresh effect, just like The SwipeRefreshlayout provided by Google. Do you feel a little tired of reading too much? If you give your users creative effects while they are pulling down, it will definitely make a difference to their experience. Today we will introduce a fireworks drop down refresh effect -FireworkyPullToRefresh.

Talk is cheap ,show me the gif:

Is it explosive? Take a look at how to apply this cool pull-down refresh effect to our app:

Add dependencies to build.gradle:

 compile 'com. Cleveroad: fireworkypulltorefresh: 1.0.3'
Copy the code

In an XML file, the parent of RecyclerView uses FireworkyPullToRefresh:

<com.cleveroad.pulltorefresh.firework.FireworkyPullToRefreshLayout
        android:id="@+id/pullToRefresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

</com.cleveroad.ptr.FireworkyPullToRefreshLayout>
Copy the code

FireworkyPullToRefresh provides the following properties that can be configured:

  • Ptr_fireworkColors: Sets the color of the fireworks

  • Ptr_background: The background image of the lower part of the header

  • Ptr_rocketAnimDuration: animation duration of firework launch

  • Ptr_fireworkStyle: Classic or Modern

The above four configurations can be used directly in XML:

<com.cleveroad.pulltorefresh.firework.FireworkyPullToRefreshLayout
        xmlns:app="http://schemas.android.com/apk/res-auto". app:ptr_fireworkColors="@array/fireworkColors"
        app:ptr_background="@drawable/background"
        app:ptr_rocketAnimDuration="1000">
Copy the code

It can also be set in code:

//use .config() methods:

mPullToRefresh.getConfig().setBackground(backgroundDrawable);
mPullToRefresh.getConfig().setBackground(backgroundBitmap);
mPullToRefresh.getConfig().setBackground(R.drawable.background);
mPullToRefresh.getConfig().setBackgroundColor(Color.BLACK);
mPullToRefresh.getConfig().setBackgroundColorFromResources(R.color.background);

mPullToRefresh.getConfig().setFireworkColors(colorsIntArray);
mPullToRefresh.getConfig().setFireworkColors(R.array.fireworkColors);

mPullRefreshView.getConfig().setFireworkStyle(Configuration.FireworkStyle.MODERN);

mPullToRefresh.getConfig().setRocketAnimDuration(1000L);
Copy the code
Refresh the callback

Are similar in usage with SwipeRefreshlayout, by implementing an interface PullToRefreshView. OnRefreshListener to add refresh logic:

mPullToRefresh.setOnRefreshListener(new PullToRefreshView.OnRefreshListener() {
    @Override
    public void onRefresh() {
        //refresh your data here        
    }
});
Copy the code

To start or unanimate:

mPullRefreshView.setRefreshing(isRefreshing);
Copy the code
Custom animation

If you want to achieve animation, also can, rewrite FireworkyPullToRefreshLayout. OnChildScrollUpCallback logic to implement your own animation

mPullToRefresh.setOnChildScrollUpCallback(new FireworkyPullToRefreshLayout.OnChildScrollUpCallback() {
    @Override
    public boolean canChildScrollUp(@NonNull FireworkyPullToRefreshLayout parent, @Nullable View child) {
        //put your implementation here}});Copy the code

Specific implementation details may refer to the source code, github:github.com/Cleveroad/F…