Convert Figma logo to code with AI

liaohuqiu logoandroid-Ultra-Pull-To-Refresh

Ultra Pull to Refresh for Android. Support all the views.

9,585
2,657
9,585
172

Top Related Projects

DEPRECATED

DEPRECATED This project aims to provide a reusable pull to refresh widget for Android.

4,015

Phoenix Pull-to-Refresh

The implementation of https://dribbble.com/shots/2067564-Replace

🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫酷的Header和 Footer。

A pull to refresh layout for android, the RecyclerRefreshLayout is based on the SwipeRefreshLayout. support all the views, highly customizable, code simplicity, etc. really a practical RefreshLayout!

Quick Overview

Android-Ultra-Pull-To-Refresh is a popular Android library that provides a highly customizable pull-to-refresh UI component. It offers a flexible and easy-to-use solution for implementing pull-to-refresh functionality in Android applications, supporting various types of content views and custom header styles.

Pros

  • Highly customizable with support for different header styles and animations
  • Compatible with all kinds of ScrollView and ListView
  • Easy integration with existing projects
  • Supports both vertical and horizontal pull-to-refresh

Cons

  • Last updated in 2018, which may indicate lack of recent maintenance
  • Some reported issues with newer Android versions and Material Design components
  • Limited documentation for advanced customization

Code Examples

  1. Basic implementation:
PtrFrameLayout mPtrFrame = (PtrFrameLayout) findViewById(R.id.rotate_header_list_view_frame);
mPtrFrame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        frame.postDelayed(new Runnable() {
            @Override
            public void run() {
                mPtrFrame.refreshComplete();
            }
        }, 1800);
    }

    @Override
    public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
        return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
    }
});
  1. Custom header:
StoreHouseHeader header = new StoreHouseHeader(context);
header.setPadding(0, PtrLocalDisplay.dp2px(15), 0, 0);
header.initWithString("Ultra PTR");
mPtrFrame.setHeaderView(header);
mPtrFrame.addPtrUIHandler(header);
  1. Auto refresh:
mPtrFrame.postDelayed(new Runnable() {
    @Override
    public void run() {
        mPtrFrame.autoRefresh(true);
    }
}, 100);

Getting Started

  1. Add the dependency to your build.gradle file:
dependencies {
    implementation 'in.srain.cube:ultra-ptr:1.0.11'
}
  1. Add the PtrFrameLayout to your layout XML:
<in.srain.cube.views.ptr.PtrFrameLayout
    android:id="@+id/ptr_frame"
    xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    cube_ptr:ptr_resistance="1.7"
    cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2"
    cube_ptr:ptr_duration_to_close="300"
    cube_ptr:ptr_duration_to_close_header="2000"
    cube_ptr:ptr_keep_header_when_refresh="true"
    cube_ptr:ptr_pull_to_fresh="false" >

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white" />

</in.srain.cube.views.ptr.PtrFrameLayout>
  1. Initialize and use the PtrFrameLayout in your Activity or Fragment as shown in the code examples above.

Competitor Comparisons

DEPRECATED

Pros of Android-PullToRefresh

  • More established and widely used in the Android community
  • Supports a variety of views including ListView, GridView, WebView, and ScrollView
  • Offers multiple styles of pull-to-refresh indicators

Cons of Android-PullToRefresh

  • No longer actively maintained (last commit in 2015)
  • Limited customization options for the refresh indicator
  • May not be compatible with newer Android versions and libraries

Code Comparison

Android-PullToRefresh:

PullToRefreshListView mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);
mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
    @Override
    public void onRefresh(PullToRefreshBase<ListView> refreshView) {
        // Do work to refresh the list here
    }
});

android-Ultra-Pull-To-Refresh:

PtrFrameLayout frame = (PtrFrameLayout) findViewById(R.id.store_house_ptr_frame);
frame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        // Do refresh work here
    }
});

The android-Ultra-Pull-To-Refresh library offers a more flexible and customizable approach, with support for custom header views and animations. It also has better performance and smoother animations compared to Android-PullToRefresh. However, Android-PullToRefresh may be easier to implement for developers familiar with older Android patterns.

DEPRECATED This project aims to provide a reusable pull to refresh widget for Android.

Pros of android-pulltorefresh

  • Simpler implementation, making it easier to integrate for basic pull-to-refresh functionality
  • Lightweight library with minimal dependencies
  • Supports both ListView and ScrollView out of the box

Cons of android-pulltorefresh

  • Less customizable compared to android-Ultra-Pull-To-Refresh
  • Limited animation options and visual styles
  • Not actively maintained, with the last update several years ago

Code Comparison

android-pulltorefresh:

PullToRefreshListView pullToRefreshView = (PullToRefreshListView) findViewById(R.id.pull_to_refresh_listview);
pullToRefreshView.setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh() {
        // Your code to refresh the list contents
    }
});

android-Ultra-Pull-To-Refresh:

PtrFrameLayout frame = (PtrFrameLayout) findViewById(R.id.store_house_ptr_frame);
frame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        // Your code to refresh the list contents
    }
});

Both libraries offer similar basic functionality, but android-Ultra-Pull-To-Refresh provides more advanced features and customization options. While android-pulltorefresh is simpler to implement, it lacks the flexibility and ongoing support of its counterpart. The code comparison shows that both libraries have a similar approach to setting up the refresh listener, but android-Ultra-Pull-To-Refresh offers more control over the refresh process and UI elements.

4,015

Phoenix Pull-to-Refresh

Pros of Phoenix

  • Visually appealing and customizable animation
  • Smooth and fluid user experience
  • Easy integration with existing projects

Cons of Phoenix

  • Limited to pull-to-refresh functionality
  • May have higher resource consumption due to complex animations
  • Less actively maintained compared to Ultra-Pull-To-Refresh

Code Comparison

Phoenix:

val refreshLayout = findViewById<PullToRefreshView>(R.id.pull_to_refresh)
refreshLayout.setOnRefreshListener {
    // Refresh logic here
    refreshLayout.setRefreshing(false)
}

Ultra-Pull-To-Refresh:

PtrFrameLayout frame = findViewById(R.id.pull_to_refresh);
frame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        // Refresh logic here
        frame.refreshComplete();
    }
});

Summary

Phoenix offers a visually striking pull-to-refresh experience with customizable animations, making it ideal for projects prioritizing aesthetics. However, it's limited to pull-to-refresh functionality and may consume more resources.

Ultra-Pull-To-Refresh provides a more comprehensive solution with additional features and better performance optimization. It's also more actively maintained, making it suitable for long-term projects requiring stability and regular updates.

The choice between the two depends on project requirements, with Phoenix excelling in visual appeal and Ultra-Pull-To-Refresh offering broader functionality and better long-term support.

The implementation of https://dribbble.com/shots/2067564-Replace

Pros of FlyRefresh

  • Unique and visually appealing animation with a paper airplane
  • Smooth and fluid user experience
  • Customizable animation elements

Cons of FlyRefresh

  • Less flexible for different use cases compared to Ultra-Pull-To-Refresh
  • May not be suitable for more professional or minimalist app designs
  • Limited documentation and examples

Code Comparison

FlyRefresh:

mFlightView = (FlyRefreshLayout) findViewById(R.id.fly_layout);
mFlightView.setOnPullRefreshListener(new FlyRefreshLayout.OnPullRefreshListener() {
    @Override
    public void onRefresh(FlyRefreshLayout view) {
        // Handle refresh action
    }
});

Ultra-Pull-To-Refresh:

PtrFrameLayout mPtrFrame = (PtrFrameLayout) findViewById(R.id.rotate_header_list_view_frame);
mPtrFrame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        // Handle refresh action
    }
});

Both libraries offer easy-to-implement refresh functionality, but FlyRefresh focuses on a specific animation style, while Ultra-Pull-To-Refresh provides more flexibility in terms of customization and header types. Ultra-Pull-To-Refresh also offers better documentation and examples, making it easier for developers to integrate and customize. However, FlyRefresh stands out with its unique and visually appealing animation, which can enhance the user experience in certain app designs.

🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫酷的Header和 Footer。

Pros of SmartRefreshLayout

  • More comprehensive feature set, including multiple refresh styles and animations
  • Active development with frequent updates and bug fixes
  • Extensive documentation and examples for easier implementation

Cons of SmartRefreshLayout

  • Larger library size due to additional features
  • Steeper learning curve for advanced customizations
  • May be overkill for simple pull-to-refresh implementations

Code Comparison

SmartRefreshLayout:

RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
refreshLayout.setRefreshHeader(new ClassicsHeader(this));
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh(RefreshLayout refreshlayout) {
        refreshlayout.finishRefresh(2000/*,false*/);
    }
});

Android-Ultra-Pull-To-Refresh:

PtrFrameLayout frame = findViewById(R.id.frame);
frame.setHeaderView(new PtrClassicDefaultHeader(this));
frame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        frame.refreshComplete();
    }
});

Both libraries offer easy-to-use APIs for implementing pull-to-refresh functionality. SmartRefreshLayout provides more options for customization out of the box, while Android-Ultra-Pull-To-Refresh focuses on a simpler, lightweight approach. The choice between the two depends on the specific requirements of your project and the level of customization needed.

A pull to refresh layout for android, the RecyclerRefreshLayout is based on the SwipeRefreshLayout. support all the views, highly customizable, code simplicity, etc. really a practical RefreshLayout!

Pros of RecyclerRefreshLayout

  • Specifically designed for RecyclerView, providing better integration and performance
  • Supports both pull-down refresh and pull-up load more functionality
  • More recent and actively maintained repository

Cons of RecyclerRefreshLayout

  • Less flexible compared to Ultra-Pull-To-Refresh, as it's primarily focused on RecyclerView
  • Fewer customization options for the refresh header and footer
  • Smaller community and fewer resources available for troubleshooting

Code Comparison

RecyclerRefreshLayout:

RecyclerRefreshLayout refreshLayout = findViewById(R.id.refresh_layout);
refreshLayout.setOnRefreshListener(new RecyclerRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {
        // Refresh logic here
    }
});

Ultra-Pull-To-Refresh:

PtrFrameLayout frame = findViewById(R.id.ptr_frame);
frame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        // Refresh logic here
    }
});

Both libraries offer simple implementation, but RecyclerRefreshLayout is more specific to RecyclerView, while Ultra-Pull-To-Refresh provides a more general-purpose solution. The code structure is similar, with slight differences in method names and setup.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Welcome to follow me on GitHub or Twitter

GitHub: https://github.com/liaohuqiu

Twitter: https://twitter.com/liaohuqiu


Build Status Android Arsenal

中文版文档

Wanna auto-load-more? This will be what you want: https://github.com/liaohuqiu/android-cube-app

Ultra Pull To Refresh

It's a replacement for the deprecated pull to refresh solution. It can contain any view you want.

It's easy to use and more powerful than SwipeRefreshLayout.

It's well designed, you can customize the UI effect you want as easy as adding a headview to ListView.

Support API LEVEL >= 8, all snapshots are taken from Genymotion, 2.3.7.

Download APK

  • StoreHouse Style first! Thanks to CBStoreHouseRefreshControl.

  • Material Style, added @ 2014-12-09. There is a beautiful shadow which looks terrible in gif snapshot. Please Check out the DEMO.

  • Supports all of the views: ListView, GridView, ScrollView, FrameLayout, or Even a single TextView.

  • Supports all of the refresh types.

    • pull to refresh

    • release to refresh

    • keep header when refresh

    • hide header when refresh

    • auto refresh

Usage

Maven Central

This project has been pushed to Maven Central, both in aar and apklib.

The latest version: 1.0.11, has been published to: https://oss.sonatype.org/content/repositories/snapshots, in gradle:

maven {
    url 'https://oss.sonatype.org/content/repositories/snapshots'
}

The stable version: 1.0.11, https://oss.sonatype.org/content/repositories/releases, in gradle:

mavenCentral()

pom.xml, latest version:

<dependency>
    <groupId>in.srain.cube</groupId>
    <artifactId>ultra-ptr</artifactId>
    <type>aar</type>
    <!-- or apklib format, if you want -->
    <!-- <type>apklib</type> -->
    <version>1.0.11</version>
</dependency>

pom.xml, stable version:

<dependency>
    <groupId>in.srain.cube</groupId>
    <artifactId>ultra-ptr</artifactId>
    <type>aar</type>
    <!-- or apklib format, if you want -->
    <!-- <type>apklib</type> -->
    <version>1.0.11</version>
</dependency>

gradle, latest version:

compile 'in.srain.cube:ultra-ptr:1.0.11'

gradle, stable version:

compile 'in.srain.cube:ultra-ptr:1.0.11'

Config

There are 6 properties:

  • Resistence

    This is the resistence while you are moving the frame, default is: 1.7f.

  • Ratio of the Height of the Header to Refresh

    The ratio of the height of the header to trigger refresh, default is: 1.2f.

  • Duration to Close

    The duration for moving from the position you relase the view to the height of header, default is 200ms.

  • Duration to Close Header

    The default value is 1000ms

  • Keep Header while Refreshing

    The default value is true.

  • Pull to Refresh / Release to Refresh

    The default value is Release to Refresh.

Config in xml
<in.srain.cube.views.ptr.PtrFrameLayout
    android:id="@+id/store_house_ptr_frame"
    xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    cube_ptr:ptr_resistance="1.7"
    cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2"
    cube_ptr:ptr_duration_to_close="300"
    cube_ptr:ptr_duration_to_close_header="2000"
    cube_ptr:ptr_keep_header_when_refresh="true"
    cube_ptr:ptr_pull_to_fresh="false" >

    <LinearLayout
        android:id="@+id/store_house_ptr_image_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/cube_mints_333333"
        android:clickable="true"
        android:padding="10dp">

        <in.srain.cube.image.CubeImageView
            android:id="@+id/store_house_ptr_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

</in.srain.cube.views.ptr.PtrFrameLayout>

Or config in java code

// the following are default settings
mPtrFrame.setResistance(1.7f);
mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);
mPtrFrame.setDurationToClose(200);
mPtrFrame.setDurationToCloseHeader(1000);
// default is false
mPtrFrame.setPullToRefresh(false);
// default is true
mPtrFrame.setKeepHeaderWhenRefresh(true);

Other Config

  • setPinContent. Pin the content, only the HeaderView will be moved.

    This's the the performance of material style in support package v19.

StoreHouse Style

  • Config using string:
// header
final StoreHouseHeader header = new StoreHouseHeader(getContext());
header.setPadding(0, LocalDisplay.dp2px(15), 0, 0);

/**
 * using a string, support: A-Z 0-9 - .
 * you can add more letters by {@link in.srain.cube.views.ptr.header.StoreHousePath#addChar}
 */
header.initWithString('Alibaba');
  • Config using string array from xml:
header.initWithStringArray(R.array.storehouse);

And in res/values/arrays.xml:

<resources>
    <string-array name="storehouse">
        <item>0,35,12,42,</item>
        <item>12,42,24,35,</item>
        <item>24,35,12,28,</item>
        <item>0,35,12,28,</item>
        <item>0,21,12,28,</item>
        <item>12,28,24,21,</item>
        <item>24,35,24,21,</item>
        <item>24,21,12,14,</item>
        <item>0,21,12,14,</item>
        <item>0,21,0,7,</item>
        <item>12,14,0,7,</item>
        <item>12,14,24,7,</item>
        <item>24,7,12,0,</item>
        <item>0,7,12,0,</item>
    </string-array>
</resources>

Process Refresh

There is a PtrHandler, by which you can refresh the data.

public interface PtrHandler {

    /**
     * Check can do refresh or not. For example the content is empty or the first child is in view.
     * <p/>
     * {@link in.srain.cube.views.ptr.PtrDefaultHandler#checkContentCanBePulledDown}
     */
    public boolean checkCanDoRefresh(final PtrFrameLayout frame, final View content, final View header);

    /**
     * When refresh begin
     *
     * @param frame
     */
    public void onRefreshBegin(final PtrFrameLayout frame);
}

An example:

ptrFrame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        frame.postDelayed(new Runnable() {
            @Override
            public void run() {
                ptrFrame.refreshComplete();
            }
        }, 1800);
    }

    @Override
    public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
        return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
    }
});

Customize

You can add a PtrUIHandler to PtrFrameLayout to implement any UI effect you want.

public interface PtrUIHandler {

    /**
     * When the content view has reached top and refresh has been completed, view will be reset.
     *
     * @param frame
     */
    public void onUIReset(PtrFrameLayout frame);

    /**
     * prepare for loading
     *
     * @param frame
     */
    public void onUIRefreshPrepare(PtrFrameLayout frame);

    /**
     * perform refreshing UI
     */
    public void onUIRefreshBegin(PtrFrameLayout frame);

    /**
     * perform UI after refresh
     */
    public void onUIRefreshComplete(PtrFrameLayout frame);

    public void onUIPositionChange(PtrFrameLayout frame, boolean isUnderTouch, byte status, int oldPosition, int currentPosition, float oldPercent, float currentPercent);
}

Q & A

  • work with ViewPager: disableWhenHorizontalMove()

  • work with LongPressed, setInterceptEventWhileWorking()

Contact & Help

Please fell free to contact me if there is any problem when using the library.