Giter Club home page Giter Club logo

actionbar-pulltorefresh's Introduction

ActionBar-PullToRefresh

ActionBar-PullToRefresh

ActionBar-PullToRefresh provides an easy way to add a modern version of the pull-to-refresh interaction to your application.

Please note that this is not an update to Android-PullToRefresh, this has been created from new. You should think of this as Android-PullToRefresh's younger, leaner cousin.

This is a Preview

Please note that this is currently in a preview state. This basically means that the API is not fixed and you should expect changes between releases.


Sample Apps

There are two sample applications, the stock sample which uses the standard library and is therefore has a minSdkVersion of 14. There is also a sample which uses the ActionBarSherlock extra so has a minSdkVersion of 7.

Stock Sample

Get it on Google Play

ActionBarSherlock Sample

Get it on Google Play

Video

Sample Video


Supported Views

ActionBar-PullToRefresh has in-built support for:

  • AbsListView derivatives (ListView & GridView).
  • ScrollView
  • WebView

If the View you want to use is not listed above, you can easily add support in your own code by providing a ViewDelegate. See the ViewDelegate section below for more info.


Usage

You just need to create an instance of PullToRefreshAttacher, giving it the Activity and the View for which will scroll.

private PullToRefreshAttacher mPullToRefreshHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        
    // Get View for which the user will scroll…
    View scrollableView = findViewById(R.id.blah); 

    // Create a PullToRefreshAttacher instance
    mPullToRefreshHelper = new PullToRefreshAttacher(this);

    // Set the Refreshable View and provide the refresh listener
    mPullToRefreshAttacher.setRefreshableView(scrollableView, this);
}

See the ListView sample for more info.

Fragments

One thing to note is that the PullToRefreshAttacher needs to be created in the onCreate() phase of the Activity. If you plan on using this library with Fragments then the best practice is for your Activity to create the PullToRefreshAttacher, and then have your fragments retrieve it from the Activity.

An example is provided in the Fragment & Tabs sample.


Customisation

There are many ways you can customise the pull-to-refresh experience to your needs. See the GridView sample for more info on all of these.

ViewDelegate

ViewDelegates provide support for handling scrollable Views. The main use of a ViewDelegate is to being able to tell when a scrollable view is scrolled to the top. There is currently inbuilt support for:

So what if you want the view you want to use a view which isn't in the list above? Well you can just provide your own ViewDelegate.

// Create a PullToRefresh Attacher
mPullToRefreshAttacher = new PullToRefreshAttacher(this);

// Create ViewDelegate which can handle your scrollable view.
// In this case we're creating a ficticious class
PullToRefreshAttacher.ViewDelegate delegate = new XYZViewDelegate();

// Set the Refreshable View, along with your ViewDelegate
mPullToRefreshAttacher.setRefreshableView(xyzView, delegate, listener);

Options

When instatiating a PullToRefreshAttacher you can provide an Options instance which contains a number of configuration elements:

  • headerLayout: Layout resource to be inflated as the header view (see below).
  • headerTransformer: The HeaderTransformer for the heard view (see below).
  • headerInAnimation: The animation resource which is used when the header view is shown.
  • headerOutAnimation: The animation resource which is used when the header view is hidden.
  • refreshScrollDistance: The vertical distance (percentage of the scrollable view height) that the user needs to scroll for a refresh to start.
  • refreshOnUp: Whether to wait to start the refresh until when the user has lifted their finger.

HeaderTransformers

HeaderTransformers are responsible for updating the header view to match the current state. If you do not provide a HeaderTransformer, there is a default implementation created for you called DefaultHeaderTransformer. This default implementation is what provides the default behaviour (growing progress bar, etc).

Customised Header View layout

If you feel that the default header view layout does not provide what you require, you can provide your own which is inflated for you. For the majority of cases, you will probably want to provide your own HeaderTransformer as well, to update your custom layout.

Maven

For the standard library (APIv14+) add the following as a dependency in you pom.xml:

<dependency>
    <groupId>com.github.chrisbanes.actionbarpulltorefresh</groupId>
    <artifactId>library</artifactId>
    <version>0.5</version>
</dependency>

If you're using ActionBarSherlock (APIv7+) add the following as a dependency in you pom.xml:

<dependency>
    <groupId>com.github.chrisbanes.actionbarpulltorefresh</groupId>
    <artifactId>extra-abs</artifactId>
    <version>0.5</version>
</dependency>

License

Copyright 2013 Chris Banes

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

actionbar-pulltorefresh's People

Contributors

intrications avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.