Ultra Pull To Refresh


Source link: https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh

Welcome to follow me on GitHub or Twitter

GitHub: https://github.com/liaohuqiu

Twitter: https://twitter.com/liaohuqiu


?????

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.

Resources

An Android library to make a flowing gradient effect, similar to login screen in Instagram app.

An Android Banner that supports auto scrolling and decent animation.

AutoValue Extension to add Map generation support. Generates a Map<String,Object> where the keys are the field names and the values the related field values.

A very simple implementation for social login on android.

It's a cute button.

Toolbelt is an Android library for common tools and utilities for optional values, easier logging and operations on Strings. I need these mostly boilerplate stuff for almost all of my Android projects so I decided to serve them as a library.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes