|
| 1 | +# ActionBar-PullToRefresh |
| 2 | + |
| 3 | + |
| 4 | +ActionBar-PullToRefresh provides an easy way to add a modern version of the pull-to-refresh interaction to your application. |
| 5 | + |
| 6 | +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. |
| 7 | + |
| 8 | +### This is a Preview |
| 9 | +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. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Supported Views |
| 14 | + |
| 15 | +ActionBar-PullToRefresh has in-built support for: |
| 16 | + |
| 17 | + * AbsListView derivatives (ListView & GridView). |
| 18 | + * ScrollView |
| 19 | + |
| 20 | +If the View you want to use is not listed above, you can easily add support by providing a `Delegate`. See the 'Delegates' section below for more info. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Usage |
| 25 | +There are two ways to use this library, programmatically or declaratively. |
| 26 | + |
| 27 | +### Programmatically |
| 28 | +You just need to create an instance of `PullToRefreshAttacher`, giving it the Activity and the View for which will scroll. |
| 29 | + |
| 30 | +``` java |
| 31 | +private PullToRefreshAttacher mPullToRefreshHelper; |
| 32 | + |
| 33 | +@Override |
| 34 | +public void onCreate(Bundle savedInstanceState) { |
| 35 | + super.onCreate(savedInstanceState); |
| 36 | + |
| 37 | + // Get View for which the user will scroll… |
| 38 | + View scrollableView = findViewById(R.id.blah); |
| 39 | + |
| 40 | + mPullToRefreshHelper = new PullToRefreshAttacher(this, scrollableView); |
| 41 | + mPullToRefreshHelper.setRefreshListener(this); |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +__See the [ListView]() sample for more info.__ |
| 46 | + |
| 47 | +### Declaratively |
| 48 | +Here you just wrap your scrollable view in a `PullToRefreshLayout` in your layout XML: |
| 49 | + |
| 50 | +``` xml |
| 51 | +<uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout |
| 52 | + android:id="@+id/ptr_layout" |
| 53 | + xmlns:android="http://schemas.android.com/apk/res/android" |
| 54 | + xmlns:ptr="http://schemas.android.com/apk/res-auto" |
| 55 | + android:layout_width="fill_parent" |
| 56 | + android:layout_height="fill_parent" |
| 57 | + ptr:refreshScrollDistance="0.75"> |
| 58 | + |
| 59 | + <ScrollView |
| 60 | + android:layout_width="fill_parent" |
| 61 | + android:layout_height="fill_parent" |
| 62 | + android:padding="8dp" |
| 63 | + android:scrollbarStyle="outsideInset"> |
| 64 | + |
| 65 | + <TextView |
| 66 | + android:layout_width="fill_parent" |
| 67 | + android:layout_height="wrap_content" |
| 68 | + android:text="@string/filler_text" /> |
| 69 | + |
| 70 | + </ScrollView> |
| 71 | + |
| 72 | +</uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout> |
| 73 | +``` |
| 74 | +In you Activity/Fragment you then do the following to retrieve the generated PullToRefreshAttacher |
| 75 | + |
| 76 | +``` java |
| 77 | +// Retrieve PullToRefreshAttacher from PullToRefreshLayout |
| 78 | +mPullToRefreshAttacher = PullToRefreshLayout.getAttacher(this, R.id.ptr_layout); |
| 79 | + |
| 80 | +// Set Listener to know when a refresh should be started |
| 81 | +mPullToRefreshAttacher.setRefreshListener(this); |
| 82 | +``` |
| 83 | + |
| 84 | +__See the [ScrollView]() sample for more info.__ |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## Customisation |
| 89 | + |
| 90 | +### Delegates |
| 91 | +TODO |
| 92 | + |
| 93 | +### HeaderTransformers |
| 94 | +TODO |
| 95 | + |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## License |
| 100 | + |
| 101 | + Copyright 2013 Chris Banes |
| 102 | + |
| 103 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 104 | + you may not use this file except in compliance with the License. |
| 105 | + You may obtain a copy of the License at |
| 106 | + |
| 107 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 108 | + |
| 109 | + Unless required by applicable law or agreed to in writing, software |
| 110 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 111 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 112 | + See the License for the specific language governing permissions and |
| 113 | + limitations under the License. |
0 commit comments