Repository: naver/android-pull-to-refresh Branch: master Commit: bafeabc7d1fe Files: 151 Total size: 470.5 KB Directory structure: gitextract_lf3pz0t7/ ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── downloads/ │ └── sample-3.0.0.apk ├── extras/ │ ├── PullToRefreshListFragment/ │ │ ├── AndroidManifest.xml │ │ ├── LICENSE │ │ ├── build.gradle │ │ ├── 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 │ │ ├── build.gradle │ │ ├── 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 ├── gradle.properties ├── library/ │ ├── AndroidManifest.xml │ ├── LICENSE │ ├── build.gradle │ ├── 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/ │ │ │ ├── indicator_bg_bottom.xml │ │ │ ├── indicator_bg_top.xml │ │ │ ├── progress_horizontal_holo_light.xml │ │ │ ├── progress_horizontal_holo_light_right.xml │ │ │ └── progress_indeterminate_horizontal_holo.xml │ │ ├── layout/ │ │ │ ├── pull_to_refresh_header_google_style.xml │ │ │ ├── pull_to_refresh_header_horizontal.xml │ │ │ ├── pull_to_refresh_header_vertical.xml │ │ │ ├── pull_to_refresh_progress_google_style.xml │ │ │ └── pulling_progress_layout.xml │ │ ├── values/ │ │ │ ├── attrs.xml │ │ │ ├── dimens.xml │ │ │ ├── ids.xml │ │ │ └── pull_refresh_strings.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/ │ │ │ └── pull_refresh_strings.xml │ │ ├── values-pt-rBR/ │ │ │ └── pull_refresh_strings.xml │ │ ├── values-ro/ │ │ │ └── pull_refresh_strings.xml │ │ ├── values-ru/ │ │ │ └── pull_refresh_strings.xml │ │ ├── values-zh/ │ │ │ └── pull_refresh_strings.xml │ │ └── xml/ │ │ └── pulltorefresh.xml │ └── src/ │ └── main/ │ └── java/ │ └── com/ │ └── handmark/ │ └── pulltorefresh/ │ ├── configuration/ │ │ └── xml/ │ │ ├── ExtendedXmlConfigParserFactory.java │ │ ├── PullToRefreshConfigXmlParser.java │ │ ├── PullToRefreshNode.java │ │ ├── PullToRefreshXmlConfiguration.java │ │ ├── XmlPullNode.java │ │ ├── XmlPullNodeParser.java │ │ └── XmlPullParserWrapper.java │ └── library/ │ ├── AlphaAnimator.java │ ├── GoogleStyleProgressLayout.java │ ├── GoogleStyleProgressLayoutFactory.java │ ├── GoogleStyleViewLayout.java │ ├── GoogleStyleViewLayoutFactory.java │ ├── IGoogleStyleProgressLayout.java │ ├── IGoogleStyleViewLayout.java │ ├── IIndicatorLayout.java │ ├── ILoadingLayout.java │ ├── IPullToRefresh.java │ ├── IPullToRefreshConsumer.java │ ├── IndicatorLayoutFactory.java │ ├── LoadingLayoutFactory.java │ ├── LoadingLayoutProxy.java │ ├── OverscrollHelper.java │ ├── PullToRefreshAdapterViewBase.java │ ├── PullToRefreshBase.java │ ├── PullToRefreshExpandableListView.java │ ├── PullToRefreshGridView.java │ ├── PullToRefreshHorizontalScrollView.java │ ├── PullToRefreshListView.java │ ├── PullToRefreshScrollView.java │ ├── PullToRefreshWebView.java │ ├── extras/ │ │ ├── PullToRefreshWebView2.java │ │ └── SoundPullEventListener.java │ └── internal/ │ ├── AbstractDefaultGoogleStyleViewLayout.java │ ├── Assert.java │ ├── DefaultGoogleStyleProgressLayout.java │ ├── DefaultGoogleStyleViewLayout.java │ ├── DefaultIndicatorLayout.java │ ├── EmptyViewMethodAccessor.java │ ├── FlipLoadingLayout.java │ ├── FlippedProgressBar.java │ ├── IndicatorLayout.java │ ├── LoadingLayout.java │ ├── PullingProgressLayout.java │ ├── RotateLoadingLayout.java │ ├── Utils.java │ └── ViewCompat.java ├── pom.xml ├── sample/ │ ├── AndroidManifest.xml │ ├── LICENSE │ ├── assets/ │ │ ├── ptr_webview2_sample.html │ │ └── pulltorefresh.xml │ ├── libs/ │ │ └── android-support-v4.jar │ ├── pom.xml │ ├── project.properties │ ├── res/ │ │ ├── layout/ │ │ │ ├── activity_ptr_custom_loadinglayout.xml │ │ │ ├── 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 │ │ └── values/ │ │ ├── strings.xml │ │ └── styles.xml │ └── src/ │ └── com/ │ └── handmark/ │ └── pulltorefresh/ │ └── samples/ │ ├── LauncherActivity.java │ ├── PullToRefreshCustomLoadingLayoutActivity.java │ ├── PullToRefreshExpandableListActivity.java │ ├── PullToRefreshGridActivity.java │ ├── PullToRefreshHorizontalScrollViewActivity.java │ ├── PullToRefreshListActivity.java │ ├── PullToRefreshListFragmentActivity.java │ ├── PullToRefreshListInViewPagerActivity.java │ ├── PullToRefreshScrollViewActivity.java │ ├── PullToRefreshViewPagerActivity.java │ ├── PullToRefreshWebView2Activity.java │ ├── PullToRefreshWebViewActivity.java │ └── loadinglayout/ │ └── CustomLoadingLayout.java └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ #Android generated bin gen library/build/ #Eclipse .project .classpath .settings #IntelliJ IDEA .idea *.iml *.ipr *.iws out #Maven target release.properties pom.xml.* #Ant build.xml local.properties proguard.cfg #OSX .DS_Store ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ # Pull To Refresh Views for Android `Renewal`! v3.2 ### This project is a fork of Chris Banes' Android-PullToRefresh project. The project provides flexibility in customization in addition to adding brand new features listed below. - __New!__ AAR package support - Google-like pull to refresh animation support (in Android 3.x or 4.x) *__NOTE__: This style is now supported in [Android Support Library](http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html). I recommend you to use the support library instead of this library, unless you are already using and want to change the style from old style to it.* - Easy layout customization - no need to include the library's source code directly into your project. - Easily Customizable loading layouts, labels, and icons. - Ability to customize and add multiple indicator layouts. - Configurable friction and smooth scroll duration. - This fork project is __not__ being deprecated. Please send issues or pull requests to me, and I will provide you with feedbacks. - __Are you are using Pull To Refresh v2.1.x? You'd better [MIGRATE](https://github.com/nhnopensource/android-pull-to-refresh/wiki/Migration-from-v2.1.x-to-v3.0.0) to v3.2 now!__ ### Introduction * * * ![Screenshot](https://github.com/nhnopensource/android-pull-to-refresh/raw/master/header_graphic.png) 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. ## Included Features * Supports both Pulling Down from the top, and Pulling Up from the bottom (or even both). * Animated Scrolling for all devices. * Over Scroll supports for devices on Android v2.3+. * Currently works with: * **ListView** * **ExpandableListView** * **GridView** * **WebView** * **ScrollView** * **HorizontalScrollView** * **ViewPager** * Integrated End of List Listener for use of detecting when the user has scrolled to the bottom. * Maven Central Support. * Indicators to show the user when a Pull-to-Refresh is available. * Support for **ListFragment**! * Lots of [Customization](https://github.com/nhnopensource/android-pull-to-refresh/wiki/Customization) options! Repository at . ## Sample Application Sample application is being provided as APK file (the source is in the repository): [Download Here!](http://search.maven.org/remotecontent?filepath=com/navercorp/pulltorefresh/sample/3.2.2/sample-3.2.2.apk) ## Usage To begin using the library, please see the [Quick Start Guide](https://github.com/nhnopensource/android-pull-to-refresh/wiki/Quick-Start-Guide). ### Customization Our [Customization](https://github.com/nhnopensource/android-pull-to-refresh/wiki/Customization) page contains detailed information on how to change the behaviour and look of the View. ### Pull Up to Refresh By default this library is set to Pull Down to Refresh, but if you want to allow Pull Up to Refresh then you can do so. You can even set the View to enable both Pull Up and Pull Down using the 'both' setting. See the [Customization](https://github.com/nhnopensource/android-pull-to-refresh/wiki/Customization) page for more information on how to set this. ## Apps Want to see which Apps are already using Android-PullToRefresh? Have a look [here](https://github.com/nhnopensource/android-pull-to-refresh/wiki/Apps). ## Changelog Please see the new [Changelog](https://github.com/nhnopensource/android-pull-to-refresh/wiki/Changelog) page to see what's recently changed. ## Pull Requests 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. ## Acknowledgments * [Stefano Dacchille](https://github.com/stefanodacchille) * [Steve Lhomme](https://github.com/robUx4) * [Maxim Galkin](https://github.com/mgalkin) * [Scorcher](https://github.com/Scorcher) ## License Copyright 2011, 2012 Chris Banes Copyright 2013 Naver Business Platform Corp. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: build.gradle ================================================ buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.11.+' } } allprojects { version = PULLTOREFRESH_RELEASE_VERSION group = PULLTOREFRESH_RELEASE_GROUP repositories { mavenCentral() } } ================================================ FILE: extras/PullToRefreshListFragment/AndroidManifest.xml ================================================ ================================================ FILE: extras/PullToRefreshListFragment/LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: extras/PullToRefreshListFragment/build.gradle ================================================ apply plugin: 'android-library' dependencies { compile project(':library') compile 'com.android.support:support-v4:18.0.+' } archivesBaseName = 'extra-listfragment' android { compileSdkVersion Integer.parseInt(ANDROID_COMPILE_SDK_VERSION) buildToolsVersion ANDROID_BUILD_TOOLS_VERSION sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs=['src'] res.srcDirs=['res'] } } } ================================================ FILE: extras/PullToRefreshListFragment/pom.xml ================================================ 4.0.0 com.navercorp.pulltorefresh extra-listfragment apklib Android-PullToRefresh Extras: ListFragment com.navercorp.pulltorefresh extras 3.3.0-SNAPSHOT com.google.android android com.google.android support-v4 r7 ${project.groupId} library apklib ${project.version} com.jayway.maven.plugins.android.generation2 android-maven-plugin 3.7.0 org.codehaus.mojo build-helper-maven-plugin package attach-artifact aar ${project.basedir}/build/libs/${project.artifactId}-${parent.version}.aar org.apache.maven.plugins maven-eclipse-plugin ================================================ FILE: extras/PullToRefreshListFragment/project.properties ================================================ # This file is automatically generated by Android Tools. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must be checked in Version Control Systems. # # To customize properties used by the Ant build system edit # "ant.properties", and override values to adapt the script to your # project structure. # # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt android.library=true # Project target. target=android-16 android.library.reference.1=../../library ================================================ FILE: extras/PullToRefreshListFragment/res/layout/need_this_for_maven.xml ================================================ ================================================ FILE: extras/PullToRefreshListFragment/src/com/handmark/pulltorefresh/extras/listfragment/PullToRefreshBaseListFragment.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.extras.listfragment; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.ListView; import com.handmark.pulltorefresh.library.PullToRefreshBase; abstract class PullToRefreshBaseListFragment> extends ListFragment { private T mPullToRefreshListView; @Override public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) layout.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) lv.getParent(); // Remove ListView and add PullToRefreshListView in its place int lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex); mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); return layout; } /** * @return The {@link PullToRefreshBase} attached to this ListFragment. */ public final T getPullToRefreshListView() { return mPullToRefreshListView; } /** * Returns the {@link PullToRefreshBase} which will replace the ListView * created from ListFragment. You should override this method if you wish to * customise the {@link PullToRefreshBase} from the default. * * @param inflater - LayoutInflater which can be used to inflate from XML. * @param savedInstanceState - Bundle passed through from * {@link ListFragment#onCreateView(LayoutInflater, ViewGroup, Bundle) * onCreateView(...)} * @return The {@link PullToRefreshBase} which will replace the ListView. */ protected abstract T onCreatePullToRefreshListView(LayoutInflater inflater, Bundle savedInstanceState); } ================================================ FILE: extras/PullToRefreshListFragment/src/com/handmark/pulltorefresh/extras/listfragment/PullToRefreshExpandableListFragment.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.extras.listfragment; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.view.LayoutInflater; import com.handmark.pulltorefresh.library.PullToRefreshExpandableListView; /** * A sample implementation of how to use {@link PullToRefreshExpandableListView} * with {@link ListFragment}. This implementation simply replaces the ListView * that {@code ListFragment} creates with a new * {@code PullToRefreshExpandableListView}. This means that ListFragment still * works 100% (e.g. setListShown(...) ). *

* The new PullToRefreshListView is created in the method * {@link #onCreatePullToRefreshListView(LayoutInflater, Bundle)}. If you wish * to customise the {@code PullToRefreshExpandableListView} then override this * method and return your customised instance. * * @author Chris Banes * */ public class PullToRefreshExpandableListFragment extends PullToRefreshBaseListFragment { protected PullToRefreshExpandableListView onCreatePullToRefreshListView(LayoutInflater inflater, Bundle savedInstanceState) { return new PullToRefreshExpandableListView(getActivity()); } } ================================================ FILE: extras/PullToRefreshListFragment/src/com/handmark/pulltorefresh/extras/listfragment/PullToRefreshListFragment.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.extras.listfragment; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.view.LayoutInflater; import com.handmark.pulltorefresh.library.PullToRefreshListView; /** * A sample implementation of how to use {@link PullToRefreshListView} with * {@link ListFragment}. This implementation simply replaces the ListView that * {@code ListFragment} creates with a new PullToRefreshListView. This means * that ListFragment still works 100% (e.g. setListShown(...) ). *

* The new PullToRefreshListView is created in the method * {@link #onCreatePullToRefreshListView(LayoutInflater, Bundle)}. If you wish * to customise the {@code PullToRefreshListView} then override this method and * return your customised instance. * * @author Chris Banes * */ public class PullToRefreshListFragment extends PullToRefreshBaseListFragment { protected PullToRefreshListView onCreatePullToRefreshListView(LayoutInflater inflater, Bundle savedInstanceState) { return new PullToRefreshListView(getActivity()); } } ================================================ FILE: extras/PullToRefreshViewPager/AndroidManifest.xml ================================================ ================================================ FILE: extras/PullToRefreshViewPager/ant.properties ================================================ # This file is used to override default values used by the Ant build system. # # This file must be checked into Version Control Systems, as it is # integral to the build system of your project. # This file is only used by the Ant script. # You can use this to override default values such as # 'source.dir' for the location of your java source folder and # 'out.dir' for the location of your output folder. # You can also use it define how the release builds are signed by declaring # the following properties: # 'key.store' for the location of your keystore and # 'key.alias' for the name of the key to use. # The password will be asked during the build when you use the 'release' target. ================================================ FILE: extras/PullToRefreshViewPager/build.gradle ================================================ apply plugin: 'android-library' buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.6.+' } } archivesBaseName = 'extra-viewpager' dependencies { compile project(':library') compile 'com.android.support:support-v4:18.0.+' } android { compileSdkVersion Integer.parseInt(ANDROID_COMPILE_SDK_VERSION) buildToolsVersion ANDROID_BUILD_TOOLS_VERSION sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs=['src'] res.srcDirs=['res'] } } } ================================================ FILE: extras/PullToRefreshViewPager/pom.xml ================================================ 4.0.0 com.navercorp.pulltorefresh extra-viewpager apklib Android-PullToRefresh Extras: ViewPager com.navercorp.pulltorefresh extras 3.3.0-SNAPSHOT com.google.android android com.google.android support-v4 r7 ${project.groupId} library apklib ${project.version} com.jayway.maven.plugins.android.generation2 android-maven-plugin 3.7.0 org.codehaus.mojo build-helper-maven-plugin package attach-artifact aar ${project.basedir}/build/libs/${project.artifactId}-${parent.version}.aar org.apache.maven.plugins maven-eclipse-plugin ================================================ FILE: extras/PullToRefreshViewPager/proguard-project.txt ================================================ # To enable ProGuard in your project, edit project.properties # to define the proguard.config property as described in that file. # # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in ${sdk.dir}/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the ProGuard # include property in project.properties. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} ================================================ FILE: extras/PullToRefreshViewPager/project.properties ================================================ # This file is automatically generated by Android Tools. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must be checked in Version Control Systems. # # To customize properties used by the Ant build system edit # "ant.properties", and override values to adapt the script to your # project structure. # # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt android.library=true # Project target. target=android-16 android.library.reference.1=../../library ================================================ FILE: extras/PullToRefreshViewPager/res/layout/need_this_for_maven.xml ================================================ ================================================ FILE: extras/PullToRefreshViewPager/res/values/ids.xml ================================================ ================================================ FILE: extras/PullToRefreshViewPager/src/com/handmark/pulltorefresh/extras/viewpager/PullToRefreshViewPager.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.extras.viewpager; import android.content.Context; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import com.handmark.pulltorefresh.library.PullToRefreshBase; public class PullToRefreshViewPager extends PullToRefreshBase { public PullToRefreshViewPager(Context context) { super(context); } public PullToRefreshViewPager(Context context, AttributeSet attrs) { super(context, attrs); } @Override public final Orientation getPullToRefreshScrollDirection() { return Orientation.HORIZONTAL; } @Override protected ViewPager createRefreshableView(Context context, AttributeSet attrs) { ViewPager viewPager = new ViewPager(context, attrs); viewPager.setId(R.id.viewpager); return viewPager; } @Override protected boolean isReadyForPullStart() { ViewPager refreshableView = getRefreshableView(); PagerAdapter adapter = refreshableView.getAdapter(); if (null != adapter) { return refreshableView.getCurrentItem() == 0; } return false; } @Override protected boolean isReadyForPullEnd() { ViewPager refreshableView = getRefreshableView(); PagerAdapter adapter = refreshableView.getAdapter(); if (null != adapter) { return refreshableView.getCurrentItem() == adapter.getCount() - 1; } return false; } } ================================================ FILE: extras/pom.xml ================================================ 4.0.0 com.navercorp.pulltorefresh extras pom Android-PullToRefresh Extras com.navercorp.pulltorefresh parent 3.3.0-SNAPSHOT PullToRefreshListFragment PullToRefreshViewPager ================================================ FILE: gradle.properties ================================================ PULLTOREFRESH_RELEASE_VERSION=3.2.3 PULLTOREFRESH_RELEASE_GROUP=com.navercorp.pulltorefresh ANDROID_COMPILE_SDK_VERSION=19 ANDROID_BUILD_TOOLS_VERSION=19.1.0 ================================================ FILE: library/AndroidManifest.xml ================================================ ================================================ FILE: library/LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: library/build.gradle ================================================ apply plugin: 'android-library' buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.11.+' } } apply plugin: 'maven' apply plugin: 'signing' android { compileSdkVersion Integer.parseInt(ANDROID_COMPILE_SDK_VERSION) buildToolsVersion ANDROID_BUILD_TOOLS_VERSION sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs=['src/main/java'] res.srcDirs=['res'] } } } ================================================ FILE: library/pom.xml ================================================ 4.0.0 library apklib Android-PullToRefresh Library com.navercorp.pulltorefresh parent 3.3.0-SNAPSHOT UTF-8 4.1.1.4 16 r7 1.6 com.google.android android ${android.version} src/main/java src/test/java target/test-classes src/test/resources com.jayway.maven.plugins.android.generation2 android-maven-plugin 3.7.0 org.codehaus.mojo build-helper-maven-plugin package attach-artifact aar ${project.basedir}/build/libs/${project.artifactId}-${parent.version}.aar org.apache.maven.plugins maven-compiler-plugin 3.1 ${java.version} ${java.version} org.apache.maven.plugins maven-source-plugin 2.2.1 attach-sources jar org.apache.maven.plugins maven-javadoc-plugin 2.9 **/R.java attach-javadocs jar ================================================ FILE: library/project.properties ================================================ # This file is automatically generated by Android Tools. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must be checked in Version Control Systems. # # To customize properties used by the Ant build system use, # "ant.properties", and override values to adapt the script to your # project structure. # Project target. target=android-16 android.library=true ================================================ FILE: library/res/anim/slide_in_from_bottom.xml ================================================ ================================================ FILE: library/res/anim/slide_in_from_top.xml ================================================ ================================================ FILE: library/res/anim/slide_out_to_bottom.xml ================================================ ================================================ FILE: library/res/anim/slide_out_to_top.xml ================================================ ================================================ FILE: library/res/drawable/indicator_bg_bottom.xml ================================================ ================================================ FILE: library/res/drawable/indicator_bg_top.xml ================================================ ================================================ FILE: library/res/drawable/progress_horizontal_holo_light.xml ================================================ ================================================ FILE: library/res/drawable/progress_horizontal_holo_light_right.xml ================================================ ================================================ FILE: library/res/drawable/progress_indeterminate_horizontal_holo.xml ================================================ ================================================ FILE: library/res/layout/pull_to_refresh_header_google_style.xml ================================================ ================================================ FILE: library/res/layout/pull_to_refresh_header_horizontal.xml ================================================ ================================================ FILE: library/res/layout/pull_to_refresh_header_vertical.xml ================================================ ================================================ FILE: library/res/layout/pull_to_refresh_progress_google_style.xml ================================================ ================================================ FILE: library/res/layout/pulling_progress_layout.xml ================================================ ================================================ FILE: library/res/values/attrs.xml ================================================ ================================================ FILE: library/res/values/dimens.xml ================================================ 10dp 12dp 4dp 24dp 12dp 10px ================================================ FILE: library/res/values/ids.xml ================================================ ================================================ FILE: library/res/values/pull_refresh_strings.xml ================================================ Pull to refresh… Release to refresh… Loading… @string/pull_to_refresh_pull_label @string/pull_to_refresh_release_label @string/pull_to_refresh_refreshing_label ================================================ FILE: library/res/values-ar/pull_refresh_strings.xml ================================================ اسحب للتحديث… اترك للتحديث… تحميل… ================================================ FILE: library/res/values-cs/pull_refresh_strings.xml ================================================ Tažením aktualizujete… Uvolněním aktualizujete… Načítání… ================================================ FILE: library/res/values-de/pull_refresh_strings.xml ================================================ Ziehen zum Aktualisieren… Loslassen zum Aktualisieren… Laden… ================================================ FILE: library/res/values-es/pull_refresh_strings.xml ================================================ Tirar para actualizar… Soltar para actualizar… Cargando… ================================================ FILE: library/res/values-fi/pull_refresh_strings.xml ================================================ Päivitä vetämällä alas… Päivitä vapauttamalla… Päivitetään… Päivitä vetämällä ylös… @string/pull_to_refresh_release_label @string/pull_to_refresh_refreshing_label ================================================ FILE: library/res/values-fr/pull_refresh_strings.xml ================================================ Tirez pour rafraîchir… Relâcher pour rafraîchir… Chargement… ================================================ FILE: library/res/values-he/pull_refresh_strings.xml ================================================ משוך לרענון… שחרר לרענון… טוען… ================================================ FILE: library/res/values-it/pull_refresh_strings.xml ================================================ Tira per aggiornare… Rilascia per aggionare… Caricamento… ================================================ FILE: library/res/values-iw/pull_refresh_strings.xml ================================================ משוך לרענון… שחרר לרענון… טוען… ================================================ FILE: library/res/values-ja/pull_refresh_strings.xml ================================================ 画面を引っ張って… 指を離して更新… 読み込み中… ================================================ FILE: library/res/values-ko/pull_refresh_strings.xml ================================================ 당겨서 새로 고침… 놓아서 새로 고침… 로드 중… ================================================ FILE: library/res/values-nl/pull_refresh_strings.xml ================================================ Sleep om te vernieuwen… Loslaten om te vernieuwen… Laden… ================================================ FILE: library/res/values-pl/pull_refresh_strings.xml ================================================ Pociągnij, aby odświeżyć… Puść, aby odświeżyć… Wczytywanie… ================================================ FILE: library/res/values-pt/pull_refresh_strings.xml ================================================ Puxe para atualizar… Liberação para atualizar… A carregar… ================================================ FILE: library/res/values-pt-rBR/pull_refresh_strings.xml ================================================ Puxe para atualizar… Libere para atualizar… Carregando… ================================================ FILE: library/res/values-ro/pull_refresh_strings.xml ================================================ Trage pentru a reîmprospăta… Eliberează pentru a reîmprospăta… Încărcare… ================================================ FILE: library/res/values-ru/pull_refresh_strings.xml ================================================ Потяните для обновления… Отпустите для обновления… Загрузка… ================================================ FILE: library/res/values-zh/pull_refresh_strings.xml ================================================ 下拉刷新… 放开以刷新… 正在载入… ================================================ FILE: library/res/xml/pulltorefresh.xml ================================================ com.handmark.pulltorefresh.library.internal.RotateLoadingLayout com.handmark.pulltorefresh.library.internal.FlipLoadingLayout com.handmark.pulltorefresh.library.internal.DefaultIndicatorLayout com.handmark.pulltorefresh.library.internal.DefaultGoogleStyleViewLayout com.handmark.pulltorefresh.library.internal.DefaultGoogleStyleProgressLayout ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/configuration/xml/ExtendedXmlConfigParserFactory.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.configuration.xml; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; import android.content.Context; import android.content.res.AssetManager; import android.util.Log; /** * Parser of assets/pulltorefresh.xml creation factory * @author Wonjun Kim */ class ExtendedConfigXmlParserFactory { private static final String LOG_TAG = ExtendedConfigXmlParserFactory.class.getName(); /** * pulltorefresh.xml path in assets folder */ private static final String XML_PATH_IN_ASSETS = "pulltorefresh.xml"; /** * pulltorefresh.xml encoding type */ private static final String DEFAULT_ENCODING_TYPE = "utf-8"; /** * Create a parser of assets/pulltorefresh.xml * @param context * @return {@code parser} if creating parser has done, or {@code null} if an error occured during creation */ public static XmlPullParser createParser(Context context) { AssetManager am = context.getAssets(); XmlPullParser parser = null; try { InputStream is = am.open(XML_PATH_IN_ASSETS); parser = XmlPullParserFactory.newInstance().newPullParser(); parser.setInput(is, DEFAULT_ENCODING_TYPE); } catch (FileNotFoundException e) { Log.d(LOG_TAG, "The configuration file 'assets/" + XML_PATH_IN_ASSETS + "' is missing. But the file is just an option. It is necessary only if you want to customize something in Pull To Refresh."); // explicitly assign null parser = null; } catch (XmlPullParserException e) { Log.w(LOG_TAG, "The error occurs below when generating parser.", e); // explicitly assign null parser = null; } catch (IOException e) { Log.w(LOG_TAG, "Loading "+XML_PATH_IN_ASSETS+" file has failed.", e); // explicitly assign null parser = null; } // NOTE: this code makes a fatal error. so omit the code. // am.close(); return parser; } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/configuration/xml/PullToRefreshConfigXmlParser.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.configuration.xml; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import com.handmark.pulltorefresh.library.internal.Assert; /** * {@code PullToRefreshConfigXmlParser} does parsing pulltorefresh.xml as {@code XmlPullNode}s * @author Wonjun Kim */ final class PullToRefreshConfigXmlParser extends XmlPullNodeParser { /** * Repetition limit is only one */ private static final int ONLY_ONE_REPEAT = 1; /** * Parsed data */ private PullToRefreshResult result; /** * @param parser Must be not null */ public PullToRefreshConfigXmlParser(XmlPullParserWrapper parser) { super(parser); } /** * Generate a node tree matched by pulltorefresh.xml * @return root node of a tree */ private XmlPullNode init() { // prepare a result instance result = new PullToRefreshResult(); // make nodes XmlPullNode root = new XmlPullNode("PullToRefresh"); XmlPullNode loadingLayouts = new XmlPullNode("LoadingLayouts"); XmlPullNode indicatorLayouts = new XmlPullNode("IndicatorLayouts"); XmlPullNode googleStyleViewLayouts = new XmlPullNode("GoogleStyleViewLayouts"); XmlPullNode googleStyleProgressLayouts = new XmlPullNode("GoogleStyleProgressLayouts"); XmlPullNode loadingLayout = new XmlPullNode("layout",new LayoutNodeCallback(result.loadingLayoutClazzNameMap)); XmlPullNode indicatorLayout = new XmlPullNode("layout",new LayoutNodeCallback(result.indicatorLayoutClazzNameMap)); XmlPullNode googleStyleViewLayout = new XmlPullNode("layout",new LayoutNodeCallback(result.googleStyleViewLayoutClazzNameMap)); XmlPullNode googleStyleProgressLayout = new XmlPullNode("layout",new LayoutNodeCallback(result.googleStyleProgressLayoutClazzNameMap)); // make a tree structure root.addChildNode(loadingLayouts, ONLY_ONE_REPEAT); root.addChildNode(indicatorLayouts, ONLY_ONE_REPEAT); root.addChildNode(googleStyleViewLayouts, ONLY_ONE_REPEAT); root.addChildNode(googleStyleProgressLayouts, ONLY_ONE_REPEAT); loadingLayouts.addChildNode(loadingLayout); indicatorLayouts.addChildNode(indicatorLayout); googleStyleViewLayouts.addChildNode(googleStyleViewLayout); googleStyleProgressLayouts.addChildNode(googleStyleProgressLayout); // return root node return root; } /** * @return root node of a tree */ @Override protected XmlPullNode generateRootNode() { return init(); } /** * @return Parsed result data as {@code PullToRefreshNode} instance */ @Override protected PullToRefreshNode getResult() { return new PullToRefreshNode(result.loadingLayoutClazzNameMap, result.indicatorLayoutClazzNameMap, result.googleStyleViewLayoutClazzNameMap, result.googleStyleProgressLayoutClazzNameMap); } /** * Parsed Result to be sent to {@code PullToRefreshNode} * @author Wonjun Kim * */ private static class PullToRefreshResult { public final Map loadingLayoutClazzNameMap = new HashMap(); public final Map indicatorLayoutClazzNameMap = new HashMap(); public final Map googleStyleViewLayoutClazzNameMap = new HashMap(); public final Map googleStyleProgressLayoutClazzNameMap = new HashMap(); } /** * Callback of the node 'PullToRefresh/IndicatorLayouts/layout' and 'PullToRefresh/LoadingLayouts/layout' * @author Wonjun Kim * */ private static class LayoutNodeCallback implements XmlPullNode.XmlPullNodeCallback { /** * {@code Map} storing Layouts' information */ private Map layoutClazzNameMap; /** * @param layoutClazzNameMap Must not be null and be clean for which put new values */ public LayoutNodeCallback(Map layoutClazzNameMap) { Assert.notNull(layoutClazzNameMap, "Class Map"); this.layoutClazzNameMap = layoutClazzNameMap; } /** * Be called when parser has found 'layout' node at a time */ @Override public void process(XmlPullParser parser) throws XmlPullParserException, IOException { int attributesCount = parser.getAttributeCount(); String attributeName, attributeValue; // Iterate attributes! for (int i = 0; i < attributesCount; ++i) { attributeName = parser.getAttributeName(i); attributeValue = parser.getAttributeValue(i); // The 'name' attribute is as a layout code of each layout's class if ( "name".equals(attributeName)) { // Skip if attribute value is null or empty if ( attributeValue == null || attributeValue.length() == 0 ) { continue; } // Get layout's class name String clazzName = parser.nextText(); // Insert new class name layoutClazzNameMap.put(attributeValue, clazzName); // Do 'break' because nextText() method has been called break; } } } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/configuration/xml/PullToRefreshNode.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.configuration.xml; import java.util.Map; import com.handmark.pulltorefresh.library.internal.Assert; /** * {@code PullToRefreshNode} has an information in contents of pulltorefresh.xml,
such as loading layout and indicator layout class name * @author Wonjun Kim * */ class PullToRefreshNode { /** * Map Storing LoadingLayout class names
* Key : layout code (String)
* Value : class name (String) */ private final Map loadingLayoutClazzNameMap; /** * Map Storing IndicatorLayout class names
* Key : layout code (String)
* Value : Class name (String) */ private final Map indicatorLayoutClazzNameMap; /** * Map Storing GoogleStyleViewLayout class names
* Key : layout code (String)
* Value : Class name (String) */ private Map googleStyleViewLayoutClazzNameMap; /** * Map Storing GoogleStyleProgressLayout class names
* Key : layout code (String)
* Value : Class name (String) */ private Map googleStyleProgressLayoutClazzNameMap; /** * Constructor needs two class name {@code Map}s, which are LoadingLayout class name map and Indicator class name {@code map}.
* NOTE: Parameters must go in order. First Parameter : loading layout / Second Parameter : indicator layout * @param loadingLayoutClazzNameMap LoadingLayout class names * @param indicatorLayoutClazzNameMap */ public PullToRefreshNode(Map loadingLayoutClazzNameMap, Map indicatorLayoutClazzNameMap, Map googleStyleViewLayoutClazzNameMap, Map googleStyleProgressLayoutClazzNameMap) { Assert.notNull(loadingLayoutClazzNameMap, "LoadingLayout Class Name Map"); Assert.notNull(indicatorLayoutClazzNameMap, "Loading Layout Class Name Map"); this.loadingLayoutClazzNameMap = loadingLayoutClazzNameMap; this.indicatorLayoutClazzNameMap = indicatorLayoutClazzNameMap; this.googleStyleViewLayoutClazzNameMap = googleStyleViewLayoutClazzNameMap; this.googleStyleProgressLayoutClazzNameMap = googleStyleProgressLayoutClazzNameMap; } /** * @param layoutCode LoadingLayout layout code * @return LoadingLayout class name */ public String getIndicatorLayoutClazzName(String layoutCode) { return indicatorLayoutClazzNameMap.get(layoutCode); } /** * @param layoutCode LoadingLayout layout code * @return LoadingLayout class name */ public String getLoadingLayoutClazzName(String layoutCode) { return loadingLayoutClazzNameMap.get(layoutCode); } /** * @param layoutCode GoogleStyleViewLayout layout code * @return GoogleStyleViewLayout class name */ public String getGoogleStyleViewLayoutClazzName(String layoutCode) { return googleStyleViewLayoutClazzNameMap.get(layoutCode); } /** * @param layoutCode GoogleStyleProgressLayout layout code * @return GoogleStyleProgressLayout class name */ public String getGoogleStyleProgressLayoutClazzName(String layoutCode) { return googleStyleProgressLayoutClazzNameMap.get(layoutCode); } /** * Add an information from other {@code PullToRefreshNode} instance * @param extendedNode Other {@code PullToRefresNode} to be combined */ public void extendProperties(PullToRefreshNode extendedNode) { Assert.notNull(extendedNode, "Extended Node"); Map indicatorMap = extendedNode.indicatorLayoutClazzNameMap; Map loadingMap = extendedNode.loadingLayoutClazzNameMap; Map googleStyleViewMap = extendedNode.googleStyleViewLayoutClazzNameMap; Map googleStyleProgressMap = extendedNode.googleStyleProgressLayoutClazzNameMap; indicatorLayoutClazzNameMap.putAll(indicatorMap); loadingLayoutClazzNameMap.putAll(loadingMap); googleStyleViewLayoutClazzNameMap.putAll(googleStyleViewMap); googleStyleProgressLayoutClazzNameMap.putAll(googleStyleProgressMap); } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/configuration/xml/PullToRefreshXmlConfiguration.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.configuration.xml; import java.io.IOException; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import com.handmark.pulltorefresh.library.R; import com.handmark.pulltorefresh.library.internal.Assert; import com.handmark.pulltorefresh.library.internal.Utils; import android.content.Context; import android.content.res.Resources; import android.util.Log; /** * {@code PullToRefreshXmlConfiguration} is an information set of PullToRefresh. It contains a list of indicator layouts and of loading layouts. An information set of PullToRefresh is converted from pulltorefresh.xml.
* This Class is Singleton, and you MUST call {@link #init(Context)} before using this class. * @author Wonjun Kim */ public class PullToRefreshXmlConfiguration { private static final String LOG_TAG = PullToRefreshXmlConfiguration.class.getName(); /** * Singleton instance * @author Wonjun Kim */ private static class InstanceHolder { private final static PullToRefreshXmlConfiguration instance = new PullToRefreshXmlConfiguration(); private static PullToRefreshXmlConfiguration getInstance() { return instance; } } /** * Parsed information from pulltorefresh.xml */ private PullToRefreshNode node = null; /** * Default pulltorefresh path id is got from R class. */ private static final int XML_PATH_ID = R.xml.pulltorefresh; /** * flag whether it has called {@link #init(Context)} */ private boolean initialized = false; /** * Constructor
* nothing to do */ private PullToRefreshXmlConfiguration() {} /** * Get singleton instance * @return {@code PullToRefreshXmlConfiguration} instance */ public static PullToRefreshXmlConfiguration getInstance() { return InstanceHolder.getInstance(); } /** * Initialize the instance before using.
* Load 'res/xml/pulltorefresh.xml' in PullToRefresh library package and 'assets/pulltofresh.xml' in Android Project if it exists.
* Combine information of 'res/xml/pulltorefresh.xml' and 'assets/pulltofresh.xml', and then save the information into the instance's fields.
*
* NOTE: This method MUST be called before using! * @param context Context instance and not null */ public void init(Context context) { // If an initialization was happened already, skip. if ( initialized == true ) { return; } Assert.notNull(context, "Context"); // get resources Resources resources = context.getResources(); // read the file XmlPullParser parser = resources.getXml(XML_PATH_ID); // parser the xml XmlPullParserWrapper wrapper = new XmlPullParserWrapper(parser); try { node = new PullToRefreshConfigXmlParser(wrapper).parse(); // load extended xml XmlPullParser extendedXmlParser = ExtendedConfigXmlParserFactory.createParser(context); if ( extendedXmlParser != null) { XmlPullParserWrapper extendedXmlWrapper = new XmlPullParserWrapper(extendedXmlParser); // NOTE : if some exception is thrown from PullToRefreshConfigXmlParser, Loading extended xml will be skipped. PullToRefreshNode extendedNode = new PullToRefreshConfigXmlParser(extendedXmlWrapper).parse(); node.extendProperties(extendedNode); } } catch (XmlPullParserException e) { Log.d(LOG_TAG, "It has failed to parse the xmlpullparser xml.", e); } catch (IOException e) { Log.d(LOG_TAG, "It has failed to parse the xmlpullparser xml.\n ", e); } // Intialization can be done whether reading XML has failed or not! initialized = true; } /** * @param layoutCode Layout name * @return Layout Class name ( ex: com.handmark.pulltorefresh.library.internal.FlipLoadingLayout ) */ public String getLoadingLayoutClazzName(String layoutCode) { assertInitialized(); if ( isNodeNull() ) { return null; } return node.getLoadingLayoutClazzName(layoutCode); } /** * @param layoutCode Layout name * @return Layout Class name ( ex: com.handmark.pulltorefresh.library.internal.DefaultLoadingLayout ) */ public String getIndicatorLayoutClazzName(String layoutCode) { assertInitialized(); if ( isNodeNull() ) { return null; } return node.getIndicatorLayoutClazzName(layoutCode); } /** * @param layoutCode Layout name * @return Layout Class name ( ex: com.handmark.pulltorefresh.library.internal.DefaultGoogleStyleViewLayout ) */ public String getGoogleStyleViewLayoutClazzName(String layoutCode) { assertInitialized(); if ( isNodeNull() ) { return null; } return node.getGoogleStyleViewLayoutClazzName(layoutCode); } /** * @param layoutCode Layout name * @return Layout Class name ( ex: com.handmark.pulltorefresh.library.internal.DefaultGoogleStyleProgressLayout ) */ public String getGoogleStyleProgressLayoutClazzName(String layoutCode) { assertInitialized(); if ( isNodeNull() ) { return null; } return node.getGoogleStyleProgressLayoutClazzName(layoutCode); } /** * @return true if {@code node} is null */ private boolean isNodeNull() { return node == null; } /** * @return true if {@link #init(Context)} method has not been called */ private boolean notInitialized() { return !initialized; } /** * @return throw an exception if {@link #init(Context)} method has not been called */ private void assertInitialized() { if ( notInitialized() ) { throw new IllegalStateException(PullToRefreshXmlConfiguration.class.getName()+" has not initialized. Call init() method first."); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/configuration/xml/XmlPullNode.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.configuration.xml; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import com.handmark.pulltorefresh.library.internal.Assert; /** * {@code XmlPullNode} is used for parsing xml as a node tree.
* If you implement {@link XmlPullNode#XmlPullNodeCallback} and pass that on to this class,
{@link XmlPullNodeParser} calls {@link XmlPullNode#XmlPullNodeCallback#process(XmlPullParser)} when it has found this current node during parse.
* When it has found a child node of current node' children, and if the child node has been added in current node as child XmlPullNode, {@link XmlPullNodeParser} continues parsing at the child. * @author Wonjun Kim * */ class XmlPullNode { /** * Unlimited repeat value
* If you add a child (by calling {@link #addChildNode(XmlPullNode, int)} with setting repeat limit and the limit is {@code INFINITE}, the limit becomes meaningless.
*/ public static final int INFINITE = -1; /** * Map which store children
* child's node name can have upper case or lower. all is the same whether that is upper or lower. */ private final Map children = new TreeMap( String.CASE_INSENSITIVE_ORDER); /** * Current node's name */ private final String tagName; /** * Callback
{@code XmlPullNodeCallback.process(XmlPullParser)} method is called when this node has found in xml. */ private final XmlPullNodeCallback callback; /** * Default callback. This doesn't any kind of action. */ private static final XmlPullNodeCallback nullCallback = new XmlPullNodeCallback() { @Override public void process(XmlPullParser parser) { // do nothing } }; /** * Default Constructor (only set a node name) * @param tagName Node name. this must not be null */ public XmlPullNode(String tagName) { this(tagName, null); } /** * Constructor with {@code tagName} and {@code callback} * @param tagName Node name. this must not be null * @param callback */ public XmlPullNode(String tagName, XmlPullNodeCallback callback) { Assert.notNull(tagName, "Tag Name"); this.tagName = tagName; this.callback = (callback == null) ? nullCallback : callback; } /** * @return Current node name */ public String getName() { return tagName; } /** * Add a child node into this node without repeat limit
* NOTE: When it has found a child node of current node' children, and if the child node has been added in current node as child XmlPullNode, {@link XmlPullNodeParser} continues parsing at the child. * @param node Child node to add * @return true if it is successful to add */ public boolean addChildNode(XmlPullNode node) { return addChildNode(node, INFINITE); } /** * Add a child node into this node with repeat limit
* NOTE: When it has found a child node of current node' children, and if the child node has been added in current node as child XmlPullNode, {@link XmlPullNodeParser} continues parsing at the child. * @param node Child node to add * @param repeatLimit Repeat limit. if a child repeats over the limit, an error occurs during parse. * @return true if it is successful to add */ public boolean addChildNode(XmlPullNode node, int repeatLimit) { XmlPullNodeContainer pullNodeContainer = children.get(node.getName()); if (pullNodeContainer != null) { return false; } children.put(node.getName(), new XmlPullNodeContainer(node, repeatLimit)); return true; } /** * Get a child of this node's chidren * @param tagName Child node name to find * @return Child node if the child has been found or null * @throws XmlPullParserException */ public XmlPullNode getChild(String tagName) throws XmlPullParserException { XmlPullNodeContainer pullNodeContainer = children.get(tagName); if (pullNodeContainer == null) { return null; } return pullNodeContainer.takeXmlPullNode(); } /** * @return Callback instance */ public XmlPullNodeCallback getCallback() { return callback; } /** * Callback to process some action for {@code XmlPullNode}.
* * NOTE: If you implement {@link XmlPullNode#XmlPullNodeCallback} and pass that on to {@code XmlPullNode} class,
{@link XmlPullNodeParser} calls {@link XmlPullNode#XmlPullNodeCallback#process(XmlPullParser)} when it has found this the node during parse. * @author Wonjun Kim * */ public static interface XmlPullNodeCallback { /** * @param parser {@code XmlPullParser} instance which are parsing xml. WARNING: Must carefully use {@code parser}. using {@code parser} can affect to cause an parsing error. Because {@code parser} can easily go to some wrong position during usage. * @throws XmlPullParserException * @throws IOException */ void process(XmlPullParser parser) throws XmlPullParserException, IOException; } /** * {@XmlPullNodeContainer} is a container for saving {@code repeatLimit}. And check the limit to occur an error.
* NOTE : Justly, this Class is not thread-safe. :) * @author Wonjun Kim * */ private static class XmlPullNodeContainer { /** * Real {@code XmlPullnode} instance */ private XmlPullNode node; /** * Repetition limit value decreasing one by which a node occurs at a time */ private int repeatLimit; /** * Default Constructor * @param node Infinite repeat {@code XmlPullNode} instance */ public XmlPullNodeContainer(XmlPullNode node) { this(node, INFINITE); } /** * Constructor with {@code node} and {@code repeatLimit} * @param node Finite repeat (only if you set positive {@code repeatLimit}) {@code XmlPullNode} instance * @param repeatLimit Repeat limit value. This must be positive. */ public XmlPullNodeContainer(XmlPullNode node, int repeatLimit) { Assert.notNull(node, "XmlPullNode"); this.node = node; this.repeatLimit = repeatLimit; } /** * Return {@code XmlPullNode} instance or throw a limit error * @return {@code XmlPullNode} instance if the node repeats under the limit * @throws XmlPullParserException if a number of repetitions reaches the limit */ public XmlPullNode takeXmlPullNode() throws XmlPullParserException { if (repeatLimit > 0) { decreaseRepeatLimit(); return node; } // throw an error if (repeatLimit == 0) { String tagName = node.getName(); throw new XmlPullParserException("Tag '" + tagName + "' should not have more " + repeatLimit + " nodes."); } // if infinite repeats, return node; } /** * one step forward to the limit error! */ private void decreaseRepeatLimit() { --repeatLimit; } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/configuration/xml/XmlPullNodeParser.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.configuration.xml; import java.io.IOException; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import android.util.Log; import com.handmark.pulltorefresh.configuration.xml.XmlPullParserWrapper.DocumentState; import com.handmark.pulltorefresh.library.internal.Assert; /** * * {@code XmlPullNode}-based Parser using XmlPullParser
* When you override this class, you must define parse strategies, and return the root node (in {@link #generateRootNode()} of {@code XmlPullNode}s containing each parse strategy, * and return the result (in {@link #getResult()} for which provide that to client after parse. * @author Wonjun Kim * @param Result type */ abstract class XmlPullNodeParser { private final XmlPullParserWrapper parser; private final XmlPullNode rootNode; /** * this flag prevents duplicate parse. */ private boolean isParsed = false; /** * @param parser which has not been read yet.
throw {@code NullPointerException} if {@code parser} is null */ public XmlPullNodeParser(XmlPullParserWrapper parser) { Assert.notNull(parser, "XmlPullParser"); this.parser = parser; this.rootNode = generateRootNode(); } /** * @return entry point for {@code XmlPullNode}-based parse */ protected abstract XmlPullNode generateRootNode(); /** * Parse the data and return {@code } type result
* even if you call this methods several times, parsing happens once and no more duplicate parse * @return parsed data * @throws XmlPullParserException * @throws IOException */ public final R parse() throws XmlPullParserException, IOException { // avoid duplicate parse if ( isParsed == true ) { return getResult(); } // First, Find the root node. DocumentState documentState; String rootName = rootNode.getName(); documentState = parser.nextStartTagByName(rootName); if ( documentState.END.equals(documentState)) { throw new XmlPullParserException(rootName + " tag has not found."); } // deeply parsing parseInternal(rootNode); isParsed = true; return getResult(); } /** * Return a result after parse
Be called from {@link #parse()} method * @return result value to return after parsing is done */ protected abstract R getResult(); /** * Call {@link XmlPullNode.XmlPullNodeCallback#process(XmlPullParser)} and parse child nodes of current node * * @param currentNode target of which call a callback and parse children * @throws XmlPullParserException * @throws IOException */ private void parseInternal(XmlPullNode currentNode) throws XmlPullParserException, IOException { // NOTE : too many permissions to node currentNode.getCallback().process(parser); while ( true ) { // if document is end during finding the end tag of this current node, it throws the exception below. if ( parser.isEndDocument() ) { throw new XmlPullParserException("XML document is invalid."); } // if the end tag is found, parsing this scope is being ended. if ( parser.isEndTag() && parser.matchCurrentTagName(currentNode.getName())) { break; } // get next tag parser.next(); // when a child node is found, deeply parsing if ( parser.isStartTag() ) { String currentTagName = parser.getName(); XmlPullNode childNode = currentNode.getChild(currentTagName); if ( childNode != null ) { // recursively! parseInternal(childNode); } } } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/configuration/xml/XmlPullParserWrapper.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.configuration.xml; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import com.handmark.pulltorefresh.library.internal.Assert; /** *

* {@code XmlPullParser} Wrapper
* This class provide util methods such as {@link #nextStartTag()}, {@link #isStartTag()} , and so on *

* @author Wonjun Kim * */ class XmlPullParserWrapper implements XmlPullParser { /** * {@code XmlPullParserWrapper} call this {@code parser} as delegatee */ private final XmlPullParser parser; /** *

* Need {@code XmlPullParser}
* If {@code parser} is null, It throws {@code NullPointerException} *

* @param parser delegated {@link XmlPullParser} */ public XmlPullParserWrapper(XmlPullParser parser) { Assert.notNull(parser, "XmlPullParser"); this.parser = parser; } /** *

* {@code DocumentState} represents current state (instead of event type) of a document which the parser reads.
*

* @author Wonjun Kim * */ public static enum DocumentState { /** * READ : Document is readable yet */ READ, /** * FOUNDTAG : Document is readable yet and current event is a tag type */ FOUNDTAG, /** * END : Document is completely read. There is no more token */ END; } /** * @return true if current type is {@code START_TAG} * @throws XmlPullParserException */ public boolean isStartTag() throws XmlPullParserException { return getEventType() == START_TAG; } /** * @return true if current type is {@code END_TAG} * @throws XmlPullParserException */ public boolean isEndTag() throws XmlPullParserException { return getEventType() == END_TAG; } /** * @return true if current type is {@code TEXT} * @throws XmlPullParserException */ public boolean isText() throws XmlPullParserException { return getEventType() == TEXT; } /** * @return true if current type is {@code START_DOCUMENT} * @throws XmlPullParserException */ public boolean isStartDocument() throws XmlPullParserException { return getEventType() == START_DOCUMENT; } /** * @return true if current type is {@code END_DOCUMENT} * @throws XmlPullParserException */ public boolean isEndDocument() throws XmlPullParserException { return getEventType() == END_DOCUMENT; } /** * @return true if current type is {@code COMMENT} * @throws XmlPullParserException */ public boolean isComment() throws XmlPullParserException { return getEventType() == COMMENT; } /** *

* Find next start tag by calling {@link XmlPullParser#next()} again and again * If the parser reaches the end of a document, this method will returns {@code DocumentState.END} *

* @return {@link DocumentState.FOUNDTAG} if start tag has been found * {@link DocumentState.END} if the parser reaches the end of a document * @throws XmlPullParserException * @throws IOException */ public DocumentState nextStartTag() throws XmlPullParserException, IOException { while (true) { int evt = next(); if (evt == XmlPullParser.START_TAG) { return DocumentState.FOUNDTAG; } if (evt == XmlPullParser.END_DOCUMENT) { return DocumentState.END; } } } /** *

* Find next start tag whose name is same as {@code tagName} by calling {@link XmlPullParser#next()} again and again * If the parser reaches the end of a document, this method will returns {@code DocumentState.END} *

* @param tagName Tag name you want to find * @return {@link DocumentState.FOUNDTAG} if start tag has been found * {@link DocumentState.END} if the parser reaches the end of a document * @throws XmlPullParserException * @throws IOException */ public DocumentState nextStartTagByName(String tagName) throws XmlPullParserException, IOException { while (true) { DocumentState documentState = nextStartTag(); if (documentState.equals(DocumentState.END)) { return documentState; } if (matchCurrentTagName(tagName)) { break; } } return DocumentState.FOUNDTAG; } /** *

* Find next end tag by calling {@link XmlPullParser#next()} again and again * If the parser reaches the end of a document, this method will returns {@code DocumentState.END} *

* @return {@link DocumentState.FOUNDTAG} if end tag has been found * {@link DocumentState.END} if the parser reaches the end of a document * @throws XmlPullParserException * @throws IOException */ public DocumentState nextEndTag() throws XmlPullParserException, IOException { while (true) { int evt = next(); if (evt == XmlPullParser.END_TAG) { return DocumentState.FOUNDTAG; } if (evt == XmlPullParser.END_DOCUMENT) { return DocumentState.END; } } } /** *

* Find next end tag whose name is same as {@code tagName} by calling {@link XmlPullParser#next()} again and again * If the parser reaches the end of a document, this method will returns {@code DocumentState.END} *

* @param tagName Tag name you want to find * @return {@link DocumentState.FOUNDTAG} if start tag has been found * {@link DocumentState.END} if the parser reaches the end of a document * @throws XmlPullParserException * @throws IOException */ public DocumentState nextEndTagByName(String tagName) throws XmlPullParserException, IOException { while (true) { DocumentState documentState = nextEndTag(); if (documentState.equals(DocumentState.END)) { return documentState; } if (matchCurrentTagName(tagName)) { break; } } return DocumentState.FOUNDTAG; } /** * Check that current tag name is same as {@code tagName} * * @param tagName Tag name you want to check whether current tag is same as * @return true if current tag name is same * @throws XmlPullParserException * @throws IOException */ public boolean matchCurrentTagName(String tagName) { Assert.notNull(tagName, "Tag Name"); return getName().equals(tagName); } /** Wrapper method for {@link XmlPullParser#setFeature(String, boolean)} */ @Override public void setFeature(String name, boolean state) throws XmlPullParserException { parser.setFeature(name, state); } /** Wrapper method for {@link XmlPullParser#getFeature(String)} */ @Override public boolean getFeature(String name) { return parser.getFeature(name); } /** Wrapper method for {@link XmlPullParser#setProperty(String, Object)} */ @Override public void setProperty(String name, Object value) throws XmlPullParserException { parser.setProperty(name, value); } /** Wrapper method for {@link XmlPullParser#getProperty(String)} */ @Override public Object getProperty(String name) { return parser.getProperty(name); } /** Wrapper method for {@link XmlPullParser#setInput(Reader)} */ @Override public void setInput(Reader in) throws XmlPullParserException { parser.setInput(in); } /** Wrapper method for {@link XmlPullParser#setInput(InputStream, String)} */ @Override public void setInput(InputStream inputStream, String inputEncoding) throws XmlPullParserException { parser.setInput(inputStream, inputEncoding); } /** Wrapper method for {@link XmlPullParser#getInputEncoding()} */ @Override public String getInputEncoding() { return parser.getInputEncoding(); } /** Wrapper method for {@link XmlPullParser#defineEntityReplacementText(String, String)} */ @Override public void defineEntityReplacementText(String entityName, String replacementText) throws XmlPullParserException { parser.defineEntityReplacementText(entityName, replacementText); } /** Wrapper method for {@link XmlPullParser#getNamespaceCount(int)} */ @Override public int getNamespaceCount(int depth) throws XmlPullParserException { // TODO Auto-generated method stub return parser.getNamespaceCount(depth); } /** Wrapper method for {@link XmlPullParser#getNamespacePrefix(int)} */ @Override public String getNamespacePrefix(int pos) throws XmlPullParserException { return parser.getNamespacePrefix(pos); } /** Wrapper method for {@link XmlPullParser#getNamespaceUri(int)} */ @Override public String getNamespaceUri(int pos) throws XmlPullParserException { return parser.getNamespaceUri(pos); } /** Wrapper method for {@link XmlPullParser#getNamespace(String)} */ @Override public String getNamespace(String prefix) { return parser.getNamespace(prefix); } /** Wrapper method for {@link XmlPullParser#getDepth()} */ @Override public int getDepth() { return parser.getDepth(); } /** Wrapper method for {@link XmlPullParser#getPositionDescription()} */ @Override public String getPositionDescription() { return parser.getPositionDescription(); } /** Wrapper method for {@link XmlPullParser#getLineNumber()} */ @Override public int getLineNumber() { return parser.getLineNumber(); } /** Wrapper method for {@link XmlPullParser#getColumnNumber()} */ @Override public int getColumnNumber() { return parser.getColumnNumber(); } /** Wrapper method for {@link XmlPullParser#isWhiteSpace()} */ @Override public boolean isWhitespace() throws XmlPullParserException { return parser.isWhitespace(); } /** Wrapper method for {@link XmlPullParser#getText()} */ @Override public String getText() { return parser.getText(); } /** Wrapper method for {@link XmlPullParser#getTextCharacters(int[])} */ @Override public char[] getTextCharacters(int[] holderForStartAndLength) { return parser.getTextCharacters(holderForStartAndLength); } /** Wrapper method for {@link XmlPullParser#getNamespace()} */ @Override public String getNamespace() { return parser.getNamespace(); } /** Wrapper method for {@link XmlPullParser#getName()} */ @Override public String getName() { return parser.getName(); } /** Wrapper method for {@link XmlPullParser#getPrefix()} */ @Override public String getPrefix() { return parser.getPrefix(); } /** Wrapper method for {@link XmlPullParser#isEmptyElementTag()} */ @Override public boolean isEmptyElementTag() throws XmlPullParserException { return parser.isEmptyElementTag(); } /** Wrapper method for {@link XmlPullParser#getAttributeCount()} */ @Override public int getAttributeCount() { return parser.getAttributeCount(); } /** Wrapper method for {@link XmlPullParser#getAttributeNamespace(int)} */ @Override public String getAttributeNamespace(int index) { return parser.getAttributeNamespace(index); } /** Wrapper method for {@link XmlPullParser#getAttributeName(int)} */ @Override public String getAttributeName(int index) { return parser.getAttributeName(index); } /** Wrapper method for {@link XmlPullParser#getAttributePrefix(int)} */ @Override public String getAttributePrefix(int index) { return parser.getAttributePrefix(index); } /** Wrapper method for {@link XmlPullParser#getAttributeType(int)} */ @Override public String getAttributeType(int index) { return parser.getAttributeType(index); } /** Wrapper method for {@link XmlPullParser#isAttributeDefault(int)} */ @Override public boolean isAttributeDefault(int index) { return parser.isAttributeDefault(index); } /** Wrapper method for {@link XmlPullParser#getAttributeValue(int)} */ @Override public String getAttributeValue(int index) { return parser.getAttributeValue(index); } /** Wrapper method for {@link XmlPullParser#getAttributeValue(String, String)} */ @Override public String getAttributeValue(String namespace, String name) { return parser.getAttributeValue(namespace, name); } /** Wrapper method for {@link XmlPullParser#getEventType()} */ @Override public int getEventType() throws XmlPullParserException { return parser.getEventType(); } /** Wrapper method for {@link XmlPullParser#next()} */ @Override public int next() throws XmlPullParserException, IOException { return parser.next(); } /** Wrapper method for {@link XmlPullParser#nextToken()} */ @Override public int nextToken() throws XmlPullParserException, IOException { return parser.nextToken(); } /** Wrapper method for {@link XmlPullParser#require(int, String, String)} */ @Override public void require(int type, String namespace, String name) throws XmlPullParserException, IOException { parser.require(type, namespace, name); } /** Wrapper method for {@link XmlPullParser#nextTag()} */ @Override public String nextText() throws XmlPullParserException, IOException { return parser.nextText(); } /** Wrapper method for {@link XmlPullParser#nextTag()} */ @Override public int nextTag() throws XmlPullParserException, IOException { return parser.nextTag(); } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/AlphaAnimator.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation.AnimationListener; /** * AlphaAnimation Helper * Just supports fade-in and fade-out * @author Wonjun Kim * */ class AlphaAnimator { public static void fadein(View view, int duration) { fadein(view, duration, null); } public static void fadein(View view, int duration, AnimationListener listener) { animate(view, duration, listener, 0.0f, 1.0f); } public static void fadeout(View view, int duration) { fadeout(view, duration, null); } public static void fadeout(View view, int duration, AnimationListener listener) { animate(view, duration, listener, 1.0f, 0.0f); } private static void animate(View view, int duration, AnimationListener listener, float fromAlpha, float targetAlpha) { // Create new animation AlphaAnimation newAnimation = new AlphaAnimation(fromAlpha, targetAlpha); newAnimation.setDuration(duration); // Force fillAfter flag to be true newAnimation.setFillAfter(true); newAnimation.setAnimationListener(listener); // Start fading view.startAnimation(newAnimation); } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/GoogleStyleProgressLayout.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import android.content.Context; import android.content.res.TypedArray; import android.view.ViewGroup; import android.widget.FrameLayout; /** * Abstract class of Google style progress layout * You can override this class and implement specific layout, for example, {@see DefaultGoogleStyleProgressLayout}. * * @author Wonjun Kim * */ public abstract class GoogleStyleProgressLayout extends FrameLayout implements IGoogleStyleProgressLayout { public GoogleStyleProgressLayout(Context context, TypedArray attrs){ super(context); } /** * Set Y position of this layout by using margin property.
* If you don't want to set default y position given by {@code PullToRefreshBase}, you have to this method and customize it. */ public void setTopMargin(int height) { ViewGroup.LayoutParams params = getLayoutParams(); if ( params instanceof FrameLayout.LayoutParams ) { ((FrameLayout.LayoutParams) params).topMargin = height; } } /** * Create a specific {@code LayoutParams}.
* Pull To Refresh will add this layout with applying this {@code LayoutParams} to the layout * @return {@code LayoutParams} you implemented */ public FrameLayout.LayoutParams createLayoutParams() { return GoogleStyleProgressLayout.createDefaultLayoutParams(getContext()); } /** * Create a default specific {@code LayoutParams}.
* @param Context * @return Default {@code LayoutParams} */ public static FrameLayout.LayoutParams createDefaultLayoutParams(Context context) { @SuppressWarnings("deprecation") FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); return params; } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/GoogleStyleProgressLayoutFactory.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import android.content.Context; import android.content.res.TypedArray; import android.util.Log; import android.view.View; import com.handmark.pulltorefresh.configuration.xml.PullToRefreshXmlConfiguration; import com.handmark.pulltorefresh.library.internal.DefaultGoogleStyleProgressLayout; import com.handmark.pulltorefresh.library.GoogleStyleProgressLayout; /** * Factory which creates google style progress layouts *
Google style progress layouts must be listed in pulltorefresh.xml as "PullToRefresh/GoogleStyleProgressLayouts/layout" nodes * @author Wonjun Kim */ class GoogleStyleProgressLayoutFactory { private static final String LOG_TAG = GoogleStyleProgressLayoutFactory.class .getSimpleName(); /** * Create the class token matched by {@code layoutCode} * @param layoutCode Google style progress layout code, which must be defined in pulltorefresh.xml * @return Class token which is matched by {@code layoutCode}, or the class token of {@code RotateGoogleStyleProgressLayout} instance if not */ public static Class createGoogleStyleProgressLayoutClazzByLayoutCode(String layoutCode) { String clazzName = PullToRefreshXmlConfiguration.getInstance().getGoogleStyleProgressLayoutClazzName(layoutCode); return createGoogleStyleProgressLayoutClazz(clazzName); } /** * Create a {@code GoogleStyleProgressLayout} instance matched by {@code clazz} token * @param layoutCode Google style progress layout code, which must be defined in pulltorefresh.xml * @param context * @return {@code GoogleStyleProgressLayout} instance if the class matched by {@code layoutCode} exists, or {@code RotateGoogleStyleProgressLayout} instance if not */ @SuppressWarnings("unchecked") public static Class createGoogleStyleProgressLayoutClazz( String clazzName) { Class googleStyleProgressLayoutClazz = null; if ( clazzName == null ) { googleStyleProgressLayoutClazz = DefaultGoogleStyleProgressLayoutFactory.createGoogleStyleProgressLayoutClazz(clazzName); return googleStyleProgressLayoutClazz; } try { googleStyleProgressLayoutClazz = (Class) Class.forName(clazzName); } catch (ClassNotFoundException e) { Log.e(LOG_TAG,"The google style progress layout you have chosen class has not been found.", e); googleStyleProgressLayoutClazz = DefaultGoogleStyleProgressLayoutFactory.createGoogleStyleProgressLayoutClazz(clazzName); } return googleStyleProgressLayoutClazz; } /** * Create a {@code GoogleStyleProgressLayout} instance matched by {@code layoutCode} * @param layoutCode Google style progress layout code, which must be defined in pulltorefresh.xml * @param context * @return {@code GoogleStyleProgressLayout} instance if the class matched by {@code layoutCode} exists, or {@code DefaultGoogleStyleProgressLayout} instance if not */ public static GoogleStyleProgressLayout createGoogleStyleProgressLayout(String layoutCode, Context context, TypedArray attrs) { Class clazz = createGoogleStyleProgressLayoutClazz(layoutCode); return createGoogleStyleProgressLayout(clazz, context, attrs); } /** * Create a {@code GoogleStyleProgressLayout} instance matched by {@code clazz} token * @param layoutCode Google style progress layout code, which must be defined in pulltorefresh.xml * @param context * @return {@code GoogleStyleProgressLayout} instance if the class matched by {@code layoutCode} exists, or {@code DefaultGoogleStyleProgressLayout} instance if not */ public static GoogleStyleProgressLayout createGoogleStyleProgressLayout( Class clazz, Context context, TypedArray attrs) { GoogleStyleProgressLayout layout = null; // Prevent NullPointerException if ( clazz == null ) { Log.i(LOG_TAG, "The Class token of the GoogleStyleProgressLayout is missing. Default google style progress layout will be used."); clazz = DefaultGoogleStyleProgressLayoutFactory.createGoogleStyleProgressLayoutClazz(""); } layout = tryNewInstance(clazz, context, attrs); // If trying to create new instance has failed, if (layout == null) { layout = DefaultGoogleStyleProgressLayoutFactory.createGoogleStyleProgressLayout(clazz, context, attrs); } layout.setVisibility(View.INVISIBLE); return layout; } private static GoogleStyleProgressLayout tryNewInstance( Class clazz, Context context, TypedArray attrs) { GoogleStyleProgressLayout layout = null; try { Constructor constructor = clazz .getConstructor(Context.class, TypedArray.class); layout = (GoogleStyleProgressLayout) constructor.newInstance(context, attrs); } catch (IllegalArgumentException e) { Log.e(LOG_TAG, "The google style progress layout has failed to be created. ", e); } catch (InvocationTargetException e) { Log.e(LOG_TAG, "The google style progress layout has failed to be created. ", e); } catch (SecurityException e) { Log.e(LOG_TAG, "The google style progress layout has failed to be created. ", e); } catch (NoSuchMethodException e) { Log.e(LOG_TAG, "The google style progress layout has failed to be created. ", e); } catch (InstantiationException e) { Log.e(LOG_TAG, "The google style progress layout has failed to be created. ", e); } catch (IllegalAccessException e) { Log.e(LOG_TAG, "The google style progress layout has failed to be created. ", e); } catch (NullPointerException e) { Log.e(LOG_TAG, "The google style progress layout has failed to be created. ", e); } return layout; } /** * Factory which creates a default google style progress layout instance. This is used when {@code GoogleStyleProgressLayoutFactory} fails to create a instance * @author Wonjun Kim * */ private static class DefaultGoogleStyleProgressLayoutFactory { /** * @param clazzName This class name is being ignored * @return Class token of {@code DefaultGoogleStyleProgressLayout} */ public static Class createGoogleStyleProgressLayoutClazz( String clazzName) { return DefaultGoogleStyleProgressLayout.class; } /** * @param clazz Class token is being ignored. * @param context * @return {@code DefaultGoogleStyleProgressLayout} instance */ public static GoogleStyleProgressLayout createGoogleStyleProgressLayout( Class clazz, Context context, TypedArray attrs) { return new DefaultGoogleStyleProgressLayout(context, attrs); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/GoogleStyleViewLayout.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import android.content.Context; import android.content.res.TypedArray; import android.view.ViewGroup; import android.widget.FrameLayout; /** * Abstract class of Google style view layout * You can override this class and implement specific layout like {@link LoadingLayout} style. * @author Wonjun Kim * */ public abstract class GoogleStyleViewLayout extends FrameLayout implements IGoogleStyleViewLayout { public GoogleStyleViewLayout(Context context, TypedArray attrs) { super(context); } public void setHeight(int height) { ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams(); lp.height = height; requestLayout(); } public void setWidth(int width) { ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams(); lp.width = width; requestLayout(); } public int getContentSize() { return getHeight(); } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/GoogleStyleViewLayoutFactory.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import android.content.Context; import android.content.res.TypedArray; import android.util.Log; import android.view.View; import com.handmark.pulltorefresh.configuration.xml.PullToRefreshXmlConfiguration; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation; import com.handmark.pulltorefresh.library.internal.DefaultGoogleStyleViewLayout; import com.handmark.pulltorefresh.library.GoogleStyleViewLayout; /** * Factory which creates google style view layouts *
Google style view layouts must be listed in pulltorefresh.xml as "PullToRefresh/GoogleStyleViewLayouts/layout" nodes * @author Wonjun Kim */ class GoogleStyleViewLayoutFactory { private static final String LOG_TAG = GoogleStyleViewLayoutFactory.class .getSimpleName(); /** * Create the class token matched by {@code layoutCode} * @param layoutCode Google style view layout code, which must be defined in pulltorefresh.xml * @return Class token which is matched by {@code layoutCode}, or the class token of {@code RotateGoogleStyleViewLayout} instance if not */ public static Class createGoogleStyleViewLayoutClazzByLayoutCode(String layoutCode) { String clazzName = PullToRefreshXmlConfiguration.getInstance().getGoogleStyleViewLayoutClazzName(layoutCode); return createGoogleStyleViewLayoutClazz(clazzName); } /** * Create a {@code GoogleStyleViewLayout} instance matched by {@code clazz} token * @param layoutCode Google style view layout code, which must be defined in pulltorefresh.xml * @param context * @return {@code GoogleStyleViewLayout} instance if the class matched by {@code layoutCode} exists, or {@code RotateGoogleStyleViewLayout} instance if not */ @SuppressWarnings("unchecked") public static Class createGoogleStyleViewLayoutClazz( String clazzName) { Class googleStyleViewLayoutClazz = null; if ( clazzName == null ) { googleStyleViewLayoutClazz = DefaultGoogleStyleViewLayoutFactory.createGoogleStyleViewLayoutClazz(clazzName); return googleStyleViewLayoutClazz; } try { googleStyleViewLayoutClazz = (Class) Class.forName(clazzName); } catch (ClassNotFoundException e) { Log.e(LOG_TAG,"The google style view layout you have chosen class has not been found.", e); googleStyleViewLayoutClazz = DefaultGoogleStyleViewLayoutFactory.createGoogleStyleViewLayoutClazz(clazzName); } return googleStyleViewLayoutClazz; } /** * Create a {@code GoogleStyleViewLayout} instance matched by {@code layoutCode} * @param layoutCode Google style view layout code, which must be defined in pulltorefresh.xml * @param context * @return {@code GoogleStyleViewLayout} instance if the class matched by {@code layoutCode} exists, or {@code DefaultGoogleStyleViewLayout} instance if not */ public static GoogleStyleViewLayout createGoogleStyleViewLayout(String layoutCode, Context context, TypedArray attrs) { Class clazz = createGoogleStyleViewLayoutClazz(layoutCode); return createGoogleStyleViewLayout(clazz, context, attrs); } /** * Create a {@code GoogleStyleViewLayout} instance matched by {@code clazz} token * @param layoutCode Google style view layout code, which must be defined in pulltorefresh.xml * @param context * @return {@code GoogleStyleViewLayout} instance if the class matched by {@code layoutCode} exists, or {@code DefaultGoogleStyleViewLayout} instance if not */ public static GoogleStyleViewLayout createGoogleStyleViewLayout( Class clazz, Context context, TypedArray attrs) { GoogleStyleViewLayout layout = null; // Prevent NullPointerException if ( clazz == null ) { Log.i(LOG_TAG, "The Class token of the GoogleStyleViewLayout is missing. Default google style view layout will be used."); clazz = DefaultGoogleStyleViewLayoutFactory.createGoogleStyleViewLayoutClazz(""); } layout = tryNewInstance(clazz, context, attrs); // If trying to create new instance has failed, if (layout == null) { layout = DefaultGoogleStyleViewLayoutFactory.createGoogleStyleViewLayout(clazz, context, attrs); } layout.setVisibility(View.INVISIBLE); return layout; } private static GoogleStyleViewLayout tryNewInstance( Class clazz, Context context, TypedArray attrs) { GoogleStyleViewLayout layout = null; try { Constructor constructor = clazz .getConstructor(Context.class, TypedArray.class); layout = (GoogleStyleViewLayout) constructor.newInstance(context, attrs); } catch (IllegalArgumentException e) { Log.e(LOG_TAG, "The google style view layout has failed to be created. ", e); } catch (InvocationTargetException e) { Log.e(LOG_TAG, "The google style view layout has failed to be created. ", e); } catch (SecurityException e) { Log.e(LOG_TAG, "The google style view layout has failed to be created. ", e); } catch (NoSuchMethodException e) { Log.e(LOG_TAG, "The google style view layout has failed to be created. ", e); } catch (InstantiationException e) { Log.e(LOG_TAG, "The google style view layout has failed to be created. ", e); } catch (IllegalAccessException e) { Log.e(LOG_TAG, "The google style view layout has failed to be created. ", e); } catch (NullPointerException e) { Log.e(LOG_TAG, "The google style view layout has failed to be created. ", e); } return layout; } /** * Factory which creates a default google style view layout instance. This is used when {@code GoogleStyleViewLayoutFactory} fails to create a instance * @author Wonjun Kim * */ private static class DefaultGoogleStyleViewLayoutFactory { /** * @param clazzName This class name is being ignored * @return Class token of {@code DefaultGoogleStyleViewLayout} */ public static Class createGoogleStyleViewLayoutClazz( String clazzName) { return DefaultGoogleStyleViewLayout.class; } /** * @param clazz Class token is being ignored. * @param context * @return {@code DefaultGoogleStyleViewLayout} instance */ public static GoogleStyleViewLayout createGoogleStyleViewLayout( Class clazz, Context context, TypedArray attrs) { return new DefaultGoogleStyleViewLayout(context, attrs); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/IGoogleStyleProgressLayout.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; /** * Marker interface for Google style progress layout * @author Wonjun Kim * */ public interface IGoogleStyleProgressLayout extends IPullToRefreshConsumer { } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/IGoogleStyleViewLayout.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; /** * Marker interface for Google style progress layout * @author Wonjun Kim * */ public interface IGoogleStyleViewLayout extends IPullToRefreshConsumer { } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/IIndicatorLayout.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import com.handmark.pulltorefresh.library.internal.IndicatorLayout; /** * Indicator layout which react pulling or releasing of Pull To Refresh *
* NOTE : To make new Indicator layout, You have to override {@link IndicatorLayout} instead of IIndicatorLayout. *
Because {@link PullToRefreshAdapterViewBase} uses indicator layouts as a kind of View component. {@link IndicatorLayout} is a descendant class of {@code View}. * * @author Wonjun Kim */ public interface IIndicatorLayout { /** * Show the Indicator Layout */ public void show(); /** * Hide the Indicator Layout */ public void hide(); /** * Check whether this indicator layout is being shown or not * @return true if the indicator layout is visible now */ public boolean isVisible(); /** * Make a Action when "PullToRefresh" event has been fired */ public void pullToRefresh(); /** * Make a Action when "ReleaseToRefresh" event has been fired */ public void releaseToRefresh(); } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/ILoadingLayout.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import android.graphics.Typeface; import android.graphics.drawable.Drawable; public interface ILoadingLayout { /** * Set the Last Updated Text. This displayed under the main label when * Pulling * * @param label - Label to set */ public void setLastUpdatedLabel(CharSequence label); /** * Set the drawable used in the loading layout. This is the same as calling * setLoadingDrawable(drawable, Mode.BOTH) * * @param drawable - Drawable to display */ public void setLoadingDrawable(Drawable drawable); /** * Set Text to show when the Widget is being Pulled * setPullLabel(releaseLabel, Mode.BOTH) * * @param pullLabel - CharSequence to display */ public void setPullLabel(CharSequence pullLabel); /** * Set Text to show when the Widget is refreshing * setRefreshingLabel(releaseLabel, Mode.BOTH) * * @param refreshingLabel - CharSequence to display */ public void setRefreshingLabel(CharSequence refreshingLabel); /** * Set Text to show when the Widget is being pulled, and will refresh when * released. This is the same as calling * setReleaseLabel(releaseLabel, Mode.BOTH) * * @param releaseLabel - CharSequence to display */ public void setReleaseLabel(CharSequence releaseLabel); /** * Set's the Sets the typeface and style in which the text should be * displayed. Please see * {@link android.widget.TextView#setTypeface(Typeface) * TextView#setTypeface(Typeface)}. */ public void setTextTypeface(Typeface tf); } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/IPullToRefresh.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import android.view.View; import android.view.animation.Interpolator; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnPullEventListener; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2; import com.handmark.pulltorefresh.library.PullToRefreshBase.State; public interface IPullToRefresh { /** * Demos the Pull-to-Refresh functionality to the user so that they are * aware it is there. This could be useful when the user first opens your * app, etc. The animation will only happen if the Refresh View (ListView, * ScrollView, etc) is in a state where a Pull-to-Refresh could occur by a * user's touch gesture (i.e. scrolled to the top/bottom). * * @return true - if the Demo has been started, false if not. */ @Deprecated public boolean demo(); /** * Get the mode that this view is currently in. This is only really useful * when using Mode.BOTH. * * @return Mode that the view is currently in */ public Mode getCurrentMode(); /** * Returns whether the Touch Events are filtered or not. If true is * returned, then the View will only use touch events where the difference * in the Y-axis is greater than the difference in the X-axis. This means * that the View will not interfere when it is used in a horizontal * scrolling View (such as a ViewPager). * * @return boolean - true if the View is filtering Touch Events */ public boolean getFilterTouchEvents(); /** * Returns a proxy object which allows you to call methods on all of the * LoadingLayouts (the Views which show when Pulling/Refreshing). *

* You should not keep the result of this method any longer than you need * it. * * @return Object which will proxy any calls you make on it, to all of the * LoadingLayouts. */ public ILoadingLayout getLoadingLayoutProxy(); /** * Returns a proxy object which allows you to call methods on the * LoadingLayouts (the Views which show when Pulling/Refreshing). The actual * LoadingLayout(s) which will be affected, are chosen by the parameters you * give. *

* You should not keep the result of this method any longer than you need * it. * * @param includeStart - Whether to include the Start/Header Views * @param includeEnd - Whether to include the End/Footer Views * @return Object which will proxy any calls you make on it, to the * LoadingLayouts included. */ public ILoadingLayout getLoadingLayoutProxy(boolean includeStart, boolean includeEnd); /** * Get the mode that this view has been set to. If this returns * Mode.BOTH, you can use getCurrentMode() to * check which mode the view is currently in * * @return Mode that the view has been set to */ public Mode getMode(); /** * Get the Wrapped Refreshable View. Anything returned here has already been * added to the content view. * * @return The View which is currently wrapped */ public T getRefreshableView(); /** * Get whether the 'Refreshing' View should be automatically shown when * refreshing. Returns true by default. * * @return - true if the Refreshing View will be show */ public boolean getShowViewWhileRefreshing(); /** * @return - The state that the View is currently in. */ public State getState(); /** * Whether Pull-to-Refresh is enabled * * @return enabled */ public boolean isPullToRefreshEnabled(); /** * Gets whether Overscroll support is enabled. This is different to * Android's standard Overscroll support (the edge-glow) which is available * from GINGERBREAD onwards * * @return true - if both PullToRefresh-OverScroll and Android's inbuilt * OverScroll are enabled */ public boolean isPullToRefreshOverScrollEnabled(); /** * Returns whether the Widget is currently in the Refreshing mState * * @return true if the Widget is currently refreshing */ public boolean isRefreshing(); /** * Stops the current refreshing view when the user needs to stop. * This method is only an alias to onRefreshComplete. * * */ public void stopRefreshing(); /** * Returns whether the widget has enabled scrolling on the Refreshable View * while refreshing. * * @return true if the widget has enabled scrolling while refreshing */ public boolean isScrollingWhileRefreshingEnabled(); /** * Mark the current Refresh as complete. Will Reset the UI and hide the * Refreshing View */ public void onRefreshComplete(); /** * Set the Touch Events to be filtered or not. If set to true, then the View * will only use touch events where the difference in the Y-axis is greater * than the difference in the X-axis. This means that the View will not * interfere when it is used in a horizontal scrolling View (such as a * ViewPager), but will restrict which types of finger scrolls will trigger * the View. * * @param filterEvents - true if you want to filter Touch Events. Default is * true. */ public void setFilterTouchEvents(boolean filterEvents); /** * Set the mode of Pull-to-Refresh that this view will use. * * @param mode - Mode to set the View to */ public void setMode(Mode mode); /** * Set OnPullEventListener for the Widget * * @param listener - Listener to be used when the Widget has a pull event to * propogate. */ public void setOnPullEventListener(OnPullEventListener listener); /** * Set OnRefreshListener for the Widget * * @param listener - Listener to be used when the Widget is set to Refresh */ public void setOnRefreshListener(OnRefreshListener listener); /** * Set OnRefreshListener for the Widget * * @param listener - Listener to be used when the Widget is set to Refresh */ public void setOnRefreshListener(OnRefreshListener2 listener); /** * Sets whether Overscroll support is enabled. This is different to * Android's standard Overscroll support (the edge-glow). This setting only * takes effect when running on device with Android v2.3 or greater. * * @param enabled - true if you want Overscroll enabled */ public void setPullToRefreshOverScrollEnabled(boolean enabled); /** * Sets the Widget to be in the refresh state. The UI will be updated to * show the 'Refreshing' view, and be scrolled to show such. */ public void setRefreshing(); /** * Sets the Widget to be in the refresh state. The UI will be updated to * show the 'Refreshing' view. * * @param doScroll - true if you want to force a scroll to the Refreshing * view. */ public void setRefreshing(boolean doScroll); /** * Sets the Animation Interpolator that is used for animated scrolling. * Defaults to a DecelerateInterpolator * * @param interpolator - Interpolator to use */ public void setScrollAnimationInterpolator(Interpolator interpolator); /** * By default the Widget disables scrolling on the Refreshable View while * refreshing. This method can change this behaviour. * * @param scrollingWhileRefreshingEnabled - true if you want to enable * scrolling while refreshing */ public void setScrollingWhileRefreshingEnabled(boolean scrollingWhileRefreshingEnabled); /** * A mutator to enable/disable whether the 'Refreshing' View should be * automatically shown when refreshing. * * @param showView */ public void setShowViewWhileRefreshing(boolean showView); } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/IPullToRefreshConsumer.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; /** * Interface for communations with {@code PullToRefreshBase} * @author Wonjun Kim * */ public interface IPullToRefreshConsumer { void reset(); void refreshing(); void releaseToRefresh(); void pullToRefresh(); void onPull(float scale); } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/IndicatorLayoutFactory.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import android.content.Context; import android.util.Log; import android.view.View; import com.handmark.pulltorefresh.configuration.xml.PullToRefreshXmlConfiguration; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.internal.IndicatorLayout; import com.handmark.pulltorefresh.library.internal.DefaultIndicatorLayout; import com.handmark.pulltorefresh.library.internal.Utils; /** * Factory which creates indicator layouts *
Indicator layouts must be listed in pulltorefresh.xml as "PullToRefresh/IndicatorLayouts/layout" nodes * @author Wonjun Kim */ public class IndicatorLayoutFactory { private static final String LOG_TAG = IndicatorLayoutFactory.class.getName(); /** * Create the class token matched by {@code layoutCode} * @param layoutCode Indicator layout code, which must be defined in pulltorefresh.xml * @return Class token which is matched by {@code layoutCode}, or the class token of {@code DefaultIndicatorLayout} instance if not */ public static Class createIndicatorLayoutClazzByLayoutCode(String layoutCode) { String clazzName = PullToRefreshXmlConfiguration.getInstance().getIndicatorLayoutClazzName(layoutCode); return createIndicatorLayoutClazz(clazzName); } /** * Create the class token matched by class name * @param clazzName Class name such as "com.handmark.pulltorefresh.library.internal.DefaultIndicatorLayout" * @return Class token if the class matched by class name exists, or the class token of {@code DefaultIndicatorLayout} instance if not */ @SuppressWarnings("unchecked") public static Class createIndicatorLayoutClazz(String clazzName) { Class clazz = null; if (clazzName == null) { clazz = DefaultIndicatorLayoutFactory.createIndicatorLayoutClazz(clazzName); return clazz; } try { clazz = (Class )Class.forName(clazzName); } catch (ClassNotFoundException e) { Log.e(LOG_TAG, "The indicator layout you have chosen class has not been found.", e); clazz = DefaultIndicatorLayoutFactory.createIndicatorLayoutClazz(clazzName); } return clazz; } /** * Create a {@code IndicatorLayout} instance matched by {@code layoutCode} * @param layoutCode Indicator layout code, which must be defined in pulltorefresh.xml * @param context * @param mode * @return {@code IndicatorLayout} instance if the class matched by {@code layoutCode} exists, or {@code DefaultIndicatorLayout} instance if not */ public static IndicatorLayout createIndicatorLayout(String layoutCode, Context context, PullToRefreshBase.Mode mode) { Class clazz = createIndicatorLayoutClazz(layoutCode); return createIndicatorLayout(clazz, context, mode); } /** * Create a {@code IndicatorLayout} instance matched by {@code clazz} token * @param clazz Indicator layout class token, which must be defined in pulltorefresh.xml * @param context * @param mode * @return {@code IndicatorLayout} instance if the class matched by {@code layoutCode} exists, or {@code DefaultIndicatorLayout} instance if not */ public static IndicatorLayout createIndicatorLayout( Class clazz, Context context, Mode mode) { IndicatorLayout layout = null; // Prevent NullPointerException if ( clazz == null ) { Log.i(LOG_TAG, "The Class token of the Indicator Layout is missing. Default Indicator Layout will be used."); clazz = DefaultIndicatorLayoutFactory.createIndicatorLayoutClazz(""); } layout = tryNewInstance(clazz, context, mode); // If trying to create new instance has failed, if (layout == null) { layout = DefaultIndicatorLayoutFactory.createIndicatorLayout(clazz, context, mode); } layout.setVisibility(View.INVISIBLE); return layout; } private static IndicatorLayout tryNewInstance( Class clazz, Context context, Mode mode) { IndicatorLayout layout = null; try { Constructor constructor = clazz .getConstructor(Context.class, Mode.class); layout = (IndicatorLayout) constructor.newInstance(context, mode); } catch (IllegalArgumentException e) { Log.e(LOG_TAG, "The indicator layout has failed to be created. ", e); } catch (InvocationTargetException e) { Log.e(LOG_TAG, "The indicator layout has failed to be created. ", e); } catch (SecurityException e) { Log.e(LOG_TAG, "The indicator layout has failed to be created. ", e); } catch (NoSuchMethodException e) { Log.e(LOG_TAG, "The indicator layout has failed to be created. ", e); } catch (InstantiationException e) { Log.e(LOG_TAG, "The indicator layout has failed to be created. ", e); } catch (IllegalAccessException e) { Log.e(LOG_TAG, "The indicator layout has failed to be created. ", e); } catch (NullPointerException e) { Log.e(LOG_TAG, "The indicator layout has failed to be created. ", e); } return layout; } /** * Factory which creates a default indicator layout instance. This is used when {@code IndicatorLayoutFactory} fails to create a instance * @author Wonjun Kim * */ private static class DefaultIndicatorLayoutFactory { /** * @param clazzName This class name is being ignored * @return Class token of {@code DefaultIndicatorLayout} */ public static Class createIndicatorLayoutClazz(String clazzName) { return DefaultIndicatorLayout.class; } /** * @param clazz Class token is being ignored. * @param context * @param mode * @return {@code DefaultIndicatorLayout} instance */ public static IndicatorLayout createIndicatorLayout(Class clazz, Context context, PullToRefreshBase.Mode mode) { return new DefaultIndicatorLayout(context, mode); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/LoadingLayoutFactory.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import android.content.Context; import android.content.res.TypedArray; import android.util.Log; import android.view.View; import com.handmark.pulltorefresh.configuration.xml.PullToRefreshXmlConfiguration; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation; import com.handmark.pulltorefresh.library.internal.RotateLoadingLayout; import com.handmark.pulltorefresh.library.internal.LoadingLayout; /** * Factory which creates loading layouts *
Loading layouts must be listed in pulltorefresh.xml as "PullToRefresh/LoadingLayouts/layout" nodes * @author Wonjun Kim */ class LoadingLayoutFactory { private static final String LOG_TAG = LoadingLayoutFactory.class .getSimpleName(); /** * Create the class token matched by {@code layoutCode} * @param layoutCode Loading layout code, which must be defined in pulltorefresh.xml * @return Class token which is matched by {@code layoutCode}, or the class token of {@code RotateLoadingLayout} instance if not */ public static Class createLoadingLayoutClazzByLayoutCode(String layoutCode) { String clazzName = PullToRefreshXmlConfiguration.getInstance().getLoadingLayoutClazzName(layoutCode); return createLoadingLayoutClazz(clazzName); } /** * Create a {@code LoadingLayout} instance matched by {@code clazz} token * @param layoutCode Loading layout code, which must be defined in pulltorefresh.xml * @param context * @param mode * @return {@code LoadingLayout} instance if the class matched by {@code layoutCode} exists, or {@code RotateLoadingLayout} instance if not */ @SuppressWarnings("unchecked") public static Class createLoadingLayoutClazz( String clazzName) { Class loadingLayoutClazz = null; if ( clazzName == null ) { loadingLayoutClazz = DefaultLoadingLayoutFactory.createLoadingLayoutClazz(clazzName); return loadingLayoutClazz; } try { loadingLayoutClazz = (Class) Class.forName(clazzName); } catch (ClassNotFoundException e) { Log.e(LOG_TAG,"The loading layout you have chosen class has not been found.", e); loadingLayoutClazz = DefaultLoadingLayoutFactory.createLoadingLayoutClazz(clazzName); } return loadingLayoutClazz; } /** * Create a {@code LoadingLayout} instance matched by {@code layoutCode} * @param layoutCode Loading layout code, which must be defined in pulltorefresh.xml * @param context * @param mode * @return {@code LoadingLayout} instance if the class matched by {@code layoutCode} exists, or {@code RotateLoadingLayout} instance if not */ public static LoadingLayout createLoadingLayout(String layoutCode, Context context, Mode mode, Orientation orientation, TypedArray attrs) { Class clazz = createLoadingLayoutClazz(layoutCode); return createLoadingLayout(clazz, context, mode, orientation, attrs); } /** * Create a {@code LoadingLayout} instance matched by {@code clazz} token * @param layoutCode Loading layout code, which must be defined in pulltorefresh.xml * @param context * @param mode * @return {@code LoadingLayout} instance if the class matched by {@code layoutCode} exists, or {@code RotateLoadingLayout} instance if not */ public static LoadingLayout createLoadingLayout( Class clazz, Context context, Mode mode, Orientation orientation, TypedArray attrs) { LoadingLayout layout = null; // Prevent NullPointerException if ( clazz == null ) { Log.i(LOG_TAG, "The Class token of the Loading Layout is missing. Default Loading Layout will be used."); clazz = DefaultLoadingLayoutFactory.createLoadingLayoutClazz(""); } layout = tryNewInstance(clazz, context, mode, orientation, attrs); // If trying to create new instance has failed, if (layout == null) { layout = DefaultLoadingLayoutFactory.createLoadingLayout(clazz, context, mode, orientation, attrs); } layout.setVisibility(View.INVISIBLE); return layout; } private static LoadingLayout tryNewInstance( Class clazz, Context context, Mode mode, Orientation orientation, TypedArray attrs) { LoadingLayout layout = null; try { Constructor constructor = clazz .getConstructor(Context.class, Mode.class, Orientation.class, TypedArray.class); layout = (LoadingLayout) constructor.newInstance(context, mode, orientation, attrs); } catch (IllegalArgumentException e) { Log.e(LOG_TAG, "The loading layout has failed to be created. ", e); } catch (InvocationTargetException e) { Log.e(LOG_TAG, "The loading layout has failed to be created. ", e); } catch (SecurityException e) { Log.e(LOG_TAG, "The loading layout has failed to be created. ", e); } catch (NoSuchMethodException e) { Log.e(LOG_TAG, "The loading layout has failed to be created. ", e); } catch (InstantiationException e) { Log.e(LOG_TAG, "The loading layout has failed to be created. ", e); } catch (IllegalAccessException e) { Log.e(LOG_TAG, "The loading layout has failed to be created. ", e); } catch (NullPointerException e) { Log.e(LOG_TAG, "The loading layout has failed to be created. ", e); } return layout; } /** * Factory which creates a default loading layout instance. This is used when {@code LoadingLayoutFactory} fails to create a instance * @author Wonjun Kim * */ private static class DefaultLoadingLayoutFactory { /** * @param clazzName This class name is being ignored * @return Class token of {@code RotateLoadingLayout} */ public static Class createLoadingLayoutClazz( String clazzName) { return RotateLoadingLayout.class; } /** * @param clazz Class token is being ignored. * @param context * @param mode * @return {@code RotateLoadingLayout} instance */ public static LoadingLayout createLoadingLayout( Class clazz, Context context, Mode mode, Orientation orientation, TypedArray attrs) { return new RotateLoadingLayout(context, mode, orientation, attrs); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/LoadingLayoutProxy.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import java.util.HashSet; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import com.handmark.pulltorefresh.library.internal.LoadingLayout; public class LoadingLayoutProxy implements ILoadingLayout { private final HashSet mLoadingLayouts; LoadingLayoutProxy() { mLoadingLayouts = new HashSet(); } /** * This allows you to add extra LoadingLayout instances to this proxy. This * is only necessary if you keep your own instances, and want to have them * included in any * {@link PullToRefreshBase#createLoadingLayoutProxy(boolean, boolean) * createLoadingLayoutProxy(...)} calls. * * @param layout - LoadingLayout to have included. */ public void addLayout(LoadingLayout layout) { if (null != layout) { mLoadingLayouts.add(layout); } } @Override public void setLastUpdatedLabel(CharSequence label) { for (LoadingLayout layout : mLoadingLayouts) { layout.setLastUpdatedLabel(label); } } @Override public void setLoadingDrawable(Drawable drawable) { for (LoadingLayout layout : mLoadingLayouts) { layout.setLoadingDrawable(drawable); } } @Override public void setRefreshingLabel(CharSequence refreshingLabel) { for (LoadingLayout layout : mLoadingLayouts) { layout.setRefreshingLabel(refreshingLabel); } } @Override public void setPullLabel(CharSequence label) { for (LoadingLayout layout : mLoadingLayouts) { layout.setPullLabel(label); } } @Override public void setReleaseLabel(CharSequence label) { for (LoadingLayout layout : mLoadingLayouts) { layout.setReleaseLabel(label); } } public void setTextTypeface(Typeface tf) { for (LoadingLayout layout : mLoadingLayouts) { layout.setTextTypeface(tf); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/OverscrollHelper.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import android.annotation.TargetApi; import android.util.Log; import android.view.View; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.State; @TargetApi(9) public final class OverscrollHelper { static final String LOG_TAG = "OverscrollHelper"; static final float DEFAULT_OVERSCROLL_SCALE = 1f; /** * Helper method for Overscrolling that encapsulates all of the necessary * function. *

* This should only be used on AdapterView's such as ListView as it just * calls through to overScrollBy() with the scrollRange = 0. AdapterView's * do not have a scroll range (i.e. getScrollY() doesn't work). * * @param view - PullToRefreshView that is calling this. * @param deltaX - Change in X in pixels, passed through from from * overScrollBy call * @param scrollX - Current X scroll value in pixels before applying deltaY, * passed through from from overScrollBy call * @param deltaY - Change in Y in pixels, passed through from from * overScrollBy call * @param scrollY - Current Y scroll value in pixels before applying deltaY, * passed through from from overScrollBy call * @param isTouchEvent - true if this scroll operation is the result of a * touch event, passed through from from overScrollBy call */ public static void overScrollBy(final PullToRefreshBase view, final int deltaX, final int scrollX, final int deltaY, final int scrollY, final boolean isTouchEvent) { overScrollBy(view, deltaX, scrollX, deltaY, scrollY, 0, isTouchEvent); } /** * Helper method for Overscrolling that encapsulates all of the necessary * function. This version of the call is used for Views that need to specify * a Scroll Range but scroll back to it's edge correctly. * * @param view - PullToRefreshView that is calling this. * @param deltaX - Change in X in pixels, passed through from from * overScrollBy call * @param scrollX - Current X scroll value in pixels before applying deltaY, * passed through from from overScrollBy call * @param deltaY - Change in Y in pixels, passed through from from * overScrollBy call * @param scrollY - Current Y scroll value in pixels before applying deltaY, * passed through from from overScrollBy call * @param scrollRange - Scroll Range of the View, specifically needed for * ScrollView * @param isTouchEvent - true if this scroll operation is the result of a * touch event, passed through from from overScrollBy call */ public static void overScrollBy(final PullToRefreshBase view, final int deltaX, final int scrollX, final int deltaY, final int scrollY, final int scrollRange, final boolean isTouchEvent) { overScrollBy(view, deltaX, scrollX, deltaY, scrollY, scrollRange, 0, DEFAULT_OVERSCROLL_SCALE, isTouchEvent); } /** * Helper method for Overscrolling that encapsulates all of the necessary * function. This is the advanced version of the call. * * @param view - PullToRefreshView that is calling this. * @param deltaX - Change in X in pixels, passed through from from * overScrollBy call * @param scrollX - Current X scroll value in pixels before applying deltaY, * passed through from from overScrollBy call * @param deltaY - Change in Y in pixels, passed through from from * overScrollBy call * @param scrollY - Current Y scroll value in pixels before applying deltaY, * passed through from from overScrollBy call * @param scrollRange - Scroll Range of the View, specifically needed for * ScrollView * @param fuzzyThreshold - Threshold for which the values how fuzzy we * should treat the other values. Needed for WebView as it * doesn't always scroll back to it's edge. 0 = no fuzziness. * @param scaleFactor - Scale Factor for overscroll amount * @param isTouchEvent - true if this scroll operation is the result of a * touch event, passed through from from overScrollBy call */ public static void overScrollBy(final PullToRefreshBase view, final int deltaX, final int scrollX, final int deltaY, final int scrollY, final int scrollRange, final int fuzzyThreshold, final float scaleFactor, final boolean isTouchEvent) { final int deltaValue, currentScrollValue, scrollValue; switch (view.getPullToRefreshScrollDirection()) { case HORIZONTAL: deltaValue = deltaX; scrollValue = scrollX; currentScrollValue = view.getScrollX(); break; case VERTICAL: default: deltaValue = deltaY; scrollValue = scrollY; currentScrollValue = view.getScrollY(); break; } // Check that OverScroll is enabled and that we're not currently // refreshing. if (view.isPullToRefreshOverScrollEnabled() && !view.isRefreshing()) { final Mode mode = view.getMode(); // Check that Pull-to-Refresh is enabled, and the event isn't from // touch if (mode.permitsPullToRefresh() && !isTouchEvent && deltaValue != 0) { final int newScrollValue = (deltaValue + scrollValue); if (PullToRefreshBase.DEBUG) { Log.d(LOG_TAG, "OverScroll. DeltaX: " + deltaX + ", ScrollX: " + scrollX + ", DeltaY: " + deltaY + ", ScrollY: " + scrollY + ", NewY: " + newScrollValue + ", ScrollRange: " + scrollRange + ", CurrentScroll: " + currentScrollValue); } if (newScrollValue < (0 - fuzzyThreshold)) { // Check the mode supports the overscroll direction, and // then move scroll if (mode.showHeaderLoadingLayout()) { // If we're currently at zero, we're about to start // overscrolling, so change the state if (currentScrollValue == 0) { view.setState(State.OVERSCROLLING); } view.setHeaderScroll((int) (scaleFactor * (currentScrollValue + newScrollValue))); } } else if (newScrollValue > (scrollRange + fuzzyThreshold)) { // Check the mode supports the overscroll direction, and // then move scroll if (mode.showFooterLoadingLayout()) { // If we're currently at zero, we're about to start // overscrolling, so change the state if (currentScrollValue == 0) { view.setState(State.OVERSCROLLING); } view.setHeaderScroll((int) (scaleFactor * (currentScrollValue + newScrollValue - scrollRange))); } } else if (Math.abs(newScrollValue) <= fuzzyThreshold || Math.abs(newScrollValue - scrollRange) <= fuzzyThreshold) { // Means we've stopped overscrolling, so scroll back to 0 view.setState(State.RESET); } } else if (isTouchEvent && State.OVERSCROLLING == view.getState()) { // This condition means that we were overscrolling from a fling, // but the user has touched the View and is now overscrolling // from touch instead. We need to just reset. view.setState(State.RESET); } } } static boolean isAndroidOverScrollEnabled(View view) { return view.getOverScrollMode() != View.OVER_SCROLL_NEVER; } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/PullToRefreshAdapterViewBase.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import java.util.Arrays; import java.util.List; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; import android.widget.AbsListView; import android.widget.AbsListView.OnScrollListener; import android.widget.Adapter; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.ListAdapter; import com.handmark.pulltorefresh.library.internal.IndicatorLayout; import com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor; import com.handmark.pulltorefresh.library.internal.LoadingLayout; public abstract class PullToRefreshAdapterViewBase extends PullToRefreshBase implements OnScrollListener { private static FrameLayout.LayoutParams convertEmptyViewLayoutParams(ViewGroup.LayoutParams lp) { FrameLayout.LayoutParams newLp = null; if (null != lp) { newLp = new FrameLayout.LayoutParams(lp); if (lp instanceof LinearLayout.LayoutParams) { newLp.gravity = ((LinearLayout.LayoutParams) lp).gravity; } else { newLp.gravity = Gravity.CENTER; } } return newLp; } private boolean mLastItemVisible; private OnScrollListener mOnScrollListener; private OnLastItemVisibleListener mOnLastItemVisibleListener; private View mEmptyView; private IndicatorLayout mIndicatorIvTop; private IndicatorLayout mIndicatorIvBottom; private boolean mShowIndicator; private boolean mScrollEmptyView = true; /** *

* Indicator Layout Class Token
{@link IndicatorLayoutFactory} will create instances by using this class token. * The token must not be null. {@link IndicatorLayoutFacoty} ensures that class token exists always. * Assignment some class token into this variable is implemented at {@link #handleStyledAttributes(TypedArray)}. *

*/ private Class mIndicatorLayoutClazz; public PullToRefreshAdapterViewBase(Context context) { super(context); mRefreshableView.setOnScrollListener(this); } public PullToRefreshAdapterViewBase(Context context, AttributeSet attrs) { super(context, attrs); mRefreshableView.setOnScrollListener(this); } public PullToRefreshAdapterViewBase(Context context, Mode mode) { super(context, mode); mRefreshableView.setOnScrollListener(this); } public PullToRefreshAdapterViewBase(Context context, Mode mode, Class loadingLayoutClazz) { super(context, mode, loadingLayoutClazz); mRefreshableView.setOnScrollListener(this); } /** * Gets whether an indicator graphic should be displayed when the View is in * a state where a Pull-to-Refresh can happen. An example of this state is * when the Adapter View is scrolled to the top and the mode is set to * {@link PullToRefreshBase.Mode#PULL_FROM_START}. The default value is true if * {@link PullToRefreshBase#isPullToRefreshOverScrollEnabled() * isPullToRefreshOverScrollEnabled()} returns false. * * @return true if the indicators will be shown */ public boolean getShowIndicator() { return mShowIndicator; } public final void onScroll(final AbsListView view, final int firstVisibleItem, final int visibleItemCount, final int totalItemCount) { if (DEBUG) { Log.d(LOG_TAG, "First Visible: " + firstVisibleItem + ". Visible Count: " + visibleItemCount + ". Total Items:" + totalItemCount); } /** * Set whether the Last Item is Visible. lastVisibleItemIndex is a * zero-based index, so we minus one totalItemCount to check */ if (null != mOnLastItemVisibleListener) { mLastItemVisible = (totalItemCount > 0) && (firstVisibleItem + visibleItemCount >= totalItemCount - 1); } // If we're showing the indicator, check positions... if (getShowIndicatorInternal()) { updateIndicatorViewsVisibility(); } // Finally call OnScrollListener if we have one if (null != mOnScrollListener) { mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); } } public final void onScrollStateChanged(final AbsListView view, final int state) { /** * Check that the scrolling has stopped, and that the last item is * visible. */ if (state == OnScrollListener.SCROLL_STATE_IDLE && null != mOnLastItemVisibleListener && mLastItemVisible) { mOnLastItemVisibleListener.onLastItemVisible(); } if (null != mOnScrollListener) { mOnScrollListener.onScrollStateChanged(view, state); } } /** * Pass-through method for {@link PullToRefreshBase#getRefreshableView() * getRefreshableView()}. * {@link AdapterView#setAdapter(android.widget.Adapter)} * setAdapter(adapter)}. This is just for convenience! * * @param adapter - Adapter to set */ public void setAdapter(ListAdapter adapter) { ((AdapterView) mRefreshableView).setAdapter(adapter); } /** * Sets the Empty View to be used by the Adapter View. *

* We need it handle it ourselves so that we can Pull-to-Refresh when the * Empty View is shown. *

* Please note, you do not usually need to call this method * yourself. Calling setEmptyView on the AdapterView will automatically call * this method and set everything up. This includes when the Android * Framework automatically sets the Empty View based on it's ID. * * @param newEmptyView - Empty View to be used */ public final void setEmptyView(View newEmptyView) { FrameLayout refreshableViewWrapper = getRefreshableViewWrapper(); if (null != newEmptyView) { // New view needs to be clickable so that Android recognizes it as a // target for Touch Events newEmptyView.setClickable(true); ViewParent newEmptyViewParent = newEmptyView.getParent(); if (null != newEmptyViewParent && newEmptyViewParent instanceof ViewGroup) { ((ViewGroup) newEmptyViewParent).removeView(newEmptyView); } // We need to convert any LayoutParams so that it works in our // FrameLayout FrameLayout.LayoutParams lp = convertEmptyViewLayoutParams(newEmptyView.getLayoutParams()); if (null != lp) { refreshableViewWrapper.addView(newEmptyView, lp); } else { refreshableViewWrapper.addView(newEmptyView); } } if (mRefreshableView instanceof EmptyViewMethodAccessor) { ((EmptyViewMethodAccessor) mRefreshableView).setEmptyViewInternal(newEmptyView); } else { mRefreshableView.setEmptyView(newEmptyView); } mEmptyView = newEmptyView; } /** * Pass-through method for {@link PullToRefreshBase#getRefreshableView() * getRefreshableView()}. * {@link AdapterView#setOnItemClickListener(OnItemClickListener) * setOnItemClickListener(listener)}. This is just for convenience! * * @param listener - OnItemClickListener to use */ public void setOnItemClickListener(OnItemClickListener listener) { mRefreshableView.setOnItemClickListener(listener); } public final void setOnLastItemVisibleListener(OnLastItemVisibleListener listener) { mOnLastItemVisibleListener = listener; } public final void setOnItemLongClickListener(AdapterView.OnItemLongClickListener listener) { mRefreshableView.setOnItemLongClickListener(listener); } public final void setOnScrollListener(OnScrollListener listener) { mOnScrollListener = listener; } public final void setScrollEmptyView(boolean doScroll) { mScrollEmptyView = doScroll; } /** * Sets whether an indicator graphic should be displayed when the View is in * a state where a Pull-to-Refresh can happen. An example of this state is * when the Adapter View is scrolled to the top and the mode is set to * {@link PullToRefreshBase.Mode#PULL_FROM_START} * * @param showIndicator - true if the indicators should be shown. */ public void setShowIndicator(boolean showIndicator) { mShowIndicator = showIndicator; if (getShowIndicatorInternal()) { // If we're set to Show Indicator, add/update them addIndicatorViews(); } else { // If not, then remove then removeIndicatorViews(); } } ; @Override protected void onPullToRefresh() { super.onPullToRefresh(); if (getShowIndicatorInternal()) { switch (getCurrentMode()) { case PULL_FROM_END: mIndicatorIvBottom.pullToRefresh(); break; case PULL_FROM_START: mIndicatorIvTop.pullToRefresh(); break; default: // NO-OP break; } } } protected void onRefreshing(boolean doScroll) { super.onRefreshing(doScroll); if (getShowIndicatorInternal()) { updateIndicatorViewsVisibility(); } } @Override protected void onReleaseToRefresh() { super.onReleaseToRefresh(); if (getShowIndicatorInternal()) { switch (getCurrentMode()) { case PULL_FROM_END: mIndicatorIvBottom.releaseToRefresh(); break; case PULL_FROM_START: mIndicatorIvTop.releaseToRefresh(); break; default: // NO-OP break; } } } @Override protected void onReset() { super.onReset(); if (getShowIndicatorInternal()) { updateIndicatorViewsVisibility(); } } @Override protected void handleStyledAttributes(TypedArray a) { // Set Show Indicator to the XML value, or default value mShowIndicator = a.getBoolean(R.styleable.PullToRefresh_ptrShowIndicator, !isPullToRefreshOverScrollEnabled()); // Get IndicatorLayout code String layoutCode = null; if (a.hasValue(R.styleable.PullToRefresh_ptrIndicatorStyle)) { layoutCode = a.getString(R.styleable.PullToRefresh_ptrIndicatorStyle); } // Convert layoutCode to a class token, and assign the class token into mIndicatorLayoutClazz mIndicatorLayoutClazz = IndicatorLayoutFactory.createIndicatorLayoutClazzByLayoutCode(layoutCode); } protected boolean isReadyForPullStart() { return isFirstItemVisible(); } protected boolean isReadyForPullEnd() { return isLastItemVisible(); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if (null != mEmptyView && !mScrollEmptyView) { mEmptyView.scrollTo(-l, -t); } } @Override protected void onFinishInflate() { super.onFinishInflate(); if (isInEditMode()) { // Only when the preview mode of IDE createSampleList(); } } /** *

	 * Create the sample list to be shown on the preview layout of IDE.
	 * _NOTE_ : This method is used only for the preview mode of IDE.
	 * 
*/ private void createSampleList() { List listItems = Arrays.asList(new String[]{"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7"}); ListAdapter sampleAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, listItems); setAdapter(sampleAdapter); } @Override protected void updateUIForMode() { super.updateUIForMode(); // Check Indicator Views consistent with new Mode if (getShowIndicatorInternal()) { addIndicatorViews(); } else { removeIndicatorViews(); } } private void addIndicatorViews() { Mode mode = getMode(); FrameLayout refreshableViewWrapper = getRefreshableViewWrapper(); if (mode.showHeaderLoadingLayout() && null == mIndicatorIvTop) { // If the mode can pull down, and we don't have one set already mIndicatorIvTop = IndicatorLayoutFactory.createIndicatorLayout(mIndicatorLayoutClazz, getContext(), Mode.PULL_FROM_START); ViewGroup.LayoutParams params = mIndicatorIvTop.createApplicableHeaderLayoutParams(); refreshableViewWrapper.addView(mIndicatorIvTop, params); } else if (!mode.showHeaderLoadingLayout() && null != mIndicatorIvTop) { // If we can't pull down, but have a View then remove it refreshableViewWrapper.removeView(mIndicatorIvTop); mIndicatorIvTop = null; } if (mode.showFooterLoadingLayout() && null == mIndicatorIvBottom) { // If the mode can pull down, and we don't have one set already mIndicatorIvBottom = IndicatorLayoutFactory.createIndicatorLayout(mIndicatorLayoutClazz, getContext(), Mode.PULL_FROM_END); ViewGroup.LayoutParams params = mIndicatorIvBottom.createApplicableFooterLayoutParams(); refreshableViewWrapper.addView(mIndicatorIvBottom, params); } else if (!mode.showFooterLoadingLayout() && null != mIndicatorIvBottom) { // If we can't pull down, but have a View then remove it refreshableViewWrapper.removeView(mIndicatorIvBottom); mIndicatorIvBottom = null; } } private boolean getShowIndicatorInternal() { return mShowIndicator && isPullToRefreshEnabled(); } private boolean isFirstItemVisible() { final Adapter adapter = mRefreshableView.getAdapter(); if (null == adapter || adapter.isEmpty()) { if (DEBUG) { Log.d(LOG_TAG, "isFirstItemVisible. Empty View."); } return true; } else { /** * This check should really just be: * mRefreshableView.getFirstVisiblePosition() == 0, but PtRListView * internally use a HeaderView which messes the positions up. For * now we'll just add one to account for it and rely on the inner * condition which checks getTop(). */ if (mRefreshableView.getFirstVisiblePosition() <= 1) { final View firstVisibleChild = mRefreshableView.getChildAt(0); if (firstVisibleChild != null) { return firstVisibleChild.getTop() >= mRefreshableView.getTop(); } } } return false; } private boolean isLastItemVisible() { final Adapter adapter = mRefreshableView.getAdapter(); if (null == adapter || adapter.isEmpty()) { if (DEBUG) { Log.d(LOG_TAG, "isLastItemVisible. Empty View."); } return true; } else { final int lastItemPosition = mRefreshableView.getCount() - 1; final int lastVisiblePosition = mRefreshableView.getLastVisiblePosition(); if (DEBUG) { Log.d(LOG_TAG, "isLastItemVisible. Last Item Position: " + lastItemPosition + " Last Visible Pos: " + lastVisiblePosition); } /** * This check should really just be: lastVisiblePosition == * lastItemPosition, but PtRListView internally uses a FooterView * which messes the positions up. For me we'll just subtract one to * account for it and rely on the inner condition which checks * getBottom(). */ if (lastVisiblePosition >= lastItemPosition - 1) { final int childIndex = lastVisiblePosition - mRefreshableView.getFirstVisiblePosition(); final View lastVisibleChild = mRefreshableView.getChildAt(childIndex); if (lastVisibleChild != null) { return lastVisibleChild.getBottom() <= mRefreshableView.getBottom(); } } } return false; } private void removeIndicatorViews() { if (null != mIndicatorIvTop) { getRefreshableViewWrapper().removeView(mIndicatorIvTop); mIndicatorIvTop = null; } if (null != mIndicatorIvBottom) { getRefreshableViewWrapper().removeView(mIndicatorIvBottom); mIndicatorIvBottom = null; } } private void updateIndicatorViewsVisibility() { if (null != mIndicatorIvTop) { if (!isRefreshing() && isReadyForPullStart()) { if (!mIndicatorIvTop.isVisible()) { mIndicatorIvTop.show(); } } else { if (mIndicatorIvTop.isVisible()) { mIndicatorIvTop.hide(); } } } if (null != mIndicatorIvBottom) { if (!isRefreshing() && isReadyForPullEnd()) { if (!mIndicatorIvBottom.isVisible()) { mIndicatorIvBottom.show(); } } else { if (mIndicatorIvBottom.isVisible()) { mIndicatorIvBottom.hide(); } } } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/PullToRefreshBase.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.os.Parcelable; import android.util.AttributeSet; import android.util.Log; import android.view.Gravity; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationSet; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import android.view.animation.TranslateAnimation; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.ProgressBar; import com.handmark.pulltorefresh.configuration.xml.PullToRefreshXmlConfiguration; import com.handmark.pulltorefresh.library.internal.LoadingLayout; import com.handmark.pulltorefresh.library.internal.Utils; import com.handmark.pulltorefresh.library.internal.ViewCompat; public abstract class PullToRefreshBase extends LinearLayout implements IPullToRefresh { // =========================================================== // Constants // =========================================================== static final boolean DEBUG = false; static final boolean USE_HW_LAYERS = false; static final String LOG_TAG = "PullToRefresh"; public static final float DEFAULT_FRICTION = 2.0f; public static final int DEFAULT_SMOOTH_SCROLL_DURATION_MS = 200; public static final int DEFAULT_SMOOTH_SCROLL_LONG_DURATION_MS = 325; static final int DEMO_SCROLL_INTERVAL = 225; static final String STATE_STATE = "ptr_state"; static final String STATE_MODE = "ptr_mode"; static final String STATE_CURRENT_MODE = "ptr_current_mode"; static final String STATE_SCROLLING_REFRESHING_ENABLED = "ptr_disable_scrolling"; static final String STATE_SHOW_REFRESHING_VIEW = "ptr_show_refreshing_view"; static final String STATE_SUPER = "ptr_super"; static final int REFRESHABLEVIEW_REFRESHING_BAR_VIEW_WHILE_REFRESHING_DURATION = 100; static final int REFRESHABLE_VIEW_HIDE_WHILE_REFRESHING_DURATION = 500; static final int GOOGLE_STYLE_VIEW_APPEAREANCE_DURATION = 200; static final int DFEAULT_REFRESHABLEVIEW_REFRESHING_BAR_SIZE = ViewGroup.LayoutParams.WRAP_CONTENT; static final int LAYER_TYPE_HARDWARE = 2; static final int LAYER_TYPE_NONE = 0; // =========================================================== // Fields // =========================================================== private int mTouchSlop; private float mLastMotionX, mLastMotionY; private float mInitialMotionX, mInitialMotionY; // needed properties while scrolling private float mFriction; private int mSmoothScrollDurationMs = 200; private int mSmoothScrollLongDurationMs = 325; private boolean mIsBeingDragged = false; private State mState = State.RESET; private Mode mMode = Mode.getDefault(); private Mode mCurrentMode; T mRefreshableView; private FrameLayout mRefreshableViewWrapper; private boolean mShowViewWhileRefreshing = true; private boolean mScrollingWhileRefreshingEnabled = false; private boolean mFilterTouchEvents = true; private boolean mOverScrollEnabled = true; private boolean mLayoutVisibilityChangesEnabled = true; private Interpolator mScrollAnimationInterpolator; private Class mLoadingLayoutClazz = null; private LoadingLayout mHeaderLayout; private LoadingLayout mFooterLayout; /** * Top DecorView for containing google style pull to refresh */ private FrameLayout mTopActionbarLayout; /** * Flag whether {@link #onAttachedToWindow()} event has been called */ private boolean mWindowAttached = false; /** * View Layout being shown over ActionBar */ private GoogleStyleViewLayout mGoogleStyleViewLayout; /** * Progress Bar being shown over ActionBar */ private GoogleStyleProgressLayout mGoogleStyleProgressLayout; /** * Progress bar ratating on center while Refreshing */ private ProgressBar mRefreshableViewProgressBar; private OnRefreshListener mOnRefreshListener; private OnRefreshListener2 mOnRefreshListener2; private OnPullEventListener mOnPullEventListener; private SmoothScrollRunnable mCurrentSmoothScrollRunnable; private int mStatusBarHeight; /** * Current actionbar size */ private int mActionBarHeight; /** * Flag whether {@link #onRefreshing(boolean)} has been called */ private boolean mRefreshing; /** * Flag whether Google style view layout appearance animation will be shown */ private boolean mShowGoogleStyleViewAnimationEnabled = true; /** * Duration of Google style view layout appearance animation */ private int mShowGoogleStyleViewAnimationDuration = GOOGLE_STYLE_VIEW_APPEAREANCE_DURATION; /** * Flag whether {@code mRefreshaleView} will be hidden while refreshing */ private boolean mRefeshableViewHideWhileRefreshingEnabled = true; /** * {@code mRefreshableView}'s fade-out Duration */ private int mRefeshableViewHideWhileRefreshingDuration = REFRESHABLE_VIEW_HIDE_WHILE_REFRESHING_DURATION; /** * Flag whether some {@code ProgressBar} will be shown while refreshing */ private boolean mRefeshableViewRefreshingBarViewWhileRefreshingEnabled = true; /** * {@code mRefreshableViewRefreshingBar}'s fade-in Duration */ private int mRefeshableViewRefreshingBarViewWhileRefreshingDuration = REFRESHABLEVIEW_REFRESHING_BAR_VIEW_WHILE_REFRESHING_DURATION; /** * Width of {@code mRefreshableViewRefreshingBar} */ private int mRefeshableViewRefreshingBarWidth = DFEAULT_REFRESHABLEVIEW_REFRESHING_BAR_SIZE; /** * Height of {@code mRefreshableViewRefreshingBar} */ private int mRefeshableViewRefreshingBarHeight = DFEAULT_REFRESHABLEVIEW_REFRESHING_BAR_SIZE; /** * Flag whether Google style view layout's size is set to ActionBar's size * (Don't set to false as possible, it's hard to control height if this flag is false) */ private boolean mSetGoogleViewLayoutSizeToActionbarHeight = true; private int mYPositionOfGoogleStyleViewLayout; private int mYPositionOfGoogleStyleProgressLayout; // =========================================================== // Constructors // =========================================================== public PullToRefreshBase(Context context) { super(context); init(context, null); } public PullToRefreshBase(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); } public PullToRefreshBase(Context context, Mode mode) { super(context); mMode = mode; init(context, null); } public PullToRefreshBase(Context context, Mode mode, Class loadingLayoutClazz) { super(context); mMode = mode; mLoadingLayoutClazz = loadingLayoutClazz; init(context, null); } @Override public void addView(View child, int index, ViewGroup.LayoutParams params) { if (DEBUG) { Log.d(LOG_TAG, "addView: " + child.getClass().getSimpleName()); } final T refreshableView = getRefreshableView(); if (refreshableView instanceof ViewGroup) { ((ViewGroup) refreshableView).addView(child, index, params); } else { throw new UnsupportedOperationException("Refreshable View is not a ViewGroup so can't addView"); } } @Deprecated @Override public final boolean demo() { if (mMode.showHeaderLoadingLayout() && isReadyForPullStart()) { smoothScrollToAndBack(-getHeaderSize() * 2); return true; } else if (mMode.showFooterLoadingLayout() && isReadyForPullEnd()) { smoothScrollToAndBack(getFooterSize() * 2); return true; } return false; } @Override public final Mode getCurrentMode() { return mCurrentMode; } @Override public final boolean getFilterTouchEvents() { return mFilterTouchEvents; } @Override public final ILoadingLayout getLoadingLayoutProxy() { return getLoadingLayoutProxy(true, true); } @Override public final ILoadingLayout getLoadingLayoutProxy(boolean includeStart, boolean includeEnd) { return createLoadingLayoutProxy(includeStart, includeEnd); } @Override public final Mode getMode() { return mMode; } @Override public final T getRefreshableView() { return mRefreshableView; } @Override public final boolean getShowViewWhileRefreshing() { return mShowViewWhileRefreshing; } @Override public final State getState() { return mState; } /** * @deprecated See {@link #isScrollingWhileRefreshingEnabled()}. */ public final boolean isDisableScrollingWhileRefreshing() { return !isScrollingWhileRefreshingEnabled(); } @Override public final boolean isPullToRefreshEnabled() { return mMode.permitsPullToRefresh(); } @Override public final boolean isPullToRefreshOverScrollEnabled() { return VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD && mOverScrollEnabled && OverscrollHelper.isAndroidOverScrollEnabled(mRefreshableView); } @Override public final boolean isRefreshing() { return mState == State.REFRESHING || mState == State.MANUAL_REFRESHING; } @Override public final void stopRefreshing() { onRefreshComplete(); } @Override public final boolean isScrollingWhileRefreshingEnabled() { return mScrollingWhileRefreshingEnabled; } @Override public final boolean onInterceptTouchEvent(MotionEvent event) { if (!isPullToRefreshEnabled()) { return false; } final int action = event.getAction(); if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mIsBeingDragged = false; return false; } if (action != MotionEvent.ACTION_DOWN && mIsBeingDragged) { return true; } switch (action) { case MotionEvent.ACTION_MOVE: { // If we're refreshing, and the flag is set. Eat all MOVE events if (!mScrollingWhileRefreshingEnabled && isRefreshing()) { return true; } if (isReadyForPull()) { final float y = event.getY(), x = event.getX(); final float diff, oppositeDiff, absDiff; // We need to use the correct values, based on scroll // direction switch (getFilteredPullToRefreshScrollDirection()) { case HORIZONTAL: diff = x - mLastMotionX; oppositeDiff = y - mLastMotionY; break; case VERTICAL: default: diff = y - mLastMotionY; oppositeDiff = x - mLastMotionX; break; } absDiff = Math.abs(diff); if (absDiff > mTouchSlop && (!mFilterTouchEvents || absDiff > Math.abs(oppositeDiff))) { if ((mMode.showHeaderLoadingLayout() || mMode.showGoogleStyle()) && diff >= 1f && isReadyForPullStart()) { mLastMotionY = y; mLastMotionX = x; mIsBeingDragged = true; if (mMode == Mode.BOTH) { mCurrentMode = Mode.PULL_FROM_START; } } else if (mMode.showFooterLoadingLayout() && diff <= -1f && isReadyForPullEnd()) { mLastMotionY = y; mLastMotionX = x; mIsBeingDragged = true; if (mMode == Mode.BOTH) { mCurrentMode = Mode.PULL_FROM_END; } } } } break; } case MotionEvent.ACTION_DOWN: { if (isReadyForPull()) { mLastMotionY = mInitialMotionY = event.getY(); mLastMotionX = mInitialMotionX = event.getX(); mIsBeingDragged = false; } break; } } return mIsBeingDragged; } @Override public final void onRefreshComplete() { if (isRefreshing()) { setState(State.RESET); } } @Override public final boolean onTouchEvent(MotionEvent event) { if (!isPullToRefreshEnabled()) { return false; } // If we're refreshing, and the flag is set. Eat the event if (!mScrollingWhileRefreshingEnabled && isRefreshing()) { return true; } if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) { return false; } switch (event.getAction()) { case MotionEvent.ACTION_MOVE: { if (mIsBeingDragged) { mLastMotionY = event.getY(); mLastMotionX = event.getX(); pullEvent(); return true; } break; } case MotionEvent.ACTION_DOWN: { if (isReadyForPull()) { mLastMotionY = mInitialMotionY = event.getY(); mLastMotionX = mInitialMotionX = event.getX(); return true; } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { if (mIsBeingDragged) { mIsBeingDragged = false; if (mState == State.RELEASE_TO_REFRESH && (null != mOnRefreshListener || null != mOnRefreshListener2)) { setState(State.REFRESHING, true); return true; } // If we're already refreshing, just scroll back to the top if (isRefreshing()) { smoothScrollTo(0); return true; } // If we haven't returned by here, then we're not in a state // to pull, so just reset setState(State.RESET); return true; } break; } } return false; } /** * Set new friction * @param friction New friction value. Must be float. The default value is {@value #DEFAULT_FRICTION}. */ public final void setFriction(float friction) { this.mFriction = friction; } /** * Set new smooth scroll duration * @param smoothScrollDurationMs Milliseconds. The default value is {@value #DEFAULT_SMOOTH_SCROLL_DURATION_MS}. */ public final void setSmoothScrollDuration(int smoothScrollDurationMs) { this.mSmoothScrollDurationMs = smoothScrollDurationMs; } /** * Set new smooth scroll longer duration.
This duration is only used by calling {@link #smoothScrollToLonger(int)}. * @param smoothScrollLongDurationMs Milliseconds. The default value is {@value #DEFAULT_SMOOTH_SCROLL_LONG_DURATION_MS}. */ public final void setSmoothScrollLongDuration(int smoothScrollLongDurationMs) { this.mSmoothScrollLongDurationMs = smoothScrollLongDurationMs; } /** * */ public final void setScrollingWhileRefreshingEnabled(boolean allowScrollingWhileRefreshing) { mScrollingWhileRefreshingEnabled = allowScrollingWhileRefreshing; } /** * @deprecated See {@link #setScrollingWhileRefreshingEnabled(boolean)} */ public void setDisableScrollingWhileRefreshing(boolean disableScrollingWhileRefreshing) { setScrollingWhileRefreshingEnabled(!disableScrollingWhileRefreshing); } @Override public final void setFilterTouchEvents(boolean filterEvents) { mFilterTouchEvents = filterEvents; } /** * @deprecated You should now call this method on the result of * {@link #getLoadingLayoutProxy()}. */ public void setLastUpdatedLabel(CharSequence label) { getLoadingLayoutProxy().setLastUpdatedLabel(label); } /** * @deprecated You should now call this method on the result of * {@link #getLoadingLayoutProxy()}. */ public void setLoadingDrawable(Drawable drawable) { getLoadingLayoutProxy().setLoadingDrawable(drawable); } /** * @deprecated You should now call this method on the result of * {@link #getLoadingLayoutProxy(boolean, boolean)}. */ public void setLoadingDrawable(Drawable drawable, Mode mode) { getLoadingLayoutProxy(mode.showHeaderLoadingLayout(), mode.showFooterLoadingLayout()).setLoadingDrawable( drawable); } @Override public void setLongClickable(boolean longClickable) { getRefreshableView().setLongClickable(longClickable); } @Override public final void setMode(Mode mode) { if (mode != mMode) { if (DEBUG) { Log.d(LOG_TAG, "Setting mode to: " + mode); } mMode = mode; updateUIForMode(); updateUIForGoogleStyleMode(); } } public void setOnPullEventListener(OnPullEventListener listener) { mOnPullEventListener = listener; } @Override public final void setOnRefreshListener(OnRefreshListener listener) { mOnRefreshListener = listener; mOnRefreshListener2 = null; } @Override public final void setOnRefreshListener(OnRefreshListener2 listener) { mOnRefreshListener2 = listener; mOnRefreshListener = null; } /** * @deprecated You should now call this method on the result of * {@link #getLoadingLayoutProxy()}. */ public void setPullLabel(CharSequence pullLabel) { getLoadingLayoutProxy().setPullLabel(pullLabel); } /** * @deprecated You should now call this method on the result of * {@link #getLoadingLayoutProxy(boolean, boolean)}. */ public void setPullLabel(CharSequence pullLabel, Mode mode) { getLoadingLayoutProxy(mode.showHeaderLoadingLayout(), mode.showFooterLoadingLayout()).setPullLabel(pullLabel); } /** * @param enable Whether Pull-To-Refresh should be used * @deprecated This simple calls setMode with an appropriate mode based on * the passed value. */ public final void setPullToRefreshEnabled(boolean enable) { setMode(enable ? Mode.getDefault() : Mode.DISABLED); } @Override public final void setPullToRefreshOverScrollEnabled(boolean enabled) { mOverScrollEnabled = enabled; } @Override public final void setRefreshing() { setRefreshing(true); } @Override public final void setRefreshing(boolean doScroll) { if (!isRefreshing()) { setState(State.MANUAL_REFRESHING, doScroll); } } /** * @deprecated You should now call this method on the result of * {@link #getLoadingLayoutProxy()}. */ public void setRefreshingLabel(CharSequence refreshingLabel) { getLoadingLayoutProxy().setRefreshingLabel(refreshingLabel); } /** * @deprecated You should now call this method on the result of * {@link #getLoadingLayoutProxy(boolean, boolean)}. */ public void setRefreshingLabel(CharSequence refreshingLabel, Mode mode) { getLoadingLayoutProxy(mode.showHeaderLoadingLayout(), mode.showFooterLoadingLayout()).setRefreshingLabel( refreshingLabel); } /** * @deprecated You should now call this method on the result of * {@link #getLoadingLayoutProxy()}. */ public void setReleaseLabel(CharSequence releaseLabel) { setReleaseLabel(releaseLabel, Mode.BOTH); } /** * @deprecated You should now call this method on the result of * {@link #getLoadingLayoutProxy(boolean, boolean)}. */ public void setReleaseLabel(CharSequence releaseLabel, Mode mode) { getLoadingLayoutProxy(mode.showHeaderLoadingLayout(), mode.showFooterLoadingLayout()).setReleaseLabel( releaseLabel); } public void setScrollAnimationInterpolator(Interpolator interpolator) { mScrollAnimationInterpolator = interpolator; } @Override public final void setShowViewWhileRefreshing(boolean showView) { mShowViewWhileRefreshing = showView; } /** * @return Either {@link Orientation#VERTICAL} or * {@link Orientation#HORIZONTAL} depending on the scroll direction. */ public abstract Orientation getPullToRefreshScrollDirection(); /** *

* Wrap {@link #getPullToRefreshScrollDirection()} method
* Other methods Use this method instead of {@link #getPullToRefreshScrollDirection()} method, because an orientation must be VERTICAL when mode is google style *

* @return Oreintation.VERTICAL if mMode.showGoogleStyle() is true,
Return value of {@link #getPullToRefreshScrollDirection()} method if else */ public final Orientation getFilteredPullToRefreshScrollDirection() { Orientation orientation = getPullToRefreshScrollDirection(); if (mMode.showGoogleStyle() ) { orientation = Orientation.VERTICAL; } return orientation; } final void setState(State state, final boolean... params) { mState = state; if (DEBUG) { Log.d(LOG_TAG, "State: " + mState.name()); } switch (mState) { case RESET: onReset(); break; case PULL_TO_REFRESH: onPullToRefresh(); break; case RELEASE_TO_REFRESH: onReleaseToRefresh(); break; case REFRESHING: case MANUAL_REFRESHING: onRefreshing(params[0]); break; case OVERSCROLLING: // NO-OP break; } // Call OnPullEventListener if (null != mOnPullEventListener) { mOnPullEventListener.onPullEvent(this, mState, mCurrentMode); } } /** * Used internally for adding view. Need because we override addView to * pass-through to the Refreshable View */ protected final void addViewInternal(View child, int index, ViewGroup.LayoutParams params) { super.addView(child, index, params); } /** * Used internally for adding view. Need because we override addView to * pass-through to the Refreshable View */ protected final void addViewInternal(View child, ViewGroup.LayoutParams params) { super.addView(child, -1, params); } /** * Create a new loading layout instance by using the class token {@link #mLoadingLayoutClazz} * @param context * @param mode * @param attrs * @return Loading layout instance which was created by using the class token {@link #mLoadingLayoutClazz} */ protected LoadingLayout createLoadingLayout(Context context, Mode mode, TypedArray attrs) { return LoadingLayoutFactory.createLoadingLayout(mLoadingLayoutClazz, context, mode, getFilteredPullToRefreshScrollDirection(), attrs); } /** * Create a new google style view layout instance by using the class token * @param layoutCode Google style view layout code to be converted to some class token * @param context * @param mode * @param attrs * @return Google style view layout instance which was created by using the class token */ private GoogleStyleViewLayout createGoogleStyleViewLayout( String layoutCode, Context context, TypedArray a) { Class clazz = GoogleStyleViewLayoutFactory.createGoogleStyleViewLayoutClazzByLayoutCode(layoutCode); return GoogleStyleViewLayoutFactory.createGoogleStyleViewLayout(clazz, context, a); } /** * Create a new google style progress layout instance by using the class token * @param layoutCode google style progress layout code to be converted to some class token * @param context * @param mode * @param attrs * @return Google style progress layout instance which was created by using the class token */ private GoogleStyleProgressLayout createGoogleStyleProgressLayout( String layoutCode, Context context, TypedArray a) { Class clazz = GoogleStyleProgressLayoutFactory.createGoogleStyleProgressLayoutClazzByLayoutCode(layoutCode); return GoogleStyleProgressLayoutFactory.createGoogleStyleProgressLayout(clazz, context, a); } /** * Used internally for {@link #getLoadingLayoutProxy(boolean, boolean)}. * Allows derivative classes to include any extra LoadingLayouts. */ protected LoadingLayoutProxy createLoadingLayoutProxy(final boolean includeStart, final boolean includeEnd) { LoadingLayoutProxy proxy = new LoadingLayoutProxy(); if (includeStart && mMode.showHeaderLoadingLayout()) { proxy.addLayout(mHeaderLayout); } if (includeEnd && mMode.showFooterLoadingLayout()) { proxy.addLayout(mFooterLayout); } return proxy; } /** * This is implemented by derived classes to return the created View. If you * need to use a custom View (such as a custom ListView), override this * method and return an instance of your custom class. *

* Be sure to set the ID of the view in this method, especially if you're * using a ListActivity or ListFragment. * * @param context Context to create view with * @param attrs AttributeSet from wrapped class. Means that anything you * include in the XML layout declaration will be routed to the * created View * @return New instance of the Refreshable View */ protected abstract T createRefreshableView(Context context, AttributeSet attrs); protected final void disableLoadingLayoutVisibilityChanges() { mLayoutVisibilityChangesEnabled = false; } protected final LoadingLayout getFooterLayout() { return mFooterLayout; } protected final int getFooterSize() { return mFooterLayout.getContentSize(); } protected final LoadingLayout getHeaderLayout() { return mHeaderLayout; } protected final int getHeaderSize() { return mHeaderLayout.getContentSize(); } protected final int getGoogleStyleViewSize() { return mGoogleStyleViewLayout.getContentSize(); } protected int getPullToRefreshScrollDuration() { return mSmoothScrollDurationMs; } protected int getPullToRefreshScrollDurationLonger() { return mSmoothScrollLongDurationMs; } protected FrameLayout getRefreshableViewWrapper() { return mRefreshableViewWrapper; } /** * Allows Derivative classes to handle the XML Attrs without creating a * TypedArray themsevles * * @param a - TypedArray of PullToRefresh Attributes */ protected void handleStyledAttributes(TypedArray a) { } /** * Implemented by derived class to return whether the View is in a state * where the user can Pull to Refresh by scrolling from the end. * * @return true if the View is currently in the correct state (for example, * bottom of a ListView) */ protected abstract boolean isReadyForPullEnd(); /** * Implemented by derived class to return whether the View is in a state * where the user can Pull to Refresh by scrolling from the start. * * @return true if the View is currently the correct state (for example, top * of a ListView) */ protected abstract boolean isReadyForPullStart(); /** * Called by {@link #onRestoreInstanceState(Parcelable)} so that derivative * classes can handle their saved instance state. * * @param savedInstanceState - Bundle which contains saved instance state. */ protected void onPtrRestoreInstanceState(Bundle savedInstanceState) { } /** * Called by {@link #onSaveInstanceState()} so that derivative classes can * save their instance state. * * @param saveState - Bundle to be updated with saved state. */ protected void onPtrSaveInstanceState(Bundle saveState) { } /** * Called when the UI has been to be updated to be in the * {@link State#PULL_TO_REFRESH} state. */ protected void onPullToRefresh() { switch (mCurrentMode) { case PULL_FROM_END: mFooterLayout.pullToRefresh(); break; case GOOGLE_STYLE: showViewTopLayout(); mGoogleStyleViewLayout.pullToRefresh(); mGoogleStyleProgressLayout.pullToRefresh(); break; case PULL_FROM_START: mHeaderLayout.pullToRefresh(); break; default: // NO-OP break; } } /** * Called when the UI has been to be updated to be in the * {@link State#REFRESHING} or {@link State#MANUAL_REFRESHING} state. * * @param doScroll - Whether the UI should scroll for this event. */ protected void onRefreshing(final boolean doScroll) { // Set the flag as below for fade-in animation of mRefreshableView when releasing mRefreshing = true; if (mMode.showHeaderLoadingLayout()) { mHeaderLayout.refreshing(); } if (mMode.showFooterLoadingLayout()) { mFooterLayout.refreshing(); } if (mMode.showGoogleStyle()) { // Fade-out mRefreshableView if ( mRefeshableViewHideWhileRefreshingEnabled == true ) { AlphaAnimator.fadeout(mRefreshableView, mRefeshableViewHideWhileRefreshingDuration); } // Fade-in refreshing bar on center if (mRefeshableViewRefreshingBarViewWhileRefreshingEnabled == true ) { mRefreshableViewProgressBar.setVisibility(View.VISIBLE); AlphaAnimator.fadein(mRefreshableViewProgressBar, mRefeshableViewRefreshingBarViewWhileRefreshingDuration); } mGoogleStyleViewLayout.refreshing(); mGoogleStyleProgressLayout.refreshing(); } if (doScroll) { if (mShowViewWhileRefreshing) { // Call Refresh Listener when the Scroll has finished OnSmoothScrollFinishedListener listener = new OnSmoothScrollFinishedListener() { @Override public void onSmoothScrollFinished() { callRefreshListener(); } }; switch (mCurrentMode) { case MANUAL_REFRESH_ONLY: case PULL_FROM_END: smoothScrollTo(getFooterSize(), listener); break; default: case PULL_FROM_START: smoothScrollTo(-getHeaderSize(), listener); break; } } else { smoothScrollTo(0); } } else { // We're not scrolling, so just call Refresh Listener now callRefreshListener(); } } /** * Called when the UI has been to be updated to be in the * {@link State#RELEASE_TO_REFRESH} state. */ protected void onReleaseToRefresh() { switch (mCurrentMode) { case PULL_FROM_END: mFooterLayout.releaseToRefresh(); break; case GOOGLE_STYLE: mGoogleStyleViewLayout.releaseToRefresh(); mGoogleStyleProgressLayout.releaseToRefresh(); break; case PULL_FROM_START: mHeaderLayout.releaseToRefresh(); break; default: // NO-OP break; } } /** * Called when the UI has been to be updated to be in the * {@link State#RESET} state. */ protected void onReset() { mIsBeingDragged = false; mLayoutVisibilityChangesEnabled = true; // Always reset both layouts, just in case... mHeaderLayout.reset(); mFooterLayout.reset(); if (mMode.showGoogleStyle()) { mGoogleStyleViewLayout.reset(); hideViewTopLayout(); mGoogleStyleProgressLayout.reset(); // Fade-in mRefreshableView if ( mRefreshing == true && mRefeshableViewHideWhileRefreshingEnabled == true ) { mRefreshableView.clearAnimation(); AlphaAnimator.fadein(mRefreshableView, mRefeshableViewHideWhileRefreshingDuration); } // Fade-out refreshing bar on center if (mRefeshableViewRefreshingBarViewWhileRefreshingEnabled == true ) { AlphaAnimator.fadeout(mRefreshableViewProgressBar, mRefeshableViewRefreshingBarViewWhileRefreshingDuration, new AnimationListener(){ @Override public void onAnimationEnd(Animation animation) { mRefreshableViewProgressBar.setVisibility(View.INVISIBLE); } @Override public void onAnimationRepeat(Animation animation) { // do nothing } @Override public void onAnimationStart(Animation animation) { // do nothing }}); } } mRefreshing = false; smoothScrollTo(0); } @Override protected final void onRestoreInstanceState(Parcelable state) { if (state instanceof Bundle) { Bundle bundle = (Bundle) state; setMode(Mode.mapIntToValue(bundle.getInt(STATE_MODE, 0))); mCurrentMode = Mode.mapIntToValue(bundle.getInt(STATE_CURRENT_MODE, 0)); mScrollingWhileRefreshingEnabled = bundle.getBoolean(STATE_SCROLLING_REFRESHING_ENABLED, false); mShowViewWhileRefreshing = bundle.getBoolean(STATE_SHOW_REFRESHING_VIEW, true); // Let super Restore Itself super.onRestoreInstanceState(bundle.getParcelable(STATE_SUPER)); State viewState = State.mapIntToValue(bundle.getInt(STATE_STATE, 0)); if (viewState == State.REFRESHING || viewState == State.MANUAL_REFRESHING) { setState(viewState, true); } // Now let derivative classes restore their state onPtrRestoreInstanceState(bundle); return; } super.onRestoreInstanceState(state); } @Override protected final Parcelable onSaveInstanceState() { Bundle bundle = new Bundle(); // Let derivative classes get a chance to save state first, that way we // can make sure they don't overrite any of our values onPtrSaveInstanceState(bundle); bundle.putInt(STATE_STATE, mState.getIntValue()); bundle.putInt(STATE_MODE, mMode.getIntValue()); bundle.putInt(STATE_CURRENT_MODE, mCurrentMode.getIntValue()); bundle.putBoolean(STATE_SCROLLING_REFRESHING_ENABLED, mScrollingWhileRefreshingEnabled); bundle.putBoolean(STATE_SHOW_REFRESHING_VIEW, mShowViewWhileRefreshing); bundle.putParcelable(STATE_SUPER, super.onSaveInstanceState()); return bundle; } @Override protected final void onSizeChanged(int w, int h, int oldw, int oldh) { if (DEBUG) { Log.d(LOG_TAG, String.format("onSizeChanged. W: %d, H: %d", w, h)); } super.onSizeChanged(w, h, oldw, oldh); // Skip if this view is loaded from preview mode of IDE if (isInEditMode()) { return; } // We need to update the header/footer when our size changes refreshLoadingViewsSize(); // Update the Refreshable View layout refreshRefreshableViewSize(w, h); /** * As we're currently in a Layout Pass, we need to schedule another one * to layout any changes we've made here */ post(new Runnable() { @Override public void run() { requestLayout(); } }); } /** * Re-measure the Loading Views height, and adjust internal padding as * necessary */ protected final void refreshLoadingViewsSize() { final int maximumPullScroll = (int) (getMaximumPullScroll() * 1.2f); int pLeft = getPaddingLeft(); int pTop = getPaddingTop(); int pRight = getPaddingRight(); int pBottom = getPaddingBottom(); switch (getFilteredPullToRefreshScrollDirection()) { case HORIZONTAL: if (mMode.showHeaderLoadingLayout()) { mHeaderLayout.setWidth(maximumPullScroll); pLeft = -maximumPullScroll; } else { pLeft = 0; } if (mMode.showFooterLoadingLayout()) { mFooterLayout.setWidth(maximumPullScroll); pRight = -maximumPullScroll; } else { pRight = 0; } break; case VERTICAL: if (mMode.showHeaderLoadingLayout()) { mHeaderLayout.setHeight(maximumPullScroll); pTop = -maximumPullScroll; } else if (mMode.showGoogleStyle() && mWindowAttached == true ) { /** * Set size of {@code GoogleStyleViewLayout} to ActionBar's size if {@code mSetGoogleViewLayoutSizeToActionbarHeight} is true * This code is a default action, but if you want to use custom size of {@code GoogleStyleViewLayout}, set {@code ptrSetGoogleViewLayoutSizeToActionbarHeight} to false in layout xml (but not recommended). */ if (mSetGoogleViewLayoutSizeToActionbarHeight == true) { mGoogleStyleViewLayout.setHeight(mActionBarHeight); } pTop = 0; } else { pTop = 0; } if (mMode.showFooterLoadingLayout()) { mFooterLayout.setHeight(maximumPullScroll); pBottom = -maximumPullScroll; } else { pBottom = 0; } break; } if (DEBUG) { Log.d(LOG_TAG, String.format("Setting Padding. L: %d, T: %d, R: %d, B: %d", pLeft, pTop, pRight, pBottom)); } setPadding(pLeft, pTop, pRight, pBottom); } protected final void refreshRefreshableViewSize(int width, int height) { // We need to set the Height of the Refreshable View to the same as // this layout LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mRefreshableViewWrapper.getLayoutParams(); switch (getFilteredPullToRefreshScrollDirection()) { case HORIZONTAL: if (lp.width != width) { lp.width = width; mRefreshableViewWrapper.requestLayout(); } break; case VERTICAL: if (lp.height != height) { lp.height = height; mRefreshableViewWrapper.requestLayout(); } break; } } /** * Helper method which just calls scrollTo() in the correct scrolling * direction. * * @param value - New Scroll value */ protected final void setHeaderScroll(int value) { if (DEBUG) { Log.d(LOG_TAG, "setHeaderScroll: " + value); } // Clamp value to with pull scroll range final int maximumPullScroll = getMaximumPullScroll(); value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value)); if (mLayoutVisibilityChangesEnabled) { if (value < 0) { switch (mCurrentMode) { case GOOGLE_STYLE: mGoogleStyleViewLayout.setVisibility(View.VISIBLE); break; default: case PULL_FROM_START: mHeaderLayout.setVisibility(View.VISIBLE); break; } } else if (value > 0) { mFooterLayout.setVisibility(View.VISIBLE); } else { mHeaderLayout.setVisibility(View.INVISIBLE); mFooterLayout.setVisibility(View.INVISIBLE); } } if (USE_HW_LAYERS) { /** * Use a Hardware Layer on the Refreshable View if we've scrolled at * all. We don't use them on the Header/Footer Views as they change * often, which would negate any HW layer performance boost. */ ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? LAYER_TYPE_HARDWARE : LAYER_TYPE_NONE /* View.LAYER_TYPE_NONE */); } // skip ScrollTo(...) if (mMode.showGoogleStyle() ) { return; } switch (getFilteredPullToRefreshScrollDirection()) { case VERTICAL: scrollTo(0, value); break; case HORIZONTAL: scrollTo(value, 0); break; } } /** * Smooth Scroll to position using the duration of * {@link #mSmoothScrollDurationMs} ms. * * @param scrollValue - Position to scroll to */ protected final void smoothScrollTo(int scrollValue) { smoothScrollTo(scrollValue, getPullToRefreshScrollDuration()); } /** * Smooth Scroll to position using the the duration of * {@link #mSmoothScrollDurationMs} ms. * * @param scrollValue - Position to scroll to * @param listener - Listener for scroll */ protected final void smoothScrollTo(int scrollValue, OnSmoothScrollFinishedListener listener) { smoothScrollTo(scrollValue, getPullToRefreshScrollDuration(), 0, listener); } /** * Smooth Scroll to position using the longer the duration of * {@link #mSmoothScrollLongDurationMs} ms. * * @param scrollValue - Position to scroll to */ protected final void smoothScrollToLonger(int scrollValue) { smoothScrollTo(scrollValue, getPullToRefreshScrollDurationLonger()); } /** * Updates the View State when the mode has been set. This does not do any * checking that the mode is different to current state so always updates. */ protected void updateUIForMode() { // We need to use the correct LayoutParam values, based on scroll // direction final LinearLayout.LayoutParams lp = getLoadingLayoutLayoutParams(); // Remove Header, and then add Header Loading View again if needed if (this == mHeaderLayout.getParent()) { removeView(mHeaderLayout); } if (mMode.showHeaderLoadingLayout()) { addViewInternal(mHeaderLayout, 0, lp); } // Remove Footer, and then add Footer Loading View again if needed if (this == mFooterLayout.getParent()) { removeView(mFooterLayout); } if (mMode.showFooterLoadingLayout()) { addViewInternal(mFooterLayout, lp); } // Hide Loading Views refreshLoadingViewsSize(); // If we're not using Mode.BOTH, set mCurrentMode to mMode, otherwise // set it to pull down mCurrentMode = (mMode != Mode.BOTH) ? mMode : Mode.PULL_FROM_START; } /** * Be called separately for google style mode when updating ui */ protected void updateUIForGoogleStyleMode() { // Skip if this view is loaded from preview mode of IDE if (isInEditMode()) { return; } if ( mWindowAttached == false ) { return; } if ( mMode.showGoogleStyle() == false ) { return; } // We need to use the correct LayoutParam values, based on scroll // direction // if ( mTopActionbarLayout == mGoogleStyleViewLayout.getParent()) { mTopActionbarLayout.removeView(mGoogleStyleViewLayout); } Log.d(LOG_TAG, "mViewOnTopLayout has been added." + mGoogleStyleViewLayout); mTopActionbarLayout.addView(mGoogleStyleViewLayout); /** * Set size of {@code GoogleStyleViewLayout} to ActionBar's size if {@code mSetGoogleViewLayoutSizeToActionbarHeight} is true * This code is a default action, but if you want to use custom size of {@code GoogleStyleViewLayout}, set {@code ptrSetGoogleViewLayoutSizeToActionbarHeight} to false in layout xml (but not recommended). */ if (mSetGoogleViewLayoutSizeToActionbarHeight == true) { // If it has called setHeight(...) method immediately after {@code view} has been added, the height isn't set correct post(new Runnable(){ @Override public void run() { mGoogleStyleViewLayout.setHeight(mActionBarHeight); }}); } // Show Google style view layout to screen mGoogleStyleViewLayout.setVisibility(View.VISIBLE); // Hide Loading Views refreshLoadingViewsSize(); // If we're not using Mode.BOTH, set mCurrentMode to mMode, otherwise // set it to pull down mCurrentMode = (mMode != Mode.BOTH) ? mMode : Mode.PULL_FROM_START; } private void addRefreshableView(Context context, T refreshableView) { mRefreshableViewWrapper = new FrameLayout(context); mRefreshableViewWrapper.addView(refreshableView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); addViewInternal(mRefreshableViewWrapper, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); } private void callRefreshListener() { if (null != mOnRefreshListener) { mOnRefreshListener.onRefresh(this); } else if (null != mOnRefreshListener2) { if (mCurrentMode == Mode.PULL_FROM_START || mCurrentMode == Mode.GOOGLE_STYLE) { mOnRefreshListener2.onPullDownToRefresh(this); } else if (mCurrentMode == Mode.PULL_FROM_END) { mOnRefreshListener2.onPullUpToRefresh(this); } } } @SuppressWarnings("deprecation") private void init(Context context, AttributeSet attrs) { // Skip if this view is loaded from preview mode of IDE if (isInEditMode()) { // Create the refreshable view and finish the initialization mRefreshableView = createRefreshableView(context, attrs); addRefreshableView(context, mRefreshableView); return; } // PullToRefreshXmlConfiguration must be initialized. PullToRefreshXmlConfiguration.getInstance().init(context); /** * start initialization */ // Styleables from XML // Getting mMode is first, because It uses mMode in getFilteredPullToRefreshScrollDirection() TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullToRefresh); if (a.hasValue(R.styleable.PullToRefresh_ptrMode)) { mMode = Mode.mapIntToValue(a.getInteger(R.styleable.PullToRefresh_ptrMode, 0)); filterModeForSDKVersion(); } switch (getFilteredPullToRefreshScrollDirection()) { case HORIZONTAL: setOrientation(LinearLayout.HORIZONTAL); break; case VERTICAL: default: setOrientation(LinearLayout.VERTICAL); break; } ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); // Default value of PTR View's gravity is center. So let the value be set center when the gravity is not set yet in XML. if (!Utils.existAttributeValue(attrs, "gravity")) { setGravity(Gravity.CENTER); } // Get a loading layout class token String loadingLayoutCode = null; if (a.hasValue(R.styleable.PullToRefresh_ptrAnimationStyle)) { loadingLayoutCode = a.getString(R.styleable.PullToRefresh_ptrAnimationStyle); } mLoadingLayoutClazz = LoadingLayoutFactory.createLoadingLayoutClazzByLayoutCode(loadingLayoutCode); // Refreshable View // By passing the attrs, we can add ListView/GridView params via XML mRefreshableView = createRefreshableView(context, attrs); addRefreshableView(context, mRefreshableView); // We need to create now layouts now mHeaderLayout = createLoadingLayout(context, Mode.PULL_FROM_START, a); mFooterLayout = createLoadingLayout(context, Mode.PULL_FROM_END, a); /** * Initialization for Google Style mode */ // Get a Google style view layout class token String googleStyleViewLayoutCode = null; if (a.hasValue(R.styleable.PullToRefresh_ptrGoogleViewStyle)) { googleStyleViewLayoutCode = a.getString(R.styleable.PullToRefresh_ptrGoogleViewStyle); } // Get a Google style progress layout class token String googleStyleProgressLayoutCode = null; if (a.hasValue(R.styleable.PullToRefresh_ptrGoogleViewStyle)) { googleStyleProgressLayoutCode = a.getString(R.styleable.PullToRefresh_ptrGoogleProgressStyle); } // Get a google style view layout mGoogleStyleViewLayout = createGoogleStyleViewLayout(googleStyleViewLayoutCode, context, a); // Get a google style progress layout mGoogleStyleProgressLayout = createGoogleStyleProgressLayout(googleStyleProgressLayoutCode, context, a); // Get animation options for Google style mode if (a.hasValue(R.styleable.PullToRefresh_ptrShowGoogleStyleViewAnimationEnabled)) { mShowGoogleStyleViewAnimationEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrShowGoogleStyleViewAnimationEnabled, true); } if (a.hasValue(R.styleable.PullToRefresh_ptrHideRefeshableViewWhileRefreshingEnabled)) { mRefeshableViewHideWhileRefreshingEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrHideRefeshableViewWhileRefreshingEnabled, true); } if (a.hasValue(R.styleable.PullToRefresh_ptrViewRefeshableViewProgressBarOnCenterWhileRefreshingEnabled)) { mRefeshableViewRefreshingBarViewWhileRefreshingEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrViewRefeshableViewProgressBarOnCenterWhileRefreshingEnabled, true); } if (a.hasValue(R.styleable.PullToRefresh_ptrShowGoogleStyleViewAnimationDuration)) { mShowGoogleStyleViewAnimationDuration = a.getInteger(R.styleable.PullToRefresh_ptrShowGoogleStyleViewAnimationDuration, GOOGLE_STYLE_VIEW_APPEAREANCE_DURATION); } if (a.hasValue(R.styleable.PullToRefresh_ptrHideRefeshableViewWhileRefreshingDuration)) { mRefeshableViewHideWhileRefreshingDuration = a.getInteger(R.styleable.PullToRefresh_ptrHideRefeshableViewWhileRefreshingDuration, REFRESHABLE_VIEW_HIDE_WHILE_REFRESHING_DURATION); } if (a.hasValue(R.styleable.PullToRefresh_ptrViewRefeshableViewProgressBarOnCenterWhileRefreshingDuration)) { mRefeshableViewRefreshingBarViewWhileRefreshingDuration = a.getInteger(R.styleable.PullToRefresh_ptrViewRefeshableViewProgressBarOnCenterWhileRefreshingDuration, REFRESHABLEVIEW_REFRESHING_BAR_VIEW_WHILE_REFRESHING_DURATION); } // Get a flag that decides Google View Layout's size is set to ActionBar's if (a.hasValue(R.styleable.PullToRefresh_ptrSetGoogleViewLayoutSizeToActionbarHeight)) { mSetGoogleViewLayoutSizeToActionbarHeight = a.getBoolean(R.styleable.PullToRefresh_ptrSetGoogleViewLayoutSizeToActionbarHeight, true); } // Get width or height attr of refreshing bar if (a.hasValue(R.styleable.PullToRefresh_ptrRefeshableViewProgressBarOnCenterWidth)) { mRefeshableViewRefreshingBarWidth = a.getInteger(R.styleable.PullToRefresh_ptrRefeshableViewProgressBarOnCenterWidth, DFEAULT_REFRESHABLEVIEW_REFRESHING_BAR_SIZE); } if (a.hasValue(R.styleable.PullToRefresh_ptrRefeshableViewProgressBarOnCenterHeight)) { mRefeshableViewRefreshingBarHeight = a.getInteger(R.styleable.PullToRefresh_ptrRefeshableViewProgressBarOnCenterHeight, DFEAULT_REFRESHABLEVIEW_REFRESHING_BAR_SIZE); } /** * Styleables from XML */ if (a.hasValue(R.styleable.PullToRefresh_ptrRefreshableViewBackground)) { Drawable background = a.getDrawable(R.styleable.PullToRefresh_ptrRefreshableViewBackground); if (null != background) { mRefreshableView.setBackgroundDrawable(background); } } else if (a.hasValue(R.styleable.PullToRefresh_ptrAdapterViewBackground)) { Utils.warnDeprecation("ptrAdapterViewBackground", "ptrRefreshableViewBackground"); Drawable background = a.getDrawable(R.styleable.PullToRefresh_ptrAdapterViewBackground); if (null != background) { mRefreshableView.setBackgroundDrawable(background); } } if (a.hasValue(R.styleable.PullToRefresh_ptrOverScroll)) { mOverScrollEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrOverScroll, true); } if (a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) { mScrollingWhileRefreshingEnabled = a.getBoolean( R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled, false); } // set scroll properties from attributes float friction = a.getFloat(R.styleable.PullToRefresh_ptrFriction, DEFAULT_FRICTION); int smoothScrollDuration = a.getInt(R.styleable.PullToRefresh_ptrSmoothScrollDuration, DEFAULT_SMOOTH_SCROLL_DURATION_MS); int smoothScrollLongDuration = a.getInt(R.styleable.PullToRefresh_ptrSmoothScrollLongDuration, DEFAULT_SMOOTH_SCROLL_LONG_DURATION_MS); setFriction(friction); setSmoothScrollDuration(smoothScrollDuration); setSmoothScrollLongDuration(smoothScrollLongDuration); // Let the derivative classes have a go at handling attributes, then // recycle them... handleStyledAttributes(a); a.recycle(); // Get action bar height and status bar height initActionBarSize(context); initStatusBarSize(context); determineYPositionOfGoogleStyleViewLayout(); // Finally update the UI for the modes updateUIForMode(); // updateUIForGoogleStyleMode() method will be called when onAttachedToWindow() event has been fired. } private void filterModeForSDKVersion() { // If SDK version is 2.x or lower, Let the mode not be google mode. // Because google mode should not be supported in those versions. if ( VERSION.SDK_INT < VERSION_CODES.HONEYCOMB && mMode == Mode.GOOGLE_STYLE ) { mMode = Mode.PULL_FROM_START; } } private void determineYPositionOfGoogleStyleViewLayout() { if ( VERSION.SDK_INT < VERSION_CODES.ICE_CREAM_SANDWICH ) { mYPositionOfGoogleStyleViewLayout = 0; } else { mYPositionOfGoogleStyleViewLayout = mStatusBarHeight; } } /** * NOTE : This method must be called after initStatusBarSize() and initActionBarSize() have already been called. Also, mGoogleStyleProgressLayout should be initialized before calling this method. */ private void determineYPositionOfGoogleStyleProgressLayout() { if ( VERSION.SDK_INT < VERSION_CODES.ICE_CREAM_SANDWICH ) { mYPositionOfGoogleStyleProgressLayout = mStatusBarHeight + 1; } else { mYPositionOfGoogleStyleProgressLayout = mActionBarHeight + mGoogleStyleProgressLayout.getHeight() + 1; } } /** * Show google view layout and google progress layout when pulling */ private void showViewTopLayout() { if (mMode.showGoogleStyle() == false ) { return; } // Initialize Translate and Alpha animation if ( mShowGoogleStyleViewAnimationEnabled == true ) { AnimationSet set = new AnimationSet(true /* share interpolator */); set.setDuration(mShowGoogleStyleViewAnimationDuration); set.setFillAfter(true); set.setAnimationListener(new AnimationListener(){ @Override public void onAnimationEnd(Animation anim) { } @Override public void onAnimationRepeat(Animation anim) { } @Override public void onAnimationStart(Animation anim) { mTopActionbarLayout.setVisibility(View.VISIBLE); }}); TranslateAnimation transAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0,Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -mActionBarHeight, Animation.ABSOLUTE, mYPositionOfGoogleStyleViewLayout); AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f); set.addAnimation(transAnimation); set.addAnimation(alphaAnimation); // Start animation mTopActionbarLayout.startAnimation(set); } else { // Show Google style view layout without animation ((FrameLayout.LayoutParams) mTopActionbarLayout.getLayoutParams()).topMargin = mYPositionOfGoogleStyleViewLayout; mTopActionbarLayout.setVisibility(View.VISIBLE); } mGoogleStyleProgressLayout.setVisibility(View.VISIBLE); } /** * Hide google view layout and google progress layout when releasing */ private void hideViewTopLayout() { if (mMode.showGoogleStyle() == false ) { return; } if ( mShowGoogleStyleViewAnimationEnabled == true ) { // Initialize Translate and Alpha animation AnimationSet set = new AnimationSet(true /* share interpolator */); set.setDuration(mShowGoogleStyleViewAnimationDuration); set.setFillAfter(true); set.setAnimationListener(new AnimationListener(){ @Override public void onAnimationEnd(Animation anim) { mTopActionbarLayout.setVisibility(View.INVISIBLE); } @Override public void onAnimationRepeat(Animation anim) { } @Override public void onAnimationStart(Animation anim) { }}); TranslateAnimation transAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0,Animation.ABSOLUTE, 0, Animation.ABSOLUTE, mTopActionbarLayout.getTop(), Animation.ABSOLUTE, -mStatusBarHeight); AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f); set.addAnimation(transAnimation); set.addAnimation(alphaAnimation); // Start animation mTopActionbarLayout.startAnimation(set); } else { // Hide Google style view layout without animation ((FrameLayout.LayoutParams) mTopActionbarLayout.getLayoutParams()).topMargin = -mActionBarHeight; mTopActionbarLayout.setVisibility(View.INVISIBLE); } mGoogleStyleProgressLayout.setVisibility(View.INVISIBLE); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); mWindowAttached = true; initTopViewGroup(); updateUIForGoogleStyleMode(); } /** * Initialize {@code mTopActionbarLayout} and add that into Top DecorView(this is the root view), * and initialize needed components */ private void initTopViewGroup() { // Skip if this view is loaded from preview mode of IDE if (isInEditMode()) { return; } if ( mMode.showGoogleStyle() == false ) { return; } View view = this.getRootView(); ViewGroup topViewGroup = null; Context context = getContext(); if (view instanceof ViewGroup == false) { Log.w(LOG_TAG, "Current root view is not ViewGroup type. Google Style Pull To Refresh mode will be disabled."); topViewGroup = new ViewGroup(context) { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // do nothing }}; } else { topViewGroup = (ViewGroup) view; } // Initialize Top Layout Layout FrameLayout layout = new FrameLayout(context); @SuppressWarnings("deprecation") int matchParent = ViewGroup.LayoutParams.FILL_PARENT; ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(matchParent, mActionBarHeight); topViewGroup.addView(layout, params); layout.setVisibility(View.INVISIBLE); // Initialize refreshing bar on center if (mMode.showGoogleStyle()) { mRefreshableViewProgressBar = generateCircleProgressBar(context); FrameLayout.LayoutParams barParams = new FrameLayout.LayoutParams(mRefeshableViewRefreshingBarWidth, mRefeshableViewRefreshingBarHeight); barParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; mRefreshableViewProgressBar.setVisibility(View.INVISIBLE); mRefreshableViewWrapper.addView(mRefreshableViewProgressBar, -1, barParams); } // Initialize Google style progress layout topViewGroup.addView(mGoogleStyleProgressLayout, mGoogleStyleProgressLayout.createLayoutParams()); mGoogleStyleProgressLayout.setVisibility(View.INVISIBLE); // Set height of Google style progress layout post(new Runnable(){ @Override public void run() { determineYPositionOfGoogleStyleProgressLayout(); mGoogleStyleProgressLayout.setTopMargin(mYPositionOfGoogleStyleProgressLayout); }}); // Finally assign mTopActionbarLayout = layout; } /** * Get an actionBar's size and save into a field * @param context */ private void initActionBarSize(Context context) { mActionBarHeight = Utils.getActionBarSize(context); } /** * Get an StatusBar's size and save into a field * @param context */ private void initStatusBarSize(Context context) { mStatusBarHeight = Utils.getStatusBarSize(context); } /** * Generate Progress bar UI Component on center * @param context * @return Generated ProgressBar instance */ private ProgressBar generateCircleProgressBar(Context context) { ProgressBar circleProgressBar = new ProgressBar(context); circleProgressBar.setScrollBarStyle(android.R.attr.progressBarStyle); circleProgressBar.setIndeterminate(true); return circleProgressBar; } private boolean isReadyForPull() { switch (mMode) { case PULL_FROM_START: case GOOGLE_STYLE: return isReadyForPullStart(); case PULL_FROM_END: return isReadyForPullEnd(); case BOTH: return isReadyForPullEnd() || isReadyForPullStart(); default: return false; } } /** * Actions a Pull Event * * @return true if the Event has been handled, false if there has been no * change */ private void pullEvent() { final int newScrollValue; final int itemDimension; final float initialMotionValue, lastMotionValue; switch (getFilteredPullToRefreshScrollDirection()) { case HORIZONTAL: initialMotionValue = mInitialMotionX; lastMotionValue = mLastMotionX; break; case VERTICAL: default: initialMotionValue = mInitialMotionY; lastMotionValue = mLastMotionY; break; } switch (mCurrentMode) { case PULL_FROM_END: newScrollValue = Math.round(Math.max(initialMotionValue - lastMotionValue, 0) / mFriction); itemDimension = getFooterSize(); break; case GOOGLE_STYLE: newScrollValue = Math.round(Math.min(initialMotionValue - lastMotionValue, 0) / mFriction); itemDimension = getGoogleStyleViewSize(); break; case PULL_FROM_START: default: newScrollValue = Math.round(Math.min(initialMotionValue - lastMotionValue, 0) / mFriction); itemDimension = getHeaderSize(); break; } setHeaderScroll(newScrollValue); if (newScrollValue != 0 && !isRefreshing()) { float scale = Math.abs(newScrollValue) / (float) itemDimension; switch (mCurrentMode) { case PULL_FROM_END: mFooterLayout.onPull(scale); break; case GOOGLE_STYLE: mGoogleStyleViewLayout.onPull(scale); mGoogleStyleProgressLayout.onPull(scale); break; case PULL_FROM_START: default: mHeaderLayout.onPull(scale); break; } if (mState != State.PULL_TO_REFRESH && itemDimension >= Math.abs(newScrollValue)) { setState(State.PULL_TO_REFRESH); } else if (mState == State.PULL_TO_REFRESH && itemDimension < Math.abs(newScrollValue)) { setState(State.RELEASE_TO_REFRESH); } } } @SuppressWarnings("deprecation") private LinearLayout.LayoutParams getLoadingLayoutLayoutParams() { switch (getFilteredPullToRefreshScrollDirection()) { case HORIZONTAL: return new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT); case VERTICAL: default: return new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); } } private int getMaximumPullScroll() { switch (getFilteredPullToRefreshScrollDirection()) { case HORIZONTAL: return Math.round(getWidth() / mFriction); case VERTICAL: default: return Math.round(getHeight() / mFriction); } } /** * Smooth Scroll to position using the specific duration * * @param scrollValue - Position to scroll to * @param duration - Duration of animation in milliseconds */ private final void smoothScrollTo(int scrollValue, long duration) { smoothScrollTo(scrollValue, duration, 0, null); } private final void smoothScrollTo(int newScrollValue, long duration, long delayMillis, OnSmoothScrollFinishedListener listener) { if (null != mCurrentSmoothScrollRunnable) { mCurrentSmoothScrollRunnable.stop(); } final int oldScrollValue; switch (getFilteredPullToRefreshScrollDirection()) { case HORIZONTAL: oldScrollValue = getScrollX(); break; case VERTICAL: default: oldScrollValue = getScrollY(); break; } if (oldScrollValue != newScrollValue) { if (null == mScrollAnimationInterpolator) { // Default interpolator is a Decelerate Interpolator mScrollAnimationInterpolator = new DecelerateInterpolator(); } mCurrentSmoothScrollRunnable = new SmoothScrollRunnable(oldScrollValue, newScrollValue, duration, listener); if (delayMillis > 0) { postDelayed(mCurrentSmoothScrollRunnable, delayMillis); } else { post(mCurrentSmoothScrollRunnable); } } else if ( listener != null ) { // Call listener immediately listener.onSmoothScrollFinished(); } } private final void smoothScrollToAndBack(int y) { smoothScrollTo(y, mSmoothScrollDurationMs, 0, new OnSmoothScrollFinishedListener() { @Override public void onSmoothScrollFinished() { smoothScrollTo(0, mSmoothScrollDurationMs, DEMO_SCROLL_INTERVAL, null); } }); } public static enum Mode { /** * Disable all Pull-to-Refresh gesture and Refreshing handling */ DISABLED(0x0), /** * Only allow the user to Pull from the start of the Refreshable View to * refresh. The start is either the Top or Left, depending on the * scrolling direction. */ PULL_FROM_START(0x1), /** * Only allow the user to Pull from the end of the Refreshable View to * refresh. The start is either the Bottom or Right, depending on the * scrolling direction. */ PULL_FROM_END(0x2), /** * Allow the user to both Pull from the start, from the end to refresh. */ BOTH(0x3), /** * Disables Pull-to-Refresh gesture handling, but allows manually * setting the Refresh state via * {@link PullToRefreshBase#setRefreshing() setRefreshing()}. */ MANUAL_REFRESH_ONLY(0x4), /** * Google style pull-to-refresh mode * */ GOOGLE_STYLE(0x5); /** * @deprecated Use {@link #PULL_FROM_START} from now on. */ public static Mode PULL_DOWN_TO_REFRESH = Mode.PULL_FROM_START; /** * @deprecated Use {@link #PULL_FROM_END} from now on. */ public static Mode PULL_UP_TO_REFRESH = Mode.PULL_FROM_END; /** * Maps an int to a specific mode. This is needed when saving state, or * inflating the view from XML where the mode is given through a attr * int. * * @param modeInt - int to map a Mode to * @return Mode that modeInt maps to, or PULL_FROM_START by default. */ static Mode mapIntToValue(final int modeInt) { for (Mode value : Mode.values()) { if (modeInt == value.getIntValue()) { return value; } } // If not, return default return getDefault(); } static Mode getDefault() { return PULL_FROM_START; } private int mIntValue; // The modeInt values need to match those from attrs.xml Mode(int modeInt) { mIntValue = modeInt; } /** * @return true if the mode permits Pull-to-Refresh */ boolean permitsPullToRefresh() { return !(this == DISABLED || this == MANUAL_REFRESH_ONLY); } /** * @return true if this mode wants the Loading Layout Header to be shown */ public boolean showHeaderLoadingLayout() { return this == PULL_FROM_START || this == BOTH; } /** * @return true if this mode wants the Loading Layout Footer to be shown */ public boolean showFooterLoadingLayout() { return this == PULL_FROM_END || this == BOTH || this == MANUAL_REFRESH_ONLY; } /** * @return true if this mode wants the Loading Layout to be shown like Google style pull-to-refresh */ public boolean showGoogleStyle() { return this == GOOGLE_STYLE; } int getIntValue() { return mIntValue; } } // =========================================================== // Inner, Anonymous Classes, and Enumerations // =========================================================== /** * Simple Listener that allows you to be notified when the user has scrolled * to the end of the AdapterView. See ( * {@link PullToRefreshAdapterViewBase#setOnLastItemVisibleListener}. * * @author Chris Banes */ public static interface OnLastItemVisibleListener { /** * Called when the user has scrolled to the end of the list */ public void onLastItemVisible(); } /** * Listener that allows you to be notified when the user has started or * finished a touch event. Useful when you want to append extra UI events * (such as sounds). See ( * {@link PullToRefreshAdapterViewBase#setOnPullEventListener}. * * @author Chris Banes */ public static interface OnPullEventListener { /** * Called when the internal state has been changed, usually by the user * pulling. * * @param refreshView - View which has had it's state change. * @param state - The new state of View. * @param direction - One of {@link Mode#PULL_FROM_START} or * {@link Mode#PULL_FROM_END} depending on which direction * the user is pulling. Only useful when state is * {@link State#PULL_TO_REFRESH} or * {@link State#RELEASE_TO_REFRESH}. */ public void onPullEvent(final PullToRefreshBase refreshView, State state, Mode direction); } /** * Simple Listener to listen for any callbacks to Refresh. * * @author Chris Banes */ public static interface OnRefreshListener { /** * onRefresh will be called for both a Pull from start, and Pull from * end */ public void onRefresh(final PullToRefreshBase refreshView); } /** * An advanced version of the Listener to listen for callbacks to Refresh. * This listener is different as it allows you to differentiate between Pull * Ups, and Pull Downs. * * @author Chris Banes */ public static interface OnRefreshListener2 { // TODO These methods need renaming to START/END rather than DOWN/UP /** * onPullDownToRefresh will be called only when the user has Pulled from * the start, and released. */ public void onPullDownToRefresh(final PullToRefreshBase refreshView); /** * onPullUpToRefresh will be called only when the user has Pulled from * the end, and released. */ public void onPullUpToRefresh(final PullToRefreshBase refreshView); } public static enum Orientation { VERTICAL, HORIZONTAL; } public static enum State { /** * When the UI is in a state which means that user is not interacting * with the Pull-to-Refresh function. */ RESET(0x0), /** * When the UI is being pulled by the user, but has not been pulled far * enough so that it refreshes when released. */ PULL_TO_REFRESH(0x1), /** * When the UI is being pulled by the user, and has * been pulled far enough so that it will refresh when released. */ RELEASE_TO_REFRESH(0x2), /** * When the UI is currently refreshing, caused by a pull gesture. */ REFRESHING(0x8), /** * When the UI is currently refreshing, caused by a call to * {@link PullToRefreshBase#setRefreshing() setRefreshing()}. */ MANUAL_REFRESHING(0x9), /** * When the UI is currently overscrolling, caused by a fling on the * Refreshable View. */ OVERSCROLLING(0x10); /** * Maps an int to a specific state. This is needed when saving state. * * @param stateInt - int to map a State to * @return State that stateInt maps to */ static State mapIntToValue(final int stateInt) { for (State value : State.values()) { if (stateInt == value.getIntValue()) { return value; } } // If not, return default return RESET; } private int mIntValue; State(int intValue) { mIntValue = intValue; } int getIntValue() { return mIntValue; } } final class SmoothScrollRunnable implements Runnable { private final Interpolator mInterpolator; private final int mScrollToY; private final int mScrollFromY; private final long mDuration; private OnSmoothScrollFinishedListener mListener; private boolean mContinueRunning = true; private long mStartTime = -1; private int mCurrentY = -1; public SmoothScrollRunnable(int fromY, int toY, long duration, OnSmoothScrollFinishedListener listener) { mScrollFromY = fromY; mScrollToY = toY; mInterpolator = mScrollAnimationInterpolator; mDuration = duration; mListener = listener; } @Override public void run() { /** * Only set mStartTime if this is the first time we're starting, * else actually calculate the Y delta */ if (mStartTime == -1) { mStartTime = System.currentTimeMillis(); } else { /** * We do do all calculations in long to reduce software float * calculations. We use 1000 as it gives us good accuracy and * small rounding errors */ long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration; normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0); final int deltaY = Math.round((mScrollFromY - mScrollToY) * mInterpolator.getInterpolation(normalizedTime / 1000f)); mCurrentY = mScrollFromY - deltaY; setHeaderScroll(mCurrentY); } // If we're not at the target Y, keep going... if (mContinueRunning && mScrollToY != mCurrentY) { ViewCompat.postOnAnimation(PullToRefreshBase.this, this); } else { if (null != mListener) { mListener.onSmoothScrollFinished(); } } } public void stop() { mContinueRunning = false; removeCallbacks(this); } } static interface OnSmoothScrollFinishedListener { void onSmoothScrollFinished(); } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/PullToRefreshExpandableListView.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import android.annotation.TargetApi; import android.content.Context; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.util.AttributeSet; import android.view.View; import android.widget.ExpandableListView; import com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor; import com.handmark.pulltorefresh.library.internal.LoadingLayout; public class PullToRefreshExpandableListView extends PullToRefreshAdapterViewBase { public PullToRefreshExpandableListView(Context context) { super(context); } public PullToRefreshExpandableListView(Context context, AttributeSet attrs) { super(context, attrs); } public PullToRefreshExpandableListView(Context context, Mode mode) { super(context, mode); } public PullToRefreshExpandableListView(Context context, Mode mode, Class loadingLayoutClazz) { super(context, mode, loadingLayoutClazz); } @Override public final Orientation getPullToRefreshScrollDirection() { return Orientation.VERTICAL; } @Override protected ExpandableListView createRefreshableView(Context context, AttributeSet attrs) { final ExpandableListView lv; if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { lv = new InternalExpandableListViewSDK9(context, attrs); } else { lv = new InternalExpandableListView(context, attrs); } // Set it to this so it can be used in ListActivity/ListFragment lv.setId(android.R.id.list); return lv; } class InternalExpandableListView extends ExpandableListView implements EmptyViewMethodAccessor { public InternalExpandableListView(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void setEmptyView(View emptyView) { PullToRefreshExpandableListView.this.setEmptyView(emptyView); } @Override public void setEmptyViewInternal(View emptyView) { super.setEmptyView(emptyView); } } @TargetApi(9) final class InternalExpandableListViewSDK9 extends InternalExpandableListView { public InternalExpandableListViewSDK9(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); // Does all of the hard work... OverscrollHelper.overScrollBy(PullToRefreshExpandableListView.this, deltaX, scrollX, deltaY, scrollY, isTouchEvent); return returnValue; } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/PullToRefreshGridView.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import android.annotation.TargetApi; import android.content.Context; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.util.AttributeSet; import android.view.View; import android.widget.GridView; import com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor; import com.handmark.pulltorefresh.library.internal.LoadingLayout; public class PullToRefreshGridView extends PullToRefreshAdapterViewBase { public PullToRefreshGridView(Context context) { super(context); } public PullToRefreshGridView(Context context, AttributeSet attrs) { super(context, attrs); } public PullToRefreshGridView(Context context, Mode mode) { super(context, mode); } public PullToRefreshGridView(Context context, Mode mode, Class loadingLayoutClazz) { super(context, mode, loadingLayoutClazz); } @Override public final Orientation getPullToRefreshScrollDirection() { return Orientation.VERTICAL; } @Override protected final GridView createRefreshableView(Context context, AttributeSet attrs) { final GridView gv; if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { gv = new InternalGridViewSDK9(context, attrs); } else { gv = new InternalGridView(context, attrs); } // Use Generated ID (from res/values/ids.xml) gv.setId(R.id.gridview); return gv; } class InternalGridView extends GridView implements EmptyViewMethodAccessor { public InternalGridView(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void setEmptyView(View emptyView) { PullToRefreshGridView.this.setEmptyView(emptyView); } @Override public void setEmptyViewInternal(View emptyView) { super.setEmptyView(emptyView); } } @TargetApi(9) final class InternalGridViewSDK9 extends InternalGridView { public InternalGridViewSDK9(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); // Does all of the hard work... OverscrollHelper.overScrollBy(PullToRefreshGridView.this, deltaX, scrollX, deltaY, scrollY, isTouchEvent); return returnValue; } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/PullToRefreshHorizontalScrollView.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import com.handmark.pulltorefresh.library.internal.LoadingLayout; import android.annotation.TargetApi; import android.content.Context; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.util.AttributeSet; import android.view.View; import android.widget.HorizontalScrollView; public class PullToRefreshHorizontalScrollView extends PullToRefreshBase { public PullToRefreshHorizontalScrollView(Context context) { super(context); } public PullToRefreshHorizontalScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public PullToRefreshHorizontalScrollView(Context context, Mode mode) { super(context, mode); } public PullToRefreshHorizontalScrollView(Context context, Mode mode, Class loadingLayoutClazz) { super(context, mode, loadingLayoutClazz); } @Override public final Orientation getPullToRefreshScrollDirection() { return Orientation.HORIZONTAL; } @Override protected HorizontalScrollView createRefreshableView(Context context, AttributeSet attrs) { HorizontalScrollView scrollView; if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { scrollView = new InternalHorizontalScrollViewSDK9(context, attrs); } else { scrollView = new HorizontalScrollView(context, attrs); } scrollView.setId(R.id.scrollview); return scrollView; } @Override protected boolean isReadyForPullStart() { return mRefreshableView.getScrollX() == 0; } @Override protected boolean isReadyForPullEnd() { View scrollViewChild = mRefreshableView.getChildAt(0); if (null != scrollViewChild) { return mRefreshableView.getScrollX() >= (scrollViewChild.getWidth() - getWidth()); } return false; } @TargetApi(9) final class InternalHorizontalScrollViewSDK9 extends HorizontalScrollView { public InternalHorizontalScrollViewSDK9(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); // Does all of the hard work... OverscrollHelper.overScrollBy(PullToRefreshHorizontalScrollView.this, deltaX, scrollX, deltaY, scrollY, getScrollRange(), isTouchEvent); return returnValue; } /** * Taken from the AOSP ScrollView source */ private int getScrollRange() { int scrollRange = 0; if (getChildCount() > 0) { View child = getChildAt(0); scrollRange = Math.max(0, child.getWidth() - (getWidth() - getPaddingLeft() - getPaddingRight())); } return scrollRange; } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/PullToRefreshListView.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.util.AttributeSet; import android.util.Log; import android.view.Gravity; import android.view.MotionEvent; import android.view.View; import android.widget.FrameLayout; import android.widget.ListAdapter; import android.widget.ListView; import com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor; import com.handmark.pulltorefresh.library.internal.LoadingLayout; public class PullToRefreshListView extends PullToRefreshAdapterViewBase { private LoadingLayout mHeaderLoadingView; private LoadingLayout mFooterLoadingView; private FrameLayout mLvFooterLoadingFrame; private boolean mListViewExtrasEnabled; public PullToRefreshListView(Context context) { super(context); } public PullToRefreshListView(Context context, AttributeSet attrs) { super(context, attrs); } public PullToRefreshListView(Context context, Mode mode) { super(context, mode); } public PullToRefreshListView(Context context, Mode mode, Class loadingLayoutClazz) { super(context, mode, loadingLayoutClazz); } @Override public final Orientation getPullToRefreshScrollDirection() { return Orientation.VERTICAL; } @Override protected void onRefreshing(final boolean doScroll) { ListAdapter adapter = mRefreshableView.getAdapter(); /** * Don't let ptrListView do refreshing if adapter is null. */ if (null == adapter) { Log.d(PullToRefreshListView.class.getSimpleName(), "Please set an adapter for PullToRefreshListView"); return; } /** * If we're not showing the Refreshing view, the * the header/footer views won't show so we use the normal method. */ if (!mListViewExtrasEnabled || !getShowViewWhileRefreshing() || getCurrentMode() == Mode.GOOGLE_STYLE) { super.onRefreshing(doScroll); return; } super.onRefreshing(false); final LoadingLayout origLoadingView, listViewLoadingView, oppositeListViewLoadingView; final int selection, scrollToY; switch (getCurrentMode()) { case MANUAL_REFRESH_ONLY: case PULL_FROM_END: origLoadingView = getFooterLayout(); listViewLoadingView = mFooterLoadingView; oppositeListViewLoadingView = mHeaderLoadingView; selection = mRefreshableView.getCount() - 1; scrollToY = getScrollY() - getFooterSize(); break; case PULL_FROM_START: default: origLoadingView = getHeaderLayout(); listViewLoadingView = mHeaderLoadingView; oppositeListViewLoadingView = mFooterLoadingView; selection = 0; scrollToY = getScrollY() + getHeaderSize(); break; } // Hide our original Loading View origLoadingView.reset(); origLoadingView.hideAllViews(); // Make sure the opposite end is hidden too oppositeListViewLoadingView.setVisibility(View.GONE); // Show the ListView Loading View and set it to refresh. listViewLoadingView.setVisibility(View.VISIBLE); listViewLoadingView.refreshing(); if (doScroll) { // We need to disable the automatic visibility changes for now disableLoadingLayoutVisibilityChanges(); // We scroll slightly so that the ListView's header/footer is at the // same Y position as our normal header/footer setHeaderScroll(scrollToY); // Make sure the ListView is scrolled to show the loading // header/footer mRefreshableView.setSelection(selection); // Smooth scroll as normal smoothScrollTo(0); } } @Override protected void onReset() { /** * If the extras are not enabled, just call up to super and return. */ if (!mListViewExtrasEnabled || getCurrentMode() == Mode.GOOGLE_STYLE) { super.onReset(); return; } final LoadingLayout originalLoadingLayout, listViewLoadingLayout; final int scrollToHeight, selection; final boolean scrollLvToEdge; switch (getCurrentMode()) { case MANUAL_REFRESH_ONLY: case PULL_FROM_END: originalLoadingLayout = getFooterLayout(); listViewLoadingLayout = mFooterLoadingView; selection = mRefreshableView.getCount() - 1; scrollToHeight = getFooterSize(); scrollLvToEdge = Math.abs(mRefreshableView.getLastVisiblePosition() - selection) <= 1; break; case PULL_FROM_START: default: originalLoadingLayout = getHeaderLayout(); listViewLoadingLayout = mHeaderLoadingView; scrollToHeight = -getHeaderSize(); selection = 0; scrollLvToEdge = Math.abs(mRefreshableView.getFirstVisiblePosition() - selection) <= 1; break; } // If the ListView header loading layout is showing, then we need to // flip so that the original one is showing instead if (listViewLoadingLayout.getVisibility() == View.VISIBLE) { // Set our Original View to Visible originalLoadingLayout.showInvisibleViews(); // Hide the ListView Header/Footer listViewLoadingLayout.setVisibility(View.GONE); /** * Scroll so the View is at the same Y as the ListView * header/footer, but only scroll if: we've pulled to refresh, it's * positioned correctly */ if (scrollLvToEdge && getState() != State.MANUAL_REFRESHING) { mRefreshableView.setSelection(selection); setHeaderScroll(scrollToHeight); } } // Finally, call up to super super.onReset(); } @Override protected LoadingLayoutProxy createLoadingLayoutProxy(final boolean includeStart, final boolean includeEnd) { LoadingLayoutProxy proxy = super.createLoadingLayoutProxy(includeStart, includeEnd); if (mListViewExtrasEnabled) { final Mode mode = getMode(); if (includeStart && mode.showHeaderLoadingLayout()) { proxy.addLayout(mHeaderLoadingView); } if (includeEnd && mode.showFooterLoadingLayout()) { proxy.addLayout(mFooterLoadingView); } } return proxy; } protected ListView createListView(Context context, AttributeSet attrs) { final ListView lv; if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { lv = new InternalListViewSDK9(context, attrs); } else { lv = new InternalListView(context, attrs); } return lv; } @Override protected ListView createRefreshableView(Context context, AttributeSet attrs) { ListView lv = createListView(context, attrs); // Set it to this so it can be used in ListActivity/ListFragment lv.setId(android.R.id.list); return lv; } @Override protected void handleStyledAttributes(TypedArray a) { super.handleStyledAttributes(a); mListViewExtrasEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrListViewExtrasEnabled, true); if ( getMode() == Mode.GOOGLE_STYLE) { mListViewExtrasEnabled = false; } if (mListViewExtrasEnabled) { final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL); // Create Loading Views ready for use later FrameLayout frame = new FrameLayout(getContext()); mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a); mHeaderLoadingView.setVisibility(View.GONE); frame.addView(mHeaderLoadingView, lp); mRefreshableView.addHeaderView(frame, null, false); mLvFooterLoadingFrame = new FrameLayout(getContext()); mFooterLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_END, a); mFooterLoadingView.setVisibility(View.GONE); mLvFooterLoadingFrame.addView(mFooterLoadingView, lp); /** * If the value for Scrolling While Refreshing hasn't been * explicitly set via XML, enable Scrolling While Refreshing. */ if (!a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) { setScrollingWhileRefreshingEnabled(true); } } } @TargetApi(9) final class InternalListViewSDK9 extends InternalListView { public InternalListViewSDK9(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); // Does all of the hard work... OverscrollHelper.overScrollBy(PullToRefreshListView.this, deltaX, scrollX, deltaY, scrollY, isTouchEvent); return returnValue; } } protected class InternalListView extends ListView implements EmptyViewMethodAccessor { private boolean mAddedLvFooter = false; public InternalListView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void dispatchDraw(Canvas canvas) { /** * This is a bit hacky, but Samsung's ListView has got a bug in it * when using Header/Footer Views and the list is empty. This masks * the issue so that it doesn't cause an FC. See Issue #66. */ try { super.dispatchDraw(canvas); } catch (IndexOutOfBoundsException e) { e.printStackTrace(); } } @Override public boolean dispatchTouchEvent(MotionEvent ev) { /** * This is a bit hacky, but Samsung's ListView has got a bug in it * when using Header/Footer Views and the list is empty. This masks * the issue so that it doesn't cause an FC. See Issue #66. */ try { return super.dispatchTouchEvent(ev); } catch (IndexOutOfBoundsException e) { e.printStackTrace(); return false; } } @Override public void setAdapter(ListAdapter adapter) { // Add the Footer View at the last possible moment if (null != mLvFooterLoadingFrame && !mAddedLvFooter) { addFooterView(mLvFooterLoadingFrame, null, false); mAddedLvFooter = true; } super.setAdapter(adapter); } @Override public void setEmptyView(View emptyView) { PullToRefreshListView.this.setEmptyView(emptyView); } @Override public void setEmptyViewInternal(View emptyView) { super.setEmptyView(emptyView); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/PullToRefreshScrollView.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import com.handmark.pulltorefresh.library.internal.LoadingLayout; import android.annotation.TargetApi; import android.content.Context; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.util.AttributeSet; import android.view.View; import android.widget.ScrollView; public class PullToRefreshScrollView extends PullToRefreshBase { public PullToRefreshScrollView(Context context) { super(context); } public PullToRefreshScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public PullToRefreshScrollView(Context context, Mode mode) { super(context, mode); } public PullToRefreshScrollView(Context context, Mode mode, Class loadingLayoutClazz) { super(context, mode, loadingLayoutClazz); } @Override public final Orientation getPullToRefreshScrollDirection() { return Orientation.VERTICAL; } @Override protected ScrollView createRefreshableView(Context context, AttributeSet attrs) { ScrollView scrollView; if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { scrollView = new InternalScrollViewSDK9(context, attrs); } else { scrollView = new ScrollView(context, attrs); } scrollView.setId(R.id.scrollview); return scrollView; } @Override protected boolean isReadyForPullStart() { return mRefreshableView.getScrollY() == 0; } @Override protected boolean isReadyForPullEnd() { View scrollViewChild = mRefreshableView.getChildAt(0); if (null != scrollViewChild) { return mRefreshableView.getScrollY() >= (scrollViewChild.getHeight() - getHeight()); } return false; } @TargetApi(9) final class InternalScrollViewSDK9 extends ScrollView { public InternalScrollViewSDK9(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); // Does all of the hard work... OverscrollHelper.overScrollBy(PullToRefreshScrollView.this, deltaX, scrollX, deltaY, scrollY, getScrollRange(), isTouchEvent); return returnValue; } /** * Taken from the AOSP ScrollView source */ private int getScrollRange() { int scrollRange = 0; if (getChildCount() > 0) { View child = getChildAt(0); scrollRange = Math.max(0, child.getHeight() - (getHeight() - getPaddingBottom() - getPaddingTop())); } return scrollRange; } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/PullToRefreshWebView.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library; import com.handmark.pulltorefresh.library.internal.LoadingLayout; import android.annotation.TargetApi; import android.content.Context; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.util.AttributeSet; import android.util.FloatMath; import android.webkit.WebChromeClient; import android.webkit.WebView; public class PullToRefreshWebView extends PullToRefreshBase { private static final OnRefreshListener defaultOnRefreshListener = new OnRefreshListener() { @Override public void onRefresh(PullToRefreshBase refreshView) { refreshView.getRefreshableView().reload(); } }; private final WebChromeClient defaultWebChromeClient = new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { onRefreshComplete(); } } }; public PullToRefreshWebView(Context context) { super(context); /** * Added so that by default, Pull-to-Refresh refreshes the page */ setOnRefreshListener(defaultOnRefreshListener); mRefreshableView.setWebChromeClient(defaultWebChromeClient); } public PullToRefreshWebView(Context context, AttributeSet attrs) { super(context, attrs); /** * Added so that by default, Pull-to-Refresh refreshes the page */ setOnRefreshListener(defaultOnRefreshListener); mRefreshableView.setWebChromeClient(defaultWebChromeClient); } public PullToRefreshWebView(Context context, Mode mode) { super(context, mode); /** * Added so that by default, Pull-to-Refresh refreshes the page */ setOnRefreshListener(defaultOnRefreshListener); mRefreshableView.setWebChromeClient(defaultWebChromeClient); } public PullToRefreshWebView(Context context, Mode mode, Class loadingLayoutClazz) { super(context, mode, loadingLayoutClazz); /** * Added so that by default, Pull-to-Refresh refreshes the page */ setOnRefreshListener(defaultOnRefreshListener); mRefreshableView.setWebChromeClient(defaultWebChromeClient); } @Override public final Orientation getPullToRefreshScrollDirection() { return Orientation.VERTICAL; } @Override protected WebView createRefreshableView(Context context, AttributeSet attrs) { WebView webView; if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) { webView = new InternalWebViewSDK9(context, attrs); } else { webView = new WebView(context, attrs); } webView.setId(R.id.webview); return webView; } @Override protected boolean isReadyForPullStart() { return mRefreshableView.getScrollY() == 0; } @Override protected boolean isReadyForPullEnd() { float exactContentHeight = FloatMath.floor(mRefreshableView.getContentHeight() * mRefreshableView.getScale()); return mRefreshableView.getScrollY() >= (exactContentHeight - mRefreshableView.getHeight()); } @Override protected void onPtrRestoreInstanceState(Bundle savedInstanceState) { super.onPtrRestoreInstanceState(savedInstanceState); mRefreshableView.restoreState(savedInstanceState); } @Override protected void onPtrSaveInstanceState(Bundle saveState) { super.onPtrSaveInstanceState(saveState); mRefreshableView.saveState(saveState); } @TargetApi(9) final class InternalWebViewSDK9 extends WebView { // WebView doesn't always scroll back to it's edge so we add some // fuzziness static final int OVERSCROLL_FUZZY_THRESHOLD = 2; // WebView seems quite reluctant to overscroll so we use the scale // factor to scale it's value static final float OVERSCROLL_SCALE_FACTOR = 1.5f; public InternalWebViewSDK9(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); // Does all of the hard work... OverscrollHelper.overScrollBy(PullToRefreshWebView.this, deltaX, scrollX, deltaY, scrollY, getScrollRange(), OVERSCROLL_FUZZY_THRESHOLD, OVERSCROLL_SCALE_FACTOR, isTouchEvent); return returnValue; } private int getScrollRange() { return (int) Math.max(0, FloatMath.floor(mRefreshableView.getContentHeight() * mRefreshableView.getScale()) - (getHeight() - getPaddingBottom() - getPaddingTop())); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/extras/PullToRefreshWebView2.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.extras; import java.util.concurrent.atomic.AtomicBoolean; import android.content.Context; import android.util.AttributeSet; import android.webkit.WebView; import com.handmark.pulltorefresh.library.PullToRefreshWebView; /** * An advanced version of {@link PullToRefreshWebView} which delegates the * triggering of the PullToRefresh gesture to the Javascript running within the * WebView. This means that you should only use this class if: *

*

    *
  • {@link PullToRefreshWebView} doesn't work correctly because you're using * overflow:scroll or something else which means * {@link WebView#getScrollY()} doesn't return correct values.
  • *
  • You control the web content being displayed, as you need to write some * Javascript callbacks.
  • *
*

*

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

* *

 * function isReadyForPullDown() {
 *   var result = ...  // Probably using the .scrollTop DOM attribute
 *   ptr.isReadyForPullDownResponse(result);
 * }
 * 
 * function isReadyForPullUp() {
 *   var result = ...  // Probably using the .scrollBottom DOM attribute
 *   ptr.isReadyForPullUpResponse(result);
 * }
 * 
* * @author Chris Banes */ public class PullToRefreshWebView2 extends PullToRefreshWebView { static final String JS_INTERFACE_PKG = "ptr"; static final String DEF_JS_READY_PULL_DOWN_CALL = "javascript:isReadyForPullDown();"; static final String DEF_JS_READY_PULL_UP_CALL = "javascript:isReadyForPullUp();"; public PullToRefreshWebView2(Context context) { super(context); } public PullToRefreshWebView2(Context context, AttributeSet attrs) { super(context, attrs); } public PullToRefreshWebView2(Context context, Mode mode) { super(context, mode); } private JsValueCallback mJsCallback; private final AtomicBoolean mIsReadyForPullDown = new AtomicBoolean(false); private final AtomicBoolean mIsReadyForPullUp = new AtomicBoolean(false); @Override protected WebView createRefreshableView(Context context, AttributeSet attrs) { WebView webView = super.createRefreshableView(context, attrs); // Need to add JS Interface so we can get the response back mJsCallback = new JsValueCallback(); webView.addJavascriptInterface(mJsCallback, JS_INTERFACE_PKG); return webView; } @Override protected boolean isReadyForPullStart() { // Call Javascript... getRefreshableView().loadUrl(DEF_JS_READY_PULL_DOWN_CALL); // Response will be given to JsValueCallback, which will update // mIsReadyForPullDown return mIsReadyForPullDown.get(); } @Override protected boolean isReadyForPullEnd() { // Call Javascript... getRefreshableView().loadUrl(DEF_JS_READY_PULL_UP_CALL); // Response will be given to JsValueCallback, which will update // mIsReadyForPullUp return mIsReadyForPullUp.get(); } /** * Used for response from Javascript * * @author Chris Banes */ final class JsValueCallback { public void isReadyForPullUpResponse(boolean response) { mIsReadyForPullUp.set(response); } public void isReadyForPullDownResponse(boolean response) { mIsReadyForPullDown.set(response); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/extras/SoundPullEventListener.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.extras; import java.util.HashMap; import android.content.Context; import android.media.MediaPlayer; import android.view.View; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.State; public class SoundPullEventListener implements PullToRefreshBase.OnPullEventListener { private final Context mContext; private final HashMap mSoundMap; private MediaPlayer mCurrentMediaPlayer; /** * Constructor * * @param context - Context */ public SoundPullEventListener(Context context) { mContext = context; mSoundMap = new HashMap(); } @Override public final void onPullEvent(PullToRefreshBase refreshView, State event, Mode direction) { Integer soundResIdObj = mSoundMap.get(event); if (null != soundResIdObj) { playSound(soundResIdObj.intValue()); } } /** * Set the Sounds to be played when a Pull Event happens. You specify which * sound plays for which events by calling this method multiple times for * each event. *

* If you've already set a sound for a certain event, and add another sound * for that event, only the new sound will be played. * * @param event - The event for which the sound will be played. * @param resId - Resource Id of the sound file to be played (e.g. * R.raw.pull_sound) */ public void addSoundEvent(State event, int resId) { mSoundMap.put(event, resId); } /** * Clears all of the previously set sounds and events. */ public void clearSounds() { mSoundMap.clear(); } /** * Gets the current (or last) MediaPlayer instance. */ public MediaPlayer getCurrentMediaPlayer() { return mCurrentMediaPlayer; } private void playSound(int resId) { // Stop current player, if there's one playing if (null != mCurrentMediaPlayer) { mCurrentMediaPlayer.stop(); mCurrentMediaPlayer.release(); } mCurrentMediaPlayer = MediaPlayer.create(mContext, resId); if (null != mCurrentMediaPlayer) { mCurrentMediaPlayer.start(); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/AbstractDefaultGoogleStyleViewLayout.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.text.TextUtils; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.TextView; import com.handmark.pulltorefresh.library.GoogleStyleViewLayout; import com.handmark.pulltorefresh.library.R; /** * Abstract class of Default Google style view layout
* Instance of UI Components are been getting as abstract method, if you override this method, abstract get...() methods must be implemented. These will be assigned to UI instance fields. * @author Wonjun Kim * */ public abstract class AbstractDefaultGoogleStyleViewLayout extends GoogleStyleViewLayout { private FrameLayout mInnerLayout; private TextView mHeaderText; private TextView mSubHeaderText; private CharSequence mPullLabel; private CharSequence mRefreshingLabel; private CharSequence mReleaseLabel; public AbstractDefaultGoogleStyleViewLayout(Context context, TypedArray attrs) { super(context, attrs); initImpl(context, attrs); initComponents(context, attrs); initProperties(context, attrs); reset(); } protected abstract void initImpl(Context context, TypedArray attrs); /** * Assign get..() methods to fields * @param context * @param attrs */ private void initComponents(Context context, TypedArray attrs) { mInnerLayout = getInnerLayout(context, attrs); mHeaderText = getHeaderText(context, attrs); mSubHeaderText = geSubHeaderTextLayout(context, attrs); } /** * Returns SubHeaderText Layout instance to be displayed * @param context * @param attrs * @return */ protected abstract TextView geSubHeaderTextLayout(Context context, TypedArray attrs); /** * Returns Inner Layout instance to be displayed * @param context * @param attrs * @return */ protected abstract TextView getHeaderText(Context context, TypedArray attrs); /** * Returns HeaderText Layout instance to be displayed * @param context * @param attrs * @return */ protected abstract FrameLayout getInnerLayout(Context context, TypedArray attrs); @Override public final void setHeight(int height) { // set Inner layout's height too ViewGroup.LayoutParams lp = mInnerLayout.getLayoutParams(); lp.height = height; ViewGroup.LayoutParams thisLp = getLayoutParams(); if ( thisLp != null ) { thisLp.height = height; } requestLayout(); } /** * Initialize text color, sub text color , and text appearance.
* If text color is not set, set default color by calling {@link #getDefaultTextColor(Context, TypedArray)}, or {@link #getDefaultSubTextColor(Context, TypedArray)}.
* Also, if background color is not set, set default color by calling {@link #getDefaultBackgroundColor(Context, TypedArray)} * @param context * @param attrs */ protected void initProperties(Context context, TypedArray attrs) { // Load Loading Layout Labels loadLoadingLayoutLabels(context, attrs); if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) { Drawable background = attrs.getDrawable(R.styleable.PullToRefresh_ptrHeaderBackground); if ( null != background ) { ViewCompat.setBackground(this, background); } } else { // Set background to white as default setBackgroundColor(getDefaultBackgroundColor(context, attrs)); } if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.getValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance, styleID); setTextAppearance(styleID.data); } if (attrs.hasValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.getValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID); setSubTextAppearance(styleID.data); } // Text Color attrs need to be set after TextAppearance attrs if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) { ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor); if (null != colors) { setTextColor(colors); } } else { // Set Text color to black as default setTextColor(getDefaultTextColor(context, attrs)); } if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderSubTextColor)) { ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderSubTextColor); if (null != colors) { setSubTextColor(colors); } } else { // Set Text color to black as default setSubTextColor(getDefaultSubTextColor(context, attrs)); } initPropertiesImpl(context, attrs); } protected abstract void initPropertiesImpl(Context context, TypedArray attrs); /** * Use {@code Color.White} color as default to set background color.
* If you want to change this default, override this method. * @param context * @param attrs * @return Color value */ protected int getDefaultBackgroundColor(Context context, TypedArray attrs) { return Color.WHITE; } /** * Use {@code Color.Black} color as default to set text color.
* If you want to change this default, override this method. * @param context * @param attrs * @return Color value */ protected int getDefaultTextColor(Context context, TypedArray attrs) { return Color.BLACK; } /** * Use {@code Color.Black} color as default to set sub text color.
* If you want to change this default, override this method. * @param context * @param attrs * @return Color value */ protected int getDefaultSubTextColor(Context context, TypedArray attrs) { return Color.BLACK; } /** * Load labels of pull, refresh, release, and assign into fields *
Convert an each attribute value such as {@code ptrPullLabel}, {@code ptrRefreshLabel} or {@code ptrReleaseLabel} to each label field if each value exists. *
Or if not, then the each label is assigned some string as default *
* NOTE : This method Must be modified if kinds of {@code Mode} are increased. * @param attrs */ private void loadLoadingLayoutLabels(Context context, TypedArray attrs) { mPullLabel = loadPullLabel(context, attrs); mRefreshingLabel = loadRefreshingLabel(context, attrs); mReleaseLabel = loadReleaseLabel(context, attrs); } /** * Load labels of pull *
Convert an {@code ptrPullLabel} attribute value to {@code mPullLabel} field if each value exists. *
Or if not, then the pull label is assigned some string as default *
If you want to set some custom pull label at sub class, you have to override this method and implement. * NOTE : This method Must be modified if kinds of {@code Mode} are increased. * @param context * @param attrs * @param mode * @return String to be a pull label */ protected String loadPullLabel(Context context, TypedArray attrs) { // Pull Label if (attrs.hasValue(R.styleable.PullToRefresh_ptrPullLabel)) { return attrs.getString(R.styleable.PullToRefresh_ptrPullLabel); } int stringId = R.string.pull_to_refresh_pull_label; return context.getString(stringId); } /** * Load labels of refreshing *
Convert an {@code ptrRefreshLabel} attribute value to {@code mRefreshingLabel} field if each value exists. *
Or if not, then the refreshing label is assigned some string as default *
If you want to set some custom refreshing label at sub class, you have to override this method and implement. * NOTE : This method Must be modified if kinds of {@code Mode} are increased. * @param context * @param attrs * @return String to be a refreshing label */ protected String loadRefreshingLabel(Context context, TypedArray attrs) { // Refresh Label if (attrs.hasValue(R.styleable.PullToRefresh_ptrRefreshLabel)) { return attrs.getString(R.styleable.PullToRefresh_ptrRefreshLabel); } int stringId = R.string.pull_to_refresh_refreshing_label; return context.getString(stringId); } /** * Load labels of release *
Convert an {@code ptrReleaseLabel} attribute value to {@code mReleaseLabel} field if each value exists. *
Or if not, then the release label is assigned some string as default *
If you want to set some custom release label at sub class, you have to override this method and implement. * NOTE : This method Must be modified if kinds of {@code Mode} are increased. * @param context * @param attrs * @return String to be a refreshing label */ protected String loadReleaseLabel(Context context, TypedArray attrs) { // Release Label if (attrs.hasValue(R.styleable.PullToRefresh_ptrReleaseLabel)) { return attrs.getString(R.styleable.PullToRefresh_ptrReleaseLabel); } int stringId = R.string.pull_to_refresh_release_label; return context.getString(stringId); } @Override public final void setWidth(int width) { ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams(); lp.width = width; requestLayout(); } @Override public final int getContentSize() { return mInnerLayout.getHeight(); } public final void hideAllViews() { hideHeaderText(); hideSubHeaderText(); } private void hideHeaderText() { if (null != mHeaderText && View.VISIBLE == mHeaderText.getVisibility()) { mHeaderText.setVisibility(View.INVISIBLE); } } private void hideSubHeaderText() { if (null != mHeaderText && View.VISIBLE == mSubHeaderText.getVisibility()) { mSubHeaderText.setVisibility(View.INVISIBLE); } } protected abstract void pullToRefreshImpl(); protected abstract void releaseToRefreshImpl(); protected abstract void refreshingImpl(); protected abstract void resetImpl(); protected abstract void onPullImpl(float scale); @Override public final void pullToRefresh() { if (null != mHeaderText) { mHeaderText.setText(mPullLabel); } pullToRefreshImpl(); } @Override public final void refreshing() { if (null != mHeaderText) { mHeaderText.setText(mRefreshingLabel); } if (null != mSubHeaderText) { mSubHeaderText.setVisibility(View.GONE); } refreshingImpl(); } @Override public final void releaseToRefresh() { if (null != mHeaderText) { mHeaderText.setText(mReleaseLabel); } releaseToRefreshImpl(); } @Override public final void reset() { if (null != mHeaderText) { mHeaderText.setText(mPullLabel); } if (null != mSubHeaderText) { if (TextUtils.isEmpty(mSubHeaderText.getText())) { mSubHeaderText.setVisibility(View.GONE); } else { mSubHeaderText.setVisibility(View.VISIBLE); } } resetImpl(); } public void setLastUpdatedLabel(CharSequence label) { setSubHeaderText(label); } public void setPullLabel(CharSequence pullLabel) { mPullLabel = pullLabel; } public void setRefreshingLabel(CharSequence refreshingLabel) { mRefreshingLabel = refreshingLabel; } public void setReleaseLabel(CharSequence releaseLabel) { mReleaseLabel = releaseLabel; } public void setTextTypeface(Typeface tf) { if (null != mHeaderText) { mHeaderText.setTypeface(tf); } } public final void showInvisibleViews() { showHeaderText(); showSubHeaderText(); } private void showSubHeaderText() { if (null != mSubHeaderText && View.INVISIBLE == mSubHeaderText.getVisibility()) { mSubHeaderText.setVisibility(View.VISIBLE); } } private void showHeaderText() { if (null != mHeaderText && View.INVISIBLE == mHeaderText.getVisibility()) { mHeaderText.setVisibility(View.VISIBLE); } } private void setSubHeaderText(CharSequence label) { if (null != mSubHeaderText) { if (TextUtils.isEmpty(label)) { mSubHeaderText.setVisibility(View.GONE); } else { mSubHeaderText.setText(label); // Only set it to Visible if we're GONE, otherwise VISIBLE will // be set soon if (View.GONE == mSubHeaderText.getVisibility()) { mSubHeaderText.setVisibility(View.VISIBLE); } } } } private void setSubTextAppearance(int value) { if (null != mSubHeaderText) { mSubHeaderText.setTextAppearance(getContext(), value); } } private void setSubTextColor(ColorStateList color) { if (null != mSubHeaderText) { mSubHeaderText.setTextColor(color); } } private void setSubTextColor(int color) { if (null != mSubHeaderText) { mSubHeaderText.setTextColor(color); } } private void setTextAppearance(int value) { if (null != mHeaderText) { mHeaderText.setTextAppearance(getContext(), value); } if (null != mSubHeaderText) { mSubHeaderText.setTextAppearance(getContext(), value); } } private void setTextColor(ColorStateList color) { if (null != mHeaderText) { mHeaderText.setTextColor(color); } if (null != mSubHeaderText) { mSubHeaderText.setTextColor(color); } } private void setTextColor(int color) { if (null != mHeaderText) { mHeaderText.setTextColor(color); } if (null != mSubHeaderText) { mSubHeaderText.setTextColor(color); } } @Override public void onPull(float scale) { onPullImpl(scale); } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/Assert.java ================================================ /******************************************************************************* * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; public class Assert { private static final String MESSAGE_FORMAT = "\"%s\" argument must be not null."; public static void notNull(Object object, String argName) { if (object == null) { // When a parameter is null, // it throws a NullPointerException instead of an IllegalArgumentException. // This rule is recommended by the item 62 on Effective Java 2nd edition as follows. // "If a caller passes null in some parameter for which null values are prohibited, // convention dictates that NullPointerException be thrown rather than IllegalArgumentException." throw new NullPointerException(String.format(MESSAGE_FORMAT, argName)); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/DefaultGoogleStyleProgressLayout.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import android.content.Context; import android.content.res.TypedArray; import android.view.LayoutInflater; import android.view.View; import android.widget.ProgressBar; import com.handmark.pulltorefresh.library.GoogleStyleProgressLayout; import com.handmark.pulltorefresh.library.R; /** * Specific implemented layout of Google style progress layout
* NOTE : This class doesn't have abstract default class because of no extend points in this class. * @author Wonjun Kim * */ public class DefaultGoogleStyleProgressLayout extends GoogleStyleProgressLayout { private PullingProgressLayout mActionBarHeaderPullingProgressLayout; private ProgressBar mActionBarHeaderRefreshingProgressBar; public DefaultGoogleStyleProgressLayout(Context context, TypedArray attrs) { super(context, attrs); initInflate(context, R.layout.pull_to_refresh_progress_google_style); initProperties(); reset(); } /** * Inflate layout by {@code inflateId} * @param context * @param inflateId inflate id value like {@code R.layout...} */ private void initInflate(Context context, int inflateId) { LayoutInflater.from(context).inflate(inflateId, this); } /** * Assign UI Components to fields */ private void initProperties() { mActionBarHeaderPullingProgressLayout = (PullingProgressLayout) findViewById(R.id.pulling_progress); mActionBarHeaderRefreshingProgressBar = (ProgressBar) findViewById(R.id.refreshing_progress); } /** * Show pulling bar and hide refreshing bar */ @Override public void reset() { mActionBarHeaderPullingProgressLayout.setVisibility(View.VISIBLE); mActionBarHeaderRefreshingProgressBar.setVisibility(View.INVISIBLE); mActionBarHeaderPullingProgressLayout.setPercent(0); } /** * Hide pulling bar and show refreshing bar */ @Override public void refreshing() { mActionBarHeaderPullingProgressLayout.setVisibility(View.INVISIBLE); mActionBarHeaderRefreshingProgressBar.setVisibility(View.VISIBLE); } @Override public void releaseToRefresh() { } @Override public void pullToRefresh() { } /** * Set progress of pulling bar */ @Override public void onPull(float scale) { int percent = (int) (scale * 100); mActionBarHeaderPullingProgressLayout.setPercent(percent); } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/DefaultGoogleStyleViewLayout.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import com.handmark.pulltorefresh.library.R; import android.content.Context; import android.content.res.TypedArray; import android.view.LayoutInflater; import android.widget.FrameLayout; import android.widget.TextView; /** * Specific implemented layout of Google style view layout
* @author Wonjun Kim */ public class DefaultGoogleStyleViewLayout extends AbstractDefaultGoogleStyleViewLayout { public DefaultGoogleStyleViewLayout(Context context, TypedArray attrs) { super(context, attrs); } /** * Inflate layout by {@code inflateId} * @param context * @param inflateId inflate id value like {@code R.layout...} */ private void initInflate(Context context, int inflateId) { LayoutInflater.from(context).inflate(inflateId, this); } /** * Initialize layout */ @Override protected void initImpl(Context context, TypedArray attrs) { initInflate(context, getLayoutInflateId()); } /** * Returns inflate id to be used when inflating * If you want to change layout xml, you have to override this method and change a return value * @return Inflate id */ protected int getLayoutInflateId() { return R.layout.pull_to_refresh_header_google_style; } /** * Bind SubHeaderText layout Component to some field */ @Override protected TextView geSubHeaderTextLayout(Context context, TypedArray attrs) { return (TextView) findViewById(R.id.pull_to_refresh_sub_text); } /** * Bind HeaderText layout Component to some field */ @Override protected TextView getHeaderText(Context context, TypedArray attrs) { return (TextView) findViewById(R.id.pull_to_refresh_text); } /** * Bind Inner layout Component to some field */ @Override protected FrameLayout getInnerLayout(Context context, TypedArray attrs) { return (FrameLayout) findViewById(R.id.fl_inner_for_google_style); } @Override protected void initPropertiesImpl(Context context, TypedArray attrs) { // do nothing } @Override protected void pullToRefreshImpl() { // do nothing } @Override protected void releaseToRefreshImpl() { // do nothing } @Override protected void refreshingImpl() { // do nothing } @Override protected void resetImpl() { // do nothing } @Override protected void onPullImpl(float scale) { // do nothing } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/DefaultIndicatorLayout.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Matrix; import android.graphics.drawable.Drawable; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.view.animation.Interpolator; import android.view.animation.LinearInterpolator; import android.view.animation.RotateAnimation; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import com.handmark.pulltorefresh.library.IIndicatorLayout; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.R; @SuppressLint("ViewConstructor") public class DefaultIndicatorLayout extends IndicatorLayout implements IIndicatorLayout, AnimationListener { static final int DEFAULT_ROTATION_ANIMATION_DURATION = 150; private Animation mInAnim, mOutAnim; private ImageView mArrowImageView; private final Animation mRotateAnimation, mResetRotateAnimation; public DefaultIndicatorLayout(Context context, PullToRefreshBase.Mode mode) { super(context); mArrowImageView = new ImageView(context); Drawable arrowD = getIconDrawable(context, mode); mArrowImageView.setImageDrawable(arrowD); final int padding = getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding); mArrowImageView.setPadding(padding, padding, padding, padding); addView(mArrowImageView); int inAnimResId, outAnimResId; switch (mode) { case PULL_FROM_END: inAnimResId = R.anim.slide_in_from_bottom; outAnimResId = R.anim.slide_out_to_bottom; setBackgroundResource(R.drawable.indicator_bg_bottom); // Rotate Arrow so it's pointing the correct way mArrowImageView.setScaleType(ScaleType.MATRIX); Matrix matrix = new Matrix(); matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f); mArrowImageView.setImageMatrix(matrix); break; default: case PULL_FROM_START: inAnimResId = R.anim.slide_in_from_top; outAnimResId = R.anim.slide_out_to_top; setBackgroundResource(R.drawable.indicator_bg_top); break; } mInAnim = AnimationUtils.loadAnimation(context, inAnimResId); mInAnim.setAnimationListener(this); mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId); mOutAnim.setAnimationListener(this); final Interpolator interpolator = new LinearInterpolator(); mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateAnimation.setInterpolator(interpolator); mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mRotateAnimation.setFillAfter(true); mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mResetRotateAnimation.setInterpolator(interpolator); mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mResetRotateAnimation.setFillAfter(true); } /** * Create an icon that default indicator layout will use * @param context * @param mode * @return Indicator icon */ protected Drawable getIconDrawable(Context context, PullToRefreshBase.Mode mode) { return getResources().getDrawable(R.drawable.indicator_arrow); } /** * {@inheritDoc} */ public final boolean isVisible() { Animation currentAnim = getAnimation(); if (null != currentAnim) { return mInAnim == currentAnim; } return getVisibility() == View.VISIBLE; } /** * {@inheritDoc} */ public void hide() { startAnimation(mOutAnim); } /** * {@inheritDoc} */ public void show() { mArrowImageView.clearAnimation(); startAnimation(mInAnim); } @Override public void onAnimationEnd(Animation animation) { if (animation == mOutAnim) { mArrowImageView.clearAnimation(); setVisibility(View.GONE); } else if (animation == mInAnim) { setVisibility(View.VISIBLE); } clearAnimation(); } @Override public void onAnimationRepeat(Animation animation) { // NO-OP } @Override public void onAnimationStart(Animation animation) { setVisibility(View.VISIBLE); } /** * {@inheritDoc} */ @Override public void releaseToRefresh() { mArrowImageView.startAnimation(mRotateAnimation); } /** * {@inheritDoc} */ @Override public void pullToRefresh() { mArrowImageView.startAnimation(mResetRotateAnimation); } /** * {@inheritDoc} */ public LayoutParams createApplicableHeaderLayoutParams() { FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.rightMargin = getResources().getDimensionPixelSize(R.dimen.indicator_right_padding); params.gravity = Gravity.TOP | Gravity.RIGHT; return params; } /** * {@inheritDoc} */ public LayoutParams createApplicableFooterLayoutParams() { FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.rightMargin = getResources().getDimensionPixelSize(R.dimen.indicator_right_padding); params.gravity = Gravity.BOTTOM | Gravity.RIGHT; return params; } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/EmptyViewMethodAccessor.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import android.view.View; /** * Interface that allows PullToRefreshBase to hijack the call to * AdapterView.setEmptyView() * * @author chris */ public interface EmptyViewMethodAccessor { /** * Calls upto AdapterView.setEmptyView() * * @param emptyView - to set as Empty View */ public void setEmptyViewInternal(View emptyView); /** * Should call PullToRefreshBase.setEmptyView() which will then * automatically call through to setEmptyViewInternal() * * @param emptyView - to set as Empty View */ public void setEmptyView(View emptyView); } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/FlipLoadingLayout.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Matrix; import android.graphics.drawable.Drawable; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.widget.ImageView.ScaleType; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation; import com.handmark.pulltorefresh.library.R; @SuppressLint("ViewConstructor") public class FlipLoadingLayout extends LoadingLayout { static final int FLIP_ANIMATION_DURATION = 150; private final Animation mRotateAnimation, mResetRotateAnimation; public FlipLoadingLayout(Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs) { super(context, mode, scrollDirection, attrs); final int rotateAngle = mode == Mode.PULL_FROM_START ? -180 : 180; mRotateAnimation = new RotateAnimation(0, rotateAngle, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR); mRotateAnimation.setDuration(FLIP_ANIMATION_DURATION); mRotateAnimation.setFillAfter(true); mResetRotateAnimation = new RotateAnimation(rotateAngle, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mResetRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR); mResetRotateAnimation.setDuration(FLIP_ANIMATION_DURATION); mResetRotateAnimation.setFillAfter(true); } @Override protected void onLoadingDrawableSet(Drawable imageDrawable) { if (null != imageDrawable) { final int dHeight = imageDrawable.getIntrinsicHeight(); final int dWidth = imageDrawable.getIntrinsicWidth(); /** * We need to set the width/height of the ImageView so that it is * square with each side the size of the largest drawable dimension. * This is so that it doesn't clip when rotated. */ ViewGroup.LayoutParams lp = mHeaderImage.getLayoutParams(); lp.width = lp.height = Math.max(dHeight, dWidth); mHeaderImage.requestLayout(); /** * We now rotate the Drawable so that is at the correct rotation, * and is centered. */ mHeaderImage.setScaleType(ScaleType.MATRIX); Matrix matrix = new Matrix(); matrix.postTranslate((lp.width - dWidth) / 2f, (lp.height - dHeight) / 2f); matrix.postRotate(getDrawableRotationAngle(), lp.width / 2f, lp.height / 2f); mHeaderImage.setImageMatrix(matrix); } } @Override protected void onPullImpl(float scaleOfLayout) { // NO-OP } @Override protected void pullToRefreshImpl() { // Only start reset Animation, we've previously show the rotate anim if (mRotateAnimation == mHeaderImage.getAnimation()) { mHeaderImage.startAnimation(mResetRotateAnimation); } } @Override protected void refreshingImpl() { mHeaderImage.clearAnimation(); mHeaderImage.setVisibility(View.INVISIBLE); mHeaderProgress.setVisibility(View.VISIBLE); } @Override protected void releaseToRefreshImpl() { mHeaderImage.startAnimation(mRotateAnimation); } @Override protected void resetImpl() { mHeaderImage.clearAnimation(); mHeaderProgress.setVisibility(View.GONE); mHeaderImage.setVisibility(View.VISIBLE); } @Override protected int getDefaultDrawableResId() { return R.drawable.default_ptr_flip; } private float getDrawableRotationAngle() { float angle = 0f; switch (mMode) { case PULL_FROM_END: if (mScrollDirection == Orientation.HORIZONTAL) { angle = 90f; } else { angle = 180f; } break; case PULL_FROM_START: if (mScrollDirection == Orientation.HORIZONTAL) { angle = 270f; } break; default: break; } return angle; } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/FlippedProgressBar.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.widget.ProgressBar; /** * Right to left ProgressBar * @author Wonjun Kim * */ public class FlippedProgressBar extends ProgressBar { public FlippedProgressBar(Context context) { super(context); } public FlippedProgressBar(Context context, AttributeSet attrs) { super(context, attrs); } public FlippedProgressBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onDraw(Canvas canvas) { canvas.save(); float centerX = this.getWidth() / 2.0f; float centerY = this.getHeight() / 2.0f; canvas.scale(-1, 1, centerX /* center of x */, centerY /* center of y */); super.onDraw(canvas); canvas.restore(); } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/IndicatorLayout.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import com.handmark.pulltorefresh.library.IIndicatorLayout; import android.content.Context; import android.util.AttributeSet; import android.widget.FrameLayout; /** * @see IIndicatorLayout * @author Wonjun Kim */ public abstract class IndicatorLayout extends FrameLayout implements IIndicatorLayout { public IndicatorLayout(Context context) { super(context); } public IndicatorLayout(Context context, AttributeSet attrs) { super(context, attrs); } public IndicatorLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } /** * Create a specific {@code LayoutParams}.
* Pull To Refresh will add this layout with applying this {@code LayoutParams} to the layout * @return {@code LayoutParams} which is applied if this indicator layout is a header of Pull To Refresh */ public abstract LayoutParams createApplicableHeaderLayoutParams(); /** * Create a specific {@code LayoutParams}.
* Pull To Refresh will add this layout with applying this {@code LayoutParams} to the layout * @return {@code LayoutParams} which is applied if this indicator layout is a footer of Pull To Refresh */ public abstract LayoutParams createApplicableFooterLayoutParams(); } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/LoadingLayout.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.Typeface; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.Drawable; import android.text.TextUtils; import android.util.TypedValue; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.Interpolator; import android.view.animation.LinearInterpolator; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; import com.handmark.pulltorefresh.library.ILoadingLayout; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation; import com.handmark.pulltorefresh.library.R; @SuppressLint("ViewConstructor") public abstract class LoadingLayout extends FrameLayout implements ILoadingLayout { static final String LOG_TAG = "PullToRefresh-LoadingLayout"; static final Interpolator ANIMATION_INTERPOLATOR = new LinearInterpolator(); protected FrameLayout mInnerLayout; protected ImageView mHeaderImage; protected ProgressBar mHeaderProgress; private boolean mUseIntrinsicAnimation; protected TextView mHeaderText; protected TextView mSubHeaderText; protected final Mode mMode; protected final Orientation mScrollDirection; private CharSequence mPullLabel; private CharSequence mRefreshingLabel; private CharSequence mReleaseLabel; private Drawable mImageDrawable; /** * The constructor to customize layout, not public scope now. * @param context * @param mode * @param scrollDirection */ protected LoadingLayout(Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs, int inflateId) { super(context); mMode = mode; mScrollDirection = scrollDirection; initInflate(context, inflateId); initComponents(); initProperties(context, mode, attrs); if (null != mImageDrawable) { setLoadingDrawable(mImageDrawable); mImageDrawable = null; } reset(); } public LoadingLayout(Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs) { super(context); mMode = mode; mScrollDirection = scrollDirection; switch (scrollDirection) { case HORIZONTAL: initInflate(context, R.layout.pull_to_refresh_header_horizontal); break; case VERTICAL: default: initInflate(context, R.layout.pull_to_refresh_header_vertical); break; } initComponents(); if (null != mInnerLayout) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInnerLayout.getLayoutParams(); switch (mode) { case PULL_FROM_END: lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.TOP : Gravity.LEFT; break; case PULL_FROM_START: default: lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.BOTTOM : Gravity.RIGHT; break; } } initProperties(context, mode, attrs); // If we don't have a user defined drawable, load the default if (null == mImageDrawable) { mImageDrawable = context.getResources().getDrawable(getDefaultDrawableResId()); } // Set Drawable, and save width/height setLoadingDrawable(mImageDrawable); mImageDrawable = null; reset(); } protected void initComponents() { mInnerLayout = (FrameLayout) findViewById(R.id.fl_inner); mHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_text); mHeaderProgress = (ProgressBar) mInnerLayout.findViewById(R.id.pull_to_refresh_progress); mSubHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_sub_text); mHeaderImage = (ImageView) mInnerLayout.findViewById(R.id.pull_to_refresh_image); } private void initInflate(Context context, int inflateId) { LayoutInflater.from(context).inflate(inflateId, this); } protected void initProperties(Context context, final Mode mode, TypedArray attrs) { // Load Loading Layout Labels loadLoadingLayoutLabels(context, attrs, mode); if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) { Drawable background = attrs.getDrawable(R.styleable.PullToRefresh_ptrHeaderBackground); if (null != background) { ViewCompat.setBackground(this, background); } } if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.getValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance, styleID); setTextAppearance(styleID.data); } if (attrs.hasValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.getValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID); setSubTextAppearance(styleID.data); } // Text Color attrs need to be set after TextAppearance attrs if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) { ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor); if (null != colors) { setTextColor(colors); } } if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderSubTextColor)) { ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderSubTextColor); if (null != colors) { setSubTextColor(colors); } } // Try and get defined drawable from Attrs if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawable)) { mImageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawable); } // Check Specific Drawable from Attrs, these overrite the generic // drawable attr above switch (mode) { case PULL_FROM_START: default: if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableStart)) { mImageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableStart); } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableTop)) { Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart"); mImageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop); } break; case PULL_FROM_END: if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableEnd)) { mImageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableEnd); } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableBottom)) { Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd"); mImageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableBottom); } break; } } /** * Load labels of pull, refresh, release, and assign into fields *
Convert an each attribute value such as {@code ptrPullLabel}, {@code ptrRefreshLabel} or {@code ptrReleaseLabel} to each label field if each value exists. *
Or if not, then the each label is assigned some string as default *
* NOTE : This method Must be modified if kinds of {@code Mode} are increased. * @param attrs * @param mode Current mode */ private void loadLoadingLayoutLabels(Context context, TypedArray attrs, Mode mode) { mPullLabel = loadPullLabel(context, attrs, mode); mRefreshingLabel = loadRefreshingLabel(context, attrs, mode); mReleaseLabel = loadReleaseLabel(context, attrs, mode); } /** * Load labels of pull *
Convert an {@code ptrPullLabel} attribute value to {@code mPullLabel} field if each value exists. *
Or if not, then the pull label is assigned some string as default *
If you want to set some custom pull label at sub class, you have to override this method and implement. * NOTE : This method Must be modified if kinds of {@code Mode} are increased. * @param context * @param attrs * @param mode * @return String to be a pull label */ protected String loadPullLabel(Context context, TypedArray attrs, Mode mode) { // Pull Label if (attrs.hasValue(R.styleable.PullToRefresh_ptrPullLabel)) { return attrs.getString(R.styleable.PullToRefresh_ptrPullLabel); } int stringId = (mode == Mode.PULL_FROM_END) ? R.string.pull_to_refresh_from_bottom_pull_label : R.string.pull_to_refresh_pull_label; return context.getString(stringId); } /** * Load labels of refreshing *
Convert an {@code ptrRefreshLabel} attribute value to {@code mRefreshingLabel} field if each value exists. *
Or if not, then the refreshing label is assigned some string as default *
If you want to set some custom refreshing label at sub class, you have to override this method and implement. * NOTE : This method Must be modified if kinds of {@code Mode} are increased. * @param context * @param attrs * @param mode * @return String to be a refreshing label */ protected String loadRefreshingLabel(Context context, TypedArray attrs, Mode mode) { // Refresh Label if (attrs.hasValue(R.styleable.PullToRefresh_ptrRefreshLabel)) { return attrs.getString(R.styleable.PullToRefresh_ptrRefreshLabel); } int stringId = (mode == Mode.PULL_FROM_END) ? R.string.pull_to_refresh_from_bottom_refreshing_label : R.string.pull_to_refresh_refreshing_label; return context.getString(stringId); } /** * Load labels of release *
Convert an {@code ptrReleaseLabel} attribute value to {@code mReleaseLabel} field if each value exists. *
Or if not, then the release label is assigned some string as default *
If you want to set some custom release label at sub class, you have to override this method and implement. * NOTE : This method Must be modified if kinds of {@code Mode} are increased. * @param context * @param attrs * @param mode * @return String to be a refreshing label */ protected String loadReleaseLabel(Context context, TypedArray attrs, Mode mode) { // Release Label if (attrs.hasValue(R.styleable.PullToRefresh_ptrReleaseLabel)) { return attrs.getString(R.styleable.PullToRefresh_ptrReleaseLabel); } int stringId = (mode == Mode.PULL_FROM_END) ? R.string.pull_to_refresh_from_bottom_release_label : R.string.pull_to_refresh_release_label; return context.getString(stringId); } public void setHeight(int height) { ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams(); lp.height = height; requestLayout(); } public final void setWidth(int width) { ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams(); lp.width = width; requestLayout(); } public final int getContentSize() { switch (mScrollDirection) { case HORIZONTAL: return mInnerLayout.getWidth(); case VERTICAL: default: return mInnerLayout.getHeight(); } } public final void hideAllViews() { hideHeaderText(); hideHeaderProgress(); hideHeaderImage(); hideSubHeaderText(); } private void hideHeaderText() { if (null != mHeaderText && View.VISIBLE == mHeaderText.getVisibility()) { mHeaderText.setVisibility(View.INVISIBLE); } } private void hideHeaderProgress() { if (null != mHeaderProgress && View.VISIBLE == mHeaderProgress.getVisibility()) { mHeaderProgress.setVisibility(View.INVISIBLE); } } private void hideSubHeaderText() { if (null != mHeaderText && View.VISIBLE == mSubHeaderText.getVisibility()) { mSubHeaderText.setVisibility(View.INVISIBLE); } } public final void onPull(float scaleOfLayout) { if (!mUseIntrinsicAnimation) { onPullImpl(scaleOfLayout); } } public final void pullToRefresh() { if (null != mHeaderText) { mHeaderText.setText(mPullLabel); } // Now call the callback pullToRefreshImpl(); } public final void refreshing() { if (null != mHeaderText) { mHeaderText.setText(mRefreshingLabel); } if (null != mHeaderImage && mUseIntrinsicAnimation) { ((AnimationDrawable) mHeaderImage.getDrawable()).start(); } else { // Now call the callback refreshingImpl(); } if (null != mSubHeaderText) { mSubHeaderText.setVisibility(View.GONE); } } public final void releaseToRefresh() { if (null != mHeaderText) { mHeaderText.setText(mReleaseLabel); } // Now call the callback releaseToRefreshImpl(); } public final void reset() { if (null != mHeaderText) { mHeaderText.setText(mPullLabel); } showHeaderImage(); if (null != mHeaderImage && mUseIntrinsicAnimation) { ((AnimationDrawable) mHeaderImage.getDrawable()).stop(); } else { // Now call the callback resetImpl(); } if (null != mSubHeaderText) { if (TextUtils.isEmpty(mSubHeaderText.getText())) { mSubHeaderText.setVisibility(View.GONE); } else { mSubHeaderText.setVisibility(View.VISIBLE); } } } private void showHeaderImage() { if (null != mHeaderImage && View.INVISIBLE == mHeaderImage.getVisibility()) { mHeaderImage.setVisibility(View.VISIBLE); } } private void hideHeaderImage() { if (null != mHeaderImage && View.VISIBLE == mHeaderImage.getVisibility() ) { mHeaderImage.setVisibility(View.INVISIBLE); } } @Override public void setLastUpdatedLabel(CharSequence label) { setSubHeaderText(label); } public final void setLoadingDrawable(Drawable imageDrawable) { // Set Drawable if ( null != mHeaderImage ) { mHeaderImage.setImageDrawable(imageDrawable); } mUseIntrinsicAnimation = (imageDrawable instanceof AnimationDrawable); // Now call the callback onLoadingDrawableSet(imageDrawable); } public void setPullLabel(CharSequence pullLabel) { mPullLabel = pullLabel; } public void setRefreshingLabel(CharSequence refreshingLabel) { mRefreshingLabel = refreshingLabel; } public void setReleaseLabel(CharSequence releaseLabel) { mReleaseLabel = releaseLabel; } @Override public void setTextTypeface(Typeface tf) { if (null != mHeaderText) { mHeaderText.setTypeface(tf); } } public final void showInvisibleViews() { showHeaderText(); showHeaderProgress(); showHeaderImage(); showSubHeaderText(); } private void showSubHeaderText() { if (null != mSubHeaderText && View.INVISIBLE == mSubHeaderText.getVisibility()) { mSubHeaderText.setVisibility(View.VISIBLE); } } private void showHeaderProgress() { if (null != mHeaderProgress && View.INVISIBLE == mHeaderProgress.getVisibility()) { mHeaderProgress.setVisibility(View.VISIBLE); } } private void showHeaderText() { if (null != mHeaderText && View.INVISIBLE == mHeaderText.getVisibility()) { mHeaderText.setVisibility(View.VISIBLE); } } /** * Callbacks for derivative Layouts */ protected abstract int getDefaultDrawableResId(); protected abstract void onLoadingDrawableSet(Drawable imageDrawable); protected abstract void onPullImpl(float scaleOfLayout); protected abstract void pullToRefreshImpl(); protected abstract void refreshingImpl(); protected abstract void releaseToRefreshImpl(); protected abstract void resetImpl(); private void setSubHeaderText(CharSequence label) { if (null != mSubHeaderText) { if (TextUtils.isEmpty(label)) { mSubHeaderText.setVisibility(View.GONE); } else { mSubHeaderText.setText(label); // Only set it to Visible if we're GONE, otherwise VISIBLE will // be set soon if (View.GONE == mSubHeaderText.getVisibility()) { mSubHeaderText.setVisibility(View.VISIBLE); } } } } private void setSubTextAppearance(int value) { if (null != mSubHeaderText) { mSubHeaderText.setTextAppearance(getContext(), value); } } private void setSubTextColor(ColorStateList color) { if (null != mSubHeaderText) { mSubHeaderText.setTextColor(color); } } private void setTextAppearance(int value) { if (null != mHeaderText) { mHeaderText.setTextAppearance(getContext(), value); } if (null != mSubHeaderText) { mSubHeaderText.setTextAppearance(getContext(), value); } } private void setTextColor(ColorStateList color) { if (null != mHeaderText) { mHeaderText.setTextColor(color); } if (null != mSubHeaderText) { mSubHeaderText.setTextColor(color); } } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/PullingProgressLayout.java ================================================ /******************************************************************************* * Copyright 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import com.handmark.pulltorefresh.library.R; import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.util.AttributeSet; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.widget.LinearLayout; import android.widget.ProgressBar; /** * Layout Class displaying specialized progress bar whose progress starts from center, * @author Wonjun Kim * */ public class PullingProgressLayout extends LinearLayout { private ProgressBar mPullingLeftBar; private ProgressBar mPullingRightBar; public PullingProgressLayout(Context context) { super(context); initializeLayout(context); } public PullingProgressLayout(Context context, AttributeSet attrs) { super(context, attrs); initializeLayout(context); } private void initializeLayout(Context context) { Resources res = context.getResources(); LayoutInflater.from(context).inflate(R.layout.pulling_progress_layout, this); mPullingLeftBar = (ProgressBar) findViewById(R.id.pulling_left_progressbar); mPullingRightBar = (ProgressBar) findViewById(R.id.pulling_right_progressbar); mPullingLeftBar.setProgressDrawable(res.getDrawable(R.drawable.progress_horizontal_holo_light)); mPullingRightBar.setProgressDrawable(res.getDrawable(R.drawable.progress_horizontal_holo_light)); mPullingLeftBar.setMax(100); mPullingRightBar.setMax(100); mPullingLeftBar.setProgress(40); mPullingRightBar.setProgress(40); } /** * Route percent value to internal bars * @param percent Positive integer value. max is 100. */ public void setPercent(int percent) { if ( percent > 100 ) { percent = 100; } if ( percent < 0 ) { percent = 0; } mPullingLeftBar.setProgress(percent); mPullingRightBar.setProgress(percent); } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/RotateLoadingLayout.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Matrix; import android.graphics.drawable.Drawable; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.widget.ImageView.ScaleType; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation; import com.handmark.pulltorefresh.library.R; public class RotateLoadingLayout extends LoadingLayout { static final int ROTATION_ANIMATION_DURATION = 1200; private final Animation mRotateAnimation; private final Matrix mHeaderImageMatrix; private float mRotationPivotX, mRotationPivotY; private final boolean mRotateDrawableWhilePulling; public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) { super(context, mode, scrollDirection, attrs); mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true); mHeaderImage.setScaleType(ScaleType.MATRIX); mHeaderImageMatrix = new Matrix(); mHeaderImage.setImageMatrix(mHeaderImageMatrix); mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR); mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION); mRotateAnimation.setRepeatCount(Animation.INFINITE); mRotateAnimation.setRepeatMode(Animation.RESTART); } public void onLoadingDrawableSet(Drawable imageDrawable) { if (null != imageDrawable) { mRotationPivotX = Math.round(imageDrawable.getIntrinsicWidth() / 2f); mRotationPivotY = Math.round(imageDrawable.getIntrinsicHeight() / 2f); } } protected void onPullImpl(float scaleOfLayout) { float angle; if (mRotateDrawableWhilePulling) { angle = scaleOfLayout * 90f; } else { angle = Math.max(0f, Math.min(180f, scaleOfLayout * 360f - 180f)); } mHeaderImageMatrix.setRotate(angle, mRotationPivotX, mRotationPivotY); mHeaderImage.setImageMatrix(mHeaderImageMatrix); } @Override protected void refreshingImpl() { mHeaderImage.startAnimation(mRotateAnimation); } @Override protected void resetImpl() { mHeaderImage.clearAnimation(); resetImageRotation(); } private void resetImageRotation() { if (null != mHeaderImageMatrix) { mHeaderImageMatrix.reset(); mHeaderImage.setImageMatrix(mHeaderImageMatrix); } } @Override protected void pullToRefreshImpl() { // NO-OP } @Override protected void releaseToRefreshImpl() { // NO-OP } @Override protected int getDefaultDrawableResId() { return R.drawable.default_ptr_rotate; } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/Utils.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.util.TypedValue; public class Utils { static final String LOG_TAG = "PullToRefresh"; /** * Android namespace for Android attributes'-related util methods */ static final String ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android"; /** * Invalid android attribute (temporarily defined, to check android attributes' values) */ static final int INVALID_INT_VALUE = -1; /** * Delegate warn logs at where some deprecated method has been called * @param depreacted Deprecated method name * @param replacement Method name to be able to switch */ public static void warnDeprecation(String depreacted, String replacement) { Log.w(LOG_TAG, "You're using the deprecated " + depreacted + " attr, please switch over to " + replacement); } /** * Try to close {@code InputStream} without any exceptions, and ignore if some exception occurs * @param is {@code InputStream} instance to close */ public static void closeSilently(InputStream is) { // If the instance is null, do nothing and return if (is == null) { return; } try { // try to close is.close(); } catch (IOException e) { // try to close once more try { is.close(); } catch (IOException e1) { // do nothing } } } /** * Try to close {@code Reader} without any exceptions, and ignore if some exception occurs * @param br {@code Reader} instance to close */ public static void closeSilently(Reader br) { // If the instance is null, do nothing and return if (br == null) { return; } try { // try to close br.close(); } catch (IOException e) { try { // try to close once more br.close(); } catch (IOException e1) { // do nothing } } } /** * Check whether android {@code attribute} exists and is set in {@code attributeSet} * @param attrs {@code AttributeSet} where the {@code attribute} is included (if that is set) * @return true if the {@code attribute} exists */ @Deprecated public static boolean existAttributeIntValue(AttributeSet attrs, String attribute) { return existAttributeIntValue(attrs, ANDROID_NAMESPACE, attribute); } /** * Check whether android {@code attribute} exists and is set in {@code attributeSet} * @param attrs {@code AttributeSet} where the {@code attribute} is included (if that is set) * @param namespace Namespace where the {@code attribute} is defined * @param attribute Attribute to be checked * @return true if the {@code attribute} exists */ @Deprecated public static boolean existAttributeIntValue(AttributeSet attrs, String namespace, String attribute) { return existAttributeIntValue(attrs, namespace, attribute, INVALID_INT_VALUE); } /** * Check whether android {@code attribute} exists and is set in {@code attributeSet} * @param attrs {@code AttributeSet} where the {@code attribute} is included (if that is set) * @param namespace Namespace where the {@code attribute} is defined * @param attribute Attribute to be checked * @param invalidValue The flag to check that the {@code attribute} is set * @return true if the {@code attribute} exists */ @Deprecated public static boolean existAttributeIntValue(AttributeSet attrs, String namespace, String attribute, int invalidValue) { // If attrs is null, assume the attribute is not set. if ( attrs == null ) { return false; } Assert.notNull(attrs, "namespace"); Assert.notNull(attrs, "attribute"); boolean isExist = true; int value = attrs.getAttributeIntValue(namespace, attribute, invalidValue); if ( value == invalidValue ) { isExist = false; } return isExist; } /** * Check whether android {@code attribute} exists and is set in {@code attributeSet} * @param attrs {@code AttributeSet} where the {@code attribute} is included (if that is set) * @param attribute Attribute to be checked * @return true if the {@code attribute} exists */ public static boolean existAttributeValue(AttributeSet attrs, String attribute) { return existAttributeValue(attrs, ANDROID_NAMESPACE, attribute); } /** * Check whether android {@code attribute} exists and is set in {@code attributeSet} * @param attrs {@code AttributeSet} where the {@code attribute} is included (if that is set) * @param namespace Namespace where the {@code attribute} is defined * @param attribute Attribute to be checked * @return true if the {@code attribute} exists */ public static boolean existAttributeValue(AttributeSet attrs, String namespace, String attribute) { // If attrs is null, assume the attribute is not set. if ( attrs == null ) { return false; } Assert.notNull(attrs, "namespace"); Assert.notNull(attrs, "attribute"); boolean isExist = true; String value = attrs.getAttributeValue(namespace, attribute); // Assume that it doesn't exist only when value is null. // An empty value can be skipped. if ( value == null ) { isExist = false; } return isExist; } /** * Get an action bar size
* {@link //stackoverflow.com/questions/7165830/what-is-the-size-of-actionbar-in-pixels} * @param context */ public static int getActionBarSize(Context context) { // Calculate ActionBar height int actionBarHeight = 0; TypedValue tv = new TypedValue(); if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,context.getResources().getDisplayMetrics()); } return actionBarHeight; } /** * Get a status bar size
* @param context */ public static int getStatusBarSize(Context context) { int result = 0; int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = context.getResources().getDimensionPixelSize(resourceId); } return result; } } ================================================ FILE: library/src/main/java/com/handmark/pulltorefresh/library/internal/ViewCompat.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * Copyright 2013 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.library.internal; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import com.handmark.pulltorefresh.configuration.xml.PullToRefreshXmlConfiguration; import android.annotation.TargetApi; import android.graphics.Paint; import android.graphics.drawable.Drawable; import android.os.Build.VERSION; import android.util.Log; import android.view.View; @SuppressWarnings("deprecation") public class ViewCompat { /** * @author Wonjun Kim */ private static class Methods { private static final String LOG_TAG = Methods.class.getName(); private static Method setLayerTypeMethod; private static Method postOnAnimationMethod; private static Method setBackgroundMethod; static { initializeMethods(); } @SuppressWarnings("unchecked") private static void initializeMethods() { Class viewClazz = null; // Initialize android.view.View class token try { viewClazz = (Class) Class.forName("android.view.View"); } catch (ClassNotFoundException e) { Log.e(LOG_TAG, "android.view.View class has not been found. Maybe Pull To Refresh might work not correctly.", e); } // If viewClazz fails to initialize, skip creating methods if ( viewClazz == null ) { return; } // Initialize setLayerType() try { setLayerTypeMethod = viewClazz.getMethod("setLayerType", int.class, Paint.class); } catch (NoSuchMethodException e) { Log.e(LOG_TAG, "android.view.View.setLayerType() method has not been found. Maybe Pull To Refresh might work not correctly.", e); } // Initialize postOnAnimation() try { postOnAnimationMethod = viewClazz.getMethod("postOnAnimation", Runnable.class); } catch (NoSuchMethodException e) { Log.e(LOG_TAG, "android.view.View.postOnAnimation() method has not been found. Maybe Pull To Refresh might work not correctly.", e); } // Initialize setBackground() try { setBackgroundMethod = viewClazz.getMethod("setBackground", Drawable.class); } catch (NoSuchMethodException e) { Log.e(LOG_TAG, "android.view.View.setBackground() method has not been found. Maybe Pull To Refresh might work not correctly.", e); } } private static void setLayerType(View view, int layerType) { Assert.notNull(view, "view"); if ( setLayerTypeMethod == null ) { Log.e(LOG_TAG, "android.view.View.setLayerType() method token has not been initialized."); } try { setLayerTypeMethod.invoke(view, layerType, null /* android.graphics.Paint */); } catch (IllegalArgumentException e) { Log.e(LOG_TAG, "Some argument is illegal to call android.view.View.setLayerType().", e); } catch (IllegalAccessException e) { Log.e(LOG_TAG, "It has failed to call android.view.View.setLayerType().", e); } catch (InvocationTargetException e) { Log.e(LOG_TAG, "It has failed to call android.view.View.setLayerType().", e); } } private static void postOnAnimation(View view, Runnable runnable) { Assert.notNull(view, "view"); if ( postOnAnimationMethod == null ) { Log.e(LOG_TAG, "android.view.View.postOnAnimation() method token has not been initialized."); } try { postOnAnimationMethod.invoke(view, runnable); } catch (IllegalArgumentException e) { Log.e(LOG_TAG, "Some argument is illegal to call android.view.View.postOnAnimation().", e); } catch (IllegalAccessException e) { Log.e(LOG_TAG, "It has failed to call android.view.View.postOnAnimation().", e); } catch (InvocationTargetException e) { Log.e(LOG_TAG, "It has failed to call android.view.View.postOnAnimation().", e); } } private static void setBackground(View view, Drawable background) { Assert.notNull(view, "view"); if ( setBackgroundMethod == null ) { Log.e(LOG_TAG, "android.view.View.setBackground() method token has not been initialized."); } try { setBackgroundMethod.invoke(view, background); } catch (IllegalArgumentException e) { Log.e(LOG_TAG, "Some argument is illegal to call android.view.View.setBackground().", e); } catch (IllegalAccessException e) { Log.e(LOG_TAG, "It has failed to call android.view.View.setBackground().", e); } catch (InvocationTargetException e) { Log.e(LOG_TAG, "It has failed to call android.view.View.setBackground().", e); } } } /* * Copied from android.os.Build.VERSION_CODES */ public static class VERSION_CODES { public static final int CUR_DEVELOPMENT = 10000; public static final int BASE = 1; public static final int BASE_1_1 = 2; public static final int CUPCAKE = 3; public static final int DONUT = 4; public static final int ECLAIR = 5; public static final int ECLAIR_0_1 = 6; public static final int ECLAIR_MR1 = 7; public static final int FROYO = 8; public static final int GINGERBREAD = 9; public static final int GINGERBREAD_MR1 = 10; public static final int HONEYCOMB = 11; public static final int HONEYCOMB_MR1 = 12; public static final int HONEYCOMB_MR2 = 13; public static final int ICE_CREAM_SANDWICH = 14; public static final int ICE_CREAM_SANDWICH_MR1 = 15; public static final int JELLY_BEAN = 16; public static final int JELLY_BEAN_MR1 = 17; public static final int JELLY_BEAN_MR2 = 18; public static final int KITKAT = 19; } public static void postOnAnimation(View view, Runnable runnable) { if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { SDK16.postOnAnimation(view, runnable); } else { view.postDelayed(runnable, 16); } } public static void setBackground(View view, Drawable background) { if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { SDK16.setBackground(view, background); } else { view.setBackgroundDrawable(background); } } public static void setLayerType(View view, int layerType) { if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) { SDK11.setLayerType(view, layerType); } } @TargetApi(11) static class SDK11 { public static void setLayerType(View view, int layerType) { Methods.setLayerType(view, layerType); } } @TargetApi(16) static class SDK16 { public static void postOnAnimation(View view, Runnable runnable) { Methods.postOnAnimation(view, runnable); } public static void setBackground(View view, Drawable background) { Methods.setBackground(view, background); } } } ================================================ FILE: pom.xml ================================================ 4.0.0 com.navercorp.pulltorefresh parent pom 3.3.0-SNAPSHOT Android-PullToRefresh Project Implementation of the Pull-to-Refresh UI Pattern for Android. https://github.com/naver/android-pull-to-refresh org.sonatype.oss oss-parent 7 Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo https://github.com/naver/android-pull-to-refresh scm:git:git://github.com/naver/android-pull-to-refresh.git scm:git:git@github.com:naver/android-pull-to-refresh.git HEAD Chris Banes http://about.me/chrisbanes chrisbanes Wonjun Kim ncoolz library sample extras UTF-8 UTF-8 1.6 4.1.1.4 16 3.2.0 com.google.android android ${android.version} provided org.apache.maven.plugins maven-compiler-plugin 3.1 ${java.version} ${java.version} org.apache.maven.plugins maven-release-plugin 2.5 forked-path v@{project.version} com.jayway.maven.plugins.android.generation2 android-maven-plugin 3.7.0 ${android.platform} true ${sourceCompatibility} ${sourceCompatibility} true org.codehaus.mojo build-helper-maven-plugin 1.8 org.codehaus.mojo exec-maven-plugin 1.2.1 false package exec gradle clean assemble org.apache.maven.plugins maven-eclipse-plugin 2.8 com.google.android:android bin com.android.ide.eclipse.adt.ANDROID_FRAMEWORK com.android.ide.eclipse.adt.AndroidNature com.android.ide.eclipse.adt.ResourceManagerBuilder com.android.ide.eclipse.adt.PreCompilerBuilder com.android.ide.eclipse.adt.ApkBuilder src release-sign-artifacts performRelease true org.apache.maven.plugins maven-gpg-plugin 1.4 sign-artifacts verify sign ================================================ FILE: sample/AndroidManifest.xml ================================================ ================================================ FILE: sample/LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: sample/assets/ptr_webview2_sample.html ================================================ PullToRefreshWebView2 Sample

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.

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.

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.

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.

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.

================================================ FILE: sample/assets/pulltorefresh.xml ================================================ com.handmark.pulltorefresh.samples.loadinglayout.CustomLoadingLayout ================================================ FILE: sample/pom.xml ================================================ 4.0.0 com.navercorp.pulltorefresh sample apk Android-PullToRefresh Sample com.navercorp.pulltorefresh parent 3.3.0-SNAPSHOT com.google.android android ${project.groupId} library apklib ${project.version} ${project.groupId} extra-listfragment apklib ${project.version} ${project.groupId} extra-viewpager apklib ${project.version} com.jayway.maven.plugins.android.generation2 android-maven-plugin org.apache.maven.plugins maven-eclipse-plugin com.google.android:android commons-logging:commons-logging xerces:xmlParserAPIs xpp3:xpp3 ================================================ FILE: sample/project.properties ================================================ # This file is automatically generated by Android Tools. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must be checked in Version Control Systems. # # To customize properties used by the Ant build system use, # "ant.properties", and override values to adapt the script to your # project structure. # Project target. target=android-16 android.library.reference.1=../library android.library.reference.2=../extras/PullToRefreshListFragment android.library.reference.3=../extras/PullToRefreshViewPager ================================================ FILE: sample/res/layout/activity_ptr_custom_loadinglayout.xml ================================================ ================================================ FILE: sample/res/layout/activity_ptr_expandable_list.xml ================================================ ================================================ FILE: sample/res/layout/activity_ptr_grid.xml ================================================ ================================================ FILE: sample/res/layout/activity_ptr_horizontalscrollview.xml ================================================ ================================================ FILE: sample/res/layout/activity_ptr_list.xml ================================================ ================================================ FILE: sample/res/layout/activity_ptr_list_fragment.xml ================================================ ================================================ FILE: sample/res/layout/activity_ptr_list_in_vp.xml ================================================ ================================================ FILE: sample/res/layout/activity_ptr_scrollview.xml ================================================ ================================================ FILE: sample/res/layout/activity_ptr_viewpager.xml ================================================ ================================================ FILE: sample/res/layout/activity_ptr_webview.xml ================================================ ================================================ FILE: sample/res/layout/activity_ptr_webview2.xml ================================================ ================================================ FILE: sample/res/layout/layout_listview_in_viewpager.xml ================================================ ================================================ FILE: sample/res/values/strings.xml ================================================ Hello World, PullToRefreshActivity! pulltorefreshexample 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. ================================================ FILE: sample/res/values/styles.xml ================================================ ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/LauncherActivity.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.samples; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class LauncherActivity extends ListActivity { public static final String[] options = { "ListView", "ExpandableListView", "GridView", "WebView", "ScrollView", "Horizontal ScrollView", "ViewPager", "ListView Fragment", "WebView Advanced", "ListView in ViewPager", "Custom LoadingLayout" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, options)); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { Intent intent; switch (position) { default: case 0: intent = new Intent(this, PullToRefreshListActivity.class); break; case 1: intent = new Intent(this, PullToRefreshExpandableListActivity.class); break; case 2: intent = new Intent(this, PullToRefreshGridActivity.class); break; case 3: intent = new Intent(this, PullToRefreshWebViewActivity.class); break; case 4: intent = new Intent(this, PullToRefreshScrollViewActivity.class); break; case 5: intent = new Intent(this, PullToRefreshHorizontalScrollViewActivity.class); break; case 6: intent = new Intent(this, PullToRefreshViewPagerActivity.class); break; case 7: intent = new Intent(this, PullToRefreshListFragmentActivity.class); break; case 8: intent = new Intent(this, PullToRefreshWebView2Activity.class); break; case 9: intent = new Intent(this, PullToRefreshListInViewPagerActivity.class); break; case 10: intent = new Intent(this, PullToRefreshCustomLoadingLayoutActivity.class); break; } startActivity(intent); } } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshCustomLoadingLayoutActivity.java ================================================ /* * Copyright (C) 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.handmark.pulltorefresh.samples; import java.util.Arrays; import java.util.LinkedList; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshListView; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.text.format.DateUtils; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.ListView; public class PullToRefreshCustomLoadingLayoutActivity extends Activity { private static final String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler" }; private PullToRefreshListView mPullRefreshListView; private LinkedList mListItems; private ArrayAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_custom_loadinglayout); initPullToRefresh(); } private void initPullToRefresh() { mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.ptrListView); // Set a listener to be invoked when the list should be refreshed. mPullRefreshListView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(PullToRefreshBase refreshView) { String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); Log.d(PullToRefreshCustomLoadingLayoutActivity.class.getCanonicalName(), "onRefreshing..." + label); // Do work to refresh the list here. new GetDataTask().execute(); } }); final ListView actualListView = mPullRefreshListView.getRefreshableView(); mListItems = new LinkedList(); mListItems.addAll(Arrays.asList(mStrings)); mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mListItems); actualListView.setAdapter(mAdapter); } private class GetDataTask extends AsyncTask { @Override protected String[] doInBackground(Void... params) { // Simulates a background job. try { Log.d(PullToRefreshCustomLoadingLayoutActivity.class.getCanonicalName(), "GetDataTask.doInBackground"); Thread.sleep(1000); } catch (InterruptedException e) { } return mStrings; } @Override protected void onPostExecute(String[] result) { mListItems.addFirst("New Item"); mAdapter.notifyDataSetChanged(); // Call onRefreshComplete when the list has been refreshed. Log.d(PullToRefreshCustomLoadingLayoutActivity.class.getCanonicalName(), "onRefreshComplete"); mPullRefreshListView.onRefreshComplete(); super.onPostExecute(result); } } } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshExpandableListActivity.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.samples; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.ExpandableListActivity; import android.os.AsyncTask; import android.os.Bundle; import android.widget.ExpandableListView; import android.widget.SimpleExpandableListAdapter; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshExpandableListView; public final class PullToRefreshExpandableListActivity extends ExpandableListActivity { private static final String KEY = "key"; private List> groupData = new ArrayList>(); private List>> childData = new ArrayList>>(); private PullToRefreshExpandableListView mPullRefreshListView; private SimpleExpandableListAdapter mAdapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_expandable_list); mPullRefreshListView = (PullToRefreshExpandableListView) findViewById(R.id.pull_refresh_expandable_list); // Set a listener to be invoked when the list should be refreshed. mPullRefreshListView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(PullToRefreshBase refreshView) { // Do work to refresh the list here. new GetDataTask().execute(); } }); for (String group : mGroupStrings) { Map groupMap1 = new HashMap(); groupData.add(groupMap1); groupMap1.put(KEY, group); List> childList = new ArrayList>(); for (String string : mChildStrings) { Map childMap = new HashMap(); childList.add(childMap); childMap.put(KEY, string); } childData.add(childList); } mAdapter = new SimpleExpandableListAdapter(this, groupData, android.R.layout.simple_expandable_list_item_1, new String[] { KEY }, new int[] { android.R.id.text1 }, childData, android.R.layout.simple_expandable_list_item_2, new String[] { KEY }, new int[] { android.R.id.text1 }); setListAdapter(mAdapter); } private class GetDataTask extends AsyncTask { @Override protected String[] doInBackground(Void... params) { // Simulates a background job. try { Thread.sleep(2000); } catch (InterruptedException e) { } return mChildStrings; } @Override protected void onPostExecute(String[] result) { Map newMap = new HashMap(); newMap.put(KEY, "Added after refresh..."); groupData.add(newMap); List> childList = new ArrayList>(); for (String string : mChildStrings) { Map childMap = new HashMap(); childMap.put(KEY, string); childList.add(childMap); } childData.add(childList); mAdapter.notifyDataSetChanged(); // Call onRefreshComplete when the list has been refreshed. mPullRefreshListView.onRefreshComplete(); super.onPostExecute(result); } } private String[] mChildStrings = { "Child One", "Child Two", "Child Three", "Child Four", "Child Five", "Child Six" }; private String[] mGroupStrings = { "Group One", "Group Two", "Group Three" }; } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshGridActivity.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.samples; import java.util.Arrays; import java.util.LinkedList; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.GridView; import android.widget.TextView; import android.widget.Toast; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2; import com.handmark.pulltorefresh.library.PullToRefreshGridView; public final class PullToRefreshGridActivity extends Activity { static final int MENU_SET_MODE = 0; private LinkedList mListItems; private PullToRefreshGridView mPullRefreshGridView; private GridView mGridView; private ArrayAdapter mAdapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_grid); mPullRefreshGridView = (PullToRefreshGridView) findViewById(R.id.pull_refresh_grid); mGridView = mPullRefreshGridView.getRefreshableView(); // Set a listener to be invoked when the list should be refreshed. mPullRefreshGridView.setOnRefreshListener(new OnRefreshListener2() { @Override public void onPullDownToRefresh(PullToRefreshBase refreshView) { Toast.makeText(PullToRefreshGridActivity.this, "Pull Down!", Toast.LENGTH_SHORT).show(); new GetDataTask().execute(); } @Override public void onPullUpToRefresh(PullToRefreshBase refreshView) { Toast.makeText(PullToRefreshGridActivity.this, "Pull Up!", Toast.LENGTH_SHORT).show(); new GetDataTask().execute(); } }); mListItems = new LinkedList(); TextView tv = new TextView(this); tv.setGravity(Gravity.CENTER); tv.setText("Empty View, Pull Down/Up to Add Items"); mPullRefreshGridView.setEmptyView(tv); mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mListItems); mGridView.setAdapter(mAdapter); } private class GetDataTask extends AsyncTask { @Override protected String[] doInBackground(Void... params) { // Simulates a background job. try { Thread.sleep(2000); } catch (InterruptedException e) { } return mStrings; } @Override protected void onPostExecute(String[] result) { mListItems.addFirst("Added after refresh..."); mListItems.addAll(Arrays.asList(result)); mAdapter.notifyDataSetChanged(); // Call onRefreshComplete when the list has been refreshed. mPullRefreshGridView.onRefreshComplete(); super.onPostExecute(result); } } @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, MENU_SET_MODE, 0, mPullRefreshGridView.getMode() == Mode.BOTH ? "Change to MODE_PULL_DOWN" : "Change to MODE_PULL_BOTH"); return super.onCreateOptionsMenu(menu); } @Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem setModeItem = menu.findItem(MENU_SET_MODE); setModeItem.setTitle(mPullRefreshGridView.getMode() == Mode.BOTH ? "Change to MODE_PULL_FROM_START" : "Change to MODE_PULL_BOTH"); return super.onPrepareOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_SET_MODE: mPullRefreshGridView .setMode(mPullRefreshGridView.getMode() == Mode.BOTH ? Mode.PULL_FROM_START : Mode.BOTH); break; } return super.onOptionsItemSelected(item); } private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler" }; } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshHorizontalScrollViewActivity.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.samples; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.widget.HorizontalScrollView; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshHorizontalScrollView; public final class PullToRefreshHorizontalScrollViewActivity extends Activity { PullToRefreshHorizontalScrollView mPullRefreshScrollView; HorizontalScrollView mScrollView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_horizontalscrollview); mPullRefreshScrollView = (PullToRefreshHorizontalScrollView) findViewById(R.id.pull_refresh_horizontalscrollview); mPullRefreshScrollView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(PullToRefreshBase refreshView) { new GetDataTask().execute(); } }); mScrollView = mPullRefreshScrollView.getRefreshableView(); } private class GetDataTask extends AsyncTask { @Override protected String[] doInBackground(Void... params) { // Simulates a background job. try { Thread.sleep(4000); } catch (InterruptedException e) { } return null; } @Override protected void onPostExecute(String[] result) { // Do some stuff here // Call onRefreshComplete when the list has been refreshed. mPullRefreshScrollView.onRefreshComplete(); super.onPostExecute(result); } } } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshListActivity.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.samples; import java.util.Arrays; import java.util.LinkedList; import android.app.ListActivity; import android.os.AsyncTask; import android.os.Bundle; import android.text.format.DateUtils; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshBase.State; import com.handmark.pulltorefresh.library.PullToRefreshListView; import com.handmark.pulltorefresh.library.extras.SoundPullEventListener; public final class PullToRefreshListActivity extends ListActivity { static final int MENU_MANUAL_REFRESH = 0; static final int MENU_DISABLE_SCROLL = 1; static final int MENU_SET_MODE = 2; static final int MENU_DEMO = 3; private LinkedList mListItems; private PullToRefreshListView mPullRefreshListView; private ArrayAdapter mAdapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_list); mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list); // Set a listener to be invoked when the list should be refreshed. mPullRefreshListView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(PullToRefreshBase refreshView) { String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); // Update the LastUpdatedLabel refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label); // Do work to refresh the list here. new GetDataTask().execute(); } }); // Add an end-of-list listener mPullRefreshListView.setOnLastItemVisibleListener(new OnLastItemVisibleListener() { @Override public void onLastItemVisible() { Toast.makeText(PullToRefreshListActivity.this, "End of List!", Toast.LENGTH_SHORT).show(); } }); ListView actualListView = mPullRefreshListView.getRefreshableView(); // Need to use the Actual ListView when registering for Context Menu registerForContextMenu(actualListView); mListItems = new LinkedList(); mListItems.addAll(Arrays.asList(mStrings)); mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mListItems); /** * Add Sound Event Listener */ SoundPullEventListener soundListener = new SoundPullEventListener(this); soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event); soundListener.addSoundEvent(State.RESET, R.raw.reset_sound); soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound); mPullRefreshListView.setOnPullEventListener(soundListener); // You can also just use setListAdapter(mAdapter) or // mPullRefreshListView.setAdapter(mAdapter) actualListView.setAdapter(mAdapter); } private class GetDataTask extends AsyncTask { @Override protected String[] doInBackground(Void... params) { // Simulates a background job. try { Thread.sleep(4000); } catch (InterruptedException e) { } return mStrings; } @Override protected void onPostExecute(String[] result) { mListItems.addFirst("Added after refresh..."); mAdapter.notifyDataSetChanged(); // Call onRefreshComplete when the list has been refreshed. mPullRefreshListView.onRefreshComplete(); super.onPostExecute(result); } } @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, MENU_MANUAL_REFRESH, 0, "Manual Refresh"); menu.add(0, MENU_DISABLE_SCROLL, 1, mPullRefreshListView.isScrollingWhileRefreshingEnabled() ? "Disable Scrolling while Refreshing" : "Enable Scrolling while Refreshing"); menu.add(0, MENU_SET_MODE, 0, mPullRefreshListView.getMode() == Mode.BOTH ? "Change to MODE_PULL_DOWN" : "Change to MODE_PULL_BOTH"); menu.add(0, MENU_DEMO, 0, "Demo"); return super.onCreateOptionsMenu(menu); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; menu.setHeaderTitle("Item: " + getListView().getItemAtPosition(info.position)); menu.add("Item 1"); menu.add("Item 2"); menu.add("Item 3"); menu.add("Item 4"); super.onCreateContextMenu(menu, v, menuInfo); } @Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem disableItem = menu.findItem(MENU_DISABLE_SCROLL); disableItem .setTitle(mPullRefreshListView.isScrollingWhileRefreshingEnabled() ? "Disable Scrolling while Refreshing" : "Enable Scrolling while Refreshing"); MenuItem setModeItem = menu.findItem(MENU_SET_MODE); setModeItem.setTitle(mPullRefreshListView.getMode() == Mode.BOTH ? "Change to MODE_FROM_START" : "Change to MODE_PULL_BOTH"); return super.onPrepareOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_MANUAL_REFRESH: new GetDataTask().execute(); mPullRefreshListView.setRefreshing(false); break; case MENU_DISABLE_SCROLL: mPullRefreshListView.setScrollingWhileRefreshingEnabled(!mPullRefreshListView .isScrollingWhileRefreshingEnabled()); break; case MENU_SET_MODE: mPullRefreshListView.setMode(mPullRefreshListView.getMode() == Mode.BOTH ? Mode.PULL_FROM_START : Mode.BOTH); break; case MENU_DEMO: mPullRefreshListView.demo(); break; } return super.onOptionsItemSelected(item); } private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler" }; } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshListFragmentActivity.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.samples; import java.util.Arrays; import java.util.LinkedList; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.widget.ArrayAdapter; import android.widget.ListView; import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshListView; public final class PullToRefreshListFragmentActivity extends FragmentActivity implements OnRefreshListener { private LinkedList mListItems; private ArrayAdapter mAdapter; private PullToRefreshListFragment mPullRefreshListFragment; private PullToRefreshListView mPullRefreshListView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_list_fragment); mPullRefreshListFragment = (PullToRefreshListFragment) getSupportFragmentManager().findFragmentById( R.id.frag_ptr_list); // Get PullToRefreshListView from Fragment mPullRefreshListView = mPullRefreshListFragment.getPullToRefreshListView(); // Set a listener to be invoked when the list should be refreshed. mPullRefreshListView.setOnRefreshListener(this); // You can also just use mPullRefreshListFragment.getListView() ListView actualListView = mPullRefreshListView.getRefreshableView(); mListItems = new LinkedList(); mListItems.addAll(Arrays.asList(mStrings)); mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mListItems); // You can also just use setListAdapter(mAdapter) or // mPullRefreshListView.setAdapter(mAdapter) actualListView.setAdapter(mAdapter); mPullRefreshListFragment.setListShown(true); } @Override public void onRefresh(PullToRefreshBase refreshView) { // Do work to refresh the list here. new GetDataTask().execute(); } private class GetDataTask extends AsyncTask { @Override protected String[] doInBackground(Void... params) { // Simulates a background job. try { Thread.sleep(4000); } catch (InterruptedException e) { } return mStrings; } @Override protected void onPostExecute(String[] result) { mListItems.addFirst("Added after refresh..."); mAdapter.notifyDataSetChanged(); // Call onRefreshComplete when the list has been refreshed. mPullRefreshListView.onRefreshComplete(); super.onPostExecute(result); } } private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler" }; } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshListInViewPagerActivity.java ================================================ package com.handmark.pulltorefresh.samples; import java.util.Arrays; import android.app.Activity; import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshListView; public class PullToRefreshListInViewPagerActivity extends Activity implements OnRefreshListener { private static final String[] STRINGS = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler" }; private ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_list_in_vp); mViewPager = (ViewPager) findViewById(R.id.vp_list); mViewPager.setAdapter(new ListViewPagerAdapter()); } private class ListViewPagerAdapter extends PagerAdapter { @Override public View instantiateItem(ViewGroup container, int position) { Context context = container.getContext(); PullToRefreshListView plv = (PullToRefreshListView) LayoutInflater.from(context).inflate( R.layout.layout_listview_in_viewpager, container, false); ListAdapter adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_1, Arrays.asList(STRINGS)); plv.setAdapter(adapter); plv.setOnRefreshListener(PullToRefreshListInViewPagerActivity.this); // Now just add ListView to ViewPager and return it container.addView(plv, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); return plv; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public int getCount() { return 3; } } @Override public void onRefresh(PullToRefreshBase refreshView) { new GetDataTask(refreshView).execute(); } private static class GetDataTask extends AsyncTask { PullToRefreshBase mRefreshedView; public GetDataTask(PullToRefreshBase refreshedView) { mRefreshedView = refreshedView; } @Override protected Void doInBackground(Void... params) { // Simulates a background job. try { Thread.sleep(4000); } catch (InterruptedException e) { } return null; } @Override protected void onPostExecute(Void result) { mRefreshedView.onRefreshComplete(); super.onPostExecute(result); } } } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshScrollViewActivity.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.samples; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.widget.ScrollView; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshScrollView; public final class PullToRefreshScrollViewActivity extends Activity { PullToRefreshScrollView mPullRefreshScrollView; ScrollView mScrollView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_scrollview); mPullRefreshScrollView = (PullToRefreshScrollView) findViewById(R.id.pull_refresh_scrollview); mPullRefreshScrollView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(PullToRefreshBase refreshView) { new GetDataTask().execute(); } }); mScrollView = mPullRefreshScrollView.getRefreshableView(); } private class GetDataTask extends AsyncTask { @Override protected String[] doInBackground(Void... params) { // Simulates a background job. try { Thread.sleep(4000); } catch (InterruptedException e) { } return null; } @Override protected void onPostExecute(String[] result) { // Do some stuff here // Call onRefreshComplete when the list has been refreshed. mPullRefreshScrollView.onRefreshComplete(); super.onPostExecute(result); } } } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshViewPagerActivity.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.samples; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.widget.ImageView; import com.handmark.pulltorefresh.extras.viewpager.PullToRefreshViewPager; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; public class PullToRefreshViewPagerActivity extends Activity implements OnRefreshListener { private PullToRefreshViewPager mPullToRefreshViewPager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_viewpager); mPullToRefreshViewPager = (PullToRefreshViewPager) findViewById(R.id.pull_refresh_viewpager); mPullToRefreshViewPager.setOnRefreshListener(this); ViewPager vp = mPullToRefreshViewPager.getRefreshableView(); vp.setAdapter(new SamplePagerAdapter()); } @Override public void onRefresh(PullToRefreshBase refreshView) { new GetDataTask().execute(); } static class SamplePagerAdapter extends PagerAdapter { private static int[] sDrawables = { R.drawable.wallpaper, R.drawable.wallpaper, R.drawable.wallpaper, R.drawable.wallpaper, R.drawable.wallpaper, R.drawable.wallpaper }; @Override public int getCount() { return sDrawables.length; } @Override public View instantiateItem(ViewGroup container, int position) { ImageView imageView = new ImageView(container.getContext()); imageView.setImageResource(sDrawables[position]); // Now just add ImageView to ViewPager and return it container.addView(imageView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); return imageView; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } } private class GetDataTask extends AsyncTask { @Override protected Void doInBackground(Void... params) { // Simulates a background job. try { Thread.sleep(4000); } catch (InterruptedException e) { } return null; } @Override protected void onPostExecute(Void result) { mPullToRefreshViewPager.onRefreshComplete(); super.onPostExecute(result); } } } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshWebView2Activity.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.samples; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.extras.PullToRefreshWebView2; public final class PullToRefreshWebView2Activity extends Activity implements OnRefreshListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_webview2); PullToRefreshWebView2 pullRefreshWebView = (PullToRefreshWebView2) findViewById(R.id.pull_refresh_webview2); pullRefreshWebView.setOnRefreshListener(this); WebView webView = pullRefreshWebView.getRefreshableView(); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new SampleWebViewClient()); // We just load a prepared HTML page from the assets folder for this // sample, see that file for the Javascript implementation webView.loadUrl("file:///android_asset/ptr_webview2_sample.html"); } private static class SampleWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } @Override public void onRefresh(final PullToRefreshBase refreshView) { // This is very contrived example, we just wait 2 seconds, then call // onRefreshComplete() refreshView.postDelayed(new Runnable() { @Override public void run() { refreshView.onRefreshComplete(); } }, 2 * 1000); } } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/PullToRefreshWebViewActivity.java ================================================ /******************************************************************************* * Copyright 2011, 2012 Chris Banes. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.handmark.pulltorefresh.samples; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; import com.handmark.pulltorefresh.library.PullToRefreshWebView; public final class PullToRefreshWebViewActivity extends Activity { PullToRefreshWebView mPullRefreshWebView; WebView mWebView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_webview); mPullRefreshWebView = (PullToRefreshWebView) findViewById(R.id.pull_refresh_webview); mWebView = mPullRefreshWebView.getRefreshableView(); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebViewClient(new SampleWebViewClient()); mWebView.loadUrl("http://www.google.com"); } private static class SampleWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } } ================================================ FILE: sample/src/com/handmark/pulltorefresh/samples/loadinglayout/CustomLoadingLayout.java ================================================ /* * Copyright (C) 2014 Naver Business Platform Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.handmark.pulltorefresh.samples.loadinglayout; import android.R; import android.content.Context; import android.content.res.TypedArray; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation; import com.handmark.pulltorefresh.library.internal.FlipLoadingLayout; public class CustomLoadingLayout extends FlipLoadingLayout { private static final float MAX_SCALE_SIZE = 3f; public CustomLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) { super(context, mode, scrollDirection, attrs); } @Override protected int getDefaultDrawableResId() { // Use the default arrow icon from android R return R.drawable.arrow_down_float; } @Override protected void onPullImpl(float scaleOfLayout) { super.onPullImpl(scaleOfLayout); int color = getHeaderTextColorBy(scaleOfLayout); mHeaderText.setTextColor(color); } private int getHeaderTextColorBy(float scaleOfLayout) { // Limit the scale size if ( scaleOfLayout > MAX_SCALE_SIZE ) { scaleOfLayout = MAX_SCALE_SIZE; } // Create the color code int alpha = (int) ((scaleOfLayout / MAX_SCALE_SIZE) * 255); int color = 0x00FFFFFF /* Transparent & White */ | (alpha << 24); return color; } @Override protected String loadPullLabel(Context context, TypedArray attrs, Mode mode) { return "Custom pull label"; } @Override protected String loadRefreshingLabel(Context context, TypedArray attrs, Mode mode) { return "Custom refresh label"; } @Override protected String loadReleaseLabel(Context context, TypedArray attrs, Mode mode) { return "Custom release label"; } } ================================================ FILE: settings.gradle ================================================ include 'library' include 'extras/PullToRefreshListFragment' include 'extras/PullToRefreshViewPager'