├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── gradle-maven-push.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── timehop │ │ └── stickyheadersrecyclerview │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── timehop │ └── stickyheadersrecyclerview │ ├── HeaderPositionCalculator.java │ ├── ItemVisibilityAdapter.java │ ├── StickyRecyclerHeadersAdapter.java │ ├── StickyRecyclerHeadersDecoration.java │ ├── StickyRecyclerHeadersTouchListener.java │ ├── caching │ ├── HeaderProvider.java │ └── HeaderViewCache.java │ ├── calculation │ └── DimensionCalculator.java │ ├── rendering │ └── HeaderRenderer.java │ └── util │ ├── LinearLayoutOrientationProvider.java │ └── OrientationProvider.java ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ └── com │ │ └── timehop │ │ └── stickyheadersrecyclerview │ │ └── sample │ │ ├── AnimalsAdapter.java │ │ ├── DividerDecoration.java │ │ ├── MainActivity.java │ │ └── RecyclerItemClickListener.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── drawable │ └── white_touch.xml │ ├── layout-land │ ├── view_header.xml │ └── view_item.xml │ ├── layout │ ├── activity_main.xml │ ├── view_header.xml │ └── view_item.xml │ └── values │ ├── arrays.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea 4 | .DS_Store 5 | /build 6 | *.iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014 Jacob Tabak - Timehop 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project is no longer being maintained 2 | ========================================== 3 | 4 | sticky-headers-recyclerview 5 | =========================== 6 | 7 | This decorator allows you to easily create section headers for RecyclerViews using a 8 | LinearLayoutManager in either vertical or horizontal orientation. 9 | 10 | Credit to [Emil Sjölander](https://github.com/emilsjolander) for creating StickyListHeaders, 11 | a library that many of us relied on for sticky headers in our listviews. 12 | 13 | Here is a quick video of it in action (click to see the full video): 14 | 15 | [![animated gif demo](http://i.imgur.com/I0ztoPw.gif)](https://www.youtube.com/watch?v=zluBwbf3aew) 16 | 17 | [![animated gif demo](http://i.imgur.com/b5pJjtL.gif)](https://www.youtube.com/watch?v=zluBwbf3aew) 18 | 19 | Download 20 | -------- 21 | 22 | Current version: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.timehop.stickyheadersrecyclerview/library/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.timehop.stickyheadersrecyclerview/library) 23 | 24 | compile 'com.timehop.stickyheadersrecyclerview:library:[latest.version.number]@aar' 25 | 26 | 27 | Usage 28 | ----- 29 | 30 | There are three main classes, `StickyRecyclerHeadersAdapter`, `StickyRecyclerHeadersDecoration`, 31 | and `StickyRecyclerHeadersTouchListener`. 32 | 33 | `StickyRecyclerHeadersAdapter` has a very similar interface to the `RecyclerView.Adapter`, and it 34 | is recommended that you make your `RecyclerView.Adapter` implement `StickyRecyclerHeadersAdapter`. 35 | 36 | There interface looks like this: 37 | 38 | ```java 39 | public interface StickyRecyclerHeadersAdapter { 40 | public long getHeaderId(int position); 41 | 42 | public VH onCreateHeaderViewHolder(ViewGroup parent); 43 | 44 | public void onBindHeaderViewHolder(VH holder, int position); 45 | 46 | public int getItemCount(); 47 | } 48 | ``` 49 | 50 | The second class, `StickyRecyclerHeadersDecoration`, is where most of the magic happens, and does 51 | not require any configuration on your end. Here's an example from `onCreate()` in an activity: 52 | 53 | ```java 54 | mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview); 55 | mAdapter = new MyStickyRecyclerHeadersAdapter(); 56 | mRecyclerView.setAdapter(mAdapter); 57 | mRecyclerView.setLayoutManager(new LinearLayoutManager(context)); 58 | mRecyclerView.addItemDecoration(new StickyRecyclerHeadersDecoration(mAdapter)); 59 | ``` 60 | 61 | `StickyRecyclerHeadersTouchListener` allows you to listen for clicks on header views. 62 | Simply create an instance of `StickyRecyclerHeadersTouchListener`, set the `OnHeaderClickListener`, 63 | and add the `StickyRecyclerHeadersTouchListener` as a touch listener to your `RecyclerView`. 64 | 65 | ```java 66 | StickyRecyclerHeadersTouchListener touchListener = 67 | new StickyRecyclerHeadersTouchListener(recyclerView, headersDecor); 68 | touchListener.setOnHeaderClickListener( 69 | new StickyRecyclerHeadersTouchListener.OnHeaderClickListener() { 70 | @Override 71 | public void onHeaderClick(View header, int position, long headerId) { 72 | Toast.makeText(MainActivity.this, "Header position: " + position + ", id: " + headerId, 73 | Toast.LENGTH_SHORT).show(); 74 | } 75 | }); 76 | mRecyclerView.addOnItemTouchListener(touchListener); 77 | ``` 78 | 79 | The StickyHeaders aren't aware of your adapter so if you must notify them when your data set changes. 80 | 81 | ```java 82 | mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { 83 | @Override public void onChanged() { 84 | headersDecor.invalidateHeaders(); 85 | } 86 | }); 87 | ``` 88 | 89 | If the Recyclerview's layout manager implements getExtraLayoutSpace (to preload more content then is 90 | visible for performance reasons), you must implement ItemVisibilityAdapter and pass an instance as a 91 | second argument to StickyRecyclerHeadersDecoration's constructor. 92 | ```java 93 | @Override 94 | public boolean isPositionVisible(final int position) { 95 | return layoutManager.findFirstVisibleItemPosition() <= position 96 | && layoutManager.findLastVisibleItemPosition() >= position; 97 | } 98 | ``` 99 | 100 | 101 | Item animators don't play nicely with RecyclerView decorations, so your mileage with that may vary. 102 | 103 | Compatibility 104 | ------------- 105 | 106 | API 11+ 107 | 108 | Known Issues 109 | ------------ 110 | 111 | * The header views aren't recycled at this time. Contributions are most welcome. 112 | 113 | * I haven't tested this with ItemAnimators yet. 114 | 115 | * The header views are drawn to a canvas, and are not actually a part of the view hierarchy. As such, they can't have touch states, and you may run into issues if you try to load images into them asynchronously. 116 | 117 | Version History 118 | --------------- 119 | 0.4.3 (12/24/2015) - Change minSDK to 11, fix issue with header bounds caching 120 | 121 | 0.4.2 (8/21/2015) - Add support for reverse `ReverseLayout` in `LinearLayoutManager` by [AntonPukhonin](https://github.com/AntonPukhonin) 122 | 123 | 0.4.1 (6/24/2015) - Fix "dancing headers" by DarkJaguar91 124 | 125 | 0.4.0 (4/16/2015) - Code reorganization by danoz73, fixes for different sized headers, performance improvements 126 | 127 | 0.3.6 (1/30/2015) - Prevent header clicks from passing on the touch event 128 | 129 | 0.3.5 (12/12/2014) - Add StickyRecyclerHeadersDecoration.invalidateHeaders() method 130 | 131 | 0.3.4 (12/3/2014) - Fix issues with rendering of header views with header ID = 0 132 | 133 | 0.3.3 (11/13/2014) - Fixes for padding, support views without headers 134 | 135 | 0.3.2 (11/1/2014) - Bug fixes for list items with margins and deleting items 136 | 137 | 0.2 (10/3/2014) - Add StickyRecyclerHeadersTouchListener 138 | 139 | 0.1 (10/2/2014) - Initial Release 140 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.5.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | ext { 22 | compileSdkVersion = 23 23 | buildToolsVersion = '23.0.2' 24 | supportLibsVersion = '23.1.1' 25 | targetSdkVersion = 22 26 | minSdkVersion = 11 27 | versionCode = 13 28 | versionName = "0.4.3" 29 | } 30 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Settings specified in this file will override any Gradle settings 5 | # configured through the IDE. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | VERSION_NAME=0.4.3 21 | VERSION_CODE=13 22 | GROUP=com.timehop.stickyheadersrecyclerview 23 | 24 | POM_DESCRIPTION=RecyclerView decorator for sticky list headers. 25 | POM_URL=https://github.com/timehop/sticky-headers-recyclerview 26 | POM_SCM_URL=https://github.com/timehop/sticky-headers-recyclerview 27 | POM_SCM_CONNECTION=scm:git@github.com:timehop/sticky-headers-recyclerview.git 28 | POM_SCM_DEV_CONNECTION=scm:git@github.com:timehop/sticky-headers-recyclerview.git 29 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 30 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 31 | POM_LICENCE_DIST=repo 32 | POM_DEVELOPER_ID=jacobtabak 33 | POM_DEVELOPER_NAME=Jacob Tabak -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timehop/sticky-headers-recyclerview/f5a9e9b8f5d96734e20439b0a41381865fa52fb7/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Dec 12 10:27:39 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.compileSdkVersion as Integer 5 | buildToolsVersion rootProject.ext.buildToolsVersion as String 6 | 7 | defaultConfig { 8 | minSdkVersion rootProject.ext.minSdkVersion as Integer 9 | targetSdkVersion rootProject.ext.targetSdkVersion as Integer 10 | versionCode rootProject.ext.versionCode as Integer 11 | versionName rootProject.ext.versionName as String 12 | } 13 | compileOptions { 14 | sourceCompatibility JavaVersion.VERSION_1_7 15 | targetCompatibility JavaVersion.VERSION_1_7 16 | } 17 | } 18 | 19 | dependencies { 20 | compile "com.android.support:recyclerview-v7:${rootProject.supportLibsVersion}" 21 | } 22 | 23 | apply from: 'gradle-maven-push.gradle' 24 | 25 | afterEvaluate { 26 | androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath 27 | } 28 | -------------------------------------------------------------------------------- /library/gradle-maven-push.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Chris Banes 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'maven' 18 | apply plugin: 'signing' 19 | 20 | def isReleaseBuild() { 21 | return VERSION_NAME.contains("SNAPSHOT") == false 22 | } 23 | 24 | def getReleaseRepositoryUrl() { 25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 27 | } 28 | 29 | def getSnapshotRepositoryUrl() { 30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 31 | : "https://oss.sonatype.org/content/repositories/snapshots/" 32 | } 33 | 34 | def getRepositoryUsername() { 35 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" 36 | } 37 | 38 | def getRepositoryPassword() { 39 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" 40 | } 41 | 42 | afterEvaluate { project -> 43 | uploadArchives { 44 | repositories { 45 | mavenDeployer { 46 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 47 | 48 | pom.groupId = GROUP 49 | pom.artifactId = POM_ARTIFACT_ID 50 | pom.version = VERSION_NAME 51 | 52 | repository(url: getReleaseRepositoryUrl()) { 53 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 54 | } 55 | snapshotRepository(url: getSnapshotRepositoryUrl()) { 56 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 57 | } 58 | 59 | pom.project { 60 | name POM_NAME 61 | packaging POM_PACKAGING 62 | description POM_DESCRIPTION 63 | url POM_URL 64 | 65 | scm { 66 | url POM_SCM_URL 67 | connection POM_SCM_CONNECTION 68 | developerConnection POM_SCM_DEV_CONNECTION 69 | } 70 | 71 | licenses { 72 | license { 73 | name POM_LICENCE_NAME 74 | url POM_LICENCE_URL 75 | distribution POM_LICENCE_DIST 76 | } 77 | } 78 | 79 | developers { 80 | developer { 81 | id POM_DEVELOPER_ID 82 | name POM_DEVELOPER_NAME 83 | } 84 | } 85 | } 86 | } 87 | } 88 | } 89 | 90 | signing { 91 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 92 | sign configurations.archives 93 | } 94 | 95 | task androidJavadocs(type: Javadoc) { 96 | source = android.sourceSets.main.java.srcDirs 97 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 98 | } 99 | 100 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 101 | classifier = 'javadoc' 102 | from androidJavadocs.destinationDir 103 | } 104 | 105 | task androidSourcesJar(type: Jar) { 106 | classifier = 'sources' 107 | from android.sourceSets.main.java.sourceFiles 108 | } 109 | 110 | artifacts { 111 | archives androidSourcesJar 112 | archives androidJavadocsJar 113 | } 114 | } -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=Sticky Headers RecyclerView 2 | POM_ARTIFACT_ID=library 3 | POM_PACKAGING=jar -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/androidTest/java/com/timehop/stickyheadersrecyclerview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/HeaderPositionCalculator.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview; 2 | 3 | import android.graphics.Rect; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.LinearLayout; 9 | 10 | import com.timehop.stickyheadersrecyclerview.caching.HeaderProvider; 11 | import com.timehop.stickyheadersrecyclerview.calculation.DimensionCalculator; 12 | import com.timehop.stickyheadersrecyclerview.util.OrientationProvider; 13 | 14 | /** 15 | * Calculates the position and location of header views 16 | */ 17 | public class HeaderPositionCalculator { 18 | 19 | private final StickyRecyclerHeadersAdapter mAdapter; 20 | private final OrientationProvider mOrientationProvider; 21 | private final HeaderProvider mHeaderProvider; 22 | private final DimensionCalculator mDimensionCalculator; 23 | 24 | /** 25 | * The following fields are used as buffers for internal calculations. Their sole purpose is to avoid 26 | * allocating new Rect every time we need one. 27 | */ 28 | private final Rect mTempRect1 = new Rect(); 29 | private final Rect mTempRect2 = new Rect(); 30 | 31 | public HeaderPositionCalculator(StickyRecyclerHeadersAdapter adapter, HeaderProvider headerProvider, 32 | OrientationProvider orientationProvider, DimensionCalculator dimensionCalculator) { 33 | mAdapter = adapter; 34 | mHeaderProvider = headerProvider; 35 | mOrientationProvider = orientationProvider; 36 | mDimensionCalculator = dimensionCalculator; 37 | } 38 | 39 | /** 40 | * Determines if a view should have a sticky header. 41 | * The view has a sticky header if: 42 | * 1. It is the first element in the recycler view 43 | * 2. It has a valid ID associated to its position 44 | * 45 | * @param itemView given by the RecyclerView 46 | * @param orientation of the Recyclerview 47 | * @param position of the list item in question 48 | * @return True if the view should have a sticky header 49 | */ 50 | public boolean hasStickyHeader(View itemView, int orientation, int position) { 51 | int offset, margin; 52 | mDimensionCalculator.initMargins(mTempRect1, itemView); 53 | if (orientation == LinearLayout.VERTICAL) { 54 | offset = itemView.getTop(); 55 | margin = mTempRect1.top; 56 | } else { 57 | offset = itemView.getLeft(); 58 | margin = mTempRect1.left; 59 | } 60 | 61 | return offset <= margin && mAdapter.getHeaderId(position) >= 0; 62 | } 63 | 64 | /** 65 | * Determines if an item in the list should have a header that is different than the item in the 66 | * list that immediately precedes it. Items with no headers will always return false. 67 | * 68 | * @param position of the list item in questions 69 | * @param isReverseLayout TRUE if layout manager has flag isReverseLayout 70 | * @return true if this item has a different header than the previous item in the list 71 | */ 72 | public boolean hasNewHeader(int position, boolean isReverseLayout) { 73 | if (indexOutOfBounds(position)) { 74 | return false; 75 | } 76 | 77 | long headerId = mAdapter.getHeaderId(position); 78 | 79 | if (headerId < 0) { 80 | return false; 81 | } 82 | 83 | long nextItemHeaderId = -1; 84 | int nextItemPosition = position + (isReverseLayout? 1: -1); 85 | if (!indexOutOfBounds(nextItemPosition)){ 86 | nextItemHeaderId = mAdapter.getHeaderId(nextItemPosition); 87 | } 88 | int firstItemPosition = isReverseLayout? mAdapter.getItemCount()-1 : 0; 89 | 90 | return position == firstItemPosition || headerId != nextItemHeaderId; 91 | } 92 | 93 | private boolean indexOutOfBounds(int position) { 94 | return position < 0 || position >= mAdapter.getItemCount(); 95 | } 96 | 97 | public void initHeaderBounds(Rect bounds, RecyclerView recyclerView, View header, View firstView, boolean firstHeader) { 98 | int orientation = mOrientationProvider.getOrientation(recyclerView); 99 | initDefaultHeaderOffset(bounds, recyclerView, header, firstView, orientation); 100 | 101 | if (firstHeader && isStickyHeaderBeingPushedOffscreen(recyclerView, header)) { 102 | View viewAfterNextHeader = getFirstViewUnobscuredByHeader(recyclerView, header); 103 | int firstViewUnderHeaderPosition = recyclerView.getChildAdapterPosition(viewAfterNextHeader); 104 | View secondHeader = mHeaderProvider.getHeader(recyclerView, firstViewUnderHeaderPosition); 105 | translateHeaderWithNextHeader(recyclerView, mOrientationProvider.getOrientation(recyclerView), bounds, 106 | header, viewAfterNextHeader, secondHeader); 107 | } 108 | } 109 | 110 | private void initDefaultHeaderOffset(Rect headerMargins, RecyclerView recyclerView, View header, View firstView, int orientation) { 111 | int translationX, translationY; 112 | mDimensionCalculator.initMargins(mTempRect1, header); 113 | 114 | ViewGroup.LayoutParams layoutParams = firstView.getLayoutParams(); 115 | int leftMargin = 0; 116 | int topMargin = 0; 117 | if (layoutParams instanceof ViewGroup.MarginLayoutParams) { 118 | ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams; 119 | leftMargin = marginLayoutParams.leftMargin; 120 | topMargin = marginLayoutParams.topMargin; 121 | } 122 | 123 | if (orientation == LinearLayoutManager.VERTICAL) { 124 | translationX = firstView.getLeft() - leftMargin + mTempRect1.left; 125 | translationY = Math.max( 126 | firstView.getTop() - topMargin - header.getHeight() - mTempRect1.bottom, 127 | getListTop(recyclerView) + mTempRect1.top); 128 | } else { 129 | translationY = firstView.getTop() - topMargin + mTempRect1.top; 130 | translationX = Math.max( 131 | firstView.getLeft() - leftMargin - header.getWidth() - mTempRect1.right, 132 | getListLeft(recyclerView) + mTempRect1.left); 133 | } 134 | 135 | headerMargins.set(translationX, translationY, translationX + header.getWidth(), 136 | translationY + header.getHeight()); 137 | } 138 | 139 | private boolean isStickyHeaderBeingPushedOffscreen(RecyclerView recyclerView, View stickyHeader) { 140 | View viewAfterHeader = getFirstViewUnobscuredByHeader(recyclerView, stickyHeader); 141 | int firstViewUnderHeaderPosition = recyclerView.getChildAdapterPosition(viewAfterHeader); 142 | if (firstViewUnderHeaderPosition == RecyclerView.NO_POSITION) { 143 | return false; 144 | } 145 | 146 | boolean isReverseLayout = mOrientationProvider.isReverseLayout(recyclerView); 147 | if (firstViewUnderHeaderPosition > 0 && hasNewHeader(firstViewUnderHeaderPosition, isReverseLayout)) { 148 | View nextHeader = mHeaderProvider.getHeader(recyclerView, firstViewUnderHeaderPosition); 149 | mDimensionCalculator.initMargins(mTempRect1, nextHeader); 150 | mDimensionCalculator.initMargins(mTempRect2, stickyHeader); 151 | 152 | if (mOrientationProvider.getOrientation(recyclerView) == LinearLayoutManager.VERTICAL) { 153 | int topOfNextHeader = viewAfterHeader.getTop() - mTempRect1.bottom - nextHeader.getHeight() - mTempRect1.top; 154 | int bottomOfThisHeader = recyclerView.getPaddingTop() + stickyHeader.getBottom() + mTempRect2.top + mTempRect2.bottom; 155 | if (topOfNextHeader < bottomOfThisHeader) { 156 | return true; 157 | } 158 | } else { 159 | int leftOfNextHeader = viewAfterHeader.getLeft() - mTempRect1.right - nextHeader.getWidth() - mTempRect1.left; 160 | int rightOfThisHeader = recyclerView.getPaddingLeft() + stickyHeader.getRight() + mTempRect2.left + mTempRect2.right; 161 | if (leftOfNextHeader < rightOfThisHeader) { 162 | return true; 163 | } 164 | } 165 | } 166 | 167 | return false; 168 | } 169 | 170 | private void translateHeaderWithNextHeader(RecyclerView recyclerView, int orientation, Rect translation, 171 | View currentHeader, View viewAfterNextHeader, View nextHeader) { 172 | mDimensionCalculator.initMargins(mTempRect1, nextHeader); 173 | mDimensionCalculator.initMargins(mTempRect2, currentHeader); 174 | if (orientation == LinearLayoutManager.VERTICAL) { 175 | int topOfStickyHeader = getListTop(recyclerView) + mTempRect2.top + mTempRect2.bottom; 176 | int shiftFromNextHeader = viewAfterNextHeader.getTop() - nextHeader.getHeight() - mTempRect1.bottom - mTempRect1.top - currentHeader.getHeight() - topOfStickyHeader; 177 | if (shiftFromNextHeader < topOfStickyHeader) { 178 | translation.top += shiftFromNextHeader; 179 | } 180 | } else { 181 | int leftOfStickyHeader = getListLeft(recyclerView) + mTempRect2.left + mTempRect2.right; 182 | int shiftFromNextHeader = viewAfterNextHeader.getLeft() - nextHeader.getWidth() - mTempRect1.right - mTempRect1.left - currentHeader.getWidth() - leftOfStickyHeader; 183 | if (shiftFromNextHeader < leftOfStickyHeader) { 184 | translation.left += shiftFromNextHeader; 185 | } 186 | } 187 | } 188 | 189 | /** 190 | * Returns the first item currently in the RecyclerView that is not obscured by a header. 191 | * 192 | * @param parent Recyclerview containing all the list items 193 | * @return first item that is fully beneath a header 194 | */ 195 | private View getFirstViewUnobscuredByHeader(RecyclerView parent, View firstHeader) { 196 | boolean isReverseLayout = mOrientationProvider.isReverseLayout(parent); 197 | int step = isReverseLayout? -1 : 1; 198 | int from = isReverseLayout? parent.getChildCount()-1 : 0; 199 | for (int i = from; i >= 0 && i <= parent.getChildCount() - 1; i += step) { 200 | View child = parent.getChildAt(i); 201 | if (!itemIsObscuredByHeader(parent, child, firstHeader, mOrientationProvider.getOrientation(parent))) { 202 | return child; 203 | } 204 | } 205 | return null; 206 | } 207 | 208 | /** 209 | * Determines if an item is obscured by a header 210 | * 211 | * 212 | * @param parent 213 | * @param item to determine if obscured by header 214 | * @param header that might be obscuring the item 215 | * @param orientation of the {@link RecyclerView} 216 | * @return true if the item view is obscured by the header view 217 | */ 218 | private boolean itemIsObscuredByHeader(RecyclerView parent, View item, View header, int orientation) { 219 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) item.getLayoutParams(); 220 | mDimensionCalculator.initMargins(mTempRect1, header); 221 | 222 | int adapterPosition = parent.getChildAdapterPosition(item); 223 | if (adapterPosition == RecyclerView.NO_POSITION || mHeaderProvider.getHeader(parent, adapterPosition) != header) { 224 | // Resolves https://github.com/timehop/sticky-headers-recyclerview/issues/36 225 | // Handles an edge case where a trailing header is smaller than the current sticky header. 226 | return false; 227 | } 228 | 229 | if (orientation == LinearLayoutManager.VERTICAL) { 230 | int itemTop = item.getTop() - layoutParams.topMargin; 231 | int headerBottom = getListTop(parent) + header.getBottom() + mTempRect1.bottom + mTempRect1.top; 232 | if (itemTop >= headerBottom) { 233 | return false; 234 | } 235 | } else { 236 | int itemLeft = item.getLeft() - layoutParams.leftMargin; 237 | int headerRight = getListLeft(parent) + header.getRight() + mTempRect1.right + mTempRect1.left; 238 | if (itemLeft >= headerRight) { 239 | return false; 240 | } 241 | } 242 | 243 | return true; 244 | } 245 | 246 | private int getListTop(RecyclerView view) { 247 | if (view.getLayoutManager().getClipToPadding()) { 248 | return view.getPaddingTop(); 249 | } else { 250 | return 0; 251 | } 252 | } 253 | 254 | private int getListLeft(RecyclerView view) { 255 | if (view.getLayoutManager().getClipToPadding()) { 256 | return view.getPaddingLeft(); 257 | } else { 258 | return 0; 259 | } 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/ItemVisibilityAdapter.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview; 2 | 3 | /** 4 | * ItemVisibilityAdapter provides a way for StickyRecyclerHeadersDecoration 5 | * to know if a row is visible or not. This comes into play if the 6 | * recyclerview's layout manager is set up to provide extra layout space (by 7 | * overriding getExtraLayoutSpace). In this case rows that aren't visible (yet) 8 | * will be bound and StickyRecyclerHeadersDecoration will need to know which 9 | * are visible to correctly calculate the row to base the sticky header on 10 | * 11 | * To use it you must pass an instance of a class that implements this 12 | * interface as a second argment StickyRecyclerHeadersDecoration's constructor. 13 | * 14 | */ 15 | public interface ItemVisibilityAdapter { 16 | 17 | /** 18 | * 19 | * Return true the specified adapter position is visible, false otherwise 20 | * 21 | * The implementation of this method will typically return true if 22 | * the position is between the layout manager's findFirstVisibleItemPosition 23 | * and findLastVisibleItemPosition (inclusive). 24 | * 25 | * @param position the adapter position 26 | */ 27 | boolean isPositionVisible(final int position); 28 | } 29 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/StickyRecyclerHeadersAdapter.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.ViewGroup; 5 | 6 | public interface StickyRecyclerHeadersAdapter { 7 | /** 8 | * Get the ID of the header associated with this item. For example, if your headers group 9 | * items by their first letter, you could return the character representation of the first letter. 10 | * Return a value < 0 if the view should not have a header (like, a header view or footer view) 11 | * 12 | * @param position the position of the view to get the header ID of 13 | * @return the header ID 14 | */ 15 | long getHeaderId(int position); 16 | 17 | /** 18 | * Creates a new ViewHolder for a header. This works the same way onCreateViewHolder in 19 | * Recycler.Adapter, ViewHolders can be reused for different views. This is usually a good place 20 | * to inflate the layout for the header. 21 | * 22 | * @param parent the view to create a header view holder for 23 | * @return the view holder 24 | */ 25 | VH onCreateHeaderViewHolder(ViewGroup parent); 26 | 27 | /** 28 | * Binds an existing ViewHolder to the specified adapter position. 29 | * 30 | * @param holder the view holder 31 | * @param position the adapter position 32 | */ 33 | void onBindHeaderViewHolder(VH holder, int position); 34 | 35 | /** 36 | * @return the number of views in the adapter 37 | */ 38 | int getItemCount(); 39 | } 40 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/StickyRecyclerHeadersDecoration.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Rect; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.util.SparseArray; 8 | import android.view.View; 9 | 10 | import com.timehop.stickyheadersrecyclerview.caching.HeaderProvider; 11 | import com.timehop.stickyheadersrecyclerview.caching.HeaderViewCache; 12 | import com.timehop.stickyheadersrecyclerview.calculation.DimensionCalculator; 13 | import com.timehop.stickyheadersrecyclerview.rendering.HeaderRenderer; 14 | import com.timehop.stickyheadersrecyclerview.util.LinearLayoutOrientationProvider; 15 | import com.timehop.stickyheadersrecyclerview.util.OrientationProvider; 16 | 17 | public class StickyRecyclerHeadersDecoration extends RecyclerView.ItemDecoration { 18 | 19 | private final StickyRecyclerHeadersAdapter mAdapter; 20 | private final ItemVisibilityAdapter mVisibilityAdapter; 21 | private final SparseArray mHeaderRects = new SparseArray<>(); 22 | private final HeaderProvider mHeaderProvider; 23 | private final OrientationProvider mOrientationProvider; 24 | private final HeaderPositionCalculator mHeaderPositionCalculator; 25 | private final HeaderRenderer mRenderer; 26 | private final DimensionCalculator mDimensionCalculator; 27 | 28 | /** 29 | * The following field is used as a buffer for internal calculations. Its sole purpose is to avoid 30 | * allocating new Rect every time we need one. 31 | */ 32 | private final Rect mTempRect = new Rect(); 33 | 34 | // TODO: Consider passing in orientation to simplify orientation accounting within calculation 35 | public StickyRecyclerHeadersDecoration(StickyRecyclerHeadersAdapter adapter) { 36 | this(adapter, new LinearLayoutOrientationProvider(), new DimensionCalculator(), null); 37 | } 38 | 39 | public StickyRecyclerHeadersDecoration(StickyRecyclerHeadersAdapter adapter, ItemVisibilityAdapter visibilityAdapter) { 40 | this(adapter, new LinearLayoutOrientationProvider(), new DimensionCalculator(), visibilityAdapter); 41 | } 42 | 43 | private StickyRecyclerHeadersDecoration(StickyRecyclerHeadersAdapter adapter, OrientationProvider orientationProvider, 44 | DimensionCalculator dimensionCalculator, ItemVisibilityAdapter visibilityAdapter) { 45 | this(adapter, orientationProvider, dimensionCalculator, new HeaderRenderer(orientationProvider), 46 | new HeaderViewCache(adapter, orientationProvider), visibilityAdapter); 47 | } 48 | 49 | private StickyRecyclerHeadersDecoration(StickyRecyclerHeadersAdapter adapter, OrientationProvider orientationProvider, 50 | DimensionCalculator dimensionCalculator, HeaderRenderer headerRenderer, HeaderProvider headerProvider, ItemVisibilityAdapter visibilityAdapter) { 51 | this(adapter, headerRenderer, orientationProvider, dimensionCalculator, headerProvider, 52 | new HeaderPositionCalculator(adapter, headerProvider, orientationProvider, 53 | dimensionCalculator), visibilityAdapter); 54 | } 55 | 56 | private StickyRecyclerHeadersDecoration(StickyRecyclerHeadersAdapter adapter, HeaderRenderer headerRenderer, 57 | OrientationProvider orientationProvider, DimensionCalculator dimensionCalculator, HeaderProvider headerProvider, 58 | HeaderPositionCalculator headerPositionCalculator, ItemVisibilityAdapter visibilityAdapter) { 59 | mAdapter = adapter; 60 | mHeaderProvider = headerProvider; 61 | mOrientationProvider = orientationProvider; 62 | mRenderer = headerRenderer; 63 | mDimensionCalculator = dimensionCalculator; 64 | mHeaderPositionCalculator = headerPositionCalculator; 65 | mVisibilityAdapter = visibilityAdapter; 66 | } 67 | 68 | @Override 69 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 70 | super.getItemOffsets(outRect, view, parent, state); 71 | int itemPosition = parent.getChildAdapterPosition(view); 72 | if (itemPosition == RecyclerView.NO_POSITION) { 73 | return; 74 | } 75 | if (mHeaderPositionCalculator.hasNewHeader(itemPosition, mOrientationProvider.isReverseLayout(parent))) { 76 | View header = getHeaderView(parent, itemPosition); 77 | setItemOffsetsForHeader(outRect, header, mOrientationProvider.getOrientation(parent)); 78 | } 79 | } 80 | 81 | /** 82 | * Sets the offsets for the first item in a section to make room for the header view 83 | * 84 | * @param itemOffsets rectangle to define offsets for the item 85 | * @param header view used to calculate offset for the item 86 | * @param orientation used to calculate offset for the item 87 | */ 88 | private void setItemOffsetsForHeader(Rect itemOffsets, View header, int orientation) { 89 | mDimensionCalculator.initMargins(mTempRect, header); 90 | if (orientation == LinearLayoutManager.VERTICAL) { 91 | itemOffsets.top = header.getHeight() + mTempRect.top + mTempRect.bottom; 92 | } else { 93 | itemOffsets.left = header.getWidth() + mTempRect.left + mTempRect.right; 94 | } 95 | } 96 | 97 | @Override 98 | public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) { 99 | super.onDrawOver(canvas, parent, state); 100 | 101 | final int childCount = parent.getChildCount(); 102 | if (childCount <= 0 || mAdapter.getItemCount() <= 0) { 103 | return; 104 | } 105 | 106 | for (int i = 0; i < childCount; i++) { 107 | View itemView = parent.getChildAt(i); 108 | int position = parent.getChildAdapterPosition(itemView); 109 | if (position == RecyclerView.NO_POSITION) { 110 | continue; 111 | } 112 | 113 | boolean hasStickyHeader = mHeaderPositionCalculator.hasStickyHeader(itemView, mOrientationProvider.getOrientation(parent), position); 114 | if (hasStickyHeader || mHeaderPositionCalculator.hasNewHeader(position, mOrientationProvider.isReverseLayout(parent))) { 115 | View header = mHeaderProvider.getHeader(parent, position); 116 | //re-use existing Rect, if any. 117 | Rect headerOffset = mHeaderRects.get(position); 118 | if (headerOffset == null) { 119 | headerOffset = new Rect(); 120 | mHeaderRects.put(position, headerOffset); 121 | } 122 | mHeaderPositionCalculator.initHeaderBounds(headerOffset, parent, header, itemView, hasStickyHeader); 123 | mRenderer.drawHeader(parent, canvas, header, headerOffset); 124 | } 125 | } 126 | } 127 | 128 | /** 129 | * Gets the position of the header under the specified (x, y) coordinates. 130 | * 131 | * @param x x-coordinate 132 | * @param y y-coordinate 133 | * @return position of header, or -1 if not found 134 | */ 135 | public int findHeaderPositionUnder(int x, int y) { 136 | for (int i = 0; i < mHeaderRects.size(); i++) { 137 | Rect rect = mHeaderRects.get(mHeaderRects.keyAt(i)); 138 | if (rect.contains(x, y)) { 139 | int position = mHeaderRects.keyAt(i); 140 | if (mVisibilityAdapter == null || mVisibilityAdapter.isPositionVisible(position)) { 141 | return position; 142 | } 143 | } 144 | } 145 | return -1; 146 | } 147 | 148 | /** 149 | * Gets the header view for the associated position. If it doesn't exist yet, it will be 150 | * created, measured, and laid out. 151 | * 152 | * @param parent the recyclerview 153 | * @param position the position to get the header view for 154 | * @return Header view 155 | */ 156 | public View getHeaderView(RecyclerView parent, int position) { 157 | return mHeaderProvider.getHeader(parent, position); 158 | } 159 | 160 | /** 161 | * Invalidates cached headers. This does not invalidate the recyclerview, you should do that manually after 162 | * calling this method. 163 | */ 164 | public void invalidateHeaders() { 165 | mHeaderProvider.invalidate(); 166 | mHeaderRects.clear(); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/StickyRecyclerHeadersTouchListener.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.GestureDetector; 5 | import android.view.MotionEvent; 6 | import android.view.SoundEffectConstants; 7 | import android.view.View; 8 | 9 | public class StickyRecyclerHeadersTouchListener implements RecyclerView.OnItemTouchListener { 10 | private final GestureDetector mTapDetector; 11 | private final RecyclerView mRecyclerView; 12 | private final StickyRecyclerHeadersDecoration mDecor; 13 | private OnHeaderClickListener mOnHeaderClickListener; 14 | 15 | public interface OnHeaderClickListener { 16 | void onHeaderClick(View header, int position, long headerId); 17 | } 18 | 19 | public StickyRecyclerHeadersTouchListener(final RecyclerView recyclerView, 20 | final StickyRecyclerHeadersDecoration decor) { 21 | mTapDetector = new GestureDetector(recyclerView.getContext(), new SingleTapDetector()); 22 | mRecyclerView = recyclerView; 23 | mDecor = decor; 24 | } 25 | 26 | public StickyRecyclerHeadersAdapter getAdapter() { 27 | if (mRecyclerView.getAdapter() instanceof StickyRecyclerHeadersAdapter) { 28 | return (StickyRecyclerHeadersAdapter) mRecyclerView.getAdapter(); 29 | } else { 30 | throw new IllegalStateException("A RecyclerView with " + 31 | StickyRecyclerHeadersTouchListener.class.getSimpleName() + 32 | " requires a " + StickyRecyclerHeadersAdapter.class.getSimpleName()); 33 | } 34 | } 35 | 36 | 37 | public void setOnHeaderClickListener(OnHeaderClickListener listener) { 38 | mOnHeaderClickListener = listener; 39 | } 40 | 41 | @Override 42 | public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) { 43 | if (this.mOnHeaderClickListener != null) { 44 | boolean tapDetectorResponse = this.mTapDetector.onTouchEvent(e); 45 | if (tapDetectorResponse) { 46 | // Don't return false if a single tap is detected 47 | return true; 48 | } 49 | if (e.getAction() == MotionEvent.ACTION_DOWN) { 50 | int position = mDecor.findHeaderPositionUnder((int)e.getX(), (int)e.getY()); 51 | return position != -1; 52 | } 53 | } 54 | return false; 55 | } 56 | 57 | @Override 58 | public void onTouchEvent(RecyclerView view, MotionEvent e) { /* do nothing? */ } 59 | 60 | @Override public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 61 | // do nothing 62 | } 63 | 64 | private class SingleTapDetector extends GestureDetector.SimpleOnGestureListener { 65 | @Override 66 | public boolean onSingleTapUp(MotionEvent e) { 67 | int position = mDecor.findHeaderPositionUnder((int) e.getX(), (int) e.getY()); 68 | if (position != -1) { 69 | View headerView = mDecor.getHeaderView(mRecyclerView, position); 70 | long headerId = getAdapter().getHeaderId(position); 71 | mOnHeaderClickListener.onHeaderClick(headerView, position, headerId); 72 | mRecyclerView.playSoundEffect(SoundEffectConstants.CLICK); 73 | headerView.onTouchEvent(e); 74 | return true; 75 | } 76 | return false; 77 | } 78 | 79 | @Override 80 | public boolean onDoubleTap(MotionEvent e) { 81 | return true; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/caching/HeaderProvider.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview.caching; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.View; 5 | 6 | /** 7 | * Implemented by objects that provide header views for decoration 8 | */ 9 | public interface HeaderProvider { 10 | 11 | /** 12 | * Will provide a header view for a given position in the RecyclerView 13 | * 14 | * @param recyclerView that will display the header 15 | * @param position that will be headed by the header 16 | * @return a header view for the given position and list 17 | */ 18 | public View getHeader(RecyclerView recyclerView, int position); 19 | 20 | /** 21 | * TODO: describe this functionality and its necessity 22 | */ 23 | void invalidate(); 24 | } 25 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/caching/HeaderViewCache.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview.caching; 2 | 3 | import android.support.v4.util.LongSparseArray; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter; 10 | import com.timehop.stickyheadersrecyclerview.util.OrientationProvider; 11 | 12 | /** 13 | * An implementation of {@link HeaderProvider} that creates and caches header views 14 | */ 15 | public class HeaderViewCache implements HeaderProvider { 16 | 17 | private final StickyRecyclerHeadersAdapter mAdapter; 18 | private final LongSparseArray mHeaderViews = new LongSparseArray<>(); 19 | private final OrientationProvider mOrientationProvider; 20 | 21 | public HeaderViewCache(StickyRecyclerHeadersAdapter adapter, 22 | OrientationProvider orientationProvider) { 23 | mAdapter = adapter; 24 | mOrientationProvider = orientationProvider; 25 | } 26 | 27 | @Override 28 | public View getHeader(RecyclerView parent, int position) { 29 | long headerId = mAdapter.getHeaderId(position); 30 | 31 | View header = mHeaderViews.get(headerId); 32 | if (header == null) { 33 | //TODO - recycle views 34 | RecyclerView.ViewHolder viewHolder = mAdapter.onCreateHeaderViewHolder(parent); 35 | mAdapter.onBindHeaderViewHolder(viewHolder, position); 36 | header = viewHolder.itemView; 37 | if (header.getLayoutParams() == null) { 38 | header.setLayoutParams(new ViewGroup.LayoutParams( 39 | ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 40 | } 41 | 42 | int widthSpec; 43 | int heightSpec; 44 | 45 | if (mOrientationProvider.getOrientation(parent) == LinearLayoutManager.VERTICAL) { 46 | widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); 47 | heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED); 48 | } else { 49 | widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.UNSPECIFIED); 50 | heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.EXACTLY); 51 | } 52 | 53 | int childWidth = ViewGroup.getChildMeasureSpec(widthSpec, 54 | parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width); 55 | int childHeight = ViewGroup.getChildMeasureSpec(heightSpec, 56 | parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height); 57 | header.measure(childWidth, childHeight); 58 | header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); 59 | mHeaderViews.put(headerId, header); 60 | } 61 | return header; 62 | } 63 | 64 | @Override 65 | public void invalidate() { 66 | mHeaderViews.clear(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/calculation/DimensionCalculator.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview.calculation; 2 | 3 | import android.graphics.Rect; 4 | import android.view.View; 5 | 6 | import static android.view.ViewGroup.LayoutParams; 7 | import static android.view.ViewGroup.MarginLayoutParams; 8 | 9 | /** 10 | * Helper to calculate various view dimensions 11 | */ 12 | public class DimensionCalculator { 13 | 14 | /** 15 | * Populates {@link Rect} with margins for any view. 16 | * 17 | * 18 | * @param margins rect to populate 19 | * @param view for which to get margins 20 | */ 21 | public void initMargins(Rect margins, View view) { 22 | LayoutParams layoutParams = view.getLayoutParams(); 23 | 24 | if (layoutParams instanceof MarginLayoutParams) { 25 | MarginLayoutParams marginLayoutParams = (MarginLayoutParams) layoutParams; 26 | initMarginRect(margins, marginLayoutParams); 27 | } else { 28 | margins.set(0, 0, 0, 0); 29 | } 30 | } 31 | 32 | /** 33 | * Converts {@link MarginLayoutParams} into a representative {@link Rect}. 34 | * 35 | * @param marginRect Rect to be initialized with margins coordinates, where 36 | * {@link MarginLayoutParams#leftMargin} is equivalent to {@link Rect#left}, etc. 37 | * @param marginLayoutParams margins to populate the Rect with 38 | */ 39 | private void initMarginRect(Rect marginRect, MarginLayoutParams marginLayoutParams) { 40 | marginRect.set( 41 | marginLayoutParams.leftMargin, 42 | marginLayoutParams.topMargin, 43 | marginLayoutParams.rightMargin, 44 | marginLayoutParams.bottomMargin 45 | ); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/rendering/HeaderRenderer.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview.rendering; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Rect; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | import android.widget.LinearLayout; 8 | 9 | import com.timehop.stickyheadersrecyclerview.calculation.DimensionCalculator; 10 | import com.timehop.stickyheadersrecyclerview.util.OrientationProvider; 11 | 12 | /** 13 | * Responsible for drawing headers to the canvas provided by the item decoration 14 | */ 15 | public class HeaderRenderer { 16 | 17 | private final DimensionCalculator mDimensionCalculator; 18 | private final OrientationProvider mOrientationProvider; 19 | 20 | /** 21 | * The following field is used as a buffer for internal calculations. Its sole purpose is to avoid 22 | * allocating new Rect every time we need one. 23 | */ 24 | private final Rect mTempRect = new Rect(); 25 | 26 | public HeaderRenderer(OrientationProvider orientationProvider) { 27 | this(orientationProvider, new DimensionCalculator()); 28 | } 29 | 30 | private HeaderRenderer(OrientationProvider orientationProvider, 31 | DimensionCalculator dimensionCalculator) { 32 | mOrientationProvider = orientationProvider; 33 | mDimensionCalculator = dimensionCalculator; 34 | } 35 | 36 | /** 37 | * Draws a header to a canvas, offsetting by some x and y amount 38 | * 39 | * @param recyclerView the parent recycler view for drawing the header into 40 | * @param canvas the canvas on which to draw the header 41 | * @param header the view to draw as the header 42 | * @param offset a Rect used to define the x/y offset of the header. Specify x/y offset by setting 43 | * the {@link Rect#left} and {@link Rect#top} properties, respectively. 44 | */ 45 | public void drawHeader(RecyclerView recyclerView, Canvas canvas, View header, Rect offset) { 46 | canvas.save(); 47 | 48 | if (recyclerView.getLayoutManager().getClipToPadding()) { 49 | // Clip drawing of headers to the padding of the RecyclerView. Avoids drawing in the padding 50 | initClipRectForHeader(mTempRect, recyclerView, header); 51 | canvas.clipRect(mTempRect); 52 | } 53 | 54 | canvas.translate(offset.left, offset.top); 55 | 56 | header.draw(canvas); 57 | canvas.restore(); 58 | } 59 | 60 | /** 61 | * Initializes a clipping rect for the header based on the margins of the header and the padding of the 62 | * recycler. 63 | * FIXME: Currently right margin in VERTICAL orientation and bottom margin in HORIZONTAL 64 | * orientation are clipped so they look accurate, but the headers are not being drawn at the 65 | * correctly smaller width and height respectively. 66 | * 67 | * @param clipRect {@link Rect} for clipping a provided header to the padding of a recycler view 68 | * @param recyclerView for which to provide a header 69 | * @param header for clipping 70 | */ 71 | private void initClipRectForHeader(Rect clipRect, RecyclerView recyclerView, View header) { 72 | mDimensionCalculator.initMargins(clipRect, header); 73 | if (mOrientationProvider.getOrientation(recyclerView) == LinearLayout.VERTICAL) { 74 | clipRect.set( 75 | recyclerView.getPaddingLeft(), 76 | recyclerView.getPaddingTop(), 77 | recyclerView.getWidth() - recyclerView.getPaddingRight() - clipRect.right, 78 | recyclerView.getHeight() - recyclerView.getPaddingBottom()); 79 | } else { 80 | clipRect.set( 81 | recyclerView.getPaddingLeft(), 82 | recyclerView.getPaddingTop(), 83 | recyclerView.getWidth() - recyclerView.getPaddingRight(), 84 | recyclerView.getHeight() - recyclerView.getPaddingBottom() - clipRect.bottom); 85 | } 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/util/LinearLayoutOrientationProvider.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview.util; 2 | 3 | import android.support.v7.widget.LinearLayoutManager; 4 | import android.support.v7.widget.RecyclerView; 5 | 6 | /** 7 | * OrientationProvider for ReyclerViews who use a LinearLayoutManager 8 | */ 9 | public class LinearLayoutOrientationProvider implements OrientationProvider { 10 | 11 | @Override 12 | public int getOrientation(RecyclerView recyclerView) { 13 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); 14 | throwIfNotLinearLayoutManager(layoutManager); 15 | return ((LinearLayoutManager) layoutManager).getOrientation(); 16 | } 17 | 18 | @Override 19 | public boolean isReverseLayout(RecyclerView recyclerView) { 20 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); 21 | throwIfNotLinearLayoutManager(layoutManager); 22 | return ((LinearLayoutManager) layoutManager).getReverseLayout(); 23 | } 24 | 25 | private void throwIfNotLinearLayoutManager(RecyclerView.LayoutManager layoutManager){ 26 | if (!(layoutManager instanceof LinearLayoutManager)) { 27 | throw new IllegalStateException("StickyListHeadersDecoration can only be used with a " + 28 | "LinearLayoutManager."); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /library/src/main/java/com/timehop/stickyheadersrecyclerview/util/OrientationProvider.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview.util; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | 5 | /** 6 | * Interface for getting the orientation of a RecyclerView from its LayoutManager 7 | */ 8 | public interface OrientationProvider { 9 | 10 | public int getOrientation(RecyclerView recyclerView); 11 | 12 | public boolean isReverseLayout(RecyclerView recyclerView); 13 | } 14 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | 4 | android { 5 | compileSdkVersion rootProject.ext.compileSdkVersion as Integer 6 | buildToolsVersion rootProject.ext.buildToolsVersion as String 7 | 8 | 9 | defaultConfig { 10 | applicationId "com.timehop.stickyheadersrecyclerview.sample" 11 | minSdkVersion rootProject.ext.minSdkVersion as Integer 12 | targetSdkVersion rootProject.ext.targetSdkVersion as Integer 13 | versionCode rootProject.ext.versionCode as Integer 14 | versionName rootProject.ext.versionName as String 15 | } 16 | compileOptions { 17 | sourceCompatibility JavaVersion.VERSION_1_7 18 | targetCompatibility JavaVersion.VERSION_1_7 19 | } 20 | } 21 | 22 | dependencies { 23 | compile project(':library') 24 | compile "com.android.support:appcompat-v7:${rootProject.supportLibsVersion}" 25 | } 26 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sample/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timehop/sticky-headers-recyclerview/f5a9e9b8f5d96734e20439b0a41381865fa52fb7/sample/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /sample/src/main/java/com/timehop/stickyheadersrecyclerview/sample/AnimalsAdapter.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview.sample; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.Collection; 8 | 9 | 10 | /** 11 | * Adapter holding a list of animal names of type String. Note that each item must be unique. 12 | */ 13 | public abstract class AnimalsAdapter 14 | extends RecyclerView.Adapter { 15 | private ArrayList items = new ArrayList(); 16 | 17 | public AnimalsAdapter() { 18 | setHasStableIds(true); 19 | } 20 | 21 | public void add(String object) { 22 | items.add(object); 23 | notifyDataSetChanged(); 24 | } 25 | 26 | public void add(int index, String object) { 27 | items.add(index, object); 28 | notifyDataSetChanged(); 29 | } 30 | 31 | public void addAll(Collection collection) { 32 | if (collection != null) { 33 | items.addAll(collection); 34 | notifyDataSetChanged(); 35 | } 36 | } 37 | 38 | public void addAll(String... items) { 39 | addAll(Arrays.asList(items)); 40 | } 41 | 42 | public void clear() { 43 | items.clear(); 44 | notifyDataSetChanged(); 45 | } 46 | 47 | public void remove(String object) { 48 | items.remove(object); 49 | notifyDataSetChanged(); 50 | } 51 | 52 | public String getItem(int position) { 53 | return items.get(position); 54 | } 55 | 56 | @Override 57 | public long getItemId(int position) { 58 | return getItem(position).hashCode(); 59 | } 60 | 61 | @Override 62 | public int getItemCount() { 63 | return items.size(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /sample/src/main/java/com/timehop/stickyheadersrecyclerview/sample/DividerDecoration.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview.sample; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Rect; 7 | import android.graphics.drawable.Drawable; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.View; 11 | 12 | 13 | public class DividerDecoration extends RecyclerView.ItemDecoration { 14 | 15 | private static final int[] ATTRS = new int[]{ 16 | android.R.attr.listDivider 17 | }; 18 | 19 | public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL; 20 | 21 | public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL; 22 | 23 | private Drawable mDivider; 24 | 25 | public DividerDecoration(Context context) { 26 | final TypedArray a = context.obtainStyledAttributes(ATTRS); 27 | mDivider = a.getDrawable(0); 28 | a.recycle(); 29 | } 30 | 31 | private int getOrientation(RecyclerView parent) { 32 | LinearLayoutManager layoutManager; 33 | try { 34 | layoutManager = (LinearLayoutManager) parent.getLayoutManager(); 35 | } catch (ClassCastException e) { 36 | throw new IllegalStateException("DividerDecoration can only be used with a " + 37 | "LinearLayoutManager.", e); 38 | } 39 | return layoutManager.getOrientation(); 40 | } 41 | 42 | @Override 43 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 44 | super.onDraw(c, parent, state); 45 | 46 | if (getOrientation(parent) == VERTICAL_LIST) { 47 | drawVertical(c, parent); 48 | } else { 49 | drawHorizontal(c, parent); 50 | } 51 | } 52 | 53 | public void drawVertical(Canvas c, RecyclerView parent) { 54 | final int left = parent.getPaddingLeft(); 55 | final int right = parent.getWidth() - parent.getPaddingRight(); 56 | final int recyclerViewTop = parent.getPaddingTop(); 57 | final int recyclerViewBottom = parent.getHeight() - parent.getPaddingBottom(); 58 | final int childCount = parent.getChildCount(); 59 | for (int i = 0; i < childCount; i++) { 60 | final View child = parent.getChildAt(i); 61 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 62 | .getLayoutParams(); 63 | final int top = Math.max(recyclerViewTop, child.getBottom() + params.bottomMargin); 64 | final int bottom = Math.min(recyclerViewBottom, top + mDivider.getIntrinsicHeight()); 65 | mDivider.setBounds(left, top, right, bottom); 66 | mDivider.draw(c); 67 | } 68 | } 69 | 70 | public void drawHorizontal(Canvas c, RecyclerView parent) { 71 | final int top = parent.getPaddingTop(); 72 | final int bottom = parent.getHeight() - parent.getPaddingBottom(); 73 | final int recyclerViewLeft = parent.getPaddingLeft(); 74 | final int recyclerViewRight = parent.getWidth() - parent.getPaddingRight(); 75 | final int childCount = parent.getChildCount(); 76 | for (int i = 0; i < childCount; i++) { 77 | final View child = parent.getChildAt(i); 78 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 79 | .getLayoutParams(); 80 | final int left = Math.max(recyclerViewLeft, child.getRight() + params.rightMargin); 81 | final int right = Math.min(recyclerViewRight, left + mDivider.getIntrinsicHeight()); 82 | mDivider.setBounds(left, top, right, bottom); 83 | mDivider.draw(c); 84 | } 85 | } 86 | 87 | @Override 88 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 89 | super.getItemOffsets(outRect, view, parent, state); 90 | if (getOrientation(parent) == VERTICAL_LIST) { 91 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); 92 | } else { 93 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/timehop/stickyheadersrecyclerview/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview.sample; 2 | 3 | import android.content.pm.ActivityInfo; 4 | import android.graphics.Color; 5 | import android.os.Bundle; 6 | import android.os.Handler; 7 | import android.os.Looper; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.Button; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | import android.widget.ToggleButton; 18 | 19 | import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter; 20 | import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration; 21 | import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersTouchListener; 22 | 23 | import java.security.SecureRandom; 24 | 25 | public class MainActivity extends AppCompatActivity { 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_main); 31 | 32 | final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview); 33 | Button button = (Button) findViewById(R.id.button_update); 34 | final ToggleButton isReverseButton = (ToggleButton) findViewById(R.id.button_is_reverse); 35 | 36 | // Set adapter populated with example dummy data 37 | final AnimalsHeadersAdapter adapter = new AnimalsHeadersAdapter(); 38 | adapter.add("Animals below!"); 39 | adapter.addAll(getDummyDataSet()); 40 | recyclerView.setAdapter(adapter); 41 | 42 | // Set button to update all views one after another (Test for the "Dance") 43 | button.setOnClickListener(new View.OnClickListener() { 44 | @Override 45 | public void onClick(View v) { 46 | Handler handler = new Handler(Looper.getMainLooper()); 47 | for (int i = 0; i < adapter.getItemCount(); i++) { 48 | final int index = i; 49 | handler.postDelayed(new Runnable() { 50 | @Override 51 | public void run() { 52 | adapter.notifyItemChanged(index); 53 | } 54 | }, 50); 55 | } 56 | } 57 | }); 58 | 59 | // Set layout manager 60 | int orientation = getLayoutManagerOrientation(getResources().getConfiguration().orientation); 61 | final LinearLayoutManager layoutManager = new LinearLayoutManager(this, orientation, isReverseButton.isChecked()); 62 | recyclerView.setLayoutManager(layoutManager); 63 | 64 | // Add the sticky headers decoration 65 | final StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(adapter); 66 | recyclerView.addItemDecoration(headersDecor); 67 | 68 | // Add decoration for dividers between list items 69 | recyclerView.addItemDecoration(new DividerDecoration(this)); 70 | 71 | // Add touch listeners 72 | StickyRecyclerHeadersTouchListener touchListener = 73 | new StickyRecyclerHeadersTouchListener(recyclerView, headersDecor); 74 | touchListener.setOnHeaderClickListener( 75 | new StickyRecyclerHeadersTouchListener.OnHeaderClickListener() { 76 | @Override 77 | public void onHeaderClick(View header, int position, long headerId) { 78 | Toast.makeText(MainActivity.this, "Header position: " + position + ", id: " + headerId, 79 | Toast.LENGTH_SHORT).show(); 80 | } 81 | }); 82 | recyclerView.addOnItemTouchListener(touchListener); 83 | recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() { 84 | @Override 85 | public void onItemClick(View view, int position) { 86 | adapter.remove(adapter.getItem(position)); 87 | } 88 | })); 89 | adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { 90 | @Override 91 | public void onChanged() { 92 | headersDecor.invalidateHeaders(); 93 | } 94 | }); 95 | 96 | isReverseButton.setOnClickListener(new View.OnClickListener() { 97 | @Override 98 | public void onClick(View v) { 99 | boolean isChecked = isReverseButton.isChecked(); 100 | isReverseButton.setChecked(isChecked); 101 | layoutManager.setReverseLayout(isChecked); 102 | adapter.notifyDataSetChanged(); 103 | } 104 | }); 105 | } 106 | 107 | private String[] getDummyDataSet() { 108 | return getResources().getStringArray(R.array.animals); 109 | } 110 | 111 | private int getLayoutManagerOrientation(int activityOrientation) { 112 | if (activityOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { 113 | return LinearLayoutManager.VERTICAL; 114 | } else { 115 | return LinearLayoutManager.HORIZONTAL; 116 | } 117 | } 118 | 119 | private class AnimalsHeadersAdapter extends AnimalsAdapter 120 | implements StickyRecyclerHeadersAdapter { 121 | @Override 122 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 123 | View view = LayoutInflater.from(parent.getContext()) 124 | .inflate(R.layout.view_item, parent, false); 125 | return new RecyclerView.ViewHolder(view) { 126 | }; 127 | } 128 | 129 | @Override 130 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 131 | TextView textView = (TextView) holder.itemView; 132 | textView.setText(getItem(position)); 133 | } 134 | 135 | @Override 136 | public long getHeaderId(int position) { 137 | if (position == 0) { 138 | return -1; 139 | } else { 140 | return getItem(position).charAt(0); 141 | } 142 | } 143 | 144 | @Override 145 | public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) { 146 | View view = LayoutInflater.from(parent.getContext()) 147 | .inflate(R.layout.view_header, parent, false); 148 | return new RecyclerView.ViewHolder(view) { 149 | }; 150 | } 151 | 152 | @Override 153 | public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) { 154 | TextView textView = (TextView) holder.itemView; 155 | textView.setText(String.valueOf(getItem(position).charAt(0))); 156 | holder.itemView.setBackgroundColor(getRandomColor()); 157 | } 158 | 159 | private int getRandomColor() { 160 | SecureRandom rgen = new SecureRandom(); 161 | return Color.HSVToColor(150, new float[]{ 162 | rgen.nextInt(359), 1, 1 163 | }); 164 | } 165 | 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /sample/src/main/java/com/timehop/stickyheadersrecyclerview/sample/RecyclerItemClickListener.java: -------------------------------------------------------------------------------- 1 | package com.timehop.stickyheadersrecyclerview.sample; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.GestureDetector; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | 9 | public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener { 10 | private OnItemClickListener mListener; 11 | 12 | public interface OnItemClickListener { 13 | void onItemClick(View view, int position); 14 | } 15 | 16 | GestureDetector mGestureDetector; 17 | 18 | public RecyclerItemClickListener(Context context, OnItemClickListener listener) { 19 | mListener = listener; 20 | mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { 21 | @Override public boolean onSingleTapUp(MotionEvent e) { 22 | return true; 23 | } 24 | }); 25 | } 26 | 27 | @Override public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) { 28 | View childView = view.findChildViewUnder(e.getX(), e.getY()); 29 | if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) { 30 | mListener.onItemClick(childView, view.getChildAdapterPosition(childView)); 31 | } 32 | return false; 33 | } 34 | 35 | @Override public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { } 36 | 37 | @Override public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 38 | // do nothing 39 | } 40 | } -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timehop/sticky-headers-recyclerview/f5a9e9b8f5d96734e20439b0a41381865fa52fb7/sample/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timehop/sticky-headers-recyclerview/f5a9e9b8f5d96734e20439b0a41381865fa52fb7/sample/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timehop/sticky-headers-recyclerview/f5a9e9b8f5d96734e20439b0a41381865fa52fb7/sample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timehop/sticky-headers-recyclerview/f5a9e9b8f5d96734e20439b0a41381865fa52fb7/sample/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable/white_touch.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /sample/src/main/res/layout-land/view_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/src/main/res/layout-land/view_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 14 | 15 |