├── .github ├── dependabot.yml └── workflows │ ├── build.yml │ ├── release.yml │ └── stale.yml ├── .gitignore ├── CODEOWNERS ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── api │ └── library.api ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── transferwise │ │ └── sequencelayout │ │ ├── Extensions.kt │ │ ├── SequenceAdapter.kt │ │ ├── SequenceLayout.kt │ │ ├── SequenceStep.kt │ │ └── SequenceStepDot.kt │ └── res │ ├── animator │ └── fading_pulse.xml │ ├── layout │ ├── sequence_dot.xml │ ├── sequence_layout.xml │ └── sequence_step.xml │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── integers.xml │ ├── strings.xml │ └── styles.xml ├── sample ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── transferwise │ │ └── sequencelayout │ │ └── sample │ │ └── MainActivity.kt │ └── res │ ├── layout │ └── activity_main.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gradle 4 | directory: "/" 5 | schedule: 6 | interval: weekly 7 | open-pull-requests-limit: 5 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | schedule: 11 | interval: weekly 12 | open-pull-requests-limit: 5 -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: [push, pull_request] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Checkout the code 8 | uses: actions/checkout@v4 9 | - name: Run Tests 10 | run: ./gradlew check --stacktrace -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | release: 4 | types: [created] 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout the code 10 | uses: actions/checkout@v4 11 | - name: Run Tests 12 | run: ./gradlew publish --stacktrace -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Maintenance 2 | 3 | permissions: 4 | issues: write 5 | pull-requests: write 6 | 7 | on: 8 | schedule: 9 | - cron: '30 1 * * *' 10 | 11 | jobs: 12 | stale: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/stale@v8 16 | with: 17 | repo-token: ${{ secrets.GITHUB_TOKEN }} 18 | 19 | stale-issue-message: 'This issue has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you for your contributions.' 20 | close-issue-message: 'This issue has now been closed. Please raise a new Issue instead of re-opening existing ones, unless you believe this was closed by accident.' 21 | days-before-issue-stale: 31 22 | days-before-issue-close: 7 23 | stale-issue-label: 'stale' 24 | only-issue-labels: 'awaiting-feedback' 25 | exempt-issue-labels: 'confirmed' 26 | 27 | stale-pr-message: 'This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you for your contributions.' 28 | close-pr-message: 'This pull request has now been closed. If you want to continue working on it or you believe it has been closed by accident, feel free to re-open it.' 29 | days-before-pr-stale: 31 30 | days-before-pr-close: 7 31 | stale-pr-label: 'stale' 32 | exempt-pr-labels: 'work-in-progress,dependencies' 33 | exempt-draft-pr: true 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | build/ 8 | /captures 9 | .externalNativeBuild 10 | .idea -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @transferwise/android -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute to sequence-layout 2 | 3 | ## **Did you find a bug?** 4 | 5 | * Ensure the bug was not already reported by searching on GitHub under [Issues](https://github.com/transferwise/sequence-layout/issues). 6 | 7 | * If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/transferwise/sequence-layout/issues/new). Be sure to include a title and clear description, as much relevant information as possible, and a code sample demonstrating the expected behavior that is not occurring. 8 | 9 | ## **Did you write a patch that fixes a bug?** 10 | 11 | * Open a new GitHub pull request with the patch. 12 | 13 | * Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable. 14 | 15 | ## **Do you intend to add a new feature or change an existing one?** 16 | 17 | * Suggest your change in the [Issues](https://github.com/transferwise/sequence-layout/issues) section and add the `feature-request` label. 18 | 19 | Thank you for feedback and contributions! 20 | 21 | The TransferWise Android team 22 | 23 | *These contribution guidelines have been adapted from https://github.com/rails/rails/blob/master/CONTRIBUTING.md* 24 | -------------------------------------------------------------------------------- /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 2018 TransferWise 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sequence-layout [![](https://jitpack.io/v/transferwise/sequence-layout.svg)](https://jitpack.io/#transferwise/sequence-layout) 2 | 3 | A vertical sequence UI component for Android. 4 | 5 | Animates a progress bar to the first active step in the sequence and then periodically runs a pulse animation on that step. 6 | 7 | ## Setup 8 | 9 | Add the JitPack maven repository to your root `build.gradle`: 10 | ```groovy 11 | allprojects { 12 | repositories { 13 | maven { url "https://jitpack.io" } 14 | } 15 | } 16 | ``` 17 | 18 | And then the actual library dependency to your module's `build.gradle`: 19 | 20 | ```groovy 21 | dependencies { 22 | implementation 'com.github.transferwise:sequence-layout:... // use latest version' 23 | } 24 | ``` 25 | 26 | ## Usage 27 | 28 | Take a look at the `sample` app in this repository. 29 | 30 | ### In XML layout 31 | You can define steps in your XML layout: 32 | 33 | ```xml 34 | 37 | 38 | 43 | 44 | 48 | 49 | 57 | 58 | 62 | 63 | 68 | 69 | ``` 70 | 71 | Custom attributes for `SequenceLayout`: 72 | 73 | | Attribute | Description | 74 | | --- | --- | 75 | | `progressForegroundColor` | foreground color of the progress bar | 76 | | `progressBackgroundColor` | background color of the progress bar | 77 | 78 | Custom attributes for `SequenceStep`: 79 | 80 | | Attribute | Description | 81 | | --- | --- | 82 | | `active` | boolean to indicate if step is active. There should only be one active step per `SequenceLayout`. | 83 | | `anchor` | text for the left side of the step | 84 | | `anchorMinWidth` | minimum width for the left side of the step | 85 | | `anchorMaxWidth` | maximum width for the left side of the step | 86 | | `anchorTextAppearance` | styling for the left side of the step | 87 | | `title` | title of the step | 88 | | `titleTextAppearance` | styling for the title of the step | 89 | | `subtitle` | subtitle of the step | 90 | | `subtitleTextAppearance` | styling for the subtitle of the step | 91 | 92 | ### Programmatically 93 | 94 | Alternatively, define an adapter that extends `SequenceAdapter`, like this: 95 | 96 | ```kotlin 97 | class MyAdapter(private val items: List) : SequenceAdapter() { 98 | 99 | override fun getCount(): Int { 100 | return items.size 101 | } 102 | 103 | override fun getItem(position: Int): MyItem { 104 | return items[position] 105 | } 106 | 107 | override fun bindView(sequenceStep: SequenceStep, item: MyItem) { 108 | with(sequenceStep) { 109 | setActive(item.isActive) 110 | setAnchor(item.formattedDate) 111 | setAnchorTextAppearance(...) 112 | setTitle(item.title) 113 | setTitleTextAppearance() 114 | setSubtitle(...) 115 | setSubtitleTextAppearance(...) 116 | } 117 | } 118 | 119 | data class MyItem(val isActive: Boolean, 120 | val formattedDate: String, 121 | val title: String) 122 | } 123 | ``` 124 | 125 | ... and use it for a `SequenceLayout`: 126 | 127 | ```kotlin 128 | val items = listOf(MyItem(...), MyItem(...), MyItem(...)) 129 | sequenceLayout.setAdapter(MyAdapter(items)) 130 | ``` 131 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | dependencies { 7 | classpath("com.android.tools.build:gradle:7.0.4") 8 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21") 9 | classpath("com.github.dcendents:android-maven-gradle-plugin:2.1") 10 | } 11 | } 12 | 13 | allprojects { 14 | repositories { 15 | google() 16 | mavenCentral() 17 | } 18 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | org.gradle.parallel=true 15 | 16 | android.enableJetifier=true 17 | android.useAndroidX=true 18 | 19 | android.defaults.buildfeatures.buildconfig=false -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/transferwise/sequence-layout/a6e5ed11026cdfeb363ecb6de3fc2e30ce27be6f/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/api/library.api: -------------------------------------------------------------------------------- 1 | public final class com/transferwise/sequencelayout/ExtensionsKt { 2 | public static final fun children (Landroid/view/ViewGroup;)Ljava/util/List; 3 | public static final fun toPx (I)I 4 | } 5 | 6 | public abstract class com/transferwise/sequencelayout/SequenceAdapter { 7 | public fun ()V 8 | public abstract fun bindView (Lcom/transferwise/sequencelayout/SequenceStep;Ljava/lang/Object;)V 9 | public abstract fun getCount ()I 10 | public abstract fun getItem (I)Ljava/lang/Object; 11 | } 12 | 13 | public final class com/transferwise/sequencelayout/SequenceLayout : android/widget/FrameLayout, com/transferwise/sequencelayout/SequenceStep$OnStepChangedListener { 14 | public fun (Landroid/content/Context;)V 15 | public fun (Landroid/content/Context;Landroid/util/AttributeSet;)V 16 | public fun (Landroid/content/Context;Landroid/util/AttributeSet;I)V 17 | public fun addView (Landroid/view/View;ILandroid/view/ViewGroup$LayoutParams;)V 18 | public fun onStepChanged ()V 19 | public final fun removeAllSteps ()V 20 | public final fun setAdapter (Lcom/transferwise/sequencelayout/SequenceAdapter;)V 21 | public final fun setProgressBackgroundColor (I)V 22 | public final fun setProgressForegroundColor (I)V 23 | public final fun setStyle (I)V 24 | } 25 | 26 | public final class com/transferwise/sequencelayout/SequenceStep : android/widget/TableRow { 27 | public fun (Landroid/content/Context;)V 28 | public fun (Landroid/content/Context;Landroid/util/AttributeSet;)V 29 | public final fun getDotOffset ()I 30 | public final fun isActive ()Z 31 | public final fun setActive (Z)V 32 | public final fun setAnchor (Ljava/lang/CharSequence;)V 33 | public final fun setAnchorMaxWidth (I)V 34 | public final fun setAnchorMinWidth (I)V 35 | public final fun setAnchorTextAppearance (I)V 36 | public final fun setSubtitle (I)V 37 | public final fun setSubtitle (Ljava/lang/CharSequence;)V 38 | public final fun setSubtitleTextAppearance (I)V 39 | public final fun setTitle (I)V 40 | public final fun setTitle (Ljava/lang/CharSequence;)V 41 | public final fun setTitleTextAppearance (I)V 42 | } 43 | 44 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.library") 3 | id("kotlin-android") 4 | id("maven-publish") 5 | id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2" 6 | } 7 | 8 | android { 9 | compileSdk 34 10 | 11 | defaultConfig { 12 | minSdkVersion(16) 13 | targetSdkVersion(34) 14 | setProperty("archivesBaseName", "com.transferwise.sequencelayout-${versionName}") 15 | } 16 | 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | 24 | compileOptions { 25 | sourceCompatibility = JavaVersion.VERSION_1_8 26 | targetCompatibility = JavaVersion.VERSION_1_8 27 | } 28 | 29 | kotlinOptions { 30 | jvmTarget = JavaVersion.VERSION_1_8.toString() 31 | } 32 | } 33 | 34 | ext { 35 | PUBLISH_GROUP_ID = "com.github.transferwise" 36 | PUBLISH_ARTIFACT_ID = "sequence-layout" 37 | PUBLISH_VERSION = "1.1.1" 38 | } 39 | 40 | group = PUBLISH_GROUP_ID 41 | version = PUBLISH_VERSION 42 | 43 | afterEvaluate { 44 | publishing { 45 | publications { 46 | release(MavenPublication) { 47 | from components.release 48 | 49 | groupId = PUBLISH_GROUP_ID 50 | artifactId = PUBLISH_ARTIFACT_ID 51 | version = PUBLISH_VERSION 52 | 53 | pom { 54 | name = PUBLISH_ARTIFACT_ID 55 | url = "https://github.com/transferwise/sequence-layout" 56 | licenses { 57 | license { 58 | name = "The Apache License, Version 2.0" 59 | url = "http://www.apache.org/licenses/LICENSE-2.0.txt" 60 | } 61 | } 62 | scm { 63 | connection = "scm:git:github.com/transferwise/sequence-layout.git" 64 | developerConnection = "scm:git:ssh://github.com/transferwise/sequence-layout.git" 65 | url = "https://github.com/transferwise/sequence-layout/tree/master" 66 | } 67 | } 68 | } 69 | } 70 | } 71 | } 72 | 73 | dependencies { 74 | implementation("androidx.appcompat:appcompat:1.4.1") 75 | implementation("androidx.core:core-ktx:1.7.0") 76 | } 77 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /library/src/main/java/com/transferwise/sequencelayout/Extensions.kt: -------------------------------------------------------------------------------- 1 | package com.transferwise.sequencelayout 2 | 3 | import android.content.res.Resources 4 | import android.view.ViewGroup 5 | 6 | fun Int.toPx() = (this * Resources.getSystem().displayMetrics.density).toInt() 7 | 8 | fun ViewGroup.children() = 0.until(childCount).map { getChildAt(it) } -------------------------------------------------------------------------------- /library/src/main/java/com/transferwise/sequencelayout/SequenceAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.transferwise.sequencelayout 2 | 3 | /** 4 | * Adapter to bind data to [com.transferwise.sequencelayout.SequenceStep]s for a [com.transferwise.sequencelayout.SequenceLayout]. 5 | */ 6 | public abstract class SequenceAdapter where T : Any { 7 | 8 | abstract fun getCount(): Int 9 | 10 | abstract fun getItem(position: Int): T 11 | 12 | abstract fun bindView(sequenceStep: SequenceStep, item: T) 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/transferwise/sequencelayout/SequenceLayout.kt: -------------------------------------------------------------------------------- 1 | package com.transferwise.sequencelayout 2 | 3 | import android.content.Context 4 | import android.content.res.TypedArray 5 | import android.graphics.Rect 6 | import android.util.AttributeSet 7 | import android.view.Gravity 8 | import android.view.LayoutInflater 9 | import android.view.View 10 | import android.view.ViewGroup 11 | import android.view.animation.LinearInterpolator 12 | import android.widget.FrameLayout 13 | import androidx.annotation.ColorInt 14 | import androidx.annotation.StyleRes 15 | import androidx.core.view.ViewCompat 16 | 17 | /** 18 | * Vertical step tracker that contains {@link com.transferwise.sequencelayout.SequenceStep}s and animates to the first active step. 19 | * 20 | *
 21 |  * <com.transferwise.sequencelayout.SequenceLayout
 22 |  *      android:layout_width="match_parent"
 23 |  *      android:layout_height="wrap_content"
 24 |  *      app:progressForegroundColor="?colorAccent"
 25 |  *      app:progressBackgroundColor="#ddd">
 26 |  *
 27 |  *      <com.transferwise.sequencelayout.SequenceStep ... />
 28 |  *      <com.transferwise.sequencelayout.SequenceStep app:active="true" ... />
 29 |  *      <com.transferwise.sequencelayout.SequenceStep ... />
 30 |  *
 31 |  * </com.transferwise.sequencelayout.SequenceLayout>
 32 |  * 
33 | * 34 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceLayout_progressForegroundColor 35 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceLayout_progressBackgroundColor 36 | * 37 | * @see com.transferwise.sequencelayout.SequenceStep 38 | */ 39 | public class SequenceLayout(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : 40 | FrameLayout(context, attrs, defStyleAttr), SequenceStep.OnStepChangedListener { 41 | 42 | public constructor(context: Context) : this(context, null) 43 | public constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) 44 | 45 | init { 46 | LayoutInflater.from(getContext()).inflate(R.layout.sequence_layout, this, true) 47 | } 48 | 49 | private val progressBarForeground = findViewById(R.id.progressBarForeground) 50 | private val progressBarBackground = findViewById(R.id.progressBarBackground) 51 | private val progressBarWrapper = findViewById(R.id.progressBarWrapper) 52 | private val stepsWrapper = findViewById(R.id.stepsWrapper) 53 | private val dotsWrapper = findViewById(R.id.dotsWrapper) 54 | 55 | init { 56 | val attributes = getContext().theme.obtainStyledAttributes( 57 | attrs, 58 | R.styleable.SequenceLayout, 59 | 0, 60 | R.style.SequenceLayout 61 | ) 62 | applyAttributes(attributes) 63 | attributes.recycle() 64 | 65 | clipToPadding = false 66 | clipChildren = false 67 | } 68 | 69 | @ColorInt 70 | private var progressBackgroundColor: Int = 0 71 | 72 | @ColorInt 73 | private var progressForegroundColor: Int = 0 74 | 75 | 76 | public fun setStyle(@StyleRes defStyleAttr: Int) { 77 | val attributes = 78 | context.theme.obtainStyledAttributes(defStyleAttr, R.styleable.SequenceLayout) 79 | applyAttributes(attributes) 80 | attributes.recycle() 81 | } 82 | 83 | /** 84 | * Sets the progress bar color 85 | * 86 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceLayout_progressForegroundColor 87 | */ 88 | public fun setProgressForegroundColor(@ColorInt color: Int) { 89 | this.progressForegroundColor = color 90 | progressBarForeground.setBackgroundColor(color) 91 | //TODO apply to existing steps 92 | } 93 | 94 | /** 95 | * Sets background resource for the dot of each contained step 96 | * 97 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceLayout_dotBackground 98 | */ 99 | public fun setProgressBackgroundColor(@ColorInt progressBackgroundColor: Int) { 100 | this.progressBackgroundColor = progressBackgroundColor 101 | progressBarBackground.setBackgroundColor(progressBackgroundColor) 102 | //TODO apply to existing steps 103 | } 104 | 105 | /** 106 | * Removes all contained [com.transferwise.sequencelayout.SequenceStep]s 107 | */ 108 | public fun removeAllSteps() { 109 | stepsWrapper.removeAllViews() 110 | } 111 | 112 | /** 113 | * Replaces all contained [com.transferwise.sequencelayout.SequenceStep]s with those provided and bound by the adapter 114 | */ 115 | public fun setAdapter(adapter: SequenceAdapter) where T : Any { 116 | removeCallbacks(animateToActive) 117 | removeAllSteps() 118 | val count = adapter.getCount() 119 | for (i in 0 until count) { 120 | val item = adapter.getItem(i) 121 | val view = SequenceStep(context) 122 | adapter.bindView(view, item) 123 | addView(view) 124 | } 125 | } 126 | 127 | private fun applyAttributes(attributes: TypedArray) { 128 | setupProgressForegroundColor(attributes) 129 | setupProgressBackgroundColor(attributes) 130 | } 131 | 132 | private fun setupProgressForegroundColor(attributes: TypedArray) { 133 | setProgressForegroundColor( 134 | attributes.getColor( 135 | R.styleable.SequenceLayout_progressForegroundColor, 136 | 0 137 | ) 138 | ) 139 | } 140 | 141 | private fun setupProgressBackgroundColor(attributes: TypedArray) { 142 | setProgressBackgroundColor( 143 | attributes.getColor( 144 | R.styleable.SequenceLayout_progressBackgroundColor, 145 | 0 146 | ) 147 | ) 148 | } 149 | 150 | private fun setProgressBarHorizontalOffset() { 151 | val firstAnchor: View = stepsWrapper.getChildAt(0).findViewById(R.id.anchor) 152 | progressBarWrapper.translationX = 153 | firstAnchor.measuredWidth + 4.toPx() - (progressBarWrapper.measuredWidth / 2f) //TODO dynamic dot size 154 | } 155 | 156 | private fun placeDots() { 157 | dotsWrapper.removeAllViews() 158 | var firstOffset = 0 159 | var lastOffset = 0 160 | 161 | stepsWrapper.children().forEachIndexed { i, view -> 162 | val sequenceStep = view as SequenceStep 163 | val sequenceStepDot = SequenceStepDot(context) 164 | sequenceStepDot.setDotBackground(progressForegroundColor, progressBackgroundColor) 165 | sequenceStepDot.setPulseColor(progressForegroundColor) 166 | sequenceStepDot.clipChildren = false 167 | sequenceStepDot.clipToPadding = false 168 | val layoutParams = LayoutParams(8.toPx(), 8.toPx()) //TODO dynamic dot size 169 | val totalDotOffset = getRelativeTop( 170 | sequenceStep, 171 | stepsWrapper 172 | ) + sequenceStep.paddingTop + sequenceStep.getDotOffset() + 2.toPx() //TODO dynamic dot size 173 | layoutParams.topMargin = totalDotOffset 174 | layoutParams.gravity = Gravity.CENTER_HORIZONTAL 175 | dotsWrapper.addView(sequenceStepDot, layoutParams) 176 | if (i == 0) { 177 | firstOffset = totalDotOffset 178 | } 179 | lastOffset = totalDotOffset 180 | } 181 | 182 | val backgroundLayoutParams = progressBarBackground.layoutParams as MarginLayoutParams 183 | backgroundLayoutParams.topMargin = firstOffset + 4.toPx() //TODO dynamic dot size 184 | backgroundLayoutParams.height = lastOffset - firstOffset 185 | progressBarBackground.requestLayout() 186 | 187 | val foregroundLayoutParams = progressBarForeground.layoutParams as MarginLayoutParams 188 | foregroundLayoutParams.topMargin = firstOffset + 4.toPx() //TODO dynamic dot size 189 | foregroundLayoutParams.height = lastOffset - firstOffset 190 | progressBarForeground.requestLayout() 191 | } 192 | 193 | private val animateToActive = { 194 | progressBarForeground.visibility = VISIBLE 195 | progressBarForeground.pivotY = 0f 196 | progressBarForeground.scaleY = 0f 197 | 198 | val activeStepIndex = 199 | stepsWrapper.children().indexOfFirst { it is SequenceStep && it.isActive() } 200 | 201 | if (activeStepIndex != -1) { 202 | val activeDot = dotsWrapper.getChildAt(activeStepIndex) 203 | val activeDotTopMargin = (activeDot.layoutParams as LayoutParams).topMargin 204 | val progressBarForegroundTopMargin = 205 | (progressBarForeground.layoutParams as LayoutParams).topMargin 206 | val scaleEnd = 207 | (activeDotTopMargin + (activeDot.measuredHeight / 2) - progressBarForegroundTopMargin) / 208 | progressBarBackground.measuredHeight.toFloat() 209 | 210 | ViewCompat.animate(progressBarForeground) 211 | .setStartDelay(resources.getInteger(R.integer.sequence_step_duration).toLong()) 212 | .scaleY(scaleEnd) 213 | .setInterpolator(LinearInterpolator()) 214 | .setDuration( 215 | activeStepIndex * resources.getInteger(R.integer.sequence_step_duration) 216 | .toLong() 217 | ) 218 | .setUpdateListener { 219 | val animatedOffset = 220 | progressBarForeground.scaleY * progressBarBackground.measuredHeight 221 | dotsWrapper 222 | .children() 223 | .forEachIndexed { i, view -> 224 | if (i > activeStepIndex) { 225 | return@forEachIndexed 226 | } 227 | val dot = view as SequenceStepDot 228 | val dotTopMargin = (dot.layoutParams as LayoutParams).topMargin - 229 | progressBarForegroundTopMargin - 230 | (dot.measuredHeight / 2) 231 | if (animatedOffset >= dotTopMargin) { 232 | if (i < activeStepIndex && !dot.isEnabled) { 233 | dot.isEnabled = true 234 | } else if (i == activeStepIndex && !dot.isActivated) { 235 | dot.isActivated = true 236 | } 237 | } 238 | } 239 | } 240 | .start() 241 | } 242 | } 243 | 244 | private fun getRelativeTop(child: View, parent: ViewGroup): Int { 245 | val offsetViewBounds = Rect() 246 | child.getDrawingRect(offsetViewBounds) 247 | parent.offsetDescendantRectToMyCoords(child, offsetViewBounds) 248 | return offsetViewBounds.top 249 | } 250 | 251 | override fun addView(child: View, index: Int, params: ViewGroup.LayoutParams) { 252 | if (child is SequenceStep) { 253 | if (child.isActive()) { 254 | child.setPadding( 255 | 0, 256 | if (stepsWrapper.childCount == 0) 0 else resources.getDimensionPixelSize(R.dimen.sequence_active_step_padding_top), //no paddingTop if first step is active 257 | 0, 258 | resources.getDimensionPixelSize(R.dimen.sequence_active_step_padding_bottom) 259 | ) 260 | } 261 | child.onStepChangedListener = this 262 | stepsWrapper.addView(child, params) 263 | return 264 | } 265 | super.addView(child, index, params) 266 | } 267 | 268 | override fun onStepChanged() { 269 | setProgressBarHorizontalOffset() 270 | placeDots() 271 | removeCallbacks(animateToActive) 272 | post(animateToActive) 273 | } 274 | } -------------------------------------------------------------------------------- /library/src/main/java/com/transferwise/sequencelayout/SequenceStep.kt: -------------------------------------------------------------------------------- 1 | package com.transferwise.sequencelayout 2 | 3 | import android.content.Context 4 | import android.content.res.TypedArray 5 | import android.util.AttributeSet 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.widget.TableRow 9 | import android.widget.TextView 10 | import androidx.annotation.Dimension 11 | import androidx.annotation.StringRes 12 | import androidx.annotation.StyleRes 13 | import androidx.core.view.doOnPreDraw 14 | import androidx.core.widget.TextViewCompat 15 | import kotlin.math.max 16 | 17 | /** 18 | * Step, represented in a row inside of {@link com.transferwise.sequencelayout.SequenceLayout}. 19 | * 20 | *
 21 |  * <com.transferwise.sequencelayout.SequenceStep
 22 |  *      android:layout_width="match_parent"
 23 |  *      android:layout_height="wrap_content"
 24 |  *      app:active="true"
 25 |  *      app:anchor="Anchor"
 26 |  *      app:anchorMinWidth="20dp"
 27 |  *      app:anchorMaxWidth="80dp"
 28 |  *      app:anchorTextAppearance="@style/TextAppearance.AppCompat.Small"
 29 |  *      app:subtitle="This is a subtitle"
 30 |  *      app:subtitleTextAppearance="@style/TextAppearance.AppCompat.Body1"
 31 |  *      app:title="Third step"
 32 |  *      app:titleTextAppearance="@style/TextAppearance.AppCompat.Title" />
 33 |  * 
34 | * 35 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_anchor 36 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_anchorTextAppearance 37 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_anchorMinWidth 38 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_anchorMaxWidth 39 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_anchorTextAppearance 40 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_title 41 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_titleTextAppearance 42 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_subtitle 43 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_subtitleTextAppearance 44 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_active 45 | * 46 | * @see com.transferwise.sequencelayout.SequenceLayout 47 | */ 48 | public class SequenceStep(context: Context?, attrs: AttributeSet?) : TableRow(context, attrs) { 49 | 50 | public constructor(context: Context) : this(context, null) 51 | 52 | private var isActive: Boolean = false 53 | internal var onStepChangedListener: OnStepChangedListener? = null 54 | 55 | init { 56 | LayoutInflater.from(getContext()).inflate(R.layout.sequence_step, this, true) 57 | } 58 | 59 | private val anchor = findViewById(R.id.anchor) 60 | private val title = findViewById(R.id.title) 61 | private val subtitle = findViewById(R.id.subtitle) 62 | 63 | init { 64 | clipToPadding = false 65 | clipChildren = false 66 | 67 | val attributes = getContext().theme.obtainStyledAttributes( 68 | attrs, 69 | R.styleable.SequenceStep, 70 | 0, 71 | R.style.SequenceStep 72 | ) 73 | 74 | setupAnchor(attributes) 75 | setupAnchorWidth(attributes) 76 | setupAnchorTextAppearance(attributes) 77 | setupTitle(attributes) 78 | setupTitleTextAppearance(attributes) 79 | setupSubtitle(attributes) 80 | setupSubtitleTextAppearance(attributes) 81 | setupActive(attributes) 82 | 83 | attributes.recycle() 84 | } 85 | 86 | /** 87 | * Sets the anchor label 88 | * 89 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_anchor 90 | */ 91 | public fun setAnchor(anchor: CharSequence?) { 92 | this.anchor.text = anchor 93 | this.anchor.visibility = View.VISIBLE 94 | this.anchor.minWidth = resources.getDimensionPixelSize(R.dimen.sequence_anchor_min_width) 95 | } 96 | 97 | /** 98 | * Sets the anchor max width 99 | */ 100 | public fun setAnchorMaxWidth(@Dimension(unit = Dimension.PX) maxWidth: Int) { 101 | anchor.maxWidth = maxWidth 102 | } 103 | 104 | /** 105 | * Sets the anchor min width 106 | */ 107 | public fun setAnchorMinWidth(@Dimension(unit = Dimension.PX) minWidth: Int) { 108 | anchor.minWidth = minWidth 109 | } 110 | 111 | /** 112 | * Sets the anchor text appearance 113 | * 114 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_anchorTextAppearance 115 | */ 116 | public fun setAnchorTextAppearance(@StyleRes resourceId: Int) { 117 | TextViewCompat.setTextAppearance(anchor, resourceId) 118 | verticallyCenter(anchor, title) 119 | } 120 | 121 | /** 122 | * Sets the title label 123 | * 124 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_title 125 | */ 126 | public fun setTitle(title: CharSequence?) { 127 | this.title.text = title 128 | this.title.visibility = View.VISIBLE 129 | } 130 | 131 | /** 132 | * Sets the title label 133 | * 134 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_title 135 | */ 136 | public fun setTitle(@StringRes resId: Int) { 137 | setTitle(context.getString(resId)) 138 | } 139 | 140 | /** 141 | * Sets the anchor text appearance 142 | * 143 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_titleTextAppearance 144 | */ 145 | public fun setTitleTextAppearance(@StyleRes resourceId: Int) { 146 | TextViewCompat.setTextAppearance(title, resourceId) 147 | verticallyCenter(anchor, title) 148 | } 149 | 150 | /** 151 | * Sets the subtitle label 152 | * 153 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_subtitle 154 | */ 155 | public fun setSubtitle(subtitle: CharSequence?) { 156 | this.subtitle.text = subtitle 157 | this.subtitle.visibility = View.VISIBLE 158 | } 159 | 160 | /** 161 | * Sets the subtitle label 162 | * 163 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_subtitle 164 | */ 165 | public fun setSubtitle(@StringRes resId: Int) { 166 | setSubtitle(context.getString(resId)) 167 | } 168 | 169 | /** 170 | * Sets the subtitle text appearance 171 | * 172 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_subtitleTextAppearance 173 | */ 174 | public fun setSubtitleTextAppearance(@StyleRes resourceId: Int) { 175 | TextViewCompat.setTextAppearance(subtitle, resourceId) 176 | } 177 | 178 | /** 179 | * Returns whether step is active step 180 | * 181 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_active 182 | */ 183 | public fun isActive(): Boolean { 184 | return isActive 185 | } 186 | 187 | /** 188 | * Sets whether step is active step 189 | * 190 | * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_active 191 | */ 192 | public fun setActive(isActive: Boolean) { 193 | this.isActive = isActive 194 | doOnPreDraw { onStepChangedListener?.onStepChanged() } 195 | } 196 | 197 | override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { 198 | super.onSizeChanged(w, h, oldw, oldh) 199 | doOnPreDraw { onStepChangedListener?.onStepChanged() } 200 | } 201 | 202 | fun getDotOffset(): Int = 203 | (max( 204 | getViewHeight(anchor), 205 | getViewHeight(title) 206 | ) - 8.toPx()) / 2 //TODO dynamic dot height 207 | 208 | private fun setupAnchor(attributes: TypedArray) { 209 | if (!attributes.hasValue(R.styleable.SequenceStep_anchor)) { 210 | anchor.visibility = View.INVISIBLE 211 | } else { 212 | setAnchor(attributes.getString(R.styleable.SequenceStep_anchor)) 213 | } 214 | } 215 | 216 | private fun setupAnchorWidth(attributes: TypedArray) { 217 | setAnchorMinWidth( 218 | attributes.getDimensionPixelSize( 219 | R.styleable.SequenceStep_anchorMinWidth, 220 | 0 221 | ) 222 | ) 223 | setAnchorMaxWidth( 224 | attributes.getDimensionPixelSize( 225 | R.styleable.SequenceStep_anchorMaxWidth, 226 | Integer.MAX_VALUE 227 | ) 228 | ) 229 | } 230 | 231 | private fun setupSubtitle(attributes: TypedArray) { 232 | if (!attributes.hasValue(R.styleable.SequenceStep_subtitle)) { 233 | subtitle.visibility = View.GONE 234 | } else { 235 | setSubtitle(attributes.getString(R.styleable.SequenceStep_subtitle)) 236 | } 237 | } 238 | 239 | private fun setupTitle(attributes: TypedArray) { 240 | if (!attributes.hasValue(R.styleable.SequenceStep_title)) { 241 | title.visibility = View.GONE 242 | } else { 243 | setTitle(attributes.getString(R.styleable.SequenceStep_title)) 244 | } 245 | } 246 | 247 | private fun setupTitleTextAppearance(attributes: TypedArray) { 248 | if (attributes.hasValue(R.styleable.SequenceStep_titleTextAppearance)) { 249 | setTitleTextAppearance( 250 | attributes.getResourceId( 251 | R.styleable.SequenceStep_titleTextAppearance, 252 | 0 253 | ) 254 | ) 255 | } 256 | } 257 | 258 | private fun setupSubtitleTextAppearance(attributes: TypedArray) { 259 | if (attributes.hasValue(R.styleable.SequenceStep_subtitleTextAppearance)) { 260 | setSubtitleTextAppearance( 261 | attributes.getResourceId( 262 | R.styleable.SequenceStep_subtitleTextAppearance, 263 | 0 264 | ) 265 | ) 266 | } 267 | } 268 | 269 | private fun setupAnchorTextAppearance(attributes: TypedArray) { 270 | if (attributes.hasValue(R.styleable.SequenceStep_anchorTextAppearance)) { 271 | setAnchorTextAppearance( 272 | attributes.getResourceId( 273 | R.styleable.SequenceStep_anchorTextAppearance, 274 | 0 275 | ) 276 | ) 277 | } 278 | } 279 | 280 | private fun setupActive(attributes: TypedArray) { 281 | setActive(attributes.getBoolean(R.styleable.SequenceStep_active, false)) 282 | } 283 | 284 | private fun verticallyCenter(vararg views: View) { 285 | val maxHeight = views.map(::getViewHeight).maxOrNull() ?: 0 286 | 287 | views.forEach { view -> 288 | val height = getViewHeight(view) 289 | (view.layoutParams as MarginLayoutParams).topMargin = (maxHeight - height) / 2 290 | view.requestLayout() 291 | } 292 | } 293 | 294 | private fun getViewHeight(view: View) = 295 | if (view is TextView) { 296 | ((view.lineHeight - view.lineSpacingExtra) / view.lineSpacingMultiplier).toInt() 297 | } else { 298 | view.measuredHeight 299 | } 300 | 301 | internal interface OnStepChangedListener { 302 | fun onStepChanged() 303 | } 304 | } -------------------------------------------------------------------------------- /library/src/main/java/com/transferwise/sequencelayout/SequenceStepDot.kt: -------------------------------------------------------------------------------- 1 | package com.transferwise.sequencelayout 2 | 3 | import android.animation.Animator 4 | import android.animation.AnimatorInflater 5 | import android.animation.AnimatorListenerAdapter 6 | import android.animation.AnimatorSet 7 | import android.content.Context 8 | import android.graphics.Color 9 | import android.graphics.drawable.GradientDrawable 10 | import android.graphics.drawable.GradientDrawable.OVAL 11 | import android.graphics.drawable.StateListDrawable 12 | import androidx.annotation.ColorInt 13 | import android.util.AttributeSet 14 | import android.view.LayoutInflater 15 | import android.view.View 16 | import android.widget.FrameLayout 17 | 18 | internal class SequenceStepDot @JvmOverloads constructor( 19 | context: Context, 20 | attrs: AttributeSet? = null, 21 | defStyleAttr: Int = 0 22 | ) : FrameLayout(context, attrs, defStyleAttr) { 23 | 24 | private var pulseAnimator: AnimatorSet? = null 25 | 26 | init { 27 | LayoutInflater.from(getContext()).inflate(R.layout.sequence_dot, this, true) 28 | } 29 | 30 | private val dotView = findViewById(R.id.dotView) 31 | private val pulseView = findViewById(R.id.pulseView) 32 | 33 | init { 34 | isEnabled = false 35 | } 36 | 37 | internal fun setDotBackground(@ColorInt color: Int, @ColorInt progressBackgroundColor: Int) { 38 | with(StateListDrawable()) { 39 | setEnterFadeDuration(resources.getInteger(R.integer.sequence_step_duration)) 40 | setExitFadeDuration(resources.getInteger(R.integer.sequence_step_duration)) 41 | 42 | addState(intArrayOf(android.R.attr.state_activated), 43 | with(GradientDrawable()) { 44 | shape = OVAL 45 | setColor(color) 46 | this 47 | }) 48 | addState(intArrayOf(android.R.attr.state_enabled), 49 | with(GradientDrawable()) { 50 | shape = OVAL 51 | setColor(color) 52 | setStroke(1.toPx(), Color.TRANSPARENT) 53 | this 54 | }) 55 | addState(intArrayOf(), 56 | with(GradientDrawable()) { 57 | shape = OVAL 58 | setColor(progressBackgroundColor) 59 | setStroke(1.toPx(), Color.TRANSPARENT) 60 | this 61 | }) 62 | dotView.background = this 63 | } 64 | } 65 | 66 | internal fun setPulseColor(@ColorInt color: Int) { 67 | with(GradientDrawable()) { 68 | shape = OVAL 69 | setColor(color) 70 | pulseView.background = this 71 | } 72 | } 73 | 74 | private fun setupAnimator() { 75 | pulseAnimator = 76 | (AnimatorInflater.loadAnimator(context, R.animator.fading_pulse) as AnimatorSet).apply { 77 | setTarget(pulseView) 78 | addListener(object : AnimatorListenerAdapter() { 79 | override fun onAnimationEnd(animator: Animator) { 80 | if (isActivated) { 81 | animator.start() 82 | } 83 | } 84 | }) 85 | start() 86 | } 87 | } 88 | 89 | private fun startAnimation() { 90 | pulseAnimator.let { 91 | if (it == null) { 92 | setupAnimator() 93 | } else if (it.isStarted) { 94 | return 95 | } 96 | pulseView.visibility = VISIBLE 97 | } 98 | } 99 | 100 | private fun stopAnimation() { 101 | pulseAnimator.let { 102 | if (it == null || !it.isStarted) { 103 | return 104 | } 105 | it.end() 106 | } 107 | pulseView.visibility = GONE 108 | } 109 | 110 | override fun setActivated(activated: Boolean) { 111 | super.setActivated(activated) 112 | if (!activated) { 113 | stopAnimation() 114 | } else { 115 | startAnimation() 116 | } 117 | } 118 | 119 | override fun setEnabled(enabled: Boolean) { 120 | super.setEnabled(enabled) 121 | if (!enabled) { 122 | stopAnimation() 123 | } else { 124 | startAnimation() 125 | } 126 | } 127 | 128 | override fun onDetachedFromWindow() { 129 | pulseAnimator?.apply { 130 | removeAllListeners() 131 | cancel() 132 | } 133 | pulseAnimator = null 134 | super.onDetachedFromWindow() 135 | } 136 | } -------------------------------------------------------------------------------- /library/src/main/res/animator/fading_pulse.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 20 | 21 | 27 | 28 | 29 | 30 | 35 | 36 | -------------------------------------------------------------------------------- /library/src/main/res/layout/sequence_dot.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 22 | 23 | -------------------------------------------------------------------------------- /library/src/main/res/layout/sequence_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 24 | 25 | 35 | 36 | 42 | 43 | 44 | 45 | 51 | -------------------------------------------------------------------------------- /library/src/main/res/layout/sequence_step.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 24 | 25 | 31 | 32 | 37 | 38 | 44 | 45 | -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /library/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ccc 4 | -------------------------------------------------------------------------------- /library/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12dp 4 | 16dp 5 | 48dp 6 | 80dp 7 | -------------------------------------------------------------------------------- /library/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 300 4 | 1000 5 | 3000 6 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SequenceLayout 3 | 4 | -------------------------------------------------------------------------------- /library/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 33 | 34 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("kotlin-android") 4 | } 5 | 6 | android { 7 | compileSdk 34 8 | defaultConfig { 9 | minSdkVersion(16) 10 | targetSdkVersion(34) 11 | applicationId = "com.transferwise.sequencelayout.sample" 12 | } 13 | compileOptions { 14 | sourceCompatibility JavaVersion.VERSION_1_8 15 | targetCompatibility JavaVersion.VERSION_1_8 16 | } 17 | } 18 | 19 | dependencies { 20 | implementation(project(":library")) 21 | implementation("androidx.appcompat:appcompat:1.4.1") 22 | } 23 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /sample/src/main/java/com/transferwise/sequencelayout/sample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.transferwise.sequencelayout.sample 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | 5 | class MainActivity : AppCompatActivity(R.layout.activity_main) 6 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 17 | 18 | 22 | 23 | 28 | 29 | 33 | 34 | 44 | 45 | 49 | 50 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SequenceLayout Sample 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ":library", ":sample" --------------------------------------------------------------------------------