← Back to liaohuqiu/android-Ultra-Pull-To-Refresh

How to Deploy & Use liaohuqiu/android-Ultra-Pull-To-Refresh

Ultra Pull To Refresh - Deployment and Usage Guide

Prerequisites

  • Android Studio (or any Android development environment)
  • Android SDK with API Level 8 or higher
  • Gradle build system (included with Android Studio)
  • Java Development Kit (JDK) 8 or higher

Installation

Option 1: Add as Dependency (Recommended)

Add the following to your build.gradle file:

dependencies {
    implementation 'in.srain.cube:ultra-ptr:1.0.11'
}

Option 2: Manual Integration

  1. Clone the repository:
git clone https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh.git
  1. Import the ptr-lib module into your Android project

  2. Add the module as a dependency in your settings.gradle:

include ':app', ':ptr-lib'
  1. In your app's build.gradle, add:
dependencies {
    implementation project(':ptr-lib')
}

Configuration

XML Configuration

Configure the PtrFrameLayout in your XML layout:

<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" >
    
    <!-- Your content view here -->
</in.srain.cube.views.ptr.PtrFrameLayout>

Java Configuration

PtrFrameLayout mPtrFrame = findViewById(R.id.store_house_ptr_frame);

// Default settings
mPtrFrame.setResistance(1.7f);
mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);
mPtrFrame.setDurationToClose(200);
mPtrFrame.setDurationToCloseHeader(1000);
mPtrFrame.setPullToRefresh(false);

Build & Run

Development

  1. Open the project in Android Studio
  2. Sync Gradle files
  3. Build and run on an emulator or physical device

Production

  1. Ensure your build.gradle has the correct version:
implementation 'in.srain.cube:ultra-ptr:1.0.11'
  1. Build the release APK:
./gradlew assembleRelease
  1. Sign the APK using your keystore

Deployment

Since this is an Android library, deployment involves:

  1. Publishing to Maven Central (if you're the maintainer):

    • Configure Sonatype OSSRH credentials
    • Use Gradle Maven Publish plugin
    • Run ./gradlew publish
  2. Using in your app:

    • Add the dependency to your app's build.gradle
    • Sync and build
  3. Testing:

Troubleshooting

Common Issues and Solutions

1. Header not showing

  • Ensure you've set a header view using mPtrFrame.setHeaderView(headerView)
  • Check that the header view is properly sized and visible

2. Pull-to-refresh not working

  • Verify you've called mPtrFrame.setPullToRefresh(true) if you want pull-to-refresh behavior
  • Ensure the content view is scrollable (ListView, ScrollView, etc.)

3. Build errors with dependency

  • Check your Gradle version compatibility
  • Ensure you have internet access for downloading dependencies
  • Try clearing the Gradle cache: ./gradlew clean

4. Runtime crashes

  • Check that you're using API Level 8 or higher
  • Verify all required views are properly initialized
  • Look for null pointer exceptions in your header view implementation

5. Custom header not animating

  • Implement the PtrUIHandler interface in your custom header
  • Ensure you're calling the appropriate UI handler methods during refresh states

6. Performance issues

  • Avoid complex layouts in the header view
  • Use ViewStub for header content if it's heavy
  • Profile with Android Studio's profiler to identify bottlenecks

Additional Resources