├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── android-artifacts.gradle ├── bintray-publish.gradle ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── yqritc │ └── recyclerviewflexibledivider │ ├── FlexibleDividerDecoration.java │ ├── HorizontalDividerItemDecoration.java │ └── VerticalDividerItemDecoration.java ├── sample ├── build.gradle ├── sample1.gif ├── sample2.gif └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── yqritc │ │ └── recyclerviewflexibledivider │ │ └── sample │ │ ├── ComplexActivity.java │ │ ├── ComplexAdapter.java │ │ ├── DrawableActivity.java │ │ ├── PaintActivity.java │ │ ├── SimpleActivity.java │ │ ├── SimpleAdapter.java │ │ └── SimpleGridActivity.java │ └── res │ ├── drawable-hdpi │ ├── ic_launcher.png │ └── sample.9.png │ ├── drawable-mdpi │ ├── ic_launcher.png │ └── sample.9.png │ ├── drawable-xhdpi │ ├── ic_launcher.png │ └── sample.9.png │ ├── drawable-xxhdpi │ ├── ic_launcher.png │ └── sample.9.png │ ├── layout │ ├── activity_sample.xml │ └── layout_sample_item.xml │ ├── menu │ └── menu_sample.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Thumbs.db 3 | 4 | # gradle files 5 | .gradle 6 | 7 | # Intellij project files 8 | .idea 9 | *.iml 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | obj/ 15 | apk/ 16 | target/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ -------------------------------------------------------------------------------- /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 {yyyy} {name of copyright owner} 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 | # RecyclerView-FlexibleDivider 2 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-RecyclerView--FlexibleDivider-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1418) 3 | [![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) 4 | [![Download](https://api.bintray.com/packages/yqritc/maven/recyclerview-flexibledivider/images/download.svg)](https://bintray.com/yqritc/maven/recyclerview-flexibledivider/_latestVersion) 5 | 6 | Android library providing simple way to control divider items of RecyclerView 7 | 8 | ![Simple Divider](/sample/sample1.gif) ![Complex Divider](/sample/sample2.gif) 9 | 10 | # Release Note 11 | 12 | [Release Note] (https://github.com/yqritc/RecyclerView-FlexibleDivider/releases) 13 | 14 | # Gradle 15 | ```groovy 16 | repositories { 17 | jcenter() 18 | } 19 | 20 | dependencies { 21 | compile 'com.yqritc:recyclerview-flexibledivider:1.4.0' 22 | } 23 | ``` 24 | 25 | # Usage 26 | 27 | The following is the simplest usage. 28 | Drawing a divider drawable retrieved from android.R.attr.listDivider between each cell. 29 | ```java 30 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview); 31 | recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).build()); 32 | ``` 33 | 34 | | ItemDecoration | Usage | 35 | |:------------------|:----------| 36 | | HorizontalDividerItemDecoration | For layout manager having vertical orientation to draw horizontal divider | 37 | | VerticalDividerItemDecoration | For layout manager having horizontal orientation to draw vertical divider | 38 | _*Please note that you can only set one of above item decorations at a time._ 39 | 40 | If you want to set color, size and margin values, you can specify as the followings. 41 | ```java 42 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview); 43 | recyclerView.addItemDecoration( 44 | new HorizontalDividerItemDecoration.Builder(this) 45 | .color(Color.RED) 46 | .sizeResId(R.dimen.divider) 47 | .marginResId(R.dimen.leftmargin, R.dimen.rightmargin) 48 | .build()); 49 | ``` 50 | 51 | 52 | Instead of setting color and size, you can set paint object. 53 | ```java 54 | Paint paint = new Paint(); 55 | paint.setStrokeWidth(5); 56 | paint.setColor(Color.BLUE); 57 | paint.setAntiAlias(true); 58 | paint.setPathEffect(new DashPathEffect(new float[]{25.0f, 25.0f}, 0)); 59 | recyclerView.addItemDecoration( 60 | new HorizontalDividerItemDecoration.Builder(this).paint(paint).build()); 61 | ``` 62 | 63 | Also 9patch drawable can be used for drawing divider. 64 | ```java 65 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview); 66 | recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this) 67 | .drawable(R.drawable.sample) 68 | .size(15) 69 | .build()); 70 | ``` 71 | 72 | If you want to customize divider depending on the position, implement the following interfaces. 73 | 74 | ### List of provider 75 | The following providers can be implemented and controllable for each divider drawn between cells. 76 | Please refer to ComplexAdapter class in the [sample](/sample/src/main/java/com/yqritc/recyclerviewflexibledivider/sample) for the usage of providers in detail. 77 | 78 | - ColorProvider 79 | Provide color for divider 80 | 81 | - PaintProvider 82 | Provide paint object for divider line to draw. 83 | 84 | - DrawableDivider 85 | Provide drawable object for divider line 86 | 87 | - SizeProvider 88 | Provide height for horizontal divider, width for vertical divider. 89 | 90 | - VisibilityProvider 91 | Enables you to control the visibility of dividers. 92 | 93 | - MarginProvider for horizontal divider (vertical list) 94 | Enables you to specify left and right margin of divider. 95 | 96 | - MarginProvider for vertical divider (horizontal list) 97 | Enables you to specify top and bottom margin of divider. 98 | 99 | **For GridLayoutManager**, the position parameter of above providers is group index of items. 100 | So, control your divider based on [group index](http://developer.android.com/intl/ja/reference/android/support/v7/widget/GridLayoutManager.SpanSizeLookup.html#getSpanGroupIndex(int, int)) instead of the position of items. 101 | 102 | ### Optional 103 | - Builder.showLastDivider 104 | Draw divider line at the end of last item in RecyclerView. 105 | If you enable this, the range of position parameter of providers listed above is 0 to itemCount-1. 106 | Otherwise, the range is 0 to itemCount-2. 107 | 108 | - Builder.positionInsideItem 109 | Draw divider inside items. 110 | If you want to follow [material design guideline](https://www.google.com/design/spec/components/dividers.html#dividers-specs), enable this feature. 111 | 112 | 113 | ### Note 114 | - When neither of color, paint, drawable is set, default divider retrieved from android.R.attr.listDivider will be used. 115 | - When you set Paint, you must use setColor and setStrokeWidth methods of paint class. 116 | - If you want to use DashPathEffect, please note the following issue. 117 | https://code.google.com/p/android/issues/detail?id=29944 118 | 119 | ##### _Looking for custom ItemDecoration to achieve equal column space for GridLayoutManager?_ 120 | Check out [https://gist.github.com/yqritc/ccca77dc42f2364777e1](https://gist.github.com/yqritc/ccca77dc42f2364777e1) 121 | 122 | # License 123 | ``` 124 | Copyright 2016 yqritc 125 | 126 | Licensed under the Apache License, Version 2.0 (the "License"); 127 | you may not use this file except in compliance with the License. 128 | You may obtain a copy of the License at 129 | 130 | http://www.apache.org/licenses/LICENSE-2.0 131 | 132 | Unless required by applicable law or agreed to in writing, software 133 | distributed under the License is distributed on an "AS IS" BASIS, 134 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135 | See the License for the specific language governing permissions and 136 | limitations under the License. 137 | ``` 138 | -------------------------------------------------------------------------------- /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:2.1.2' 9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=1.4.0 2 | VERSION_CODE=15 3 | GROUP=com.yqritc 4 | ARTIFACT_ID=recyclerview-flexibledivider 5 | 6 | COMPILE_SDK_VERSION=23 7 | BUILD_TOOLS_VERSION=23.0.3 8 | TARGET_SDK_VERSION=23 9 | MIN_SDK_VERSION=9 10 | 11 | POM_DESCRIPTION=Android library providing simple way to control divider items of RecyclerView 12 | POM_URL=https://github.com/yqritc/RecyclerView-FlexibleDivider 13 | POM_SCM_URL=git@github.com:yqritc/RecyclerView-FlexibleDivider.git 14 | POM_SCM_CONNECTION=scm:git@github.com:yqritc/RecyclerView-FlexibleDivider.git 15 | POM_SCM_DEV_CONNECTION=scm:git@github.com:yqritc/RecyclerView-FlexibleDivider.git 16 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 17 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 18 | POM_LICENCE_DIST=repo 19 | POM_DEVELOPER_ID=yqritc 20 | POM_DEVELOPER_NAME=yqritc 21 | POM_DEVELOPER_EMAIL=yqritc@gmail.com 22 | ISSUE_URL=https://github.com/yqritc/RecyclerView-FlexibleDivider/issues -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jun 23 11:31:54 JST 2016 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.10-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/android-artifacts.gradle: -------------------------------------------------------------------------------- 1 | task androidJavadocs(type: Javadoc) { 2 | source = android.sourceSets.main.java.srcDirs 3 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 4 | } 5 | 6 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 7 | classifier = 'javadoc' 8 | from androidJavadocs.destinationDir 9 | } 10 | 11 | task androidSourcesJar(type: Jar) { 12 | classifier = 'sources' 13 | from android.sourceSets.main.java.sourceFiles 14 | } 15 | 16 | task androidJar(type: Jar) { 17 | from 'build/intermediates/classes/release' 18 | } 19 | 20 | artifacts { 21 | archives androidSourcesJar 22 | archives androidJavadocsJar 23 | archives androidJar 24 | } -------------------------------------------------------------------------------- /library/bintray-publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'com.jfrog.bintray' 3 | 4 | publishing { 5 | publications { 6 | mavenJava(MavenPublication) { 7 | groupId GROUP 8 | version VERSION_NAME 9 | artifactId ARTIFACT_ID 10 | // artifact androidJar 11 | artifact "build/outputs/aar/library-release.aar" 12 | artifact androidJavadocsJar 13 | artifact androidSourcesJar 14 | pom.withXml { 15 | Node root = asNode() 16 | root.appendNode('name', ARTIFACT_ID) 17 | root.appendNode('description', POM_DESCRIPTION) 18 | root.appendNode('url', POM_URL) 19 | 20 | def issues = root.appendNode('issueManagement') 21 | issues.appendNode('system', 'github') 22 | issues.appendNode('url', ISSUE_URL) 23 | 24 | def scm = root.appendNode('scm') 25 | scm.appendNode('url', POM_SCM_URL) 26 | scm.appendNode('connection', POM_SCM_CONNECTION) 27 | scm.appendNode('developerConnection', POM_SCM_DEV_CONNECTION) 28 | 29 | def license = root.appendNode('licenses').appendNode('license') 30 | license.appendNode('name', POM_LICENCE_NAME) 31 | license.appendNode('url', POM_LICENCE_URL) 32 | license.appendNode('distribution', POM_LICENCE_DIST) 33 | 34 | def developer = root.appendNode('developers').appendNode('developer') 35 | developer.appendNode('id', POM_DEVELOPER_ID) 36 | developer.appendNode('name', POM_DEVELOPER_NAME) 37 | developer.appendNode('email', POM_DEVELOPER_EMAIL) 38 | } 39 | } 40 | } 41 | } 42 | 43 | def getBintrayUserProperty() { 44 | return hasProperty('bintrayUser') ? bintrayUser : "" 45 | } 46 | 47 | def getBintrayApiKeyProperty() { 48 | return hasProperty('bintrayApiKey') ? bintrayApiKey : "" 49 | } 50 | 51 | bintray { 52 | user = bintrayUserProperty 53 | key = bintrayApiKeyProperty 54 | publications = ['mavenJava'] 55 | 56 | dryRun = false 57 | publish = false 58 | pkg { 59 | repo = 'maven' 60 | name = ARTIFACT_ID 61 | licenses = ['Apache-2.0'] 62 | labels = ['android'] 63 | 64 | version { 65 | name = VERSION_NAME 66 | vcsTag = VERSION_NAME 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion COMPILE_SDK_VERSION as int 5 | buildToolsVersion BUILD_TOOLS_VERSION 6 | 7 | defaultConfig { 8 | minSdkVersion MIN_SDK_VERSION as int 9 | targetSdkVersion TARGET_SDK_VERSION as int 10 | versionCode VERSION_CODE as int 11 | versionName VERSION_NAME 12 | } 13 | } 14 | 15 | dependencies { 16 | compile 'com.android.support:appcompat-v7:23.4.0' 17 | compile 'com.android.support:recyclerview-v7:23.4.0' 18 | } 19 | 20 | android.libraryVariants.all { variant -> 21 | if (variant.buildType.isDebuggable()) { 22 | return; // Skip debug builds. 23 | } 24 | task("javadoc${variant.name.capitalize()}", type: Javadoc) { 25 | description "Generates Javadoc for $variant.name." 26 | source = variant.javaCompile.source 27 | ext.androidJar = System.getenv("ANDROID_HOME") + 28 | "/platforms/${android.compileSdkVersion}/android.jar" 29 | classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) 30 | } 31 | 32 | task("bundleJavadoc${variant.name.capitalize()}", type: Jar) { 33 | description "Bundles Javadoc into zip for $variant.name." 34 | classifier = "javadoc" 35 | from tasks["javadoc${variant.name.capitalize()}"] 36 | } 37 | } 38 | 39 | apply from: 'android-artifacts.gradle' 40 | apply from: 'bintray-publish.gradle' -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /library/src/main/java/com/yqritc/recyclerviewflexibledivider/FlexibleDividerDecoration.java: -------------------------------------------------------------------------------- 1 | package com.yqritc.recyclerviewflexibledivider; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.graphics.Rect; 9 | import android.graphics.drawable.Drawable; 10 | import android.support.annotation.ColorRes; 11 | import android.support.annotation.DimenRes; 12 | import android.support.annotation.DrawableRes; 13 | import android.support.v4.content.ContextCompat; 14 | import android.support.v7.widget.GridLayoutManager; 15 | import android.support.v7.widget.LinearLayoutManager; 16 | import android.support.v7.widget.RecyclerView; 17 | import android.view.View; 18 | 19 | /** 20 | * Created by yqritc on 2015/01/08. 21 | */ 22 | public abstract class FlexibleDividerDecoration extends RecyclerView.ItemDecoration { 23 | 24 | private static final int DEFAULT_SIZE = 2; 25 | private static final int[] ATTRS = new int[]{ 26 | android.R.attr.listDivider 27 | }; 28 | 29 | protected enum DividerType { 30 | DRAWABLE, PAINT, COLOR 31 | } 32 | 33 | protected DividerType mDividerType = DividerType.DRAWABLE; 34 | protected VisibilityProvider mVisibilityProvider; 35 | protected PaintProvider mPaintProvider; 36 | protected ColorProvider mColorProvider; 37 | protected DrawableProvider mDrawableProvider; 38 | protected SizeProvider mSizeProvider; 39 | protected boolean mShowLastDivider; 40 | protected boolean mPositionInsideItem; 41 | private Paint mPaint; 42 | 43 | protected FlexibleDividerDecoration(Builder builder) { 44 | if (builder.mPaintProvider != null) { 45 | mDividerType = DividerType.PAINT; 46 | mPaintProvider = builder.mPaintProvider; 47 | } else if (builder.mColorProvider != null) { 48 | mDividerType = DividerType.COLOR; 49 | mColorProvider = builder.mColorProvider; 50 | mPaint = new Paint(); 51 | setSizeProvider(builder); 52 | } else { 53 | mDividerType = DividerType.DRAWABLE; 54 | if (builder.mDrawableProvider == null) { 55 | TypedArray a = builder.mContext.obtainStyledAttributes(ATTRS); 56 | final Drawable divider = a.getDrawable(0); 57 | a.recycle(); 58 | mDrawableProvider = new DrawableProvider() { 59 | @Override 60 | public Drawable drawableProvider(int position, RecyclerView parent) { 61 | return divider; 62 | } 63 | }; 64 | } else { 65 | mDrawableProvider = builder.mDrawableProvider; 66 | } 67 | mSizeProvider = builder.mSizeProvider; 68 | } 69 | 70 | mVisibilityProvider = builder.mVisibilityProvider; 71 | mShowLastDivider = builder.mShowLastDivider; 72 | mPositionInsideItem = builder.mPositionInsideItem; 73 | } 74 | 75 | private void setSizeProvider(Builder builder) { 76 | mSizeProvider = builder.mSizeProvider; 77 | if (mSizeProvider == null) { 78 | mSizeProvider = new SizeProvider() { 79 | @Override 80 | public int dividerSize(int position, RecyclerView parent) { 81 | return DEFAULT_SIZE; 82 | } 83 | }; 84 | } 85 | } 86 | 87 | @Override 88 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 89 | RecyclerView.Adapter adapter = parent.getAdapter(); 90 | if (adapter == null) { 91 | return; 92 | } 93 | 94 | int itemCount = adapter.getItemCount(); 95 | int lastDividerOffset = getLastDividerOffset(parent); 96 | int validChildCount = parent.getChildCount(); 97 | int lastChildPosition = -1; 98 | for (int i = 0; i < validChildCount; i++) { 99 | View child = parent.getChildAt(i); 100 | int childPosition = parent.getChildAdapterPosition(child); 101 | 102 | if (childPosition < lastChildPosition) { 103 | // Avoid remaining divider when animation starts 104 | continue; 105 | } 106 | lastChildPosition = childPosition; 107 | 108 | if (!mShowLastDivider && childPosition >= itemCount - lastDividerOffset) { 109 | // Don't draw divider for last line if mShowLastDivider = false 110 | continue; 111 | } 112 | 113 | if (wasDividerAlreadyDrawn(childPosition, parent)) { 114 | // No need to draw divider again as it was drawn already by previous column 115 | continue; 116 | } 117 | 118 | int groupIndex = getGroupIndex(childPosition, parent); 119 | if (mVisibilityProvider.shouldHideDivider(groupIndex, parent)) { 120 | continue; 121 | } 122 | 123 | Rect bounds = getDividerBound(groupIndex, parent, child); 124 | switch (mDividerType) { 125 | case DRAWABLE: 126 | Drawable drawable = mDrawableProvider.drawableProvider(groupIndex, parent); 127 | drawable.setBounds(bounds); 128 | drawable.draw(c); 129 | break; 130 | case PAINT: 131 | mPaint = mPaintProvider.dividerPaint(groupIndex, parent); 132 | c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint); 133 | break; 134 | case COLOR: 135 | mPaint.setColor(mColorProvider.dividerColor(groupIndex, parent)); 136 | mPaint.setStrokeWidth(mSizeProvider.dividerSize(groupIndex, parent)); 137 | c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint); 138 | break; 139 | } 140 | } 141 | } 142 | 143 | @Override 144 | public void getItemOffsets(Rect rect, View v, RecyclerView parent, RecyclerView.State state) { 145 | int position = parent.getChildAdapterPosition(v); 146 | int itemCount = parent.getAdapter().getItemCount(); 147 | int lastDividerOffset = getLastDividerOffset(parent); 148 | if (!mShowLastDivider && position >= itemCount - lastDividerOffset) { 149 | // Don't set item offset for last line if mShowLastDivider = false 150 | return; 151 | } 152 | 153 | int groupIndex = getGroupIndex(position, parent); 154 | if (mVisibilityProvider.shouldHideDivider(groupIndex, parent)) { 155 | return; 156 | } 157 | 158 | setItemOffsets(rect, groupIndex, parent); 159 | } 160 | 161 | /** 162 | * Check if recyclerview is reverse layout 163 | * 164 | * @param parent RecyclerView 165 | * @return true if recyclerview is reverse layout 166 | */ 167 | protected boolean isReverseLayout(RecyclerView parent) { 168 | RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); 169 | if (layoutManager instanceof LinearLayoutManager) { 170 | return ((LinearLayoutManager) layoutManager).getReverseLayout(); 171 | } else { 172 | return false; 173 | } 174 | } 175 | 176 | /** 177 | * In the case mShowLastDivider = false, 178 | * Returns offset for how many views we don't have to draw a divider for, 179 | * for LinearLayoutManager it is as simple as not drawing the last child divider, 180 | * but for a GridLayoutManager it needs to take the span count for the last items into account 181 | * until we use the span count configured for the grid. 182 | * 183 | * @param parent RecyclerView 184 | * @return offset for how many views we don't have to draw a divider or 1 if its a 185 | * LinearLayoutManager 186 | */ 187 | private int getLastDividerOffset(RecyclerView parent) { 188 | if (parent.getLayoutManager() instanceof GridLayoutManager) { 189 | GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager(); 190 | GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup(); 191 | int spanCount = layoutManager.getSpanCount(); 192 | int itemCount = parent.getAdapter().getItemCount(); 193 | for (int i = itemCount - 1; i >= 0; i--) { 194 | if (spanSizeLookup.getSpanIndex(i, spanCount) == 0) { 195 | return itemCount - i; 196 | } 197 | } 198 | } 199 | 200 | return 1; 201 | } 202 | 203 | /** 204 | * Determines whether divider was already drawn for the row the item is in, 205 | * effectively only makes sense for a grid 206 | * 207 | * @param position current view position to draw divider 208 | * @param parent RecyclerView 209 | * @return true if the divider can be skipped as it is in the same row as the previous one. 210 | */ 211 | private boolean wasDividerAlreadyDrawn(int position, RecyclerView parent) { 212 | if (parent.getLayoutManager() instanceof GridLayoutManager) { 213 | GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager(); 214 | GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup(); 215 | int spanCount = layoutManager.getSpanCount(); 216 | return spanSizeLookup.getSpanIndex(position, spanCount) > 0; 217 | } 218 | 219 | return false; 220 | } 221 | 222 | /** 223 | * Returns a group index for GridLayoutManager. 224 | * for LinearLayoutManager, always returns position. 225 | * 226 | * @param position current view position to draw divider 227 | * @param parent RecyclerView 228 | * @return group index of items 229 | */ 230 | private int getGroupIndex(int position, RecyclerView parent) { 231 | if (parent.getLayoutManager() instanceof GridLayoutManager) { 232 | GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager(); 233 | GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup(); 234 | int spanCount = layoutManager.getSpanCount(); 235 | return spanSizeLookup.getSpanGroupIndex(position, spanCount); 236 | } 237 | 238 | return position; 239 | } 240 | 241 | protected abstract Rect getDividerBound(int position, RecyclerView parent, View child); 242 | 243 | protected abstract void setItemOffsets(Rect outRect, int position, RecyclerView parent); 244 | 245 | /** 246 | * Interface for controlling divider visibility 247 | */ 248 | public interface VisibilityProvider { 249 | 250 | /** 251 | * Returns true if divider should be hidden. 252 | * 253 | * @param position Divider position (or group index for GridLayoutManager) 254 | * @param parent RecyclerView 255 | * @return True if the divider at position should be hidden 256 | */ 257 | boolean shouldHideDivider(int position, RecyclerView parent); 258 | } 259 | 260 | /** 261 | * Interface for controlling paint instance for divider drawing 262 | */ 263 | public interface PaintProvider { 264 | 265 | /** 266 | * Returns {@link android.graphics.Paint} for divider 267 | * 268 | * @param position Divider position (or group index for GridLayoutManager) 269 | * @param parent RecyclerView 270 | * @return Paint instance 271 | */ 272 | Paint dividerPaint(int position, RecyclerView parent); 273 | } 274 | 275 | /** 276 | * Interface for controlling divider color 277 | */ 278 | public interface ColorProvider { 279 | 280 | /** 281 | * Returns {@link android.graphics.Color} value of divider 282 | * 283 | * @param position Divider position (or group index for GridLayoutManager) 284 | * @param parent RecyclerView 285 | * @return Color value 286 | */ 287 | int dividerColor(int position, RecyclerView parent); 288 | } 289 | 290 | /** 291 | * Interface for controlling drawable object for divider drawing 292 | */ 293 | public interface DrawableProvider { 294 | 295 | /** 296 | * Returns drawable instance for divider 297 | * 298 | * @param position Divider position (or group index for GridLayoutManager) 299 | * @param parent RecyclerView 300 | * @return Drawable instance 301 | */ 302 | Drawable drawableProvider(int position, RecyclerView parent); 303 | } 304 | 305 | /** 306 | * Interface for controlling divider size 307 | */ 308 | public interface SizeProvider { 309 | 310 | /** 311 | * Returns size value of divider. 312 | * Height for horizontal divider, width for vertical divider 313 | * 314 | * @param position Divider position (or group index for GridLayoutManager) 315 | * @param parent RecyclerView 316 | * @return Size of divider 317 | */ 318 | int dividerSize(int position, RecyclerView parent); 319 | } 320 | 321 | public static class Builder { 322 | 323 | private Context mContext; 324 | protected Resources mResources; 325 | private PaintProvider mPaintProvider; 326 | private ColorProvider mColorProvider; 327 | private DrawableProvider mDrawableProvider; 328 | private SizeProvider mSizeProvider; 329 | private VisibilityProvider mVisibilityProvider = new VisibilityProvider() { 330 | @Override 331 | public boolean shouldHideDivider(int position, RecyclerView parent) { 332 | return false; 333 | } 334 | }; 335 | private boolean mShowLastDivider = false; 336 | private boolean mPositionInsideItem = false; 337 | 338 | public Builder(Context context) { 339 | mContext = context; 340 | mResources = context.getResources(); 341 | } 342 | 343 | public T paint(final Paint paint) { 344 | return paintProvider(new PaintProvider() { 345 | @Override 346 | public Paint dividerPaint(int position, RecyclerView parent) { 347 | return paint; 348 | } 349 | }); 350 | } 351 | 352 | public T paintProvider(PaintProvider provider) { 353 | mPaintProvider = provider; 354 | return (T) this; 355 | } 356 | 357 | public T color(final int color) { 358 | return colorProvider(new ColorProvider() { 359 | @Override 360 | public int dividerColor(int position, RecyclerView parent) { 361 | return color; 362 | } 363 | }); 364 | } 365 | 366 | public T colorResId(@ColorRes int colorId) { 367 | return color(ContextCompat.getColor(mContext, colorId)); 368 | } 369 | 370 | public T colorProvider(ColorProvider provider) { 371 | mColorProvider = provider; 372 | return (T) this; 373 | } 374 | 375 | public T drawable(@DrawableRes int id) { 376 | return drawable(ContextCompat.getDrawable(mContext, id)); 377 | } 378 | 379 | public T drawable(final Drawable drawable) { 380 | return drawableProvider(new DrawableProvider() { 381 | @Override 382 | public Drawable drawableProvider(int position, RecyclerView parent) { 383 | return drawable; 384 | } 385 | }); 386 | } 387 | 388 | public T drawableProvider(DrawableProvider provider) { 389 | mDrawableProvider = provider; 390 | return (T) this; 391 | } 392 | 393 | public T size(final int size) { 394 | return sizeProvider(new SizeProvider() { 395 | @Override 396 | public int dividerSize(int position, RecyclerView parent) { 397 | return size; 398 | } 399 | }); 400 | } 401 | 402 | public T sizeResId(@DimenRes int sizeId) { 403 | return size(mResources.getDimensionPixelSize(sizeId)); 404 | } 405 | 406 | public T sizeProvider(SizeProvider provider) { 407 | mSizeProvider = provider; 408 | return (T) this; 409 | } 410 | 411 | public T visibilityProvider(VisibilityProvider provider) { 412 | mVisibilityProvider = provider; 413 | return (T) this; 414 | } 415 | 416 | public T showLastDivider() { 417 | mShowLastDivider = true; 418 | return (T) this; 419 | } 420 | 421 | public T positionInsideItem(boolean positionInsideItem) { 422 | mPositionInsideItem = positionInsideItem; 423 | return (T) this; 424 | } 425 | 426 | protected void checkBuilderParams() { 427 | if (mPaintProvider != null) { 428 | if (mColorProvider != null) { 429 | throw new IllegalArgumentException( 430 | "Use setColor method of Paint class to specify line color. Do not provider ColorProvider if you set PaintProvider."); 431 | } 432 | if (mSizeProvider != null) { 433 | throw new IllegalArgumentException( 434 | "Use setStrokeWidth method of Paint class to specify line size. Do not provider SizeProvider if you set PaintProvider."); 435 | } 436 | } 437 | } 438 | } 439 | } -------------------------------------------------------------------------------- /library/src/main/java/com/yqritc/recyclerviewflexibledivider/HorizontalDividerItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.yqritc.recyclerviewflexibledivider; 2 | 3 | import android.content.Context; 4 | import android.graphics.Rect; 5 | import android.graphics.drawable.Drawable; 6 | import android.support.annotation.DimenRes; 7 | import android.support.v4.view.ViewCompat; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.View; 10 | 11 | /** 12 | * Created by yqritc on 2015/01/15. 13 | */ 14 | public class HorizontalDividerItemDecoration extends FlexibleDividerDecoration { 15 | 16 | private MarginProvider mMarginProvider; 17 | 18 | protected HorizontalDividerItemDecoration(Builder builder) { 19 | super(builder); 20 | mMarginProvider = builder.mMarginProvider; 21 | } 22 | 23 | @Override 24 | protected Rect getDividerBound(int position, RecyclerView parent, View child) { 25 | Rect bounds = new Rect(0, 0, 0, 0); 26 | int transitionX = (int) ViewCompat.getTranslationX(child); 27 | int transitionY = (int) ViewCompat.getTranslationY(child); 28 | RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); 29 | bounds.left = parent.getPaddingLeft() + 30 | mMarginProvider.dividerLeftMargin(position, parent) + transitionX; 31 | bounds.right = parent.getWidth() - parent.getPaddingRight() - 32 | mMarginProvider.dividerRightMargin(position, parent) + transitionX; 33 | 34 | int dividerSize = getDividerSize(position, parent); 35 | boolean isReverseLayout = isReverseLayout(parent); 36 | if (mDividerType == DividerType.DRAWABLE) { 37 | // set top and bottom position of divider 38 | if (isReverseLayout) { 39 | bounds.bottom = child.getTop() - params.topMargin + transitionY; 40 | bounds.top = bounds.bottom - dividerSize; 41 | } else { 42 | bounds.top = child.getBottom() + params.bottomMargin + transitionY; 43 | bounds.bottom = bounds.top + dividerSize; 44 | } 45 | } else { 46 | // set center point of divider 47 | int halfSize = dividerSize / 2; 48 | if (isReverseLayout) { 49 | bounds.top = child.getTop() - params.topMargin - halfSize + transitionY; 50 | } else { 51 | bounds.top = child.getBottom() + params.bottomMargin + halfSize + transitionY; 52 | } 53 | bounds.bottom = bounds.top; 54 | } 55 | 56 | if (mPositionInsideItem) { 57 | if (isReverseLayout) { 58 | bounds.top += dividerSize; 59 | bounds.bottom += dividerSize; 60 | } else { 61 | bounds.top -= dividerSize; 62 | bounds.bottom -= dividerSize; 63 | } 64 | } 65 | 66 | return bounds; 67 | } 68 | 69 | @Override 70 | protected void setItemOffsets(Rect outRect, int position, RecyclerView parent) { 71 | if (mPositionInsideItem) { 72 | outRect.set(0, 0, 0, 0); 73 | return; 74 | } 75 | 76 | if (isReverseLayout(parent)) { 77 | outRect.set(0, getDividerSize(position, parent), 0, 0); 78 | } else { 79 | outRect.set(0, 0, 0, getDividerSize(position, parent)); 80 | } 81 | } 82 | 83 | private int getDividerSize(int position, RecyclerView parent) { 84 | if (mPaintProvider != null) { 85 | return (int) mPaintProvider.dividerPaint(position, parent).getStrokeWidth(); 86 | } else if (mSizeProvider != null) { 87 | return mSizeProvider.dividerSize(position, parent); 88 | } else if (mDrawableProvider != null) { 89 | Drawable drawable = mDrawableProvider.drawableProvider(position, parent); 90 | return drawable.getIntrinsicHeight(); 91 | } 92 | throw new RuntimeException("failed to get size"); 93 | } 94 | 95 | /** 96 | * Interface for controlling divider margin 97 | */ 98 | public interface MarginProvider { 99 | 100 | /** 101 | * Returns left margin of divider. 102 | * 103 | * @param position Divider position (or group index for GridLayoutManager) 104 | * @param parent RecyclerView 105 | * @return left margin 106 | */ 107 | int dividerLeftMargin(int position, RecyclerView parent); 108 | 109 | /** 110 | * Returns right margin of divider. 111 | * 112 | * @param position Divider position (or group index for GridLayoutManager) 113 | * @param parent RecyclerView 114 | * @return right margin 115 | */ 116 | int dividerRightMargin(int position, RecyclerView parent); 117 | } 118 | 119 | public static class Builder extends FlexibleDividerDecoration.Builder { 120 | 121 | private MarginProvider mMarginProvider = new MarginProvider() { 122 | @Override 123 | public int dividerLeftMargin(int position, RecyclerView parent) { 124 | return 0; 125 | } 126 | 127 | @Override 128 | public int dividerRightMargin(int position, RecyclerView parent) { 129 | return 0; 130 | } 131 | }; 132 | 133 | public Builder(Context context) { 134 | super(context); 135 | } 136 | 137 | public Builder margin(final int leftMargin, final int rightMargin) { 138 | return marginProvider(new MarginProvider() { 139 | @Override 140 | public int dividerLeftMargin(int position, RecyclerView parent) { 141 | return leftMargin; 142 | } 143 | 144 | @Override 145 | public int dividerRightMargin(int position, RecyclerView parent) { 146 | return rightMargin; 147 | } 148 | }); 149 | } 150 | 151 | public Builder margin(int horizontalMargin) { 152 | return margin(horizontalMargin, horizontalMargin); 153 | } 154 | 155 | public Builder marginResId(@DimenRes int leftMarginId, @DimenRes int rightMarginId) { 156 | return margin(mResources.getDimensionPixelSize(leftMarginId), 157 | mResources.getDimensionPixelSize(rightMarginId)); 158 | } 159 | 160 | public Builder marginResId(@DimenRes int horizontalMarginId) { 161 | return marginResId(horizontalMarginId, horizontalMarginId); 162 | } 163 | 164 | public Builder marginProvider(MarginProvider provider) { 165 | mMarginProvider = provider; 166 | return this; 167 | } 168 | 169 | public HorizontalDividerItemDecoration build() { 170 | checkBuilderParams(); 171 | return new HorizontalDividerItemDecoration(this); 172 | } 173 | } 174 | } -------------------------------------------------------------------------------- /library/src/main/java/com/yqritc/recyclerviewflexibledivider/VerticalDividerItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.yqritc.recyclerviewflexibledivider; 2 | 3 | import android.content.Context; 4 | import android.graphics.Rect; 5 | import android.graphics.drawable.Drawable; 6 | import android.support.annotation.DimenRes; 7 | import android.support.v4.view.ViewCompat; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.View; 10 | 11 | /** 12 | * Created by yqritc on 2015/01/15. 13 | */ 14 | public class VerticalDividerItemDecoration extends FlexibleDividerDecoration { 15 | 16 | private MarginProvider mMarginProvider; 17 | 18 | protected VerticalDividerItemDecoration(Builder builder) { 19 | super(builder); 20 | mMarginProvider = builder.mMarginProvider; 21 | } 22 | 23 | @Override 24 | protected Rect getDividerBound(int position, RecyclerView parent, View child) { 25 | Rect bounds = new Rect(0, 0, 0, 0); 26 | int transitionX = (int) ViewCompat.getTranslationX(child); 27 | int transitionY = (int) ViewCompat.getTranslationY(child); 28 | RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); 29 | bounds.top = parent.getPaddingTop() + 30 | mMarginProvider.dividerTopMargin(position, parent) + transitionY; 31 | bounds.bottom = parent.getHeight() - parent.getPaddingBottom() - 32 | mMarginProvider.dividerBottomMargin(position, parent) + transitionY; 33 | 34 | int dividerSize = getDividerSize(position, parent); 35 | boolean isReverseLayout = isReverseLayout(parent); 36 | if (mDividerType == DividerType.DRAWABLE) { 37 | // set left and right position of divider 38 | if (isReverseLayout) { 39 | bounds.right = child.getLeft() - params.leftMargin + transitionX; 40 | bounds.left = bounds.right - dividerSize; 41 | } else { 42 | bounds.left = child.getRight() + params.rightMargin + transitionX; 43 | bounds.right = bounds.left + dividerSize; 44 | } 45 | } else { 46 | // set center point of divider 47 | int halfSize = dividerSize / 2; 48 | if (isReverseLayout) { 49 | bounds.left = child.getLeft() - params.leftMargin - halfSize + transitionX; 50 | } else { 51 | bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX; 52 | } 53 | bounds.right = bounds.left; 54 | } 55 | 56 | if (mPositionInsideItem) { 57 | if (isReverseLayout) { 58 | bounds.left += dividerSize; 59 | bounds.right += dividerSize; 60 | } else { 61 | bounds.left -= dividerSize; 62 | bounds.right -= dividerSize; 63 | } 64 | } 65 | 66 | return bounds; 67 | } 68 | 69 | @Override 70 | protected void setItemOffsets(Rect outRect, int position, RecyclerView parent) { 71 | if (mPositionInsideItem) { 72 | outRect.set(0, 0, 0, 0); 73 | return; 74 | } 75 | 76 | if (isReverseLayout(parent)) { 77 | outRect.set(getDividerSize(position, parent), 0, 0, 0); 78 | } else { 79 | outRect.set(0, 0, getDividerSize(position, parent), 0); 80 | } 81 | } 82 | 83 | private int getDividerSize(int position, RecyclerView parent) { 84 | if (mPaintProvider != null) { 85 | return (int) mPaintProvider.dividerPaint(position, parent).getStrokeWidth(); 86 | } else if (mSizeProvider != null) { 87 | return mSizeProvider.dividerSize(position, parent); 88 | } else if (mDrawableProvider != null) { 89 | Drawable drawable = mDrawableProvider.drawableProvider(position, parent); 90 | return drawable.getIntrinsicWidth(); 91 | } 92 | throw new RuntimeException("failed to get size"); 93 | } 94 | 95 | /** 96 | * Interface for controlling divider margin 97 | */ 98 | public interface MarginProvider { 99 | 100 | /** 101 | * Returns top margin of divider. 102 | * 103 | * @param position Divider position (or group index for GridLayoutManager) 104 | * @param parent RecyclerView 105 | * @return top margin 106 | */ 107 | int dividerTopMargin(int position, RecyclerView parent); 108 | 109 | /** 110 | * Returns bottom margin of divider. 111 | * 112 | * @param position Divider position (or group index for GridLayoutManager) 113 | * @param parent RecyclerView 114 | * @return bottom margin 115 | */ 116 | int dividerBottomMargin(int position, RecyclerView parent); 117 | } 118 | 119 | public static class Builder extends FlexibleDividerDecoration.Builder { 120 | 121 | private MarginProvider mMarginProvider = new MarginProvider() { 122 | @Override 123 | public int dividerTopMargin(int position, RecyclerView parent) { 124 | return 0; 125 | } 126 | 127 | @Override 128 | public int dividerBottomMargin(int position, RecyclerView parent) { 129 | return 0; 130 | } 131 | }; 132 | 133 | public Builder(Context context) { 134 | super(context); 135 | } 136 | 137 | public Builder margin(final int topMargin, final int bottomMargin) { 138 | return marginProvider(new MarginProvider() { 139 | @Override 140 | public int dividerTopMargin(int position, RecyclerView parent) { 141 | return topMargin; 142 | } 143 | 144 | @Override 145 | public int dividerBottomMargin(int position, RecyclerView parent) { 146 | return bottomMargin; 147 | } 148 | }); 149 | } 150 | 151 | public Builder margin(int verticalMargin) { 152 | return margin(verticalMargin, verticalMargin); 153 | } 154 | 155 | public Builder marginResId(@DimenRes int topMarginId, @DimenRes int bottomMarginId) { 156 | return margin(mResources.getDimensionPixelSize(topMarginId), 157 | mResources.getDimensionPixelSize(bottomMarginId)); 158 | } 159 | 160 | public Builder marginResId(@DimenRes int verticalMarginId) { 161 | return marginResId(verticalMarginId, verticalMarginId); 162 | } 163 | 164 | public Builder marginProvider(MarginProvider provider) { 165 | mMarginProvider = provider; 166 | return this; 167 | } 168 | 169 | public VerticalDividerItemDecoration build() { 170 | checkBuilderParams(); 171 | return new VerticalDividerItemDecoration(this); 172 | } 173 | } 174 | } -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion COMPILE_SDK_VERSION as int 5 | buildToolsVersion BUILD_TOOLS_VERSION 6 | 7 | defaultConfig { 8 | applicationId "com.yqritc.recyclerviewflexibledivider.sample" 9 | minSdkVersion MIN_SDK_VERSION as int 10 | targetSdkVersion TARGET_SDK_VERSION as int 11 | versionCode VERSION_CODE as int 12 | versionName VERSION_NAME 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile project(':library') 24 | // compile 'com.yqritc:recyclerview-flexibledivider:1.4.0' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | compile 'com.android.support:recyclerview-v7:23.4.0' 27 | } 28 | -------------------------------------------------------------------------------- /sample/sample1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/sample/sample1.gif -------------------------------------------------------------------------------- /sample/sample2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/sample/sample2.gif -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 26 | 29 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yqritc/recyclerviewflexibledivider/sample/ComplexActivity.java: -------------------------------------------------------------------------------- 1 | package com.yqritc.recyclerviewflexibledivider.sample; 2 | 3 | import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration; 4 | 5 | import android.app.Activity; 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.OrientationHelper; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.view.Menu; 13 | import android.view.MenuItem; 14 | import android.view.View; 15 | 16 | 17 | public class ComplexActivity extends AppCompatActivity { 18 | 19 | public static void startActivity(Activity activity) { 20 | Intent intent = new Intent(activity, ComplexActivity.class); 21 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 22 | activity.startActivity(intent); 23 | } 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_sample); 29 | 30 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_recyclerview); 31 | // Workaround for dash path effect 32 | // https://code.google.com/p/android/issues/detail?id=29944 33 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { 34 | recyclerView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 35 | } 36 | 37 | ComplexAdapter adapter = new ComplexAdapter(this); 38 | LinearLayoutManager manager = new LinearLayoutManager(this); 39 | manager.setOrientation(OrientationHelper.VERTICAL); 40 | recyclerView.setLayoutManager(manager); 41 | recyclerView.setAdapter(adapter); 42 | recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this) 43 | .paintProvider(adapter) 44 | .visibilityProvider(adapter) 45 | .marginProvider(adapter) 46 | .build()); 47 | } 48 | 49 | 50 | @Override 51 | public boolean onCreateOptionsMenu(Menu menu) { 52 | getMenuInflater().inflate(R.menu.menu_sample, menu); 53 | return true; 54 | } 55 | 56 | @Override 57 | public boolean onOptionsItemSelected(MenuItem item) { 58 | switch (item.getItemId()) { 59 | case R.id.action_simple: 60 | SimpleActivity.startActivity(this); 61 | return true; 62 | case R.id.action_paint: 63 | PaintActivity.startActivity(this); 64 | return true; 65 | case R.id.action_drawable: 66 | DrawableActivity.startActivity(this); 67 | return true; 68 | case R.id.action_complex: 69 | ComplexActivity.startActivity(this); 70 | return true; 71 | case R.id.action_simple_grid: 72 | SimpleGridActivity.startActivity(this); 73 | return true; 74 | default: 75 | return super.onOptionsItemSelected(item); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yqritc/recyclerviewflexibledivider/sample/ComplexAdapter.java: -------------------------------------------------------------------------------- 1 | package com.yqritc.recyclerviewflexibledivider.sample; 2 | 3 | import com.yqritc.recyclerviewflexibledivider.FlexibleDividerDecoration; 4 | import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration; 5 | 6 | import android.content.Context; 7 | import android.graphics.Color; 8 | import android.graphics.DashPathEffect; 9 | import android.graphics.Paint; 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.TextView; 15 | 16 | /** 17 | * Created by yqritc on 2015/01/08. 18 | */ 19 | public class ComplexAdapter extends RecyclerView.Adapter implements 20 | FlexibleDividerDecoration.PaintProvider, 21 | // FlexibleDividerDecoration.SizeProvider, 22 | // FlexibleDividerDecoration.ColorProvider, 23 | FlexibleDividerDecoration.VisibilityProvider, 24 | HorizontalDividerItemDecoration.MarginProvider { 25 | 26 | private static final int ITEM_SIZE = 20; 27 | 28 | private LayoutInflater mLayoutInflater; 29 | 30 | public ComplexAdapter(Context context) { 31 | super(); 32 | mLayoutInflater = LayoutInflater.from(context); 33 | } 34 | 35 | @Override 36 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 37 | View view = mLayoutInflater.inflate(R.layout.layout_sample_item, parent, false); 38 | return new ViewHolder(view); 39 | } 40 | 41 | @Override 42 | public void onBindViewHolder(ViewHolder holder, int position) { 43 | holder.mSampleText.setText(String.valueOf(position)); 44 | } 45 | 46 | @Override 47 | public int getItemCount() { 48 | return ITEM_SIZE; 49 | } 50 | 51 | @Override 52 | public Paint dividerPaint(int position, RecyclerView parent) { 53 | Paint paint = new Paint(); 54 | switch (position % 10) { 55 | case 0: 56 | paint.setColor(Color.RED); 57 | paint.setStrokeWidth(30); 58 | break; 59 | case 1: 60 | paint.setColor(Color.MAGENTA); 61 | paint.setStrokeWidth(10); 62 | break; 63 | default: 64 | if (position % 2 == 0) { 65 | paint.setColor(Color.BLUE); 66 | paint.setAntiAlias(true); 67 | paint.setPathEffect(new DashPathEffect(new float[]{25.0f, 25.0f}, 0)); 68 | } else { 69 | paint.setColor(Color.GREEN); 70 | 71 | } 72 | paint.setStrokeWidth(2 + position); 73 | break; 74 | } 75 | 76 | return paint; 77 | } 78 | 79 | // @Override 80 | // public int dividerColor(int position, RecyclerView parent) { 81 | // switch (position % 10) { 82 | // case 0: 83 | // return Color.RED; 84 | // case 1: 85 | // return Color.MAGENTA; 86 | // default: 87 | // if (position % 2 == 0) { 88 | // return Color.BLUE; 89 | // } else { 90 | // return Color.GREEN; 91 | // } 92 | // } 93 | // } 94 | // 95 | // @Override 96 | // public int dividerSize(int position, RecyclerView parent) { 97 | // switch (position % 10) { 98 | // case 0: 99 | // return 30; 100 | // case 1: 101 | // return 10; 102 | // default: 103 | // return 2+position; 104 | // } 105 | // } 106 | 107 | @Override 108 | public boolean shouldHideDivider(int position, RecyclerView parent) { 109 | if (position == 14 || position == 15) { 110 | return true; 111 | } 112 | return false; 113 | } 114 | 115 | @Override 116 | public int dividerLeftMargin(int position, RecyclerView parent) { 117 | if (position < 10) { 118 | return position * 20; 119 | } else { 120 | return (20 - position) * 20; 121 | } 122 | } 123 | 124 | @Override 125 | public int dividerRightMargin(int position, RecyclerView parent) { 126 | if (position < 10) { 127 | return position * 20 + 20; 128 | } else { 129 | return (20 - position) * 20 + 20; 130 | } 131 | } 132 | 133 | static class ViewHolder extends RecyclerView.ViewHolder { 134 | 135 | TextView mSampleText; 136 | 137 | public ViewHolder(View view) { 138 | super(view); 139 | mSampleText = (TextView) view.findViewById(R.id.text_sample); 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yqritc/recyclerviewflexibledivider/sample/DrawableActivity.java: -------------------------------------------------------------------------------- 1 | package com.yqritc.recyclerviewflexibledivider.sample; 2 | 3 | import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration; 4 | 5 | import android.app.Activity; 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.OrientationHelper; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.view.Menu; 13 | import android.view.MenuItem; 14 | 15 | 16 | public class DrawableActivity extends AppCompatActivity { 17 | 18 | public static void startActivity(Activity activity) { 19 | Intent intent = new Intent(activity, DrawableActivity.class); 20 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 21 | activity.startActivity(intent); 22 | } 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_sample); 28 | 29 | SimpleAdapter adapter = new SimpleAdapter(this); 30 | LinearLayoutManager manager = new LinearLayoutManager(this); 31 | manager.setOrientation(OrientationHelper.VERTICAL); 32 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_recyclerview); 33 | recyclerView.setLayoutManager(manager); 34 | recyclerView.setAdapter(adapter); 35 | recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this) 36 | .drawable(R.drawable.sample) 37 | .size(15) 38 | .build()); 39 | } 40 | 41 | 42 | @Override 43 | public boolean onCreateOptionsMenu(Menu menu) { 44 | getMenuInflater().inflate(R.menu.menu_sample, menu); 45 | return true; 46 | } 47 | 48 | @Override 49 | public boolean onOptionsItemSelected(MenuItem item) { 50 | switch (item.getItemId()) { 51 | case R.id.action_simple: 52 | SimpleActivity.startActivity(this); 53 | return true; 54 | case R.id.action_paint: 55 | PaintActivity.startActivity(this); 56 | return true; 57 | case R.id.action_drawable: 58 | DrawableActivity.startActivity(this); 59 | return true; 60 | case R.id.action_complex: 61 | ComplexActivity.startActivity(this); 62 | return true; 63 | case R.id.action_simple_grid: 64 | SimpleGridActivity.startActivity(this); 65 | return true; 66 | default: 67 | return super.onOptionsItemSelected(item); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yqritc/recyclerviewflexibledivider/sample/PaintActivity.java: -------------------------------------------------------------------------------- 1 | package com.yqritc.recyclerviewflexibledivider.sample; 2 | 3 | import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration; 4 | 5 | import android.app.Activity; 6 | import android.content.Intent; 7 | import android.graphics.Color; 8 | import android.graphics.DashPathEffect; 9 | import android.graphics.Paint; 10 | import android.os.Bundle; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.support.v7.widget.LinearLayoutManager; 13 | import android.support.v7.widget.OrientationHelper; 14 | import android.support.v7.widget.RecyclerView; 15 | import android.view.Menu; 16 | import android.view.MenuItem; 17 | import android.view.View; 18 | 19 | 20 | public class PaintActivity extends AppCompatActivity { 21 | 22 | public static void startActivity(Activity activity) { 23 | Intent intent = new Intent(activity, PaintActivity.class); 24 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 25 | activity.startActivity(intent); 26 | } 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_sample); 32 | 33 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_recyclerview); 34 | // Workaround for dash path effect 35 | // https://code.google.com/p/android/issues/detail?id=29944 36 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { 37 | recyclerView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 38 | } 39 | 40 | SimpleAdapter adapter = new SimpleAdapter(this); 41 | LinearLayoutManager manager = new LinearLayoutManager(this); 42 | manager.setOrientation(OrientationHelper.VERTICAL); 43 | recyclerView.setLayoutManager(manager); 44 | recyclerView.setAdapter(adapter); 45 | 46 | Paint paint = new Paint(); 47 | paint.setStrokeWidth(5); 48 | paint.setColor(Color.BLUE); 49 | paint.setAntiAlias(true); 50 | paint.setPathEffect(new DashPathEffect(new float[]{25.0f, 25.0f}, 0)); 51 | recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this) 52 | .paint(paint) 53 | .showLastDivider() 54 | .build()); 55 | } 56 | 57 | 58 | @Override 59 | public boolean onCreateOptionsMenu(Menu menu) { 60 | getMenuInflater().inflate(R.menu.menu_sample, menu); 61 | return true; 62 | } 63 | 64 | @Override 65 | public boolean onOptionsItemSelected(MenuItem item) { 66 | switch (item.getItemId()) { 67 | case R.id.action_simple: 68 | SimpleActivity.startActivity(this); 69 | return true; 70 | case R.id.action_paint: 71 | PaintActivity.startActivity(this); 72 | return true; 73 | case R.id.action_drawable: 74 | DrawableActivity.startActivity(this); 75 | return true; 76 | case R.id.action_complex: 77 | ComplexActivity.startActivity(this); 78 | return true; 79 | case R.id.action_simple_grid: 80 | SimpleGridActivity.startActivity(this); 81 | return true; 82 | default: 83 | return super.onOptionsItemSelected(item); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yqritc/recyclerviewflexibledivider/sample/SimpleActivity.java: -------------------------------------------------------------------------------- 1 | package com.yqritc.recyclerviewflexibledivider.sample; 2 | 3 | import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration; 4 | 5 | import android.app.Activity; 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.OrientationHelper; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.view.Menu; 13 | import android.view.MenuItem; 14 | 15 | 16 | public class SimpleActivity extends AppCompatActivity { 17 | 18 | public static void startActivity(Activity activity) { 19 | Intent intent = new Intent(activity, SimpleActivity.class); 20 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 21 | activity.startActivity(intent); 22 | } 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_sample); 28 | 29 | SimpleAdapter adapter = new SimpleAdapter(this); 30 | LinearLayoutManager manager = new LinearLayoutManager(this); 31 | manager.setOrientation(OrientationHelper.VERTICAL); 32 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_recyclerview); 33 | recyclerView.setLayoutManager(manager); 34 | recyclerView.setAdapter(adapter); 35 | recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).build()); 36 | } 37 | 38 | 39 | @Override 40 | public boolean onCreateOptionsMenu(Menu menu) { 41 | getMenuInflater().inflate(R.menu.menu_sample, menu); 42 | return true; 43 | } 44 | 45 | @Override 46 | public boolean onOptionsItemSelected(MenuItem item) { 47 | switch (item.getItemId()) { 48 | case R.id.action_simple: 49 | SimpleActivity.startActivity(this); 50 | return true; 51 | case R.id.action_paint: 52 | PaintActivity.startActivity(this); 53 | return true; 54 | case R.id.action_drawable: 55 | DrawableActivity.startActivity(this); 56 | return true; 57 | case R.id.action_complex: 58 | ComplexActivity.startActivity(this); 59 | return true; 60 | case R.id.action_simple_grid: 61 | SimpleGridActivity.startActivity(this); 62 | return true; 63 | default: 64 | return super.onOptionsItemSelected(item); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yqritc/recyclerviewflexibledivider/sample/SimpleAdapter.java: -------------------------------------------------------------------------------- 1 | package com.yqritc.recyclerviewflexibledivider.sample; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | /** 11 | * Created by yqritc on 2015/01/08. 12 | */ 13 | public class SimpleAdapter extends RecyclerView.Adapter { 14 | 15 | private LayoutInflater mLayoutInflater; 16 | 17 | public SimpleAdapter(Context context) { 18 | super(); 19 | mLayoutInflater = LayoutInflater.from(context); 20 | } 21 | 22 | @Override 23 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 24 | View view = mLayoutInflater.inflate(R.layout.layout_sample_item, parent, false); 25 | return new ViewHolder(view); 26 | } 27 | 28 | @Override 29 | public void onBindViewHolder(ViewHolder holder, int position) { 30 | holder.mSampleText.setText(String.valueOf(position)); 31 | } 32 | 33 | @Override 34 | public int getItemCount() { 35 | return 32; 36 | } 37 | 38 | static class ViewHolder extends RecyclerView.ViewHolder { 39 | 40 | TextView mSampleText; 41 | 42 | public ViewHolder(View view) { 43 | super(view); 44 | mSampleText = (TextView) view.findViewById(R.id.text_sample); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yqritc/recyclerviewflexibledivider/sample/SimpleGridActivity.java: -------------------------------------------------------------------------------- 1 | package com.yqritc.recyclerviewflexibledivider.sample; 2 | 3 | import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration; 4 | 5 | import android.app.Activity; 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.GridLayoutManager; 10 | import android.support.v7.widget.OrientationHelper; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.view.Menu; 13 | import android.view.MenuItem; 14 | 15 | 16 | public class SimpleGridActivity extends AppCompatActivity { 17 | 18 | public static void startActivity(Activity activity) { 19 | Intent intent = new Intent(activity, SimpleGridActivity.class); 20 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 21 | activity.startActivity(intent); 22 | } 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_sample); 28 | 29 | SimpleAdapter adapter = new SimpleAdapter(this); 30 | GridLayoutManager manager = new GridLayoutManager(this, 3); 31 | manager.setOrientation(OrientationHelper.VERTICAL); 32 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_recyclerview); 33 | recyclerView.setLayoutManager(manager); 34 | recyclerView.setAdapter(adapter); 35 | recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).build()); 36 | } 37 | 38 | 39 | @Override 40 | public boolean onCreateOptionsMenu(Menu menu) { 41 | getMenuInflater().inflate(R.menu.menu_sample, menu); 42 | return true; 43 | } 44 | 45 | @Override 46 | public boolean onOptionsItemSelected(MenuItem item) { 47 | switch (item.getItemId()) { 48 | case R.id.action_simple: 49 | SimpleActivity.startActivity(this); 50 | return true; 51 | case R.id.action_paint: 52 | PaintActivity.startActivity(this); 53 | return true; 54 | case R.id.action_drawable: 55 | DrawableActivity.startActivity(this); 56 | return true; 57 | case R.id.action_complex: 58 | ComplexActivity.startActivity(this); 59 | return true; 60 | case R.id.action_simple_grid: 61 | SimpleGridActivity.startActivity(this); 62 | return true; 63 | default: 64 | return super.onOptionsItemSelected(item); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/sample/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/sample.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/sample/src/main/res/drawable-hdpi/sample.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/sample/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/sample.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/sample/src/main/res/drawable-mdpi/sample.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/sample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/sample.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/sample/src/main/res/drawable-xhdpi/sample.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/sample/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/sample.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqritc/RecyclerView-FlexibleDivider/d654bff27600aac032ac318d76b002629510d2cf/sample/src/main/res/drawable-xxhdpi/sample.9.png -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_sample.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/layout_sample_item.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu_sample.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 13 | 17 | 21 | 25 | 26 | -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | FlexibleDivider Sample 5 | Simple Divider List 6 | Paint Divider List 7 | Drawable Divider List 8 | Complex Divider List 9 | Simple Divider Grid 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':library', ':sample' 2 | --------------------------------------------------------------------------------