Skip to content

Commit

Permalink
Pull to refresh, closes todotxt#360
Browse files Browse the repository at this point in the history
Add ActionBar-PullToRefresh library
Stretch ListView to fill_parent vertical so that pull-to-refresh is detected even when list doesn't fill screen vertically
Add pull-to-refresh and remove sync button
Update ActionBar-PullToRefresh to v0.4 and actually make work with pre-Honeycomb
  • Loading branch information
intrications authored and ginatrapani committed Jun 23, 2013
1 parent deaf88e commit 9aff9c8
Show file tree
Hide file tree
Showing 52 changed files with 2,165 additions and 38 deletions.
28 changes: 28 additions & 0 deletions dependencies/ActionBar-PullToRefresh-e8e6d2b58c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#Android generated
bin
gen
gen*

#Eclipse
.classpath
.settings

#IntelliJ IDEA
.idea
*.iml
*.ipr
*.iws
out

#Maven
target
release.properties
pom.xml.*

#Ant
build.xml
local.properties
proguard.cfg

#OSX
.DS_Store
123 changes: 123 additions & 0 deletions dependencies/ActionBar-PullToRefresh-e8e6d2b58c/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# ActionBar-PullToRefresh

![ActionBar-PullToRefresh](https://github.com/chrisbanes/ActionBar-PullToRefresh/raw/master/header.png)

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](https://github.com/chrisbanes/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

Eventually the sample will be available to download on Google Play. As we're not stable yet you can find the APKs [here](https://drive.google.com/folderview?id=0BxAFUoBj0OjaYTd3SUkzYjIydG8&usp=sharing).

#### Video

[![Sample Video](http://img.youtube.com/vi/YOYtPF-4RPg/0.jpg)](https://www.youtube.com/watch?v=YOYtPF-4RPg)

---

## 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.

``` java
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](https://github.com/chrisbanes/ActionBar-PullToRefresh/blob/master/samples/stock/src/uk/co/senab/actionbarpulltorefresh/samples/stock/ListViewActivity.java) 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](https://github.com/chrisbanes/ActionBar-PullToRefresh/blob/master/samples/stock/src/uk/co/senab/actionbarpulltorefresh/samples/stock/FragmentTabsActivity.java) sample.

---

## Customisation

There are many ways you can customise the pull-to-refresh experience to your needs. See the [GridView](https://github.com/chrisbanes/ActionBar-PullToRefresh/blob/master/samples/stock/src/uk/co/senab/actionbarpulltorefresh/samples/stock/GridViewActivity.java) 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:

* AbsListView classes (through [AbsListViewDelegate](https://github.com/chrisbanes/ActionBar-PullToRefresh/blob/master/library/src/uk/co/senab/actionbarpulltorefresh/library/viewdelegates/AbsListViewDelegate.java))
* ScrollView (through [ScrollViewDelegate](https://github.com/chrisbanes/ActionBar-PullToRefresh/blob/master/library/src/uk/co/senab/actionbarpulltorefresh/library/viewdelegates/ScrollViewDelegate.java))
* WebView (through [WebViewDelegate](https://github.com/chrisbanes/ActionBar-PullToRefresh/blob/master/library/src/uk/co/senab/actionbarpulltorefresh/library/viewdelegates/WebViewDelegate.java))

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`.

``` java
// 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.

### 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.

---

## 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ActionBar-PullToRefresh-extras</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock"
android:versionCode="1"
android:versionName="0.1">

<uses-sdk android:minSdkVersion="7" />
<application />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.chrisbanes.actionbarpulltorefresh</groupId>
<artifactId>extra-abs</artifactId>
<packaging>apklib</packaging>
<name>ActionBar-PullToRefresh Extras: ActionBarSherlock</name>

<parent>
<groupId>com.github.chrisbanes.actionbarpulltorefresh</groupId>
<artifactId>extras</artifactId>
<version>0.4</version>
</parent>

<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>library</artifactId>
<type>apklib</type>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<type>apklib</type>
<version>4.3.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
android.library.reference.1=../../library

android.library.reference.2=../../../JakeWharton-ActionBarSherlock-c47975f/actionbarsherlock
android.library=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ 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.
-->

<resources>

<style name="Widget.Holo.ProgressBar.Horizontal.Center"
parent="@style/Widget.Sherlock.ProgressBar.Horizontal">
<item name="android:progressDrawable">@drawable/progress_horizontal_holo_center</item>
</style>

</resources>
Loading

0 comments on commit 9aff9c8

Please sign in to comment.