├── .gitignore ├── LICENSE ├── README.md ├── extras ├── PullToRefreshListFragment │ ├── AndroidManifest.xml │ ├── LICENSE │ ├── libs │ │ └── android-support-v4.jar │ ├── pom.xml │ ├── project.properties │ ├── res │ │ └── layout │ │ │ └── need_this_for_maven.xml │ └── src │ │ └── com │ │ └── handmark │ │ └── pulltorefresh │ │ └── extras │ │ └── listfragment │ │ ├── PullToRefreshBaseListFragment.java │ │ ├── PullToRefreshExpandableListFragment.java │ │ └── PullToRefreshListFragment.java ├── PullToRefreshViewPager │ ├── AndroidManifest.xml │ ├── ant.properties │ ├── libs │ │ └── android-support-v4.jar │ ├── pom.xml │ ├── proguard-project.txt │ ├── project.properties │ ├── res │ │ ├── layout │ │ │ └── need_this_for_maven.xml │ │ └── values │ │ │ └── ids.xml │ └── src │ │ └── com │ │ └── handmark │ │ └── pulltorefresh │ │ └── extras │ │ └── viewpager │ │ └── PullToRefreshViewPager.java └── pom.xml ├── header_graphic.png ├── library ├── AndroidManifest.xml ├── LICENSE ├── pom.xml ├── project.properties ├── res │ ├── anim │ │ ├── slide_in_from_bottom.xml │ │ ├── slide_in_from_top.xml │ │ ├── slide_out_to_bottom.xml │ │ └── slide_out_to_top.xml │ ├── drawable-hdpi │ │ ├── default_ptr_flip.png │ │ ├── default_ptr_rotate.png │ │ └── indicator_arrow.png │ ├── drawable-mdpi │ │ ├── default_ptr_flip.png │ │ ├── default_ptr_rotate.png │ │ └── indicator_arrow.png │ ├── drawable-xhdpi │ │ ├── default_ptr_flip.png │ │ ├── default_ptr_rotate.png │ │ └── indicator_arrow.png │ ├── drawable │ │ ├── indicator_bg_bottom.xml │ │ └── indicator_bg_top.xml │ ├── layout │ │ ├── pull_to_refresh_header_horizontal.xml │ │ └── pull_to_refresh_header_vertical.xml │ ├── values-ar │ │ └── pull_refresh_strings.xml │ ├── values-cs │ │ └── pull_refresh_strings.xml │ ├── values-de │ │ └── pull_refresh_strings.xml │ ├── values-es │ │ └── pull_refresh_strings.xml │ ├── values-fi │ │ └── pull_refresh_strings.xml │ ├── values-fr │ │ └── pull_refresh_strings.xml │ ├── values-he │ │ └── pull_refresh_strings.xml │ ├── values-it │ │ └── pull_refresh_strings.xml │ ├── values-iw │ │ └── pull_refresh_strings.xml │ ├── values-ja │ │ └── pull_refresh_strings.xml │ ├── values-ko │ │ └── pull_refresh_strings.xml │ ├── values-nl │ │ └── pull_refresh_strings.xml │ ├── values-pl │ │ └── pull_refresh_strings.xml │ ├── values-pt-rBR │ │ └── pull_refresh_strings.xml │ ├── values-pt │ │ └── pull_refresh_strings.xml │ ├── values-ro │ │ └── pull_refresh_strings.xml │ ├── values-ru │ │ └── pull_refresh_strings.xml │ ├── values-zh │ │ └── pull_refresh_strings.xml │ └── values │ │ ├── attrs.xml │ │ ├── dimens.xml │ │ ├── ids.xml │ │ └── pull_refresh_strings.xml └── src │ └── com │ └── handmark │ └── pulltorefresh │ └── library │ ├── ILoadingLayout.java │ ├── IPullToRefresh.java │ ├── LoadingLayoutProxy.java │ ├── OverscrollHelper.java │ ├── PullToRefreshAdapterViewBase.java │ ├── PullToRefreshBase.java │ ├── PullToRefreshExpandableListView.java │ ├── PullToRefreshGridView.java │ ├── PullToRefreshHorizontalScrollView.java │ ├── PullToRefreshListView.java │ ├── PullToRefreshRecyclerView.java │ ├── PullToRefreshScrollView.java │ ├── PullToRefreshWebView.java │ ├── extras │ ├── PullToRefreshWebView2.java │ └── SoundPullEventListener.java │ └── internal │ ├── EmptyViewMethodAccessor.java │ ├── FlipLoadingLayout.java │ ├── IndicatorLayout.java │ ├── LoadingLayout.java │ ├── RotateLoadingLayout.java │ ├── Utils.java │ └── ViewCompat.java ├── pom.xml └── sample ├── AndroidManifest.xml ├── LICENSE ├── assets └── ptr_webview2_sample.html ├── libs └── android-support-v4.jar ├── pom.xml ├── project.properties ├── res ├── drawable-hdpi │ ├── android.png │ └── icon.png ├── drawable-ldpi │ └── icon.png ├── drawable-mdpi │ └── icon.png ├── drawable-nodpi │ └── wallpaper.jpg ├── drawable-xhdpi │ └── android.png ├── drawable │ └── icon.png ├── layout │ ├── activity_ptr_expandable_list.xml │ ├── activity_ptr_grid.xml │ ├── activity_ptr_horizontalscrollview.xml │ ├── activity_ptr_list.xml │ ├── activity_ptr_list_fragment.xml │ ├── activity_ptr_list_in_vp.xml │ ├── activity_ptr_scrollview.xml │ ├── activity_ptr_viewpager.xml │ ├── activity_ptr_webview.xml │ ├── activity_ptr_webview2.xml │ └── layout_listview_in_viewpager.xml ├── raw │ ├── pull_event.mp3 │ ├── refreshing_sound.mp3 │ └── reset_sound.mp3 └── values │ ├── strings.xml │ └── styles.xml └── src └── com └── handmark └── pulltorefresh └── samples ├── LauncherActivity.java ├── PullToRefreshExpandableListActivity.java ├── PullToRefreshGridActivity.java ├── PullToRefreshHorizontalScrollViewActivity.java ├── PullToRefreshListActivity.java ├── PullToRefreshListFragmentActivity.java ├── PullToRefreshListInViewPagerActivity.java ├── PullToRefreshScrollViewActivity.java ├── PullToRefreshViewPagerActivity.java ├── PullToRefreshWebView2Activity.java └── PullToRefreshWebViewActivity.java /.gitignore: -------------------------------------------------------------------------------- 1 | #Android generated 2 | bin 3 | gen 4 | 5 | #Eclipse 6 | .project 7 | .classpath 8 | .settings 9 | 10 | #IntelliJ IDEA 11 | .idea 12 | *.iml 13 | *.ipr 14 | *.iws 15 | out 16 | 17 | #Maven 18 | target 19 | release.properties 20 | pom.xml.* 21 | 22 | #Ant 23 | build.xml 24 | local.properties 25 | proguard.cfg 26 | 27 | #OSX 28 | .DS_Store 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Add PullToRefreshRecyclerView to Support RecyclerView 2 | 3 | * * * 4 | 5 | # PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED 6 | 7 | * * * 8 | 9 | # Pull To Refresh Views for Android 10 | 11 | ![Screenshot](https://github.com/chrisbanes/Android-PullToRefresh/raw/master/header_graphic.png) 12 | 13 | This project aims to provide a reusable Pull to Refresh widget for Android. It was originally based on Johan Nilsson's [library](https://github.com/johannilsson/android-pulltorefresh) (mainly for graphics, strings and animations), but these have been replaced since. 14 | 15 | ## Features 16 | 17 | * Supports both Pulling Down from the top, and Pulling Up from the bottom (or even both). 18 | * Animated Scrolling for all devices. 19 | * Over Scroll supports for devices on Android v2.3+. 20 | * Currently works with: 21 | * **ListView** 22 | * **ExpandableListView** 23 | * **GridView** 24 | * **WebView** 25 | * **ScrollView** 26 | * **HorizontalScrollView** 27 | * **ViewPager** 28 | * Integrated End of List Listener for use of detecting when the user has scrolled to the bottom. 29 | * Maven Support. 30 | * Indicators to show the user when a Pull-to-Refresh is available. 31 | * Support for **ListFragment**! 32 | * Lots of [Customisation](https://github.com/chrisbanes/Android-PullToRefresh/wiki/Customisation) options! 33 | 34 | Repository at . 35 | 36 | ## Sample Application 37 | The sample application (the source is in the repository) has been published onto Google Play for easy access: 38 | 39 | [![Get it on Google Play](http://www.android.com/images/brand/get_it_on_play_logo_small.png)](http://play.google.com/store/apps/details?id=com.handmark.pulltorefresh.samples) 40 | 41 | ## Usage 42 | To begin using the library, please see the [Quick Start Guide](https://github.com/chrisbanes/Android-PullToRefresh/wiki/Quick-Start-Guide) page. 43 | 44 | ### Customisation 45 | Please see the [Customisation](https://github.com/chrisbanes/Android-PullToRefresh/wiki/Customisation) page for more information on how to change the behaviour and look of the View. 46 | 47 | ### Pull Up to Refresh 48 | By default this library is set to Pull Down to Refresh, but if you want to allow Pulling Up to Refresh then you can do so. You can even set the View to enable both Pulling Up and Pulling Down using the 'both' setting. See the [Customisation](https://github.com/chrisbanes/Android-PullToRefresh/wiki/Customisation) page for more information on how to set this. 49 | 50 | ## Apps 51 | Want to see which Apps are already using Android-PullToRefresh? Have a look [here](https://github.com/chrisbanes/Android-PullToRefresh/wiki/Apps). If you have an App which is not on the list, [let me know](http://www.senab.co.uk/contact/). 52 | 53 | ## Changelog 54 | Please see the new [Changelog](https://github.com/chrisbanes/Android-PullToRefresh/wiki/Changelog) page to see what's recently changed. 55 | 56 | ## Pull Requests 57 | 58 | I will gladly accept pull requests for fixes and feature enhancements but please do them in the dev branch. The master branch is for the latest stable code, dev is where I try things out before releasing them as stable. Any pull requests that are against master from now on will be closed asking for you to do another pull against dev. 59 | 60 | ## Acknowledgments 61 | 62 | * [Stefano Dacchille](https://github.com/stefanodacchille) 63 | * [Steve Lhomme](https://github.com/robUx4) 64 | * [Maxim Galkin](https://github.com/mgalkin) 65 | * [Scorcher](https://github.com/Scorcher) 66 | 67 | 68 | ## License 69 | 70 | Copyright 2011, 2012 Chris Banes 71 | 72 | Licensed under the Apache License, Version 2.0 (the "License"); 73 | you may not use this file except in compliance with the License. 74 | You may obtain a copy of the License at 75 | 76 | http://www.apache.org/licenses/LICENSE-2.0 77 | 78 | Unless required by applicable law or agreed to in writing, software 79 | distributed under the License is distributed on an "AS IS" BASIS, 80 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 81 | See the License for the specific language governing permissions and 82 | limitations under the License. -------------------------------------------------------------------------------- /extras/PullToRefreshListFragment/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /extras/PullToRefreshListFragment/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/extras/PullToRefreshListFragment/libs/android-support-v4.jar -------------------------------------------------------------------------------- /extras/PullToRefreshListFragment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.github.chrisbanes.pulltorefresh 6 | extra-listfragment 7 | apklib 8 | Android-PullToRefresh Extras: ListFragment 9 | 10 | 11 | com.github.chrisbanes.pulltorefresh 12 | extras 13 | 2.1.2-SNAPSHOT 14 | 15 | 16 | 17 | 18 | com.google.android 19 | android 20 | 21 | 22 | com.google.android 23 | support-v4 24 | r7 25 | 26 | 27 | ${project.groupId} 28 | library 29 | apklib 30 | ${project.version} 31 | 32 | 33 | 34 | 35 | 36 | 37 | com.jayway.maven.plugins.android.generation2 38 | android-maven-plugin 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-eclipse-plugin 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /extras/PullToRefreshListFragment/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | android.library=true 14 | # Project target. 15 | target=android-16 16 | android.library.reference.1=../../library 17 | -------------------------------------------------------------------------------- /extras/PullToRefreshListFragment/res/layout/need_this_for_maven.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /extras/PullToRefreshListFragment/src/com/handmark/pulltorefresh/extras/listfragment/PullToRefreshBaseListFragment.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.extras.listfragment; 17 | 18 | import android.os.Bundle; 19 | import android.support.v4.app.ListFragment; 20 | import android.view.LayoutInflater; 21 | import android.view.View; 22 | import android.view.ViewGroup; 23 | import android.widget.AbsListView; 24 | import android.widget.ListView; 25 | 26 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 27 | 28 | abstract class PullToRefreshBaseListFragment> extends ListFragment { 29 | 30 | private T mPullToRefreshListView; 31 | 32 | @Override 33 | public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 34 | View layout = super.onCreateView(inflater, container, savedInstanceState); 35 | 36 | ListView lv = (ListView) layout.findViewById(android.R.id.list); 37 | ViewGroup parent = (ViewGroup) lv.getParent(); 38 | 39 | // Remove ListView and add PullToRefreshListView in its place 40 | int lvIndex = parent.indexOfChild(lv); 41 | parent.removeViewAt(lvIndex); 42 | mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); 43 | parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); 44 | 45 | return layout; 46 | } 47 | 48 | /** 49 | * @return The {@link PullToRefreshBase} attached to this ListFragment. 50 | */ 51 | public final T getPullToRefreshListView() { 52 | return mPullToRefreshListView; 53 | } 54 | 55 | /** 56 | * Returns the {@link PullToRefreshBase} which will replace the ListView 57 | * created from ListFragment. You should override this method if you wish to 58 | * customise the {@link PullToRefreshBase} from the default. 59 | * 60 | * @param inflater - LayoutInflater which can be used to inflate from XML. 61 | * @param savedInstanceState - Bundle passed through from 62 | * {@link ListFragment#onCreateView(LayoutInflater, ViewGroup, Bundle) 63 | * onCreateView(...)} 64 | * @return The {@link PullToRefreshBase} which will replace the ListView. 65 | */ 66 | protected abstract T onCreatePullToRefreshListView(LayoutInflater inflater, Bundle savedInstanceState); 67 | 68 | } -------------------------------------------------------------------------------- /extras/PullToRefreshListFragment/src/com/handmark/pulltorefresh/extras/listfragment/PullToRefreshExpandableListFragment.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.extras.listfragment; 17 | 18 | import android.os.Bundle; 19 | import android.support.v4.app.ListFragment; 20 | import android.view.LayoutInflater; 21 | 22 | import com.handmark.pulltorefresh.library.PullToRefreshExpandableListView; 23 | 24 | /** 25 | * A sample implementation of how to use {@link PullToRefreshExpandableListView} 26 | * with {@link ListFragment}. This implementation simply replaces the ListView 27 | * that {@code ListFragment} creates with a new 28 | * {@code PullToRefreshExpandableListView}. This means that ListFragment still 29 | * works 100% (e.g. setListShown(...) ). 30 | *

31 | * The new PullToRefreshListView is created in the method 32 | * {@link #onCreatePullToRefreshListView(LayoutInflater, Bundle)}. If you wish 33 | * to customise the {@code PullToRefreshExpandableListView} then override this 34 | * method and return your customised instance. 35 | * 36 | * @author Chris Banes 37 | * 38 | */ 39 | public class PullToRefreshExpandableListFragment extends PullToRefreshBaseListFragment { 40 | 41 | protected PullToRefreshExpandableListView onCreatePullToRefreshListView(LayoutInflater inflater, 42 | Bundle savedInstanceState) { 43 | return new PullToRefreshExpandableListView(getActivity()); 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /extras/PullToRefreshListFragment/src/com/handmark/pulltorefresh/extras/listfragment/PullToRefreshListFragment.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.extras.listfragment; 17 | 18 | import android.os.Bundle; 19 | import android.support.v4.app.ListFragment; 20 | import android.view.LayoutInflater; 21 | 22 | import com.handmark.pulltorefresh.library.PullToRefreshListView; 23 | 24 | /** 25 | * A sample implementation of how to use {@link PullToRefreshListView} with 26 | * {@link ListFragment}. This implementation simply replaces the ListView that 27 | * {@code ListFragment} creates with a new PullToRefreshListView. This means 28 | * that ListFragment still works 100% (e.g. setListShown(...) ). 29 | *

30 | * The new PullToRefreshListView is created in the method 31 | * {@link #onCreatePullToRefreshListView(LayoutInflater, Bundle)}. If you wish 32 | * to customise the {@code PullToRefreshListView} then override this method and 33 | * return your customised instance. 34 | * 35 | * @author Chris Banes 36 | * 37 | */ 38 | public class PullToRefreshListFragment extends PullToRefreshBaseListFragment { 39 | 40 | protected PullToRefreshListView onCreatePullToRefreshListView(LayoutInflater inflater, Bundle savedInstanceState) { 41 | return new PullToRefreshListView(getActivity()); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /extras/PullToRefreshViewPager/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /extras/PullToRefreshViewPager/ant.properties: -------------------------------------------------------------------------------- 1 | # This file is used to override default values used by the Ant build system. 2 | # 3 | # This file must be checked into Version Control Systems, as it is 4 | # integral to the build system of your project. 5 | 6 | # This file is only used by the Ant script. 7 | 8 | # You can use this to override default values such as 9 | # 'source.dir' for the location of your java source folder and 10 | # 'out.dir' for the location of your output folder. 11 | 12 | # You can also use it define how the release builds are signed by declaring 13 | # the following properties: 14 | # 'key.store' for the location of your keystore and 15 | # 'key.alias' for the name of the key to use. 16 | # The password will be asked during the build when you use the 'release' target. 17 | 18 | -------------------------------------------------------------------------------- /extras/PullToRefreshViewPager/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/extras/PullToRefreshViewPager/libs/android-support-v4.jar -------------------------------------------------------------------------------- /extras/PullToRefreshViewPager/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.github.chrisbanes.pulltorefresh 6 | extra-viewpager 7 | apklib 8 | Android-PullToRefresh Extras: ViewPager 9 | 10 | 11 | com.github.chrisbanes.pulltorefresh 12 | extras 13 | 2.1.2-SNAPSHOT 14 | 15 | 16 | 17 | 18 | com.google.android 19 | android 20 | 21 | 22 | com.google.android 23 | support-v4 24 | r7 25 | 26 | 27 | ${project.groupId} 28 | library 29 | apklib 30 | ${project.version} 31 | 32 | 33 | 34 | 35 | 36 | 37 | com.jayway.maven.plugins.android.generation2 38 | android-maven-plugin 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-eclipse-plugin 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /extras/PullToRefreshViewPager/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /extras/PullToRefreshViewPager/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | android.library=true 14 | # Project target. 15 | target=android-16 16 | android.library.reference.1=../../library 17 | -------------------------------------------------------------------------------- /extras/PullToRefreshViewPager/res/layout/need_this_for_maven.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /extras/PullToRefreshViewPager/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /extras/PullToRefreshViewPager/src/com/handmark/pulltorefresh/extras/viewpager/PullToRefreshViewPager.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.extras.viewpager; 17 | 18 | import android.content.Context; 19 | import android.support.v4.view.PagerAdapter; 20 | import android.support.v4.view.ViewPager; 21 | import android.util.AttributeSet; 22 | 23 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 24 | 25 | public class PullToRefreshViewPager extends PullToRefreshBase { 26 | 27 | public PullToRefreshViewPager(Context context) { 28 | super(context); 29 | } 30 | 31 | public PullToRefreshViewPager(Context context, AttributeSet attrs) { 32 | super(context, attrs); 33 | } 34 | 35 | @Override 36 | public final Orientation getPullToRefreshScrollDirection() { 37 | return Orientation.HORIZONTAL; 38 | } 39 | 40 | @Override 41 | protected ViewPager createRefreshableView(Context context, AttributeSet attrs) { 42 | ViewPager viewPager = new ViewPager(context, attrs); 43 | viewPager.setId(R.id.viewpager); 44 | return viewPager; 45 | } 46 | 47 | @Override 48 | protected boolean isReadyForPullStart() { 49 | ViewPager refreshableView = getRefreshableView(); 50 | 51 | PagerAdapter adapter = refreshableView.getAdapter(); 52 | if (null != adapter) { 53 | return refreshableView.getCurrentItem() == 0; 54 | } 55 | 56 | return false; 57 | } 58 | 59 | @Override 60 | protected boolean isReadyForPullEnd() { 61 | ViewPager refreshableView = getRefreshableView(); 62 | 63 | PagerAdapter adapter = refreshableView.getAdapter(); 64 | if (null != adapter) { 65 | return refreshableView.getCurrentItem() == adapter.getCount() - 1; 66 | } 67 | 68 | return false; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /extras/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.github.chrisbanes.pulltorefresh 6 | extras 7 | pom 8 | Android-PullToRefresh Extras 9 | 10 | 11 | com.github.chrisbanes.pulltorefresh 12 | parent 13 | 2.1.2-SNAPSHOT 14 | 15 | 16 | 17 | PullToRefreshListFragment 18 | PullToRefreshViewPager 19 | 20 | 21 | -------------------------------------------------------------------------------- /header_graphic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/header_graphic.png -------------------------------------------------------------------------------- /library/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /library/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.github.chrisbanes.pulltorefresh 6 | library 7 | apklib 8 | Android-PullToRefresh Library 9 | 10 | 11 | com.github.chrisbanes.pulltorefresh 12 | parent 13 | 2.1.2-SNAPSHOT 14 | 15 | 16 | 17 | 18 | com.google.android 19 | android 20 | 21 | 22 | 23 | 24 | 25 | com.jayway.maven.plugins.android.generation2 26 | android-maven-plugin 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-eclipse-plugin 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /library/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-19 12 | android.library=true 13 | android.library.reference.1=../../RecyclerView-master/RecyclerView-master/library 14 | -------------------------------------------------------------------------------- /library/res/anim/slide_in_from_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | -------------------------------------------------------------------------------- /library/res/anim/slide_in_from_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | -------------------------------------------------------------------------------- /library/res/anim/slide_out_to_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | -------------------------------------------------------------------------------- /library/res/anim/slide_out_to_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | -------------------------------------------------------------------------------- /library/res/drawable-hdpi/default_ptr_flip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/library/res/drawable-hdpi/default_ptr_flip.png -------------------------------------------------------------------------------- /library/res/drawable-hdpi/default_ptr_rotate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/library/res/drawable-hdpi/default_ptr_rotate.png -------------------------------------------------------------------------------- /library/res/drawable-hdpi/indicator_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/library/res/drawable-hdpi/indicator_arrow.png -------------------------------------------------------------------------------- /library/res/drawable-mdpi/default_ptr_flip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/library/res/drawable-mdpi/default_ptr_flip.png -------------------------------------------------------------------------------- /library/res/drawable-mdpi/default_ptr_rotate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/library/res/drawable-mdpi/default_ptr_rotate.png -------------------------------------------------------------------------------- /library/res/drawable-mdpi/indicator_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/library/res/drawable-mdpi/indicator_arrow.png -------------------------------------------------------------------------------- /library/res/drawable-xhdpi/default_ptr_flip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/library/res/drawable-xhdpi/default_ptr_flip.png -------------------------------------------------------------------------------- /library/res/drawable-xhdpi/default_ptr_rotate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/library/res/drawable-xhdpi/default_ptr_rotate.png -------------------------------------------------------------------------------- /library/res/drawable-xhdpi/indicator_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/library/res/drawable-xhdpi/indicator_arrow.png -------------------------------------------------------------------------------- /library/res/drawable/indicator_bg_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 17 | 18 | -------------------------------------------------------------------------------- /library/res/drawable/indicator_bg_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 17 | 18 | -------------------------------------------------------------------------------- /library/res/layout/pull_to_refresh_header_horizontal.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 18 | 19 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /library/res/layout/pull_to_refresh_header_vertical.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 17 | 18 | 23 | 24 | 32 | 33 | 34 | 40 | 41 | 48 | 49 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /library/res/values-ar/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | اسحب للتحديث… 4 | اترك للتحديث… 5 | تحميل… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-cs/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tažením aktualizujete… 4 | Uvolněním aktualizujete… 5 | Načítání… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-de/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Ziehen zum Aktualisieren… 4 | Loslassen zum Aktualisieren… 5 | Laden… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-es/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tirar para actualizar… 4 | Soltar para actualizar… 5 | Cargando… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-fi/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Päivitä vetämällä alas… 5 | Päivitä vapauttamalla… 6 | Päivitetään… 7 | 8 | 9 | Päivitä vetämällä ylös… 10 | @string/pull_to_refresh_release_label 11 | @string/pull_to_refresh_refreshing_label 12 | 13 | -------------------------------------------------------------------------------- /library/res/values-fr/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tirez pour rafraîchir… 4 | Relâcher pour rafraîchir… 5 | Chargement… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-he/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | משוך לרענון… 4 | שחרר לרענון… 5 | טוען… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-it/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tira per aggiornare… 4 | Rilascia per aggionare… 5 | Caricamento… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-iw/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | משוך לרענון… 4 | שחרר לרענון… 5 | טוען… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-ja/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 画面を引っ張って… 4 | 指を離して更新… 5 | 読み込み中… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-ko/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 당겨서 새로 고침… 4 | 놓아서 새로 고침… 5 | 로드 중… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-nl/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Sleep om te vernieuwen… 4 | Loslaten om te vernieuwen… 5 | Laden… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-pl/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Pociągnij, aby odświeżyć… 4 | Puść, aby odświeżyć… 5 | Wczytywanie… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-pt-rBR/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Puxe para atualizar… 4 | Libere para atualizar… 5 | Carregando… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-pt/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Puxe para atualizar… 4 | Liberação para atualizar… 5 | A carregar… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-ro/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Trage pentru a reîmprospăta… 4 | Eliberează pentru a reîmprospăta… 5 | Încărcare… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-ru/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Потяните для обновления… 4 | Отпустите для обновления… 5 | Загрузка… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values-zh/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 下拉刷新… 4 | 放开以刷新… 5 | 正在载入… 6 | 7 | -------------------------------------------------------------------------------- /library/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 66 | 67 | 68 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /library/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10dp 5 | 12dp 6 | 4dp 7 | 24dp 8 | 12dp 9 | 10 | -------------------------------------------------------------------------------- /library/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /library/res/values/pull_refresh_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Pull to refresh… 5 | Release to refresh… 6 | Loading… 7 | 8 | 9 | @string/pull_to_refresh_pull_label 10 | @string/pull_to_refresh_release_label 11 | @string/pull_to_refresh_refreshing_label 12 | 13 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/ILoadingLayout.java: -------------------------------------------------------------------------------- 1 | package com.handmark.pulltorefresh.library; 2 | 3 | import android.graphics.Typeface; 4 | import android.graphics.drawable.Drawable; 5 | 6 | public interface ILoadingLayout { 7 | 8 | /** 9 | * Set the Last Updated Text. This displayed under the main label when 10 | * Pulling 11 | * 12 | * @param label - Label to set 13 | */ 14 | public void setLastUpdatedLabel(CharSequence label); 15 | 16 | /** 17 | * Set the drawable used in the loading layout. This is the same as calling 18 | * setLoadingDrawable(drawable, Mode.BOTH) 19 | * 20 | * @param drawable - Drawable to display 21 | */ 22 | public void setLoadingDrawable(Drawable drawable); 23 | 24 | /** 25 | * Set Text to show when the Widget is being Pulled 26 | * setPullLabel(releaseLabel, Mode.BOTH) 27 | * 28 | * @param pullLabel - CharSequence to display 29 | */ 30 | public void setPullLabel(CharSequence pullLabel); 31 | 32 | /** 33 | * Set Text to show when the Widget is refreshing 34 | * setRefreshingLabel(releaseLabel, Mode.BOTH) 35 | * 36 | * @param refreshingLabel - CharSequence to display 37 | */ 38 | public void setRefreshingLabel(CharSequence refreshingLabel); 39 | 40 | /** 41 | * Set Text to show when the Widget is being pulled, and will refresh when 42 | * released. This is the same as calling 43 | * setReleaseLabel(releaseLabel, Mode.BOTH) 44 | * 45 | * @param releaseLabel - CharSequence to display 46 | */ 47 | public void setReleaseLabel(CharSequence releaseLabel); 48 | 49 | /** 50 | * Set's the Sets the typeface and style in which the text should be 51 | * displayed. Please see 52 | * {@link android.widget.TextView#setTypeface(Typeface) 53 | * TextView#setTypeface(Typeface)}. 54 | */ 55 | public void setTextTypeface(Typeface tf); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/IPullToRefresh.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library; 17 | 18 | import android.view.View; 19 | import android.view.animation.Interpolator; 20 | 21 | import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; 22 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnPullEventListener; 23 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; 24 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2; 25 | import com.handmark.pulltorefresh.library.PullToRefreshBase.State; 26 | 27 | public interface IPullToRefresh { 28 | 29 | /** 30 | * Demos the Pull-to-Refresh functionality to the user so that they are 31 | * aware it is there. This could be useful when the user first opens your 32 | * app, etc. The animation will only happen if the Refresh View (ListView, 33 | * ScrollView, etc) is in a state where a Pull-to-Refresh could occur by a 34 | * user's touch gesture (i.e. scrolled to the top/bottom). 35 | * 36 | * @return true - if the Demo has been started, false if not. 37 | */ 38 | public boolean demo(); 39 | 40 | /** 41 | * Get the mode that this view is currently in. This is only really useful 42 | * when using Mode.BOTH. 43 | * 44 | * @return Mode that the view is currently in 45 | */ 46 | public Mode getCurrentMode(); 47 | 48 | /** 49 | * Returns whether the Touch Events are filtered or not. If true is 50 | * returned, then the View will only use touch events where the difference 51 | * in the Y-axis is greater than the difference in the X-axis. This means 52 | * that the View will not interfere when it is used in a horizontal 53 | * scrolling View (such as a ViewPager). 54 | * 55 | * @return boolean - true if the View is filtering Touch Events 56 | */ 57 | public boolean getFilterTouchEvents(); 58 | 59 | /** 60 | * Returns a proxy object which allows you to call methods on all of the 61 | * LoadingLayouts (the Views which show when Pulling/Refreshing). 62 | *

63 | * You should not keep the result of this method any longer than you need 64 | * it. 65 | * 66 | * @return Object which will proxy any calls you make on it, to all of the 67 | * LoadingLayouts. 68 | */ 69 | public ILoadingLayout getLoadingLayoutProxy(); 70 | 71 | /** 72 | * Returns a proxy object which allows you to call methods on the 73 | * LoadingLayouts (the Views which show when Pulling/Refreshing). The actual 74 | * LoadingLayout(s) which will be affected, are chosen by the parameters you 75 | * give. 76 | *

77 | * You should not keep the result of this method any longer than you need 78 | * it. 79 | * 80 | * @param includeStart - Whether to include the Start/Header Views 81 | * @param includeEnd - Whether to include the End/Footer Views 82 | * @return Object which will proxy any calls you make on it, to the 83 | * LoadingLayouts included. 84 | */ 85 | public ILoadingLayout getLoadingLayoutProxy(boolean includeStart, boolean includeEnd); 86 | 87 | /** 88 | * Get the mode that this view has been set to. If this returns 89 | * Mode.BOTH, you can use getCurrentMode() to 90 | * check which mode the view is currently in 91 | * 92 | * @return Mode that the view has been set to 93 | */ 94 | public Mode getMode(); 95 | 96 | /** 97 | * Get the Wrapped Refreshable View. Anything returned here has already been 98 | * added to the content view. 99 | * 100 | * @return The View which is currently wrapped 101 | */ 102 | public T getRefreshableView(); 103 | 104 | /** 105 | * Get whether the 'Refreshing' View should be automatically shown when 106 | * refreshing. Returns true by default. 107 | * 108 | * @return - true if the Refreshing View will be show 109 | */ 110 | public boolean getShowViewWhileRefreshing(); 111 | 112 | /** 113 | * @return - The state that the View is currently in. 114 | */ 115 | public State getState(); 116 | 117 | /** 118 | * Whether Pull-to-Refresh is enabled 119 | * 120 | * @return enabled 121 | */ 122 | public boolean isPullToRefreshEnabled(); 123 | 124 | /** 125 | * Gets whether Overscroll support is enabled. This is different to 126 | * Android's standard Overscroll support (the edge-glow) which is available 127 | * from GINGERBREAD onwards 128 | * 129 | * @return true - if both PullToRefresh-OverScroll and Android's inbuilt 130 | * OverScroll are enabled 131 | */ 132 | public boolean isPullToRefreshOverScrollEnabled(); 133 | 134 | /** 135 | * Returns whether the Widget is currently in the Refreshing mState 136 | * 137 | * @return true if the Widget is currently refreshing 138 | */ 139 | public boolean isRefreshing(); 140 | 141 | /** 142 | * Returns whether the widget has enabled scrolling on the Refreshable View 143 | * while refreshing. 144 | * 145 | * @return true if the widget has enabled scrolling while refreshing 146 | */ 147 | public boolean isScrollingWhileRefreshingEnabled(); 148 | 149 | /** 150 | * Mark the current Refresh as complete. Will Reset the UI and hide the 151 | * Refreshing View 152 | */ 153 | public void onRefreshComplete(); 154 | 155 | /** 156 | * Set the Touch Events to be filtered or not. If set to true, then the View 157 | * will only use touch events where the difference in the Y-axis is greater 158 | * than the difference in the X-axis. This means that the View will not 159 | * interfere when it is used in a horizontal scrolling View (such as a 160 | * ViewPager), but will restrict which types of finger scrolls will trigger 161 | * the View. 162 | * 163 | * @param filterEvents - true if you want to filter Touch Events. Default is 164 | * true. 165 | */ 166 | public void setFilterTouchEvents(boolean filterEvents); 167 | 168 | /** 169 | * Set the mode of Pull-to-Refresh that this view will use. 170 | * 171 | * @param mode - Mode to set the View to 172 | */ 173 | public void setMode(Mode mode); 174 | 175 | /** 176 | * Set OnPullEventListener for the Widget 177 | * 178 | * @param listener - Listener to be used when the Widget has a pull event to 179 | * propogate. 180 | */ 181 | public void setOnPullEventListener(OnPullEventListener listener); 182 | 183 | /** 184 | * Set OnRefreshListener for the Widget 185 | * 186 | * @param listener - Listener to be used when the Widget is set to Refresh 187 | */ 188 | public void setOnRefreshListener(OnRefreshListener listener); 189 | 190 | /** 191 | * Set OnRefreshListener for the Widget 192 | * 193 | * @param listener - Listener to be used when the Widget is set to Refresh 194 | */ 195 | public void setOnRefreshListener(OnRefreshListener2 listener); 196 | 197 | /** 198 | * Sets whether Overscroll support is enabled. This is different to 199 | * Android's standard Overscroll support (the edge-glow). This setting only 200 | * takes effect when running on device with Android v2.3 or greater. 201 | * 202 | * @param enabled - true if you want Overscroll enabled 203 | */ 204 | public void setPullToRefreshOverScrollEnabled(boolean enabled); 205 | 206 | /** 207 | * Sets the Widget to be in the refresh state. The UI will be updated to 208 | * show the 'Refreshing' view, and be scrolled to show such. 209 | */ 210 | public void setRefreshing(); 211 | 212 | /** 213 | * Sets the Widget to be in the refresh state. The UI will be updated to 214 | * show the 'Refreshing' view. 215 | * 216 | * @param doScroll - true if you want to force a scroll to the Refreshing 217 | * view. 218 | */ 219 | public void setRefreshing(boolean doScroll); 220 | 221 | /** 222 | * Sets the Animation Interpolator that is used for animated scrolling. 223 | * Defaults to a DecelerateInterpolator 224 | * 225 | * @param interpolator - Interpolator to use 226 | */ 227 | public void setScrollAnimationInterpolator(Interpolator interpolator); 228 | 229 | /** 230 | * By default the Widget disables scrolling on the Refreshable View while 231 | * refreshing. This method can change this behaviour. 232 | * 233 | * @param scrollingWhileRefreshingEnabled - true if you want to enable 234 | * scrolling while refreshing 235 | */ 236 | public void setScrollingWhileRefreshingEnabled(boolean scrollingWhileRefreshingEnabled); 237 | 238 | /** 239 | * A mutator to enable/disable whether the 'Refreshing' View should be 240 | * automatically shown when refreshing. 241 | * 242 | * @param showView 243 | */ 244 | public void setShowViewWhileRefreshing(boolean showView); 245 | 246 | } -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/LoadingLayoutProxy.java: -------------------------------------------------------------------------------- 1 | package com.handmark.pulltorefresh.library; 2 | 3 | import java.util.HashSet; 4 | 5 | import android.graphics.Typeface; 6 | import android.graphics.drawable.Drawable; 7 | 8 | import com.handmark.pulltorefresh.library.internal.LoadingLayout; 9 | 10 | public class LoadingLayoutProxy implements ILoadingLayout { 11 | 12 | private final HashSet mLoadingLayouts; 13 | 14 | LoadingLayoutProxy() { 15 | mLoadingLayouts = new HashSet(); 16 | } 17 | 18 | /** 19 | * This allows you to add extra LoadingLayout instances to this proxy. This 20 | * is only necessary if you keep your own instances, and want to have them 21 | * included in any 22 | * {@link PullToRefreshBase#createLoadingLayoutProxy(boolean, boolean) 23 | * createLoadingLayoutProxy(...)} calls. 24 | * 25 | * @param layout - LoadingLayout to have included. 26 | */ 27 | public void addLayout(LoadingLayout layout) { 28 | if (null != layout) { 29 | mLoadingLayouts.add(layout); 30 | } 31 | } 32 | 33 | @Override 34 | public void setLastUpdatedLabel(CharSequence label) { 35 | for (LoadingLayout layout : mLoadingLayouts) { 36 | layout.setLastUpdatedLabel(label); 37 | } 38 | } 39 | 40 | @Override 41 | public void setLoadingDrawable(Drawable drawable) { 42 | for (LoadingLayout layout : mLoadingLayouts) { 43 | layout.setLoadingDrawable(drawable); 44 | } 45 | } 46 | 47 | @Override 48 | public void setRefreshingLabel(CharSequence refreshingLabel) { 49 | for (LoadingLayout layout : mLoadingLayouts) { 50 | layout.setRefreshingLabel(refreshingLabel); 51 | } 52 | } 53 | 54 | @Override 55 | public void setPullLabel(CharSequence label) { 56 | for (LoadingLayout layout : mLoadingLayouts) { 57 | layout.setPullLabel(label); 58 | } 59 | } 60 | 61 | @Override 62 | public void setReleaseLabel(CharSequence label) { 63 | for (LoadingLayout layout : mLoadingLayouts) { 64 | layout.setReleaseLabel(label); 65 | } 66 | } 67 | 68 | public void setTextTypeface(Typeface tf) { 69 | for (LoadingLayout layout : mLoadingLayouts) { 70 | layout.setTextTypeface(tf); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/OverscrollHelper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library; 17 | 18 | import android.annotation.TargetApi; 19 | import android.util.Log; 20 | import android.view.View; 21 | 22 | import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; 23 | import com.handmark.pulltorefresh.library.PullToRefreshBase.State; 24 | 25 | @TargetApi(9) 26 | public final class OverscrollHelper { 27 | 28 | static final String LOG_TAG = "OverscrollHelper"; 29 | static final float DEFAULT_OVERSCROLL_SCALE = 1f; 30 | 31 | /** 32 | * Helper method for Overscrolling that encapsulates all of the necessary 33 | * function. 34 | *

35 | * This should only be used on AdapterView's such as ListView as it just 36 | * calls through to overScrollBy() with the scrollRange = 0. AdapterView's 37 | * do not have a scroll range (i.e. getScrollY() doesn't work). 38 | * 39 | * @param view - PullToRefreshView that is calling this. 40 | * @param deltaX - Change in X in pixels, passed through from from 41 | * overScrollBy call 42 | * @param scrollX - Current X scroll value in pixels before applying deltaY, 43 | * passed through from from overScrollBy call 44 | * @param deltaY - Change in Y in pixels, passed through from from 45 | * overScrollBy call 46 | * @param scrollY - Current Y scroll value in pixels before applying deltaY, 47 | * passed through from from overScrollBy call 48 | * @param isTouchEvent - true if this scroll operation is the result of a 49 | * touch event, passed through from from overScrollBy call 50 | */ 51 | public static void overScrollBy(final PullToRefreshBase view, final int deltaX, final int scrollX, 52 | final int deltaY, final int scrollY, final boolean isTouchEvent) { 53 | overScrollBy(view, deltaX, scrollX, deltaY, scrollY, 0, isTouchEvent); 54 | } 55 | 56 | /** 57 | * Helper method for Overscrolling that encapsulates all of the necessary 58 | * function. This version of the call is used for Views that need to specify 59 | * a Scroll Range but scroll back to it's edge correctly. 60 | * 61 | * @param view - PullToRefreshView that is calling this. 62 | * @param deltaX - Change in X in pixels, passed through from from 63 | * overScrollBy call 64 | * @param scrollX - Current X scroll value in pixels before applying deltaY, 65 | * passed through from from overScrollBy call 66 | * @param deltaY - Change in Y in pixels, passed through from from 67 | * overScrollBy call 68 | * @param scrollY - Current Y scroll value in pixels before applying deltaY, 69 | * passed through from from overScrollBy call 70 | * @param scrollRange - Scroll Range of the View, specifically needed for 71 | * ScrollView 72 | * @param isTouchEvent - true if this scroll operation is the result of a 73 | * touch event, passed through from from overScrollBy call 74 | */ 75 | public static void overScrollBy(final PullToRefreshBase view, final int deltaX, final int scrollX, 76 | final int deltaY, final int scrollY, final int scrollRange, final boolean isTouchEvent) { 77 | overScrollBy(view, deltaX, scrollX, deltaY, scrollY, scrollRange, 0, DEFAULT_OVERSCROLL_SCALE, isTouchEvent); 78 | } 79 | 80 | /** 81 | * Helper method for Overscrolling that encapsulates all of the necessary 82 | * function. This is the advanced version of the call. 83 | * 84 | * @param view - PullToRefreshView that is calling this. 85 | * @param deltaX - Change in X in pixels, passed through from from 86 | * overScrollBy call 87 | * @param scrollX - Current X scroll value in pixels before applying deltaY, 88 | * passed through from from overScrollBy call 89 | * @param deltaY - Change in Y in pixels, passed through from from 90 | * overScrollBy call 91 | * @param scrollY - Current Y scroll value in pixels before applying deltaY, 92 | * passed through from from overScrollBy call 93 | * @param scrollRange - Scroll Range of the View, specifically needed for 94 | * ScrollView 95 | * @param fuzzyThreshold - Threshold for which the values how fuzzy we 96 | * should treat the other values. Needed for WebView as it 97 | * doesn't always scroll back to it's edge. 0 = no fuzziness. 98 | * @param scaleFactor - Scale Factor for overscroll amount 99 | * @param isTouchEvent - true if this scroll operation is the result of a 100 | * touch event, passed through from from overScrollBy call 101 | */ 102 | public static void overScrollBy(final PullToRefreshBase view, final int deltaX, final int scrollX, 103 | final int deltaY, final int scrollY, final int scrollRange, final int fuzzyThreshold, 104 | final float scaleFactor, final boolean isTouchEvent) { 105 | 106 | final int deltaValue, currentScrollValue, scrollValue; 107 | switch (view.getPullToRefreshScrollDirection()) { 108 | case HORIZONTAL: 109 | deltaValue = deltaX; 110 | scrollValue = scrollX; 111 | currentScrollValue = view.getScrollX(); 112 | break; 113 | case VERTICAL: 114 | default: 115 | deltaValue = deltaY; 116 | scrollValue = scrollY; 117 | currentScrollValue = view.getScrollY(); 118 | break; 119 | } 120 | 121 | // Check that OverScroll is enabled and that we're not currently 122 | // refreshing. 123 | if (view.isPullToRefreshOverScrollEnabled() && !view.isRefreshing()) { 124 | final Mode mode = view.getMode(); 125 | 126 | // Check that Pull-to-Refresh is enabled, and the event isn't from 127 | // touch 128 | if (mode.permitsPullToRefresh() && !isTouchEvent && deltaValue != 0) { 129 | final int newScrollValue = (deltaValue + scrollValue); 130 | 131 | if (PullToRefreshBase.DEBUG) { 132 | Log.d(LOG_TAG, "OverScroll. DeltaX: " + deltaX + ", ScrollX: " + scrollX + ", DeltaY: " + deltaY 133 | + ", ScrollY: " + scrollY + ", NewY: " + newScrollValue + ", ScrollRange: " + scrollRange 134 | + ", CurrentScroll: " + currentScrollValue); 135 | } 136 | 137 | if (newScrollValue < (0 - fuzzyThreshold)) { 138 | // Check the mode supports the overscroll direction, and 139 | // then move scroll 140 | if (mode.showHeaderLoadingLayout()) { 141 | // If we're currently at zero, we're about to start 142 | // overscrolling, so change the state 143 | if (currentScrollValue == 0) { 144 | view.setState(State.OVERSCROLLING); 145 | } 146 | 147 | view.setHeaderScroll((int) (scaleFactor * (currentScrollValue + newScrollValue))); 148 | } 149 | } else if (newScrollValue > (scrollRange + fuzzyThreshold)) { 150 | // Check the mode supports the overscroll direction, and 151 | // then move scroll 152 | if (mode.showFooterLoadingLayout()) { 153 | // If we're currently at zero, we're about to start 154 | // overscrolling, so change the state 155 | if (currentScrollValue == 0) { 156 | view.setState(State.OVERSCROLLING); 157 | } 158 | 159 | view.setHeaderScroll((int) (scaleFactor * (currentScrollValue + newScrollValue - scrollRange))); 160 | } 161 | } else if (Math.abs(newScrollValue) <= fuzzyThreshold 162 | || Math.abs(newScrollValue - scrollRange) <= fuzzyThreshold) { 163 | // Means we've stopped overscrolling, so scroll back to 0 164 | view.setState(State.RESET); 165 | } 166 | } else if (isTouchEvent && State.OVERSCROLLING == view.getState()) { 167 | // This condition means that we were overscrolling from a fling, 168 | // but the user has touched the View and is now overscrolling 169 | // from touch instead. We need to just reset. 170 | view.setState(State.RESET); 171 | } 172 | } 173 | } 174 | 175 | static boolean isAndroidOverScrollEnabled(View view) { 176 | return view.getOverScrollMode() != View.OVER_SCROLL_NEVER; 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/PullToRefreshExpandableListView.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library; 17 | 18 | import android.annotation.TargetApi; 19 | import android.content.Context; 20 | import android.os.Build.VERSION; 21 | import android.os.Build.VERSION_CODES; 22 | import android.util.AttributeSet; 23 | import android.view.View; 24 | import android.widget.ExpandableListView; 25 | 26 | import com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor; 27 | 28 | public class PullToRefreshExpandableListView extends PullToRefreshAdapterViewBase { 29 | 30 | public PullToRefreshExpandableListView(Context context) { 31 | super(context); 32 | } 33 | 34 | public PullToRefreshExpandableListView(Context context, AttributeSet attrs) { 35 | super(context, attrs); 36 | } 37 | 38 | public PullToRefreshExpandableListView(Context context, Mode mode) { 39 | super(context, mode); 40 | } 41 | 42 | public PullToRefreshExpandableListView(Context context, Mode mode, AnimationStyle style) { 43 | super(context, mode, style); 44 | } 45 | 46 | @Override 47 | public final Orientation getPullToRefreshScrollDirection() { 48 | return Orientation.VERTICAL; 49 | } 50 | 51 | @Override 52 | protected ExpandableListView createRefreshableView(Context context, AttributeSet attrs) { 53 | final ExpandableListView lv; 54 | if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { 55 | lv = new InternalExpandableListViewSDK9(context, attrs); 56 | } else { 57 | lv = new InternalExpandableListView(context, attrs); 58 | } 59 | 60 | // Set it to this so it can be used in ListActivity/ListFragment 61 | lv.setId(android.R.id.list); 62 | return lv; 63 | } 64 | 65 | class InternalExpandableListView extends ExpandableListView implements EmptyViewMethodAccessor { 66 | 67 | public InternalExpandableListView(Context context, AttributeSet attrs) { 68 | super(context, attrs); 69 | } 70 | 71 | @Override 72 | public void setEmptyView(View emptyView) { 73 | PullToRefreshExpandableListView.this.setEmptyView(emptyView); 74 | } 75 | 76 | @Override 77 | public void setEmptyViewInternal(View emptyView) { 78 | super.setEmptyView(emptyView); 79 | } 80 | } 81 | 82 | @TargetApi(9) 83 | final class InternalExpandableListViewSDK9 extends InternalExpandableListView { 84 | 85 | public InternalExpandableListViewSDK9(Context context, AttributeSet attrs) { 86 | super(context, attrs); 87 | } 88 | 89 | @Override 90 | protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, 91 | int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { 92 | 93 | final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, 94 | scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); 95 | 96 | // Does all of the hard work... 97 | OverscrollHelper.overScrollBy(PullToRefreshExpandableListView.this, deltaX, scrollX, deltaY, scrollY, 98 | isTouchEvent); 99 | 100 | return returnValue; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/PullToRefreshGridView.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library; 17 | 18 | import android.annotation.TargetApi; 19 | import android.content.Context; 20 | import android.os.Build.VERSION; 21 | import android.os.Build.VERSION_CODES; 22 | import android.util.AttributeSet; 23 | import android.view.View; 24 | import android.widget.GridView; 25 | 26 | import com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor; 27 | 28 | public class PullToRefreshGridView extends PullToRefreshAdapterViewBase { 29 | 30 | public PullToRefreshGridView(Context context) { 31 | super(context); 32 | } 33 | 34 | public PullToRefreshGridView(Context context, AttributeSet attrs) { 35 | super(context, attrs); 36 | } 37 | 38 | public PullToRefreshGridView(Context context, Mode mode) { 39 | super(context, mode); 40 | } 41 | 42 | public PullToRefreshGridView(Context context, Mode mode, AnimationStyle style) { 43 | super(context, mode, style); 44 | } 45 | 46 | @Override 47 | public final Orientation getPullToRefreshScrollDirection() { 48 | return Orientation.VERTICAL; 49 | } 50 | 51 | @Override 52 | protected final GridView createRefreshableView(Context context, AttributeSet attrs) { 53 | final GridView gv; 54 | if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { 55 | gv = new InternalGridViewSDK9(context, attrs); 56 | } else { 57 | gv = new InternalGridView(context, attrs); 58 | } 59 | 60 | // Use Generated ID (from res/values/ids.xml) 61 | gv.setId(R.id.gridview); 62 | return gv; 63 | } 64 | 65 | class InternalGridView extends GridView implements EmptyViewMethodAccessor { 66 | 67 | public InternalGridView(Context context, AttributeSet attrs) { 68 | super(context, attrs); 69 | } 70 | 71 | @Override 72 | public void setEmptyView(View emptyView) { 73 | PullToRefreshGridView.this.setEmptyView(emptyView); 74 | } 75 | 76 | @Override 77 | public void setEmptyViewInternal(View emptyView) { 78 | super.setEmptyView(emptyView); 79 | } 80 | } 81 | 82 | @TargetApi(9) 83 | final class InternalGridViewSDK9 extends InternalGridView { 84 | 85 | public InternalGridViewSDK9(Context context, AttributeSet attrs) { 86 | super(context, attrs); 87 | } 88 | 89 | @Override 90 | protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, 91 | int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { 92 | 93 | final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, 94 | scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); 95 | 96 | // Does all of the hard work... 97 | OverscrollHelper.overScrollBy(PullToRefreshGridView.this, deltaX, scrollX, deltaY, scrollY, isTouchEvent); 98 | 99 | return returnValue; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/PullToRefreshHorizontalScrollView.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library; 17 | 18 | import android.annotation.TargetApi; 19 | import android.content.Context; 20 | import android.os.Build.VERSION; 21 | import android.os.Build.VERSION_CODES; 22 | import android.util.AttributeSet; 23 | import android.view.View; 24 | import android.widget.HorizontalScrollView; 25 | 26 | public class PullToRefreshHorizontalScrollView extends PullToRefreshBase { 27 | 28 | public PullToRefreshHorizontalScrollView(Context context) { 29 | super(context); 30 | } 31 | 32 | public PullToRefreshHorizontalScrollView(Context context, AttributeSet attrs) { 33 | super(context, attrs); 34 | } 35 | 36 | public PullToRefreshHorizontalScrollView(Context context, Mode mode) { 37 | super(context, mode); 38 | } 39 | 40 | public PullToRefreshHorizontalScrollView(Context context, Mode mode, AnimationStyle style) { 41 | super(context, mode, style); 42 | } 43 | 44 | @Override 45 | public final Orientation getPullToRefreshScrollDirection() { 46 | return Orientation.HORIZONTAL; 47 | } 48 | 49 | @Override 50 | protected HorizontalScrollView createRefreshableView(Context context, AttributeSet attrs) { 51 | HorizontalScrollView scrollView; 52 | 53 | if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { 54 | scrollView = new InternalHorizontalScrollViewSDK9(context, attrs); 55 | } else { 56 | scrollView = new HorizontalScrollView(context, attrs); 57 | } 58 | 59 | scrollView.setId(R.id.scrollview); 60 | return scrollView; 61 | } 62 | 63 | @Override 64 | protected boolean isReadyForPullStart() { 65 | return mRefreshableView.getScrollX() == 0; 66 | } 67 | 68 | @Override 69 | protected boolean isReadyForPullEnd() { 70 | View scrollViewChild = mRefreshableView.getChildAt(0); 71 | if (null != scrollViewChild) { 72 | return mRefreshableView.getScrollX() >= (scrollViewChild.getWidth() - getWidth()); 73 | } 74 | return false; 75 | } 76 | 77 | @TargetApi(9) 78 | final class InternalHorizontalScrollViewSDK9 extends HorizontalScrollView { 79 | 80 | public InternalHorizontalScrollViewSDK9(Context context, AttributeSet attrs) { 81 | super(context, attrs); 82 | } 83 | 84 | @Override 85 | protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, 86 | int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { 87 | 88 | final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, 89 | scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); 90 | 91 | // Does all of the hard work... 92 | OverscrollHelper.overScrollBy(PullToRefreshHorizontalScrollView.this, deltaX, scrollX, deltaY, scrollY, 93 | getScrollRange(), isTouchEvent); 94 | 95 | return returnValue; 96 | } 97 | 98 | /** 99 | * Taken from the AOSP ScrollView source 100 | */ 101 | private int getScrollRange() { 102 | int scrollRange = 0; 103 | if (getChildCount() > 0) { 104 | View child = getChildAt(0); 105 | scrollRange = Math.max(0, child.getWidth() - (getWidth() - getPaddingLeft() - getPaddingRight())); 106 | } 107 | return scrollRange; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/PullToRefreshListView.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library; 17 | 18 | import android.annotation.TargetApi; 19 | import android.content.Context; 20 | import android.content.res.TypedArray; 21 | import android.graphics.Canvas; 22 | import android.os.Build.VERSION; 23 | import android.os.Build.VERSION_CODES; 24 | import android.util.AttributeSet; 25 | import android.view.Gravity; 26 | import android.view.MotionEvent; 27 | import android.view.View; 28 | import android.widget.FrameLayout; 29 | import android.widget.ListAdapter; 30 | import android.widget.ListView; 31 | 32 | import com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor; 33 | import com.handmark.pulltorefresh.library.internal.LoadingLayout; 34 | 35 | public class PullToRefreshListView extends PullToRefreshAdapterViewBase { 36 | 37 | private LoadingLayout mHeaderLoadingView; 38 | private LoadingLayout mFooterLoadingView; 39 | 40 | private FrameLayout mLvFooterLoadingFrame; 41 | 42 | private boolean mListViewExtrasEnabled; 43 | 44 | public PullToRefreshListView(Context context) { 45 | super(context); 46 | } 47 | 48 | public PullToRefreshListView(Context context, AttributeSet attrs) { 49 | super(context, attrs); 50 | } 51 | 52 | public PullToRefreshListView(Context context, Mode mode) { 53 | super(context, mode); 54 | } 55 | 56 | public PullToRefreshListView(Context context, Mode mode, AnimationStyle style) { 57 | super(context, mode, style); 58 | } 59 | 60 | @Override 61 | public final Orientation getPullToRefreshScrollDirection() { 62 | return Orientation.VERTICAL; 63 | } 64 | 65 | @Override 66 | protected void onRefreshing(final boolean doScroll) { 67 | /** 68 | * If we're not showing the Refreshing view, or the list is empty, the 69 | * the header/footer views won't show so we use the normal method. 70 | */ 71 | ListAdapter adapter = mRefreshableView.getAdapter(); 72 | if (!mListViewExtrasEnabled || !getShowViewWhileRefreshing() || null == adapter || adapter.isEmpty()) { 73 | super.onRefreshing(doScroll); 74 | return; 75 | } 76 | 77 | super.onRefreshing(false); 78 | 79 | final LoadingLayout origLoadingView, listViewLoadingView, oppositeListViewLoadingView; 80 | final int selection, scrollToY; 81 | 82 | switch (getCurrentMode()) { 83 | case MANUAL_REFRESH_ONLY: 84 | case PULL_FROM_END: 85 | origLoadingView = getFooterLayout(); 86 | listViewLoadingView = mFooterLoadingView; 87 | oppositeListViewLoadingView = mHeaderLoadingView; 88 | selection = mRefreshableView.getCount() - 1; 89 | scrollToY = getScrollY() - getFooterSize(); 90 | break; 91 | case PULL_FROM_START: 92 | default: 93 | origLoadingView = getHeaderLayout(); 94 | listViewLoadingView = mHeaderLoadingView; 95 | oppositeListViewLoadingView = mFooterLoadingView; 96 | selection = 0; 97 | scrollToY = getScrollY() + getHeaderSize(); 98 | break; 99 | } 100 | 101 | // Hide our original Loading View 102 | origLoadingView.reset(); 103 | origLoadingView.hideAllViews(); 104 | 105 | // Make sure the opposite end is hidden too 106 | oppositeListViewLoadingView.setVisibility(View.GONE); 107 | 108 | // Show the ListView Loading View and set it to refresh. 109 | listViewLoadingView.setVisibility(View.VISIBLE); 110 | listViewLoadingView.refreshing(); 111 | 112 | if (doScroll) { 113 | // We need to disable the automatic visibility changes for now 114 | disableLoadingLayoutVisibilityChanges(); 115 | 116 | // We scroll slightly so that the ListView's header/footer is at the 117 | // same Y position as our normal header/footer 118 | setHeaderScroll(scrollToY); 119 | 120 | // Make sure the ListView is scrolled to show the loading 121 | // header/footer 122 | mRefreshableView.setSelection(selection); 123 | 124 | // Smooth scroll as normal 125 | smoothScrollTo(0); 126 | } 127 | } 128 | 129 | @Override 130 | protected void onReset() { 131 | /** 132 | * If the extras are not enabled, just call up to super and return. 133 | */ 134 | if (!mListViewExtrasEnabled) { 135 | super.onReset(); 136 | return; 137 | } 138 | 139 | final LoadingLayout originalLoadingLayout, listViewLoadingLayout; 140 | final int scrollToHeight, selection; 141 | final boolean scrollLvToEdge; 142 | 143 | switch (getCurrentMode()) { 144 | case MANUAL_REFRESH_ONLY: 145 | case PULL_FROM_END: 146 | originalLoadingLayout = getFooterLayout(); 147 | listViewLoadingLayout = mFooterLoadingView; 148 | selection = mRefreshableView.getCount() - 1; 149 | scrollToHeight = getFooterSize(); 150 | scrollLvToEdge = Math.abs(mRefreshableView.getLastVisiblePosition() - selection) <= 1; 151 | break; 152 | case PULL_FROM_START: 153 | default: 154 | originalLoadingLayout = getHeaderLayout(); 155 | listViewLoadingLayout = mHeaderLoadingView; 156 | scrollToHeight = -getHeaderSize(); 157 | selection = 0; 158 | scrollLvToEdge = Math.abs(mRefreshableView.getFirstVisiblePosition() - selection) <= 1; 159 | break; 160 | } 161 | 162 | // If the ListView header loading layout is showing, then we need to 163 | // flip so that the original one is showing instead 164 | if (listViewLoadingLayout.getVisibility() == View.VISIBLE) { 165 | 166 | // Set our Original View to Visible 167 | originalLoadingLayout.showInvisibleViews(); 168 | 169 | // Hide the ListView Header/Footer 170 | listViewLoadingLayout.setVisibility(View.GONE); 171 | 172 | /** 173 | * Scroll so the View is at the same Y as the ListView 174 | * header/footer, but only scroll if: we've pulled to refresh, it's 175 | * positioned correctly 176 | */ 177 | if (scrollLvToEdge && getState() != State.MANUAL_REFRESHING) { 178 | mRefreshableView.setSelection(selection); 179 | setHeaderScroll(scrollToHeight); 180 | } 181 | } 182 | 183 | // Finally, call up to super 184 | super.onReset(); 185 | } 186 | 187 | @Override 188 | protected LoadingLayoutProxy createLoadingLayoutProxy(final boolean includeStart, final boolean includeEnd) { 189 | LoadingLayoutProxy proxy = super.createLoadingLayoutProxy(includeStart, includeEnd); 190 | 191 | if (mListViewExtrasEnabled) { 192 | final Mode mode = getMode(); 193 | 194 | if (includeStart && mode.showHeaderLoadingLayout()) { 195 | proxy.addLayout(mHeaderLoadingView); 196 | } 197 | if (includeEnd && mode.showFooterLoadingLayout()) { 198 | proxy.addLayout(mFooterLoadingView); 199 | } 200 | } 201 | 202 | return proxy; 203 | } 204 | 205 | protected ListView createListView(Context context, AttributeSet attrs) { 206 | final ListView lv; 207 | if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { 208 | lv = new InternalListViewSDK9(context, attrs); 209 | } else { 210 | lv = new InternalListView(context, attrs); 211 | } 212 | return lv; 213 | } 214 | 215 | @Override 216 | protected ListView createRefreshableView(Context context, AttributeSet attrs) { 217 | ListView lv = createListView(context, attrs); 218 | 219 | // Set it to this so it can be used in ListActivity/ListFragment 220 | lv.setId(android.R.id.list); 221 | return lv; 222 | } 223 | 224 | @Override 225 | protected void handleStyledAttributes(TypedArray a) { 226 | super.handleStyledAttributes(a); 227 | 228 | mListViewExtrasEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrListViewExtrasEnabled, true); 229 | 230 | if (mListViewExtrasEnabled) { 231 | final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 232 | FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL); 233 | 234 | // Create Loading Views ready for use later 235 | FrameLayout frame = new FrameLayout(getContext()); 236 | mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a); 237 | mHeaderLoadingView.setVisibility(View.GONE); 238 | frame.addView(mHeaderLoadingView, lp); 239 | mRefreshableView.addHeaderView(frame, null, false); 240 | 241 | mLvFooterLoadingFrame = new FrameLayout(getContext()); 242 | mFooterLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_END, a); 243 | mFooterLoadingView.setVisibility(View.GONE); 244 | mLvFooterLoadingFrame.addView(mFooterLoadingView, lp); 245 | 246 | /** 247 | * If the value for Scrolling While Refreshing hasn't been 248 | * explicitly set via XML, enable Scrolling While Refreshing. 249 | */ 250 | if (!a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) { 251 | setScrollingWhileRefreshingEnabled(true); 252 | } 253 | } 254 | } 255 | 256 | @TargetApi(9) 257 | final class InternalListViewSDK9 extends InternalListView { 258 | 259 | public InternalListViewSDK9(Context context, AttributeSet attrs) { 260 | super(context, attrs); 261 | } 262 | 263 | @Override 264 | protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, 265 | int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { 266 | 267 | final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, 268 | scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); 269 | 270 | // Does all of the hard work... 271 | OverscrollHelper.overScrollBy(PullToRefreshListView.this, deltaX, scrollX, deltaY, scrollY, isTouchEvent); 272 | 273 | return returnValue; 274 | } 275 | } 276 | 277 | protected class InternalListView extends ListView implements EmptyViewMethodAccessor { 278 | 279 | private boolean mAddedLvFooter = false; 280 | 281 | public InternalListView(Context context, AttributeSet attrs) { 282 | super(context, attrs); 283 | } 284 | 285 | @Override 286 | protected void dispatchDraw(Canvas canvas) { 287 | /** 288 | * This is a bit hacky, but Samsung's ListView has got a bug in it 289 | * when using Header/Footer Views and the list is empty. This masks 290 | * the issue so that it doesn't cause an FC. See Issue #66. 291 | */ 292 | try { 293 | super.dispatchDraw(canvas); 294 | } catch (IndexOutOfBoundsException e) { 295 | e.printStackTrace(); 296 | } 297 | } 298 | 299 | @Override 300 | public boolean dispatchTouchEvent(MotionEvent ev) { 301 | /** 302 | * This is a bit hacky, but Samsung's ListView has got a bug in it 303 | * when using Header/Footer Views and the list is empty. This masks 304 | * the issue so that it doesn't cause an FC. See Issue #66. 305 | */ 306 | try { 307 | return super.dispatchTouchEvent(ev); 308 | } catch (IndexOutOfBoundsException e) { 309 | e.printStackTrace(); 310 | return false; 311 | } 312 | } 313 | 314 | @Override 315 | public void setAdapter(ListAdapter adapter) { 316 | // Add the Footer View at the last possible moment 317 | if (null != mLvFooterLoadingFrame && !mAddedLvFooter) { 318 | addFooterView(mLvFooterLoadingFrame, null, false); 319 | mAddedLvFooter = true; 320 | } 321 | 322 | super.setAdapter(adapter); 323 | } 324 | 325 | @Override 326 | public void setEmptyView(View emptyView) { 327 | PullToRefreshListView.this.setEmptyView(emptyView); 328 | } 329 | 330 | @Override 331 | public void setEmptyViewInternal(View emptyView) { 332 | super.setEmptyView(emptyView); 333 | } 334 | 335 | } 336 | 337 | } 338 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/PullToRefreshRecyclerView.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2014 Dean Ding. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library; 17 | 18 | import android.content.Context; 19 | import android.support.v7.widget.RecyclerView; 20 | import android.util.AttributeSet; 21 | /** 22 | * 23 | * Support RecyclerView 24 | * 25 | * @author Dean.Ding 26 | * 27 | */ 28 | public class PullToRefreshRecyclerView extends PullToRefreshBase { 29 | 30 | public PullToRefreshRecyclerView(Context context) { 31 | super(context); 32 | } 33 | 34 | public PullToRefreshRecyclerView(Context context, AttributeSet attrs) { 35 | super(context, attrs); 36 | } 37 | 38 | public PullToRefreshRecyclerView(Context context, Mode mode) { 39 | super(context, mode); 40 | } 41 | 42 | public PullToRefreshRecyclerView(Context context, Mode mode, AnimationStyle style) { 43 | super(context, mode, style); 44 | } 45 | 46 | @Override 47 | public final Orientation getPullToRefreshScrollDirection() { 48 | return Orientation.VERTICAL; 49 | } 50 | 51 | @Override 52 | protected RecyclerView createRefreshableView(Context context, AttributeSet attrs) { 53 | RecyclerView recyclerView; 54 | recyclerView = new RecyclerView(context, attrs); 55 | recyclerView.setId(R.id.recyclerview); 56 | return recyclerView; 57 | } 58 | 59 | @Override 60 | protected boolean isReadyForPullStart() { 61 | if (mRefreshableView.getChildCount() <= 0) 62 | return true; 63 | int firstVisiblePosition = mRefreshableView.getChildPosition(mRefreshableView.getChildAt(0)); 64 | if (firstVisiblePosition == 0) 65 | return mRefreshableView.getChildAt(0).getTop() == mRefreshableView.getPaddingTop(); 66 | else 67 | return false; 68 | 69 | } 70 | 71 | @Override 72 | protected boolean isReadyForPullEnd() { 73 | int lastVisiblePosition = mRefreshableView.getChildPosition(mRefreshableView.getChildAt(mRefreshableView.getChildCount() -1)); 74 | if (lastVisiblePosition >= mRefreshableView.getAdapter().getItemCount()-1) { 75 | return mRefreshableView.getChildAt(mRefreshableView.getChildCount() - 1).getBottom() <= mRefreshableView.getBottom(); 76 | } 77 | return false; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/PullToRefreshScrollView.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library; 17 | 18 | import android.annotation.TargetApi; 19 | import android.content.Context; 20 | import android.os.Build.VERSION; 21 | import android.os.Build.VERSION_CODES; 22 | import android.util.AttributeSet; 23 | import android.view.View; 24 | import android.widget.ScrollView; 25 | 26 | public class PullToRefreshScrollView extends PullToRefreshBase { 27 | 28 | public PullToRefreshScrollView(Context context) { 29 | super(context); 30 | } 31 | 32 | public PullToRefreshScrollView(Context context, AttributeSet attrs) { 33 | super(context, attrs); 34 | } 35 | 36 | public PullToRefreshScrollView(Context context, Mode mode) { 37 | super(context, mode); 38 | } 39 | 40 | public PullToRefreshScrollView(Context context, Mode mode, AnimationStyle style) { 41 | super(context, mode, style); 42 | } 43 | 44 | @Override 45 | public final Orientation getPullToRefreshScrollDirection() { 46 | return Orientation.VERTICAL; 47 | } 48 | 49 | @Override 50 | protected ScrollView createRefreshableView(Context context, AttributeSet attrs) { 51 | ScrollView scrollView; 52 | if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { 53 | scrollView = new InternalScrollViewSDK9(context, attrs); 54 | } else { 55 | scrollView = new ScrollView(context, attrs); 56 | } 57 | 58 | scrollView.setId(R.id.scrollview); 59 | return scrollView; 60 | } 61 | 62 | @Override 63 | protected boolean isReadyForPullStart() { 64 | return mRefreshableView.getScrollY() == 0; 65 | } 66 | 67 | @Override 68 | protected boolean isReadyForPullEnd() { 69 | View scrollViewChild = mRefreshableView.getChildAt(0); 70 | if (null != scrollViewChild) { 71 | return mRefreshableView.getScrollY() >= (scrollViewChild.getHeight() - getHeight()); 72 | } 73 | return false; 74 | } 75 | 76 | @TargetApi(9) 77 | final class InternalScrollViewSDK9 extends ScrollView { 78 | 79 | public InternalScrollViewSDK9(Context context, AttributeSet attrs) { 80 | super(context, attrs); 81 | } 82 | 83 | @Override 84 | protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, 85 | int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { 86 | 87 | final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, 88 | scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); 89 | 90 | // Does all of the hard work... 91 | OverscrollHelper.overScrollBy(PullToRefreshScrollView.this, deltaX, scrollX, deltaY, scrollY, 92 | getScrollRange(), isTouchEvent); 93 | 94 | return returnValue; 95 | } 96 | 97 | /** 98 | * Taken from the AOSP ScrollView source 99 | */ 100 | private int getScrollRange() { 101 | int scrollRange = 0; 102 | if (getChildCount() > 0) { 103 | View child = getChildAt(0); 104 | scrollRange = Math.max(0, child.getHeight() - (getHeight() - getPaddingBottom() - getPaddingTop())); 105 | } 106 | return scrollRange; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/PullToRefreshWebView.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library; 17 | 18 | import android.annotation.TargetApi; 19 | import android.content.Context; 20 | import android.os.Build.VERSION; 21 | import android.os.Build.VERSION_CODES; 22 | import android.os.Bundle; 23 | import android.util.AttributeSet; 24 | import android.util.FloatMath; 25 | import android.webkit.WebChromeClient; 26 | import android.webkit.WebView; 27 | 28 | public class PullToRefreshWebView extends PullToRefreshBase { 29 | 30 | private static final OnRefreshListener defaultOnRefreshListener = new OnRefreshListener() { 31 | 32 | @Override 33 | public void onRefresh(PullToRefreshBase refreshView) { 34 | refreshView.getRefreshableView().reload(); 35 | } 36 | 37 | }; 38 | 39 | private final WebChromeClient defaultWebChromeClient = new WebChromeClient() { 40 | 41 | @Override 42 | public void onProgressChanged(WebView view, int newProgress) { 43 | if (newProgress == 100) { 44 | onRefreshComplete(); 45 | } 46 | } 47 | 48 | }; 49 | 50 | public PullToRefreshWebView(Context context) { 51 | super(context); 52 | 53 | /** 54 | * Added so that by default, Pull-to-Refresh refreshes the page 55 | */ 56 | setOnRefreshListener(defaultOnRefreshListener); 57 | mRefreshableView.setWebChromeClient(defaultWebChromeClient); 58 | } 59 | 60 | public PullToRefreshWebView(Context context, AttributeSet attrs) { 61 | super(context, attrs); 62 | 63 | /** 64 | * Added so that by default, Pull-to-Refresh refreshes the page 65 | */ 66 | setOnRefreshListener(defaultOnRefreshListener); 67 | mRefreshableView.setWebChromeClient(defaultWebChromeClient); 68 | } 69 | 70 | public PullToRefreshWebView(Context context, Mode mode) { 71 | super(context, mode); 72 | 73 | /** 74 | * Added so that by default, Pull-to-Refresh refreshes the page 75 | */ 76 | setOnRefreshListener(defaultOnRefreshListener); 77 | mRefreshableView.setWebChromeClient(defaultWebChromeClient); 78 | } 79 | 80 | public PullToRefreshWebView(Context context, Mode mode, AnimationStyle style) { 81 | super(context, mode, style); 82 | 83 | /** 84 | * Added so that by default, Pull-to-Refresh refreshes the page 85 | */ 86 | setOnRefreshListener(defaultOnRefreshListener); 87 | mRefreshableView.setWebChromeClient(defaultWebChromeClient); 88 | } 89 | 90 | @Override 91 | public final Orientation getPullToRefreshScrollDirection() { 92 | return Orientation.VERTICAL; 93 | } 94 | 95 | @Override 96 | protected WebView createRefreshableView(Context context, AttributeSet attrs) { 97 | WebView webView; 98 | if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { 99 | webView = new InternalWebViewSDK9(context, attrs); 100 | } else { 101 | webView = new WebView(context, attrs); 102 | } 103 | 104 | webView.setId(R.id.webview); 105 | return webView; 106 | } 107 | 108 | @Override 109 | protected boolean isReadyForPullStart() { 110 | return mRefreshableView.getScrollY() == 0; 111 | } 112 | 113 | @Override 114 | protected boolean isReadyForPullEnd() { 115 | float exactContentHeight = FloatMath.floor(mRefreshableView.getContentHeight() * mRefreshableView.getScale()); 116 | return mRefreshableView.getScrollY() >= (exactContentHeight - mRefreshableView.getHeight()); 117 | } 118 | 119 | @Override 120 | protected void onPtrRestoreInstanceState(Bundle savedInstanceState) { 121 | super.onPtrRestoreInstanceState(savedInstanceState); 122 | mRefreshableView.restoreState(savedInstanceState); 123 | } 124 | 125 | @Override 126 | protected void onPtrSaveInstanceState(Bundle saveState) { 127 | super.onPtrSaveInstanceState(saveState); 128 | mRefreshableView.saveState(saveState); 129 | } 130 | 131 | @TargetApi(9) 132 | final class InternalWebViewSDK9 extends WebView { 133 | 134 | // WebView doesn't always scroll back to it's edge so we add some 135 | // fuzziness 136 | static final int OVERSCROLL_FUZZY_THRESHOLD = 2; 137 | 138 | // WebView seems quite reluctant to overscroll so we use the scale 139 | // factor to scale it's value 140 | static final float OVERSCROLL_SCALE_FACTOR = 1.5f; 141 | 142 | public InternalWebViewSDK9(Context context, AttributeSet attrs) { 143 | super(context, attrs); 144 | } 145 | 146 | @Override 147 | protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, 148 | int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { 149 | 150 | final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, 151 | scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); 152 | 153 | // Does all of the hard work... 154 | OverscrollHelper.overScrollBy(PullToRefreshWebView.this, deltaX, scrollX, deltaY, scrollY, 155 | getScrollRange(), OVERSCROLL_FUZZY_THRESHOLD, OVERSCROLL_SCALE_FACTOR, isTouchEvent); 156 | 157 | return returnValue; 158 | } 159 | 160 | private int getScrollRange() { 161 | return (int) Math.max(0, FloatMath.floor(mRefreshableView.getContentHeight() * mRefreshableView.getScale()) 162 | - (getHeight() - getPaddingBottom() - getPaddingTop())); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/extras/PullToRefreshWebView2.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library.extras; 17 | 18 | import java.util.concurrent.atomic.AtomicBoolean; 19 | 20 | import android.content.Context; 21 | import android.util.AttributeSet; 22 | import android.webkit.WebView; 23 | 24 | import com.handmark.pulltorefresh.library.PullToRefreshWebView; 25 | 26 | /** 27 | * An advanced version of {@link PullToRefreshWebView} which delegates the 28 | * triggering of the PullToRefresh gesture to the Javascript running within the 29 | * WebView. This means that you should only use this class if: 30 | *

31 | *

38 | *

39 | *

40 | * The way this call works is that when a PullToRefresh gesture is in action, 41 | * the following Javascript methods will be called: 42 | * isReadyForPullDown() and isReadyForPullUp(), it is 43 | * your job to calculate whether the view is in a state where a PullToRefresh 44 | * can happen, and return the result via the callback mechanism. An example can 45 | * be seen below: 46 | *

47 | * 48 | *

 49 |  * function isReadyForPullDown() {
 50 |  *   var result = ...  // Probably using the .scrollTop DOM attribute
 51 |  *   ptr.isReadyForPullDownResponse(result);
 52 |  * }
 53 |  * 
 54 |  * function isReadyForPullUp() {
 55 |  *   var result = ...  // Probably using the .scrollBottom DOM attribute
 56 |  *   ptr.isReadyForPullUpResponse(result);
 57 |  * }
 58 |  * 
59 | * 60 | * @author Chris Banes 61 | */ 62 | public class PullToRefreshWebView2 extends PullToRefreshWebView { 63 | 64 | static final String JS_INTERFACE_PKG = "ptr"; 65 | static final String DEF_JS_READY_PULL_DOWN_CALL = "javascript:isReadyForPullDown();"; 66 | static final String DEF_JS_READY_PULL_UP_CALL = "javascript:isReadyForPullUp();"; 67 | 68 | public PullToRefreshWebView2(Context context) { 69 | super(context); 70 | } 71 | 72 | public PullToRefreshWebView2(Context context, AttributeSet attrs) { 73 | super(context, attrs); 74 | } 75 | 76 | public PullToRefreshWebView2(Context context, Mode mode) { 77 | super(context, mode); 78 | } 79 | 80 | private JsValueCallback mJsCallback; 81 | private final AtomicBoolean mIsReadyForPullDown = new AtomicBoolean(false); 82 | private final AtomicBoolean mIsReadyForPullUp = new AtomicBoolean(false); 83 | 84 | @Override 85 | protected WebView createRefreshableView(Context context, AttributeSet attrs) { 86 | WebView webView = super.createRefreshableView(context, attrs); 87 | 88 | // Need to add JS Interface so we can get the response back 89 | mJsCallback = new JsValueCallback(); 90 | webView.addJavascriptInterface(mJsCallback, JS_INTERFACE_PKG); 91 | 92 | return webView; 93 | } 94 | 95 | @Override 96 | protected boolean isReadyForPullStart() { 97 | // Call Javascript... 98 | getRefreshableView().loadUrl(DEF_JS_READY_PULL_DOWN_CALL); 99 | 100 | // Response will be given to JsValueCallback, which will update 101 | // mIsReadyForPullDown 102 | 103 | return mIsReadyForPullDown.get(); 104 | } 105 | 106 | @Override 107 | protected boolean isReadyForPullEnd() { 108 | // Call Javascript... 109 | getRefreshableView().loadUrl(DEF_JS_READY_PULL_UP_CALL); 110 | 111 | // Response will be given to JsValueCallback, which will update 112 | // mIsReadyForPullUp 113 | 114 | return mIsReadyForPullUp.get(); 115 | } 116 | 117 | /** 118 | * Used for response from Javascript 119 | * 120 | * @author Chris Banes 121 | */ 122 | final class JsValueCallback { 123 | 124 | public void isReadyForPullUpResponse(boolean response) { 125 | mIsReadyForPullUp.set(response); 126 | } 127 | 128 | public void isReadyForPullDownResponse(boolean response) { 129 | mIsReadyForPullDown.set(response); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/extras/SoundPullEventListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library.extras; 17 | 18 | import java.util.HashMap; 19 | 20 | import android.content.Context; 21 | import android.media.MediaPlayer; 22 | import android.view.View; 23 | 24 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 25 | import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; 26 | import com.handmark.pulltorefresh.library.PullToRefreshBase.State; 27 | 28 | public class SoundPullEventListener implements PullToRefreshBase.OnPullEventListener { 29 | 30 | private final Context mContext; 31 | private final HashMap mSoundMap; 32 | 33 | private MediaPlayer mCurrentMediaPlayer; 34 | 35 | /** 36 | * Constructor 37 | * 38 | * @param context - Context 39 | */ 40 | public SoundPullEventListener(Context context) { 41 | mContext = context; 42 | mSoundMap = new HashMap(); 43 | } 44 | 45 | @Override 46 | public final void onPullEvent(PullToRefreshBase refreshView, State event, Mode direction) { 47 | Integer soundResIdObj = mSoundMap.get(event); 48 | if (null != soundResIdObj) { 49 | playSound(soundResIdObj.intValue()); 50 | } 51 | } 52 | 53 | /** 54 | * Set the Sounds to be played when a Pull Event happens. You specify which 55 | * sound plays for which events by calling this method multiple times for 56 | * each event. 57 | *

58 | * If you've already set a sound for a certain event, and add another sound 59 | * for that event, only the new sound will be played. 60 | * 61 | * @param event - The event for which the sound will be played. 62 | * @param resId - Resource Id of the sound file to be played (e.g. 63 | * R.raw.pull_sound) 64 | */ 65 | public void addSoundEvent(State event, int resId) { 66 | mSoundMap.put(event, resId); 67 | } 68 | 69 | /** 70 | * Clears all of the previously set sounds and events. 71 | */ 72 | public void clearSounds() { 73 | mSoundMap.clear(); 74 | } 75 | 76 | /** 77 | * Gets the current (or last) MediaPlayer instance. 78 | */ 79 | public MediaPlayer getCurrentMediaPlayer() { 80 | return mCurrentMediaPlayer; 81 | } 82 | 83 | private void playSound(int resId) { 84 | // Stop current player, if there's one playing 85 | if (null != mCurrentMediaPlayer) { 86 | mCurrentMediaPlayer.stop(); 87 | mCurrentMediaPlayer.release(); 88 | } 89 | 90 | mCurrentMediaPlayer = MediaPlayer.create(mContext, resId); 91 | if (null != mCurrentMediaPlayer) { 92 | mCurrentMediaPlayer.start(); 93 | } 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/internal/EmptyViewMethodAccessor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library.internal; 17 | 18 | import android.view.View; 19 | 20 | /** 21 | * Interface that allows PullToRefreshBase to hijack the call to 22 | * AdapterView.setEmptyView() 23 | * 24 | * @author chris 25 | */ 26 | public interface EmptyViewMethodAccessor { 27 | 28 | /** 29 | * Calls upto AdapterView.setEmptyView() 30 | * 31 | * @param emptyView - to set as Empty View 32 | */ 33 | public void setEmptyViewInternal(View emptyView); 34 | 35 | /** 36 | * Should call PullToRefreshBase.setEmptyView() which will then 37 | * automatically call through to setEmptyViewInternal() 38 | * 39 | * @param emptyView - to set as Empty View 40 | */ 41 | public void setEmptyView(View emptyView); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/internal/FlipLoadingLayout.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library.internal; 17 | 18 | import android.annotation.SuppressLint; 19 | import android.content.Context; 20 | import android.content.res.TypedArray; 21 | import android.graphics.Matrix; 22 | import android.graphics.drawable.Drawable; 23 | import android.view.View; 24 | import android.view.ViewGroup; 25 | import android.view.animation.Animation; 26 | import android.view.animation.RotateAnimation; 27 | import android.widget.ImageView.ScaleType; 28 | 29 | import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; 30 | import com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation; 31 | import com.handmark.pulltorefresh.library.R; 32 | 33 | @SuppressLint("ViewConstructor") 34 | public class FlipLoadingLayout extends LoadingLayout { 35 | 36 | static final int FLIP_ANIMATION_DURATION = 150; 37 | 38 | private final Animation mRotateAnimation, mResetRotateAnimation; 39 | 40 | public FlipLoadingLayout(Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs) { 41 | super(context, mode, scrollDirection, attrs); 42 | 43 | final int rotateAngle = mode == Mode.PULL_FROM_START ? -180 : 180; 44 | 45 | mRotateAnimation = new RotateAnimation(0, rotateAngle, Animation.RELATIVE_TO_SELF, 0.5f, 46 | Animation.RELATIVE_TO_SELF, 0.5f); 47 | mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR); 48 | mRotateAnimation.setDuration(FLIP_ANIMATION_DURATION); 49 | mRotateAnimation.setFillAfter(true); 50 | 51 | mResetRotateAnimation = new RotateAnimation(rotateAngle, 0, Animation.RELATIVE_TO_SELF, 0.5f, 52 | Animation.RELATIVE_TO_SELF, 0.5f); 53 | mResetRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR); 54 | mResetRotateAnimation.setDuration(FLIP_ANIMATION_DURATION); 55 | mResetRotateAnimation.setFillAfter(true); 56 | } 57 | 58 | @Override 59 | protected void onLoadingDrawableSet(Drawable imageDrawable) { 60 | if (null != imageDrawable) { 61 | final int dHeight = imageDrawable.getIntrinsicHeight(); 62 | final int dWidth = imageDrawable.getIntrinsicWidth(); 63 | 64 | /** 65 | * We need to set the width/height of the ImageView so that it is 66 | * square with each side the size of the largest drawable dimension. 67 | * This is so that it doesn't clip when rotated. 68 | */ 69 | ViewGroup.LayoutParams lp = mHeaderImage.getLayoutParams(); 70 | lp.width = lp.height = Math.max(dHeight, dWidth); 71 | mHeaderImage.requestLayout(); 72 | 73 | /** 74 | * We now rotate the Drawable so that is at the correct rotation, 75 | * and is centered. 76 | */ 77 | mHeaderImage.setScaleType(ScaleType.MATRIX); 78 | Matrix matrix = new Matrix(); 79 | matrix.postTranslate((lp.width - dWidth) / 2f, (lp.height - dHeight) / 2f); 80 | matrix.postRotate(getDrawableRotationAngle(), lp.width / 2f, lp.height / 2f); 81 | mHeaderImage.setImageMatrix(matrix); 82 | } 83 | } 84 | 85 | @Override 86 | protected void onPullImpl(float scaleOfLayout) { 87 | // NO-OP 88 | } 89 | 90 | @Override 91 | protected void pullToRefreshImpl() { 92 | // Only start reset Animation, we've previously show the rotate anim 93 | if (mRotateAnimation == mHeaderImage.getAnimation()) { 94 | mHeaderImage.startAnimation(mResetRotateAnimation); 95 | } 96 | } 97 | 98 | @Override 99 | protected void refreshingImpl() { 100 | mHeaderImage.clearAnimation(); 101 | mHeaderImage.setVisibility(View.INVISIBLE); 102 | mHeaderProgress.setVisibility(View.VISIBLE); 103 | } 104 | 105 | @Override 106 | protected void releaseToRefreshImpl() { 107 | mHeaderImage.startAnimation(mRotateAnimation); 108 | } 109 | 110 | @Override 111 | protected void resetImpl() { 112 | mHeaderImage.clearAnimation(); 113 | mHeaderProgress.setVisibility(View.GONE); 114 | mHeaderImage.setVisibility(View.VISIBLE); 115 | } 116 | 117 | @Override 118 | protected int getDefaultDrawableResId() { 119 | return R.drawable.default_ptr_flip; 120 | } 121 | 122 | private float getDrawableRotationAngle() { 123 | float angle = 0f; 124 | switch (mMode) { 125 | case PULL_FROM_END: 126 | if (mScrollDirection == Orientation.HORIZONTAL) { 127 | angle = 90f; 128 | } else { 129 | angle = 180f; 130 | } 131 | break; 132 | 133 | case PULL_FROM_START: 134 | if (mScrollDirection == Orientation.HORIZONTAL) { 135 | angle = 270f; 136 | } 137 | break; 138 | 139 | default: 140 | break; 141 | } 142 | 143 | return angle; 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/internal/IndicatorLayout.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library.internal; 17 | 18 | import android.annotation.SuppressLint; 19 | import android.content.Context; 20 | import android.graphics.Matrix; 21 | import android.graphics.drawable.Drawable; 22 | import android.view.View; 23 | import android.view.animation.Animation; 24 | import android.view.animation.Animation.AnimationListener; 25 | import android.view.animation.AnimationUtils; 26 | import android.view.animation.Interpolator; 27 | import android.view.animation.LinearInterpolator; 28 | import android.view.animation.RotateAnimation; 29 | import android.widget.FrameLayout; 30 | import android.widget.ImageView; 31 | import android.widget.ImageView.ScaleType; 32 | 33 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 34 | import com.handmark.pulltorefresh.library.R; 35 | 36 | @SuppressLint("ViewConstructor") 37 | public class IndicatorLayout extends FrameLayout implements AnimationListener { 38 | 39 | static final int DEFAULT_ROTATION_ANIMATION_DURATION = 150; 40 | 41 | private Animation mInAnim, mOutAnim; 42 | private ImageView mArrowImageView; 43 | 44 | private final Animation mRotateAnimation, mResetRotateAnimation; 45 | 46 | public IndicatorLayout(Context context, PullToRefreshBase.Mode mode) { 47 | super(context); 48 | mArrowImageView = new ImageView(context); 49 | 50 | Drawable arrowD = getResources().getDrawable(R.drawable.indicator_arrow); 51 | mArrowImageView.setImageDrawable(arrowD); 52 | 53 | final int padding = getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding); 54 | mArrowImageView.setPadding(padding, padding, padding, padding); 55 | addView(mArrowImageView); 56 | 57 | int inAnimResId, outAnimResId; 58 | switch (mode) { 59 | case PULL_FROM_END: 60 | inAnimResId = R.anim.slide_in_from_bottom; 61 | outAnimResId = R.anim.slide_out_to_bottom; 62 | setBackgroundResource(R.drawable.indicator_bg_bottom); 63 | 64 | // Rotate Arrow so it's pointing the correct way 65 | mArrowImageView.setScaleType(ScaleType.MATRIX); 66 | Matrix matrix = new Matrix(); 67 | matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f); 68 | mArrowImageView.setImageMatrix(matrix); 69 | break; 70 | default: 71 | case PULL_FROM_START: 72 | inAnimResId = R.anim.slide_in_from_top; 73 | outAnimResId = R.anim.slide_out_to_top; 74 | setBackgroundResource(R.drawable.indicator_bg_top); 75 | break; 76 | } 77 | 78 | mInAnim = AnimationUtils.loadAnimation(context, inAnimResId); 79 | mInAnim.setAnimationListener(this); 80 | 81 | mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId); 82 | mOutAnim.setAnimationListener(this); 83 | 84 | final Interpolator interpolator = new LinearInterpolator(); 85 | mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 86 | 0.5f); 87 | mRotateAnimation.setInterpolator(interpolator); 88 | mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); 89 | mRotateAnimation.setFillAfter(true); 90 | 91 | mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, 92 | Animation.RELATIVE_TO_SELF, 0.5f); 93 | mResetRotateAnimation.setInterpolator(interpolator); 94 | mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); 95 | mResetRotateAnimation.setFillAfter(true); 96 | 97 | } 98 | 99 | public final boolean isVisible() { 100 | Animation currentAnim = getAnimation(); 101 | if (null != currentAnim) { 102 | return mInAnim == currentAnim; 103 | } 104 | 105 | return getVisibility() == View.VISIBLE; 106 | } 107 | 108 | public void hide() { 109 | startAnimation(mOutAnim); 110 | } 111 | 112 | public void show() { 113 | mArrowImageView.clearAnimation(); 114 | startAnimation(mInAnim); 115 | } 116 | 117 | @Override 118 | public void onAnimationEnd(Animation animation) { 119 | if (animation == mOutAnim) { 120 | mArrowImageView.clearAnimation(); 121 | setVisibility(View.GONE); 122 | } else if (animation == mInAnim) { 123 | setVisibility(View.VISIBLE); 124 | } 125 | 126 | clearAnimation(); 127 | } 128 | 129 | @Override 130 | public void onAnimationRepeat(Animation animation) { 131 | // NO-OP 132 | } 133 | 134 | @Override 135 | public void onAnimationStart(Animation animation) { 136 | setVisibility(View.VISIBLE); 137 | } 138 | 139 | public void releaseToRefresh() { 140 | mArrowImageView.startAnimation(mRotateAnimation); 141 | } 142 | 143 | public void pullToRefresh() { 144 | mArrowImageView.startAnimation(mResetRotateAnimation); 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/internal/RotateLoadingLayout.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library.internal; 17 | 18 | import android.content.Context; 19 | import android.content.res.TypedArray; 20 | import android.graphics.Matrix; 21 | import android.graphics.drawable.Drawable; 22 | import android.view.animation.Animation; 23 | import android.view.animation.RotateAnimation; 24 | import android.widget.ImageView.ScaleType; 25 | 26 | import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; 27 | import com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation; 28 | import com.handmark.pulltorefresh.library.R; 29 | 30 | public class RotateLoadingLayout extends LoadingLayout { 31 | 32 | static final int ROTATION_ANIMATION_DURATION = 1200; 33 | 34 | private final Animation mRotateAnimation; 35 | private final Matrix mHeaderImageMatrix; 36 | 37 | private float mRotationPivotX, mRotationPivotY; 38 | 39 | private final boolean mRotateDrawableWhilePulling; 40 | 41 | public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) { 42 | super(context, mode, scrollDirection, attrs); 43 | 44 | mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true); 45 | 46 | mHeaderImage.setScaleType(ScaleType.MATRIX); 47 | mHeaderImageMatrix = new Matrix(); 48 | mHeaderImage.setImageMatrix(mHeaderImageMatrix); 49 | 50 | mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 51 | 0.5f); 52 | mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR); 53 | mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION); 54 | mRotateAnimation.setRepeatCount(Animation.INFINITE); 55 | mRotateAnimation.setRepeatMode(Animation.RESTART); 56 | } 57 | 58 | public void onLoadingDrawableSet(Drawable imageDrawable) { 59 | if (null != imageDrawable) { 60 | mRotationPivotX = Math.round(imageDrawable.getIntrinsicWidth() / 2f); 61 | mRotationPivotY = Math.round(imageDrawable.getIntrinsicHeight() / 2f); 62 | } 63 | } 64 | 65 | protected void onPullImpl(float scaleOfLayout) { 66 | float angle; 67 | if (mRotateDrawableWhilePulling) { 68 | angle = scaleOfLayout * 90f; 69 | } else { 70 | angle = Math.max(0f, Math.min(180f, scaleOfLayout * 360f - 180f)); 71 | } 72 | 73 | mHeaderImageMatrix.setRotate(angle, mRotationPivotX, mRotationPivotY); 74 | mHeaderImage.setImageMatrix(mHeaderImageMatrix); 75 | } 76 | 77 | @Override 78 | protected void refreshingImpl() { 79 | mHeaderImage.startAnimation(mRotateAnimation); 80 | } 81 | 82 | @Override 83 | protected void resetImpl() { 84 | mHeaderImage.clearAnimation(); 85 | resetImageRotation(); 86 | } 87 | 88 | private void resetImageRotation() { 89 | if (null != mHeaderImageMatrix) { 90 | mHeaderImageMatrix.reset(); 91 | mHeaderImage.setImageMatrix(mHeaderImageMatrix); 92 | } 93 | } 94 | 95 | @Override 96 | protected void pullToRefreshImpl() { 97 | // NO-OP 98 | } 99 | 100 | @Override 101 | protected void releaseToRefreshImpl() { 102 | // NO-OP 103 | } 104 | 105 | @Override 106 | protected int getDefaultDrawableResId() { 107 | return R.drawable.default_ptr_rotate; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/internal/Utils.java: -------------------------------------------------------------------------------- 1 | package com.handmark.pulltorefresh.library.internal; 2 | 3 | import android.util.Log; 4 | 5 | public class Utils { 6 | 7 | static final String LOG_TAG = "PullToRefresh"; 8 | 9 | public static void warnDeprecation(String depreacted, String replacement) { 10 | Log.w(LOG_TAG, "You're using the deprecated " + depreacted + " attr, please switch over to " + replacement); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /library/src/com/handmark/pulltorefresh/library/internal/ViewCompat.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.library.internal; 17 | 18 | import android.annotation.TargetApi; 19 | import android.graphics.drawable.Drawable; 20 | import android.os.Build.VERSION; 21 | import android.os.Build.VERSION_CODES; 22 | import android.view.View; 23 | 24 | @SuppressWarnings("deprecation") 25 | public class ViewCompat { 26 | 27 | public static void postOnAnimation(View view, Runnable runnable) { 28 | if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { 29 | SDK16.postOnAnimation(view, runnable); 30 | } else { 31 | view.postDelayed(runnable, 16); 32 | } 33 | } 34 | 35 | public static void setBackground(View view, Drawable background) { 36 | if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { 37 | SDK16.setBackground(view, background); 38 | } else { 39 | view.setBackgroundDrawable(background); 40 | } 41 | } 42 | 43 | public static void setLayerType(View view, int layerType) { 44 | if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) { 45 | SDK11.setLayerType(view, layerType); 46 | } 47 | } 48 | 49 | @TargetApi(11) 50 | static class SDK11 { 51 | 52 | public static void setLayerType(View view, int layerType) { 53 | view.setLayerType(layerType, null); 54 | } 55 | } 56 | 57 | @TargetApi(16) 58 | static class SDK16 { 59 | 60 | public static void postOnAnimation(View view, Runnable runnable) { 61 | view.postOnAnimation(runnable); 62 | } 63 | 64 | public static void setBackground(View view, Drawable background) { 65 | view.setBackground(background); 66 | } 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.github.chrisbanes.pulltorefresh 5 | parent 6 | pom 7 | 2.1.2-SNAPSHOT 8 | Android-PullToRefresh Project 9 | Implementation of the Pull-to-Refresh UI Pattern for Android. 10 | https://github.com/chrisbanes/Android-PullToRefresh 11 | 12 | org.sonatype.oss 13 | oss-parent 14 | 7 15 | 16 | 17 | 18 | Apache License Version 2.0 19 | http://www.apache.org/licenses/LICENSE-2.0.txt 20 | repo 21 | 22 | 23 | 24 | https://github.com/chrisbanes/Android-PullToRefresh 25 | scm:git:git://github.com/chrisbanes/Android-PullToRefresh.git 26 | scm:git:git@github.com:chrisbanes/Android-PullToRefresh.git 27 | HEAD 28 | 29 | 30 | 31 | Chris Banes 32 | http://about.me/chrisbanes 33 | chrisbanes 34 | 35 | 36 | 37 | library 38 | sample 39 | extras 40 | 41 | 42 | 43 | UTF-8 44 | UTF-8 45 | 1.6 46 | 4.1.1.4 47 | 16 48 | 3.2.0 49 | 50 | 51 | 52 | 53 | com.google.android 54 | android 55 | ${android.version} 56 | provided 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.apache.maven.plugins 66 | maven-compiler-plugin 67 | 2.3.2 68 | 69 | ${java.version} 70 | ${java.version} 71 | 72 | 73 | 74 | org.apache.maven.plugins 75 | maven-release-plugin 76 | 2.3.2 77 | 78 | v@{project.version} 79 | 80 | 81 | 82 | com.jayway.maven.plugins.android.generation2 83 | android-maven-plugin 84 | ${android-maven.version} 85 | 86 | 87 | ${android.platform} 88 | 89 | true 90 | ${sourceCompatibility} 91 | ${sourceCompatibility} 92 | 93 | true 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-eclipse-plugin 98 | 2.8 99 | 100 | 101 | com.google.android:android 102 | 103 | bin 104 | 105 | com.android.ide.eclipse.adt.ANDROID_FRAMEWORK 106 | 107 | 108 | com.android.ide.eclipse.adt.AndroidNature 109 | 110 | 111 | com.android.ide.eclipse.adt.ResourceManagerBuilder 112 | com.android.ide.eclipse.adt.PreCompilerBuilder 113 | com.android.ide.eclipse.adt.ApkBuilder 114 | 115 | 116 | 117 | 118 | 119 | src 120 | 121 | 122 | -------------------------------------------------------------------------------- /sample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 31 | 32 | 35 | 36 | 39 | 40 | 43 | 44 | 47 | 48 | 51 | 52 | 55 | 56 | 59 | 60 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /sample/assets/ptr_webview2_sample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | PullToRefreshWebView2 Sample 4 | 5 | 16 | 17 | 18 | 19 | 20 |

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sollicitudin mauris varius lacus porttitor eget blandit massa facilisis. Nulla pellentesque odio sed purus fermentum vitae viverra orci faucibus. Sed ullamcorper condimentum vulputate. Curabitur sit amet convallis velit. Vestibulum posuere eleifend risus ac adipiscing. Nam pulvinar nulla a velit faucibus imperdiet. Praesent eget nisi ac justo blandit sagittis. Maecenas at leo nisi, nec varius nisl.

21 |

In hac habitasse platea dictumst. Morbi neque tortor, vestibulum sed viverra a, luctus vel lorem. Nunc turpis eros, varius eget commodo et, euismod at eros. Sed tincidunt mi purus, vel posuere dui. Vestibulum ante lectus, porta sed mattis bibendum, scelerisque cursus sapien. Cras ultrices imperdiet fermentum. Aenean nisi nulla, euismod non blandit ac, dictum quis libero. Morbi consectetur tempor mollis. Suspendisse eget nunc arcu, vel ullamcorper augue. Integer malesuada, diam nec faucibus mollis, nisl velit euismod enim, ac mattis justo neque sit amet mauris. Vivamus pretium imperdiet pharetra.

22 |

Integer sagittis augue sit amet lectus pulvinar sit amet commodo tortor mattis. Maecenas quis tellus eget ante eleifend sollicitudin non et nibh. Maecenas luctus euismod tristique. Fusce in odio nec diam blandit facilisis. Sed nec arcu eros. Vivamus quis tortor a metus tempus aliquam eget volutpat magna. Pellentesque id ultrices dolor. Sed blandit aliquet quam. Phasellus dapibus euismod vulputate. Aenean blandit, elit vitae vestibulum tincidunt, metus dui accumsan nulla, sit amet vehicula mauris lacus in est. Etiam dignissim pellentesque nulla vel malesuada. Cras vel lorem justo.

23 |

Sed condimentum nisl sit amet libero vestibulum hendrerit. Duis auctor tempus placerat. Proin velit ante, ornare nec dictum nec, hendrerit eu arcu. Etiam ut diam ornare quam venenatis pulvinar vitae vel leo. Vivamus consectetur, ante id interdum rhoncus, magna eros pulvinar lacus, a gravida nibh arcu vitae eros. Nulla scelerisque laoreet feugiat. Mauris sit amet gravida felis.

24 |

Nulla ac dolor sapien, vestibulum venenatis justo. Cras placerat velit vitae nibh pellentesque ultricies. Suspendisse adipiscing enim eu justo iaculis eu pretium urna fermentum. Duis porttitor nunc non nunc mattis vestibulum. Etiam elit tellus, feugiat in bibendum eget, adipiscing nec metus. Ut ut sem lacus, quis faucibus diam. Curabitur a nulla fermentum tortor dignissim posuere. Fusce faucibus ante ut sem imperdiet imperdiet eget vitae lorem. Etiam fringilla ornare ipsum, in sagittis quam ornare vitae. Nullam venenatis orci sit amet sapien adipiscing gravida. Proin turpis lectus, hendrerit vitae vehicula ut, auctor ac lectus. Pellentesque sollicitudin blandit ligula quis commodo. Mauris vulputate lectus in velit luctus aliquam. Quisque eget tincidunt elit. Quisque et augue quam, sed scelerisque eros.

25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /sample/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/libs/android-support-v4.jar -------------------------------------------------------------------------------- /sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.github.chrisbanes.pulltorefresh 6 | sample 7 | apk 8 | Android-PullToRefresh Sample 9 | 10 | 11 | com.github.chrisbanes.pulltorefresh 12 | parent 13 | 2.1.2-SNAPSHOT 14 | 15 | 16 | 17 | 18 | com.google.android 19 | android 20 | 21 | 22 | ${project.groupId} 23 | library 24 | apklib 25 | ${project.version} 26 | 27 | 28 | ${project.groupId} 29 | extra-listfragment 30 | apklib 31 | ${project.version} 32 | 33 | 34 | ${project.groupId} 35 | extra-viewpager 36 | apklib 37 | ${project.version} 38 | 39 | 40 | 41 | 42 | 43 | 44 | com.jayway.maven.plugins.android.generation2 45 | android-maven-plugin 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-eclipse-plugin 50 | 51 | 52 | com.google.android:android 53 | commons-logging:commons-logging 54 | xerces:xmlParserAPIs 55 | xpp3:xpp3 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /sample/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-16 12 | android.library.reference.1=../library 13 | android.library.reference.2=../extras/PullToRefreshListFragment 14 | android.library.reference.3=../extras/PullToRefreshViewPager 15 | -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/res/drawable-hdpi/android.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /sample/res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /sample/res/drawable-nodpi/wallpaper.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/res/drawable-nodpi/wallpaper.jpg -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/res/drawable-xhdpi/android.png -------------------------------------------------------------------------------- /sample/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/res/drawable/icon.png -------------------------------------------------------------------------------- /sample/res/layout/activity_ptr_expandable_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /sample/res/layout/activity_ptr_grid.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 21 | 22 | -------------------------------------------------------------------------------- /sample/res/layout/activity_ptr_horizontalscrollview.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 16 | 17 | 21 | 22 | 27 | 28 | 33 | 34 | 39 | 40 | 45 | 46 | 51 | 52 | 57 | 58 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /sample/res/layout/activity_ptr_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 21 | 22 | -------------------------------------------------------------------------------- /sample/res/layout/activity_ptr_list_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /sample/res/layout/activity_ptr_list_in_vp.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /sample/res/layout/activity_ptr_scrollview.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 16 | 17 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /sample/res/layout/activity_ptr_viewpager.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /sample/res/layout/activity_ptr_webview.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 15 | 16 | -------------------------------------------------------------------------------- /sample/res/layout/activity_ptr_webview2.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 15 | 16 | -------------------------------------------------------------------------------- /sample/res/layout/layout_listview_in_viewpager.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /sample/res/raw/pull_event.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/res/raw/pull_event.mp3 -------------------------------------------------------------------------------- /sample/res/raw/refreshing_sound.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/res/raw/refreshing_sound.mp3 -------------------------------------------------------------------------------- /sample/res/raw/reset_sound.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkmeteor/Android-PullToRefresh-RecyclerView-Extention/25ea1350ee8a4bba8ffd8654c3b54228d88e61a5/sample/res/raw/reset_sound.mp3 -------------------------------------------------------------------------------- /sample/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World, PullToRefreshActivity! 5 | pulltorefreshexample 6 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sollicitudin mauris varius lacus porttitor eget blandit massa facilisis. Nulla pellentesque odio sed purus fermentum vitae viverra orci faucibus. Sed ullamcorper condimentum vulputate. Curabitur sit amet convallis velit. Vestibulum posuere eleifend risus ac adipiscing. Nam pulvinar nulla a velit faucibus imperdiet. Praesent eget nisi ac justo blandit sagittis. Maecenas at leo nisi, nec varius nisl.\nIn hac habitasse platea dictumst. Morbi neque tortor, vestibulum sed viverra a, luctus vel lorem. Nunc turpis eros, varius eget commodo et, euismod at eros. Sed tincidunt mi purus, vel posuere dui. Vestibulum ante lectus, porta sed mattis bibendum, scelerisque cursus sapien. Cras ultrices imperdiet fermentum. Aenean nisi nulla, euismod non blandit ac, dictum quis libero. Morbi consectetur tempor mollis. Suspendisse eget nunc arcu, vel ullamcorper augue. Integer malesuada, diam nec faucibus mollis, nisl velit euismod enim, ac mattis justo neque sit amet mauris. Vivamus pretium imperdiet pharetra.\nInteger sagittis augue sit amet lectus pulvinar sit amet commodo tortor mattis. Maecenas quis tellus eget ante eleifend sollicitudin non et nibh. Maecenas luctus euismod tristique. Fusce in odio nec diam blandit facilisis. Sed nec arcu eros. Vivamus quis tortor a metus tempus aliquam eget volutpat magna. Pellentesque id ultrices dolor. Sed blandit aliquet quam. Phasellus dapibus euismod vulputate. Aenean blandit, elit vitae vestibulum tincidunt, metus dui accumsan nulla, sit amet vehicula mauris lacus in est. Etiam dignissim pellentesque nulla vel malesuada. Cras vel lorem justo.\nSed condimentum nisl sit amet libero vestibulum hendrerit. Duis auctor tempus placerat. Proin velit ante, ornare nec dictum nec, hendrerit eu arcu. Etiam ut diam ornare quam venenatis pulvinar vitae vel leo. Vivamus consectetur, ante id interdum rhoncus, magna eros pulvinar lacus, a gravida nibh arcu vitae eros. Nulla scelerisque laoreet feugiat. Mauris sit amet gravida felis.\nNulla ac dolor sapien, vestibulum venenatis justo. Cras placerat velit vitae nibh pellentesque ultricies. Suspendisse adipiscing enim eu justo iaculis eu pretium urna fermentum. Duis porttitor nunc non nunc mattis vestibulum. Etiam elit tellus, feugiat in bibendum eget, adipiscing nec metus. Ut ut sem lacus, quis faucibus diam. Curabitur a nulla fermentum tortor dignissim posuere. Fusce faucibus ante ut sem imperdiet imperdiet eget vitae lorem. Etiam fringilla ornare ipsum, in sagittis quam ornare vitae. Nullam venenatis orci sit amet sapien adipiscing gravida. Proin turpis lectus, hendrerit vitae vehicula ut, auctor ac lectus. Pellentesque sollicitudin blandit ligula quis commodo. Mauris vulputate lectus in velit luctus aliquam. Quisque eget tincidunt elit. Quisque et augue quam, sed scelerisque eros. 7 | 8 | -------------------------------------------------------------------------------- /sample/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/LauncherActivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.samples; 17 | 18 | import android.app.ListActivity; 19 | import android.content.Intent; 20 | import android.os.Bundle; 21 | import android.view.View; 22 | import android.widget.ArrayAdapter; 23 | import android.widget.ListView; 24 | 25 | public class LauncherActivity extends ListActivity { 26 | 27 | public static final String[] options = { "ListView", "ExpandableListView", "GridView", "WebView", "ScrollView", 28 | "Horizontal ScrollView", "ViewPager", "ListView Fragment", "WebView Advanced", "ListView in ViewPager" }; 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, options)); 34 | } 35 | 36 | @Override 37 | protected void onListItemClick(ListView l, View v, int position, long id) { 38 | Intent intent; 39 | 40 | switch (position) { 41 | default: 42 | case 0: 43 | intent = new Intent(this, PullToRefreshListActivity.class); 44 | break; 45 | case 1: 46 | intent = new Intent(this, PullToRefreshExpandableListActivity.class); 47 | break; 48 | case 2: 49 | intent = new Intent(this, PullToRefreshGridActivity.class); 50 | break; 51 | case 3: 52 | intent = new Intent(this, PullToRefreshWebViewActivity.class); 53 | break; 54 | case 4: 55 | intent = new Intent(this, PullToRefreshScrollViewActivity.class); 56 | break; 57 | case 5: 58 | intent = new Intent(this, PullToRefreshHorizontalScrollViewActivity.class); 59 | break; 60 | case 6: 61 | intent = new Intent(this, PullToRefreshViewPagerActivity.class); 62 | break; 63 | case 7: 64 | intent = new Intent(this, PullToRefreshListFragmentActivity.class); 65 | break; 66 | case 8: 67 | intent = new Intent(this, PullToRefreshWebView2Activity.class); 68 | break; 69 | case 9: 70 | intent = new Intent(this, PullToRefreshListInViewPagerActivity.class); 71 | break; 72 | } 73 | 74 | startActivity(intent); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/PullToRefreshExpandableListActivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.samples; 17 | 18 | import java.util.ArrayList; 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | import android.app.ExpandableListActivity; 24 | import android.os.AsyncTask; 25 | import android.os.Bundle; 26 | import android.widget.ExpandableListView; 27 | import android.widget.SimpleExpandableListAdapter; 28 | 29 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 30 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; 31 | import com.handmark.pulltorefresh.library.PullToRefreshExpandableListView; 32 | 33 | public final class PullToRefreshExpandableListActivity extends ExpandableListActivity { 34 | private static final String KEY = "key"; 35 | 36 | private List> groupData = new ArrayList>(); 37 | private List>> childData = new ArrayList>>(); 38 | 39 | private PullToRefreshExpandableListView mPullRefreshListView; 40 | private SimpleExpandableListAdapter mAdapter; 41 | 42 | /** Called when the activity is first created. */ 43 | @Override 44 | public void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | setContentView(R.layout.activity_ptr_expandable_list); 47 | 48 | mPullRefreshListView = (PullToRefreshExpandableListView) findViewById(R.id.pull_refresh_expandable_list); 49 | 50 | // Set a listener to be invoked when the list should be refreshed. 51 | mPullRefreshListView.setOnRefreshListener(new OnRefreshListener() { 52 | @Override 53 | public void onRefresh(PullToRefreshBase refreshView) { 54 | // Do work to refresh the list here. 55 | new GetDataTask().execute(); 56 | } 57 | }); 58 | 59 | for (String group : mGroupStrings) { 60 | Map groupMap1 = new HashMap(); 61 | groupData.add(groupMap1); 62 | groupMap1.put(KEY, group); 63 | 64 | List> childList = new ArrayList>(); 65 | for (String string : mChildStrings) { 66 | Map childMap = new HashMap(); 67 | childList.add(childMap); 68 | childMap.put(KEY, string); 69 | } 70 | childData.add(childList); 71 | } 72 | 73 | mAdapter = new SimpleExpandableListAdapter(this, groupData, android.R.layout.simple_expandable_list_item_1, 74 | new String[] { KEY }, new int[] { android.R.id.text1 }, childData, 75 | android.R.layout.simple_expandable_list_item_2, new String[] { KEY }, new int[] { android.R.id.text1 }); 76 | setListAdapter(mAdapter); 77 | } 78 | 79 | private class GetDataTask extends AsyncTask { 80 | 81 | @Override 82 | protected String[] doInBackground(Void... params) { 83 | // Simulates a background job. 84 | try { 85 | Thread.sleep(2000); 86 | } catch (InterruptedException e) { 87 | } 88 | return mChildStrings; 89 | } 90 | 91 | @Override 92 | protected void onPostExecute(String[] result) { 93 | Map newMap = new HashMap(); 94 | newMap.put(KEY, "Added after refresh..."); 95 | groupData.add(newMap); 96 | 97 | List> childList = new ArrayList>(); 98 | for (String string : mChildStrings) { 99 | Map childMap = new HashMap(); 100 | childMap.put(KEY, string); 101 | childList.add(childMap); 102 | } 103 | childData.add(childList); 104 | 105 | mAdapter.notifyDataSetChanged(); 106 | 107 | // Call onRefreshComplete when the list has been refreshed. 108 | mPullRefreshListView.onRefreshComplete(); 109 | 110 | super.onPostExecute(result); 111 | } 112 | } 113 | 114 | private String[] mChildStrings = { "Child One", "Child Two", "Child Three", "Child Four", "Child Five", "Child Six" }; 115 | 116 | private String[] mGroupStrings = { "Group One", "Group Two", "Group Three" }; 117 | } 118 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/PullToRefreshGridActivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.samples; 17 | 18 | import java.util.Arrays; 19 | import java.util.LinkedList; 20 | 21 | import android.app.Activity; 22 | import android.os.AsyncTask; 23 | import android.os.Bundle; 24 | import android.view.Gravity; 25 | import android.view.Menu; 26 | import android.view.MenuItem; 27 | import android.widget.ArrayAdapter; 28 | import android.widget.GridView; 29 | import android.widget.TextView; 30 | import android.widget.Toast; 31 | 32 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 33 | import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; 34 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2; 35 | import com.handmark.pulltorefresh.library.PullToRefreshGridView; 36 | 37 | public final class PullToRefreshGridActivity extends Activity { 38 | 39 | static final int MENU_SET_MODE = 0; 40 | 41 | private LinkedList mListItems; 42 | private PullToRefreshGridView mPullRefreshGridView; 43 | private GridView mGridView; 44 | private ArrayAdapter mAdapter; 45 | 46 | /** Called when the activity is first created. */ 47 | @Override 48 | public void onCreate(Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | setContentView(R.layout.activity_ptr_grid); 51 | 52 | mPullRefreshGridView = (PullToRefreshGridView) findViewById(R.id.pull_refresh_grid); 53 | mGridView = mPullRefreshGridView.getRefreshableView(); 54 | 55 | // Set a listener to be invoked when the list should be refreshed. 56 | mPullRefreshGridView.setOnRefreshListener(new OnRefreshListener2() { 57 | 58 | @Override 59 | public void onPullDownToRefresh(PullToRefreshBase refreshView) { 60 | Toast.makeText(PullToRefreshGridActivity.this, "Pull Down!", Toast.LENGTH_SHORT).show(); 61 | new GetDataTask().execute(); 62 | } 63 | 64 | @Override 65 | public void onPullUpToRefresh(PullToRefreshBase refreshView) { 66 | Toast.makeText(PullToRefreshGridActivity.this, "Pull Up!", Toast.LENGTH_SHORT).show(); 67 | new GetDataTask().execute(); 68 | } 69 | 70 | }); 71 | 72 | mListItems = new LinkedList(); 73 | 74 | TextView tv = new TextView(this); 75 | tv.setGravity(Gravity.CENTER); 76 | tv.setText("Empty View, Pull Down/Up to Add Items"); 77 | mPullRefreshGridView.setEmptyView(tv); 78 | 79 | mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mListItems); 80 | mGridView.setAdapter(mAdapter); 81 | } 82 | 83 | private class GetDataTask extends AsyncTask { 84 | 85 | @Override 86 | protected String[] doInBackground(Void... params) { 87 | // Simulates a background job. 88 | try { 89 | Thread.sleep(2000); 90 | } catch (InterruptedException e) { 91 | } 92 | return mStrings; 93 | } 94 | 95 | @Override 96 | protected void onPostExecute(String[] result) { 97 | mListItems.addFirst("Added after refresh..."); 98 | mListItems.addAll(Arrays.asList(result)); 99 | mAdapter.notifyDataSetChanged(); 100 | 101 | // Call onRefreshComplete when the list has been refreshed. 102 | mPullRefreshGridView.onRefreshComplete(); 103 | 104 | super.onPostExecute(result); 105 | } 106 | } 107 | 108 | @Override 109 | public boolean onCreateOptionsMenu(Menu menu) { 110 | menu.add(0, MENU_SET_MODE, 0, 111 | mPullRefreshGridView.getMode() == Mode.BOTH ? "Change to MODE_PULL_DOWN" 112 | : "Change to MODE_PULL_BOTH"); 113 | return super.onCreateOptionsMenu(menu); 114 | } 115 | 116 | @Override 117 | public boolean onPrepareOptionsMenu(Menu menu) { 118 | MenuItem setModeItem = menu.findItem(MENU_SET_MODE); 119 | setModeItem.setTitle(mPullRefreshGridView.getMode() == Mode.BOTH ? "Change to MODE_PULL_FROM_START" 120 | : "Change to MODE_PULL_BOTH"); 121 | 122 | return super.onPrepareOptionsMenu(menu); 123 | } 124 | 125 | @Override 126 | public boolean onOptionsItemSelected(MenuItem item) { 127 | switch (item.getItemId()) { 128 | case MENU_SET_MODE: 129 | mPullRefreshGridView 130 | .setMode(mPullRefreshGridView.getMode() == Mode.BOTH ? Mode.PULL_FROM_START 131 | : Mode.BOTH); 132 | break; 133 | } 134 | 135 | return super.onOptionsItemSelected(item); 136 | } 137 | 138 | private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", 139 | "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", 140 | "Allgauer Emmentaler" }; 141 | } 142 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/PullToRefreshHorizontalScrollViewActivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.samples; 17 | 18 | import android.app.Activity; 19 | import android.os.AsyncTask; 20 | import android.os.Bundle; 21 | import android.widget.HorizontalScrollView; 22 | 23 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 24 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; 25 | import com.handmark.pulltorefresh.library.PullToRefreshHorizontalScrollView; 26 | 27 | public final class PullToRefreshHorizontalScrollViewActivity extends Activity { 28 | 29 | PullToRefreshHorizontalScrollView mPullRefreshScrollView; 30 | HorizontalScrollView mScrollView; 31 | 32 | /** Called when the activity is first created. */ 33 | @Override 34 | public void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_ptr_horizontalscrollview); 37 | 38 | mPullRefreshScrollView = (PullToRefreshHorizontalScrollView) findViewById(R.id.pull_refresh_horizontalscrollview); 39 | mPullRefreshScrollView.setOnRefreshListener(new OnRefreshListener() { 40 | 41 | @Override 42 | public void onRefresh(PullToRefreshBase refreshView) { 43 | new GetDataTask().execute(); 44 | } 45 | }); 46 | 47 | mScrollView = mPullRefreshScrollView.getRefreshableView(); 48 | } 49 | 50 | private class GetDataTask extends AsyncTask { 51 | 52 | @Override 53 | protected String[] doInBackground(Void... params) { 54 | // Simulates a background job. 55 | try { 56 | Thread.sleep(4000); 57 | } catch (InterruptedException e) { 58 | } 59 | return null; 60 | } 61 | 62 | @Override 63 | protected void onPostExecute(String[] result) { 64 | // Do some stuff here 65 | 66 | // Call onRefreshComplete when the list has been refreshed. 67 | mPullRefreshScrollView.onRefreshComplete(); 68 | 69 | super.onPostExecute(result); 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/PullToRefreshListActivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.samples; 17 | 18 | import java.util.Arrays; 19 | import java.util.LinkedList; 20 | 21 | import android.app.ListActivity; 22 | import android.os.AsyncTask; 23 | import android.os.Bundle; 24 | import android.text.format.DateUtils; 25 | import android.view.ContextMenu; 26 | import android.view.ContextMenu.ContextMenuInfo; 27 | import android.view.Menu; 28 | import android.view.MenuItem; 29 | import android.view.View; 30 | import android.widget.AdapterView.AdapterContextMenuInfo; 31 | import android.widget.ArrayAdapter; 32 | import android.widget.ListView; 33 | import android.widget.Toast; 34 | 35 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 36 | import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; 37 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener; 38 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; 39 | import com.handmark.pulltorefresh.library.PullToRefreshBase.State; 40 | import com.handmark.pulltorefresh.library.PullToRefreshListView; 41 | import com.handmark.pulltorefresh.library.extras.SoundPullEventListener; 42 | 43 | public final class PullToRefreshListActivity extends ListActivity { 44 | 45 | static final int MENU_MANUAL_REFRESH = 0; 46 | static final int MENU_DISABLE_SCROLL = 1; 47 | static final int MENU_SET_MODE = 2; 48 | static final int MENU_DEMO = 3; 49 | 50 | private LinkedList mListItems; 51 | private PullToRefreshListView mPullRefreshListView; 52 | private ArrayAdapter mAdapter; 53 | 54 | /** Called when the activity is first created. */ 55 | @Override 56 | public void onCreate(Bundle savedInstanceState) { 57 | super.onCreate(savedInstanceState); 58 | setContentView(R.layout.activity_ptr_list); 59 | 60 | mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list); 61 | 62 | // Set a listener to be invoked when the list should be refreshed. 63 | mPullRefreshListView.setOnRefreshListener(new OnRefreshListener() { 64 | @Override 65 | public void onRefresh(PullToRefreshBase refreshView) { 66 | String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), 67 | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); 68 | 69 | // Update the LastUpdatedLabel 70 | refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label); 71 | 72 | // Do work to refresh the list here. 73 | new GetDataTask().execute(); 74 | } 75 | }); 76 | 77 | // Add an end-of-list listener 78 | mPullRefreshListView.setOnLastItemVisibleListener(new OnLastItemVisibleListener() { 79 | 80 | @Override 81 | public void onLastItemVisible() { 82 | Toast.makeText(PullToRefreshListActivity.this, "End of List!", Toast.LENGTH_SHORT).show(); 83 | } 84 | }); 85 | 86 | ListView actualListView = mPullRefreshListView.getRefreshableView(); 87 | 88 | // Need to use the Actual ListView when registering for Context Menu 89 | registerForContextMenu(actualListView); 90 | 91 | mListItems = new LinkedList(); 92 | mListItems.addAll(Arrays.asList(mStrings)); 93 | 94 | mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mListItems); 95 | 96 | /** 97 | * Add Sound Event Listener 98 | */ 99 | SoundPullEventListener soundListener = new SoundPullEventListener(this); 100 | soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event); 101 | soundListener.addSoundEvent(State.RESET, R.raw.reset_sound); 102 | soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound); 103 | mPullRefreshListView.setOnPullEventListener(soundListener); 104 | 105 | // You can also just use setListAdapter(mAdapter) or 106 | // mPullRefreshListView.setAdapter(mAdapter) 107 | actualListView.setAdapter(mAdapter); 108 | } 109 | 110 | private class GetDataTask extends AsyncTask { 111 | 112 | @Override 113 | protected String[] doInBackground(Void... params) { 114 | // Simulates a background job. 115 | try { 116 | Thread.sleep(4000); 117 | } catch (InterruptedException e) { 118 | } 119 | return mStrings; 120 | } 121 | 122 | @Override 123 | protected void onPostExecute(String[] result) { 124 | mListItems.addFirst("Added after refresh..."); 125 | mAdapter.notifyDataSetChanged(); 126 | 127 | // Call onRefreshComplete when the list has been refreshed. 128 | mPullRefreshListView.onRefreshComplete(); 129 | 130 | super.onPostExecute(result); 131 | } 132 | } 133 | 134 | @Override 135 | public boolean onCreateOptionsMenu(Menu menu) { 136 | menu.add(0, MENU_MANUAL_REFRESH, 0, "Manual Refresh"); 137 | menu.add(0, MENU_DISABLE_SCROLL, 1, 138 | mPullRefreshListView.isScrollingWhileRefreshingEnabled() ? "Disable Scrolling while Refreshing" 139 | : "Enable Scrolling while Refreshing"); 140 | menu.add(0, MENU_SET_MODE, 0, mPullRefreshListView.getMode() == Mode.BOTH ? "Change to MODE_PULL_DOWN" 141 | : "Change to MODE_PULL_BOTH"); 142 | menu.add(0, MENU_DEMO, 0, "Demo"); 143 | return super.onCreateOptionsMenu(menu); 144 | } 145 | 146 | @Override 147 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 148 | AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; 149 | 150 | menu.setHeaderTitle("Item: " + getListView().getItemAtPosition(info.position)); 151 | menu.add("Item 1"); 152 | menu.add("Item 2"); 153 | menu.add("Item 3"); 154 | menu.add("Item 4"); 155 | 156 | super.onCreateContextMenu(menu, v, menuInfo); 157 | } 158 | 159 | @Override 160 | public boolean onPrepareOptionsMenu(Menu menu) { 161 | MenuItem disableItem = menu.findItem(MENU_DISABLE_SCROLL); 162 | disableItem 163 | .setTitle(mPullRefreshListView.isScrollingWhileRefreshingEnabled() ? "Disable Scrolling while Refreshing" 164 | : "Enable Scrolling while Refreshing"); 165 | 166 | MenuItem setModeItem = menu.findItem(MENU_SET_MODE); 167 | setModeItem.setTitle(mPullRefreshListView.getMode() == Mode.BOTH ? "Change to MODE_FROM_START" 168 | : "Change to MODE_PULL_BOTH"); 169 | 170 | return super.onPrepareOptionsMenu(menu); 171 | } 172 | 173 | @Override 174 | public boolean onOptionsItemSelected(MenuItem item) { 175 | 176 | switch (item.getItemId()) { 177 | case MENU_MANUAL_REFRESH: 178 | new GetDataTask().execute(); 179 | mPullRefreshListView.setRefreshing(false); 180 | break; 181 | case MENU_DISABLE_SCROLL: 182 | mPullRefreshListView.setScrollingWhileRefreshingEnabled(!mPullRefreshListView 183 | .isScrollingWhileRefreshingEnabled()); 184 | break; 185 | case MENU_SET_MODE: 186 | mPullRefreshListView.setMode(mPullRefreshListView.getMode() == Mode.BOTH ? Mode.PULL_FROM_START 187 | : Mode.BOTH); 188 | break; 189 | case MENU_DEMO: 190 | mPullRefreshListView.demo(); 191 | break; 192 | } 193 | 194 | return super.onOptionsItemSelected(item); 195 | } 196 | 197 | private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", 198 | "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", 199 | "Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", 200 | "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", 201 | "Allgauer Emmentaler" }; 202 | } 203 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/PullToRefreshListFragmentActivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.samples; 17 | 18 | import java.util.Arrays; 19 | import java.util.LinkedList; 20 | 21 | import android.os.AsyncTask; 22 | import android.os.Bundle; 23 | import android.support.v4.app.FragmentActivity; 24 | import android.widget.ArrayAdapter; 25 | import android.widget.ListView; 26 | 27 | import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment; 28 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 29 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; 30 | import com.handmark.pulltorefresh.library.PullToRefreshListView; 31 | 32 | public final class PullToRefreshListFragmentActivity extends FragmentActivity implements OnRefreshListener { 33 | 34 | private LinkedList mListItems; 35 | private ArrayAdapter mAdapter; 36 | 37 | private PullToRefreshListFragment mPullRefreshListFragment; 38 | private PullToRefreshListView mPullRefreshListView; 39 | 40 | /** Called when the activity is first created. */ 41 | @Override 42 | public void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | setContentView(R.layout.activity_ptr_list_fragment); 45 | 46 | mPullRefreshListFragment = (PullToRefreshListFragment) getSupportFragmentManager().findFragmentById( 47 | R.id.frag_ptr_list); 48 | 49 | // Get PullToRefreshListView from Fragment 50 | mPullRefreshListView = mPullRefreshListFragment.getPullToRefreshListView(); 51 | 52 | // Set a listener to be invoked when the list should be refreshed. 53 | mPullRefreshListView.setOnRefreshListener(this); 54 | 55 | // You can also just use mPullRefreshListFragment.getListView() 56 | ListView actualListView = mPullRefreshListView.getRefreshableView(); 57 | 58 | mListItems = new LinkedList(); 59 | mListItems.addAll(Arrays.asList(mStrings)); 60 | mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mListItems); 61 | 62 | // You can also just use setListAdapter(mAdapter) or 63 | // mPullRefreshListView.setAdapter(mAdapter) 64 | actualListView.setAdapter(mAdapter); 65 | 66 | mPullRefreshListFragment.setListShown(true); 67 | } 68 | 69 | @Override 70 | public void onRefresh(PullToRefreshBase refreshView) { 71 | // Do work to refresh the list here. 72 | new GetDataTask().execute(); 73 | } 74 | 75 | private class GetDataTask extends AsyncTask { 76 | 77 | @Override 78 | protected String[] doInBackground(Void... params) { 79 | // Simulates a background job. 80 | try { 81 | Thread.sleep(4000); 82 | } catch (InterruptedException e) { 83 | } 84 | return mStrings; 85 | } 86 | 87 | @Override 88 | protected void onPostExecute(String[] result) { 89 | mListItems.addFirst("Added after refresh..."); 90 | mAdapter.notifyDataSetChanged(); 91 | 92 | // Call onRefreshComplete when the list has been refreshed. 93 | mPullRefreshListView.onRefreshComplete(); 94 | 95 | super.onPostExecute(result); 96 | } 97 | } 98 | 99 | private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", 100 | "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", 101 | "Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", 102 | "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", 103 | "Allgauer Emmentaler" }; 104 | } 105 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/PullToRefreshListInViewPagerActivity.java: -------------------------------------------------------------------------------- 1 | package com.handmark.pulltorefresh.samples; 2 | 3 | import java.util.Arrays; 4 | 5 | import android.app.Activity; 6 | import android.content.Context; 7 | import android.os.AsyncTask; 8 | import android.os.Bundle; 9 | import android.support.v4.view.PagerAdapter; 10 | import android.support.v4.view.ViewPager; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.view.ViewGroup.LayoutParams; 15 | import android.widget.ArrayAdapter; 16 | import android.widget.ListAdapter; 17 | import android.widget.ListView; 18 | 19 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 20 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; 21 | import com.handmark.pulltorefresh.library.PullToRefreshListView; 22 | 23 | public class PullToRefreshListInViewPagerActivity extends Activity implements OnRefreshListener { 24 | 25 | private static final String[] STRINGS = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", 26 | "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", 27 | "Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", 28 | "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", 29 | "Allgauer Emmentaler" }; 30 | 31 | private ViewPager mViewPager; 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_ptr_list_in_vp); 37 | 38 | mViewPager = (ViewPager) findViewById(R.id.vp_list); 39 | mViewPager.setAdapter(new ListViewPagerAdapter()); 40 | } 41 | 42 | private class ListViewPagerAdapter extends PagerAdapter { 43 | 44 | @Override 45 | public View instantiateItem(ViewGroup container, int position) { 46 | Context context = container.getContext(); 47 | 48 | PullToRefreshListView plv = (PullToRefreshListView) LayoutInflater.from(context).inflate( 49 | R.layout.layout_listview_in_viewpager, container, false); 50 | 51 | ListAdapter adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_1, 52 | Arrays.asList(STRINGS)); 53 | plv.setAdapter(adapter); 54 | 55 | plv.setOnRefreshListener(PullToRefreshListInViewPagerActivity.this); 56 | 57 | // Now just add ListView to ViewPager and return it 58 | container.addView(plv, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 59 | 60 | return plv; 61 | } 62 | 63 | @Override 64 | public void destroyItem(ViewGroup container, int position, Object object) { 65 | container.removeView((View) object); 66 | } 67 | 68 | @Override 69 | public boolean isViewFromObject(View view, Object object) { 70 | return view == object; 71 | } 72 | 73 | @Override 74 | public int getCount() { 75 | return 3; 76 | } 77 | 78 | } 79 | 80 | @Override 81 | public void onRefresh(PullToRefreshBase refreshView) { 82 | new GetDataTask(refreshView).execute(); 83 | } 84 | 85 | private static class GetDataTask extends AsyncTask { 86 | 87 | PullToRefreshBase mRefreshedView; 88 | 89 | public GetDataTask(PullToRefreshBase refreshedView) { 90 | mRefreshedView = refreshedView; 91 | } 92 | 93 | @Override 94 | protected Void doInBackground(Void... params) { 95 | // Simulates a background job. 96 | try { 97 | Thread.sleep(4000); 98 | } catch (InterruptedException e) { 99 | } 100 | return null; 101 | } 102 | 103 | @Override 104 | protected void onPostExecute(Void result) { 105 | mRefreshedView.onRefreshComplete(); 106 | super.onPostExecute(result); 107 | } 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/PullToRefreshScrollViewActivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.samples; 17 | 18 | import android.app.Activity; 19 | import android.os.AsyncTask; 20 | import android.os.Bundle; 21 | import android.widget.ScrollView; 22 | 23 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 24 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; 25 | import com.handmark.pulltorefresh.library.PullToRefreshScrollView; 26 | 27 | public final class PullToRefreshScrollViewActivity extends Activity { 28 | 29 | PullToRefreshScrollView mPullRefreshScrollView; 30 | ScrollView mScrollView; 31 | 32 | /** Called when the activity is first created. */ 33 | @Override 34 | public void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_ptr_scrollview); 37 | 38 | mPullRefreshScrollView = (PullToRefreshScrollView) findViewById(R.id.pull_refresh_scrollview); 39 | mPullRefreshScrollView.setOnRefreshListener(new OnRefreshListener() { 40 | 41 | @Override 42 | public void onRefresh(PullToRefreshBase refreshView) { 43 | new GetDataTask().execute(); 44 | } 45 | }); 46 | 47 | mScrollView = mPullRefreshScrollView.getRefreshableView(); 48 | } 49 | 50 | private class GetDataTask extends AsyncTask { 51 | 52 | @Override 53 | protected String[] doInBackground(Void... params) { 54 | // Simulates a background job. 55 | try { 56 | Thread.sleep(4000); 57 | } catch (InterruptedException e) { 58 | } 59 | return null; 60 | } 61 | 62 | @Override 63 | protected void onPostExecute(String[] result) { 64 | // Do some stuff here 65 | 66 | // Call onRefreshComplete when the list has been refreshed. 67 | mPullRefreshScrollView.onRefreshComplete(); 68 | 69 | super.onPostExecute(result); 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/PullToRefreshViewPagerActivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.samples; 17 | 18 | import android.app.Activity; 19 | import android.os.AsyncTask; 20 | import android.os.Bundle; 21 | import android.support.v4.view.PagerAdapter; 22 | import android.support.v4.view.ViewPager; 23 | import android.view.View; 24 | import android.view.ViewGroup; 25 | import android.view.ViewGroup.LayoutParams; 26 | import android.widget.ImageView; 27 | 28 | import com.handmark.pulltorefresh.extras.viewpager.PullToRefreshViewPager; 29 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 30 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; 31 | 32 | public class PullToRefreshViewPagerActivity extends Activity implements OnRefreshListener { 33 | 34 | private PullToRefreshViewPager mPullToRefreshViewPager; 35 | 36 | @Override 37 | public void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | setContentView(R.layout.activity_ptr_viewpager); 40 | 41 | mPullToRefreshViewPager = (PullToRefreshViewPager) findViewById(R.id.pull_refresh_viewpager); 42 | mPullToRefreshViewPager.setOnRefreshListener(this); 43 | 44 | ViewPager vp = mPullToRefreshViewPager.getRefreshableView(); 45 | vp.setAdapter(new SamplePagerAdapter()); 46 | } 47 | 48 | @Override 49 | public void onRefresh(PullToRefreshBase refreshView) { 50 | new GetDataTask().execute(); 51 | } 52 | 53 | static class SamplePagerAdapter extends PagerAdapter { 54 | 55 | private static int[] sDrawables = { R.drawable.wallpaper, R.drawable.wallpaper, R.drawable.wallpaper, 56 | R.drawable.wallpaper, R.drawable.wallpaper, R.drawable.wallpaper }; 57 | 58 | @Override 59 | public int getCount() { 60 | return sDrawables.length; 61 | } 62 | 63 | @Override 64 | public View instantiateItem(ViewGroup container, int position) { 65 | ImageView imageView = new ImageView(container.getContext()); 66 | imageView.setImageResource(sDrawables[position]); 67 | 68 | // Now just add ImageView to ViewPager and return it 69 | container.addView(imageView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 70 | 71 | return imageView; 72 | } 73 | 74 | @Override 75 | public void destroyItem(ViewGroup container, int position, Object object) { 76 | container.removeView((View) object); 77 | } 78 | 79 | @Override 80 | public boolean isViewFromObject(View view, Object object) { 81 | return view == object; 82 | } 83 | } 84 | 85 | private class GetDataTask extends AsyncTask { 86 | 87 | @Override 88 | protected Void doInBackground(Void... params) { 89 | // Simulates a background job. 90 | try { 91 | Thread.sleep(4000); 92 | } catch (InterruptedException e) { 93 | } 94 | return null; 95 | } 96 | 97 | @Override 98 | protected void onPostExecute(Void result) { 99 | mPullToRefreshViewPager.onRefreshComplete(); 100 | super.onPostExecute(result); 101 | } 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/PullToRefreshWebView2Activity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.samples; 17 | 18 | import android.app.Activity; 19 | import android.os.Bundle; 20 | import android.webkit.WebView; 21 | import android.webkit.WebViewClient; 22 | 23 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 24 | import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; 25 | import com.handmark.pulltorefresh.library.extras.PullToRefreshWebView2; 26 | 27 | public final class PullToRefreshWebView2Activity extends Activity implements OnRefreshListener { 28 | 29 | /** Called when the activity is first created. */ 30 | @Override 31 | public void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_ptr_webview2); 34 | 35 | PullToRefreshWebView2 pullRefreshWebView = (PullToRefreshWebView2) findViewById(R.id.pull_refresh_webview2); 36 | pullRefreshWebView.setOnRefreshListener(this); 37 | 38 | WebView webView = pullRefreshWebView.getRefreshableView(); 39 | webView.getSettings().setJavaScriptEnabled(true); 40 | webView.setWebViewClient(new SampleWebViewClient()); 41 | 42 | // We just load a prepared HTML page from the assets folder for this 43 | // sample, see that file for the Javascript implementation 44 | webView.loadUrl("file:///android_asset/ptr_webview2_sample.html"); 45 | } 46 | 47 | private static class SampleWebViewClient extends WebViewClient { 48 | @Override 49 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 50 | view.loadUrl(url); 51 | return true; 52 | } 53 | } 54 | 55 | @Override 56 | public void onRefresh(final PullToRefreshBase refreshView) { 57 | // This is very contrived example, we just wait 2 seconds, then call 58 | // onRefreshComplete() 59 | refreshView.postDelayed(new Runnable() { 60 | @Override 61 | public void run() { 62 | refreshView.onRefreshComplete(); 63 | } 64 | }, 2 * 1000); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sample/src/com/handmark/pulltorefresh/samples/PullToRefreshWebViewActivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011, 2012 Chris Banes. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.handmark.pulltorefresh.samples; 17 | 18 | import android.app.Activity; 19 | import android.os.Bundle; 20 | import android.webkit.WebView; 21 | import android.webkit.WebViewClient; 22 | 23 | import com.handmark.pulltorefresh.library.PullToRefreshWebView; 24 | 25 | public final class PullToRefreshWebViewActivity extends Activity { 26 | 27 | PullToRefreshWebView mPullRefreshWebView; 28 | WebView mWebView; 29 | 30 | /** Called when the activity is first created. */ 31 | @Override 32 | public void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_ptr_webview); 35 | 36 | mPullRefreshWebView = (PullToRefreshWebView) findViewById(R.id.pull_refresh_webview); 37 | mWebView = mPullRefreshWebView.getRefreshableView(); 38 | 39 | mWebView.getSettings().setJavaScriptEnabled(true); 40 | mWebView.setWebViewClient(new SampleWebViewClient()); 41 | mWebView.loadUrl("http://www.google.com"); 42 | 43 | } 44 | 45 | private static class SampleWebViewClient extends WebViewClient { 46 | @Override 47 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 48 | view.loadUrl(url); 49 | return true; 50 | } 51 | } 52 | 53 | } 54 | --------------------------------------------------------------------------------