├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── WelcomeCoordinator ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── redbooth │ │ ├── WelcomeCoordinatorLayout.java │ │ ├── WelcomeCoordinatorPageInflater.java │ │ ├── WelcomeCoordinatorTouchController.java │ │ ├── WelcomePageBehavior.java │ │ └── WelcomePageLayout.java │ └── res │ └── values │ └── attrs.xml ├── app ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── redbooth │ │ └── demo │ │ ├── AnimationFillWithColor.java │ │ ├── AnimationFlightTo.java │ │ ├── AnimationLaunch.java │ │ ├── MainActivity.java │ │ ├── ParallaxSubtitleBehaviour.java │ │ ├── ParallaxTitleBehaviour.java │ │ ├── RectangleWithCapCircleView.java │ │ └── animators │ │ ├── ChatAvatarsAnimator.java │ │ ├── InSyncAnimator.java │ │ ├── RocketAvatarsAnimator.java │ │ └── RocketFlightAwayAnimator.java │ └── res │ ├── drawable-xhdpi │ ├── arrow_chart.png │ ├── avatar_fred.png │ ├── avatar_jack.png │ ├── avatar_jack2.png │ ├── avatar_lucy.png │ ├── avatar_lucy2.png │ ├── avatar_maggie.png │ ├── avatar_maggie2.png │ ├── bubble_excellent.png │ ├── bubble_finished.png │ ├── easel.png │ ├── excellent.png │ ├── file.png │ ├── finished.png │ ├── rocket_flame.png │ ├── rocket_large.png │ └── star_large_no_shadow.png │ ├── drawable │ └── ic_rocket_144dp.xml │ ├── layout │ ├── activity_main.xml │ ├── welcome_page_1.xml │ ├── welcome_page_2.xml │ ├── welcome_page_3.xml │ └── welcome_page_4.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── assets ├── onboarding_demo.gif └── welcome_demo.gif ├── build.gradle ├── buildsystem └── dependencies.gradle ├── gradle.properties └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright Txus Ballesteros 2016 (@txusballesteros) 2 | # 3 | # This file is part of some open source application. 4 | # 5 | # Licensed to the Apache Software Foundation (ASF) under one 6 | # for more contributor license agreements. See the NOTICE file 7 | # distributed with this work for additional information 8 | # regarding copyright ownership. The ASF licenses this file 9 | # to you under the Apache License, Version 2.0 (the 10 | # "License"); you may not use this file except in compliance 11 | # with the License. You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, 16 | # software distributed under the License is distributed on an 17 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 | # KIND, either express or implied. See the License for the 19 | # specific language governing permissions and limitations 20 | # under the License. 21 | # 22 | # Contact: Txus Ballesteros 23 | 24 | # built application files 25 | *.apk 26 | *.ap_ 27 | 28 | # lint folder 29 | lint 30 | 31 | # files for the dex VM 32 | *.dex 33 | 34 | # Java class files 35 | *.class 36 | 37 | # generated files 38 | bin/ 39 | gen/ 40 | classes/ 41 | gen-external-apklibs/ 42 | 43 | # maven output folder 44 | target 45 | 46 | # Local configuration file (sdk path, etc) 47 | local.properties 48 | 49 | # Eclipse project files 50 | .classpath 51 | .project 52 | .metadata 53 | .settings 54 | 55 | # IntelliJ files 56 | .idea 57 | *.iml 58 | 59 | # OSX files 60 | .DS_Store 61 | 62 | # Windows files 63 | Thumbs.db 64 | 65 | # vi swap files 66 | *.swp 67 | 68 | # backup files 69 | *.bak 70 | 71 | # gradle directory 72 | .gradle 73 | gradlew 74 | gradlew.bat 75 | gradle/ 76 | build/ 77 | captures/ 78 | /local.properties -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | # 4 | # This file is part of some open source application. 5 | # 6 | # Licensed to the Apache Software Foundation (ASF) under one 7 | # or more contributor license agreements. See the NOTICE file 8 | # distributed with this work for additional information 9 | # regarding copyright ownership. The ASF licenses this file 10 | # to you under the Apache License, Version 2.0 (the 11 | # "License"); you may not use this file except in compliance 12 | # with the License. You may obtain a copy of the License at 13 | # 14 | # http://www.apache.org/licenses/LICENSE-2.0 15 | # 16 | # Unless required by applicable law or agreed to in writing, 17 | # software distributed under the License is distributed on an 18 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | # KIND, either express or implied. See the License for the 20 | # specific language governing permissions and limitations 21 | # under the License. 22 | # 23 | # Contact: Txus Ballesteros 24 | # 25 | 26 | language: android 27 | sudo: false 28 | jdk: oraclejdk7 29 | 30 | env: 31 | matrix: 32 | - ANDROID_TARGET=android-23 ANDROID_ABI=armeabi-v7a 33 | 34 | android: 35 | components: 36 | - tools 37 | - platform-tools 38 | - build-tools-23.0.2 39 | - android-23 40 | 41 | # Additional components 42 | - extra-google-m2repository 43 | - extra-android-m2repository 44 | - extra-android-support 45 | 46 | script: 47 | - gradle build -x lint -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WelcomeCoordinator 2 | ================== 3 | 4 | ![](assets/welcome_demo.gif) ![](assets/onboarding_demo.gif) 5 | 6 | Welcome Coordinator is a library for Android that will help you create really awesome welcome wizards for your apps, but that's not all. You can also use the library to create form wizards really nicely. Take a look to how you would integrate Welcome Coordinator into your app. 7 | 8 | ## Latest Version 9 | 10 | [![Download](https://api.bintray.com/packages/txusballesteros/maven/WelcomeCoordinator/images/download.svg) ](https://bintray.com/txusballesteros/maven/WelcomeCoordinator/_latestVersion) ![](https://img.shields.io/badge/platform-android-green.svg) ![](https://img.shields.io/badge/Min%20SDK-14-green.svg) ![](https://img.shields.io/badge/Licence-Apache%20v2-green.svg) [![Build Status](https://travis-ci.org/txusballesteros/welcome-coordinator.svg?branch=master)](https://travis-ci.org/txusballesteros/welcome-coordinator) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Welcome%20Coordinator-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3351) 11 | 12 | 13 | ## How to use 14 | 15 | ### 1.- Configuring your Project Dependencies 16 | 17 | Add the library dependency to your build.gradle file. 18 | 19 | ```groovy 20 | dependencies { 21 | ... 22 | compile 'com.redbooth:WelcomeCoordinator:1.0.1' 23 | } 24 | ``` 25 | 26 | ### 2.- Adding and Customizing the View 27 | 28 | Add the view to your xml layout file. 29 | 30 | ```xml 31 | 35 | ``` 36 | 37 | ### 3.- Modeling the Pages 38 | 39 | Modeling your welcome pages is really easy. You only need to create a simple layout resource. Let me an appointment about _WelcomePageLayout_, the behavior of the layout is the same of the RelativeLayout. 40 | 41 | ```xml 42 | 44 | 45 | ... 46 | 47 | 48 | ``` 49 | 50 | **WARNING** Don't forget to create a _WelcomePageLayout_ as the root element of your page. 51 | 52 | ### 4.- Adding the Pages to Coordinator 53 | 54 | ```java 55 | @Override 56 | protected void onCreate(Bundle savedInstanceState) { 57 | ... 58 | final WelcomeCoordinatorLayout coordinatorLayout 59 | = (WelcomeCoordinatorLayout)findViewById(R.id.coordinator); 60 | coordinatorLayout.addPage(R.layout.welcome_page_1, 61 | ..., 62 | R.layout.welcome_page_4); 63 | } 64 | ``` 65 | 66 | ### 5.- Building your own Behaviors 67 | 68 | If you want to have behavior on your page views when the user navigate inside of your welcome, you can create you own behaviors. 69 | 70 | ```java 71 | public class ParallaxTitleBehaviour extends WelcomePageBehavior { 72 | @Override 73 | protected void onCreate(WelcomeCoordinatorLayout coordinator) { 74 | ... 75 | } 76 | 77 | @Override 78 | protected void onPlaytimeChange(WelcomeCoordinatorLayout coordinator, 79 | float newPlaytime, 80 | float newScrollPosition) { 81 | ... 82 | } 83 | } 84 | ``` 85 | 86 | ### 6.- Setting Up Your Own Behaviors 87 | 88 | ```xml 89 | 90 | 93 | 94 | 97 | 98 | 99 | ``` 100 | 101 | ## Developers 102 | 103 | * Francisco Sirvent ([@Narfss](https://github.com/narfss)) 104 | * Txus Ballesteros ([@Txusballesteros](https://github.com/txusballesteros)) 105 | 106 | ## Motivation 107 | 108 | We created this view as a little piece of the [Redbooth](https://redbooth.com/) app for [Android](https://play.google.com/store/apps/details?id=com.redbooth). 109 | 110 | 111 | ## License 112 | 113 | Copyright Txus Ballesteros & Francisco Sirvent 2016 114 | 115 | This file is part of some open source application. 116 | 117 | Licensed to the Apache Software Foundation (ASF) under one 118 | or more contributor license agreements. See the NOTICE file 119 | distributed with this work for additional information 120 | regarding copyright ownership. The ASF licenses this file 121 | to you under the Apache License, Version 2.0 (the 122 | "License"); you may not use this file except in compliance 123 | with the License. You may obtain a copy of the License at 124 | 125 | http://www.apache.org/licenses/LICENSE-2.0 126 | 127 | Unless required by applicable law or agreed to in writing, 128 | software distributed under the License is distributed on an 129 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 130 | KIND, either express or implied. See the License for the 131 | specific language governing permissions and limitations 132 | under the License. 133 | -------------------------------------------------------------------------------- /WelcomeCoordinator/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright Txus Ballesteros 2016 (@txusballesteros) 2 | # 3 | # This file is part of some open source application. 4 | # 5 | # Licensed to the Apache Software Foundation (ASF) under one 6 | # for more contributor license agreements. See the NOTICE file 7 | # distributed with this work for additional information 8 | # regarding copyright ownership. The ASF licenses this file 9 | # to you under the Apache License, Version 2.0 (the 10 | # "License"); you may not use this file except in compliance 11 | # with the License. You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, 16 | # software distributed under the License is distributed on an 17 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 | # KIND, either express or implied. See the License for the 19 | # specific language governing permissions and limitations 20 | # under the License. 21 | # 22 | # Contact: Txus Ballesteros 23 | 24 | /build 25 | -------------------------------------------------------------------------------- /WelcomeCoordinator/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | apply plugin: 'com.android.library' 26 | apply plugin: 'com.novoda.bintray-release' 27 | 28 | def globalConfiguration = rootProject.extensions.getByName("ext") 29 | 30 | android { 31 | compileSdkVersion globalConfiguration.getAt("androidCompileSdkVersion") 32 | buildToolsVersion globalConfiguration.getAt("androidBuildToolsVersion") 33 | 34 | defaultConfig { 35 | minSdkVersion globalConfiguration.getAt("androidMinSdkVersion") 36 | targetSdkVersion globalConfiguration.getAt("androidTargetSdkVersion") 37 | versionCode globalConfiguration.getAt("androidVersionCode") 38 | versionName globalConfiguration.getAt("androidVersionName") 39 | } 40 | 41 | compileOptions { 42 | sourceCompatibility JavaVersion.VERSION_1_7 43 | targetCompatibility JavaVersion.VERSION_1_7 44 | } 45 | 46 | buildTypes { 47 | release { 48 | minifyEnabled false 49 | } 50 | } 51 | } 52 | 53 | dependencies { 54 | def libraryDependencies = globalConfiguration.libraryDependencies 55 | compile libraryDependencies.AndroidAnnotations 56 | } 57 | publish { 58 | // Properties properties = new Properties() 59 | // properties.load(project.rootProject.file('local.properties').newDataInputStream()) 60 | 61 | userOrg = globalConfiguration.getAt("jcenterUserOrganinzation") 62 | groupId = globalConfiguration.getAt("jcenterGroupId") 63 | artifactId = globalConfiguration.getAt("jcenterArtifactId") 64 | publishVersion = globalConfiguration.getAt("androidVersionName") 65 | desc = globalConfiguration.getAt("jcenterDescription") 66 | website = globalConfiguration.getAt("jcenterWebsite") 67 | repository = globalConfiguration.getAt("jcenterRepository") 68 | // bintrayUser = properties.getProperty("bintrayUser") 69 | // bintrayKey = properties.getProperty("bintrayKey") 70 | } 71 | 72 | -------------------------------------------------------------------------------- /WelcomeCoordinator/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | -------------------------------------------------------------------------------- /WelcomeCoordinator/src/main/java/com/redbooth/WelcomeCoordinatorLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth; 26 | 27 | import android.annotation.TargetApi; 28 | import android.content.Context; 29 | import android.content.res.TypedArray; 30 | import android.graphics.Canvas; 31 | import android.graphics.Color; 32 | import android.graphics.Paint; 33 | import android.graphics.Rect; 34 | import android.os.Build; 35 | import android.support.annotation.LayoutRes; 36 | import android.util.AttributeSet; 37 | import android.view.MotionEvent; 38 | import android.view.View; 39 | import android.view.ViewGroup; 40 | import android.widget.FrameLayout; 41 | import android.widget.HorizontalScrollView; 42 | 43 | import com.redbooth.welcomecoordinator.R; 44 | 45 | import java.util.ArrayList; 46 | import java.util.List; 47 | 48 | public class WelcomeCoordinatorLayout extends HorizontalScrollView { 49 | public static final boolean ANIMATED = true; 50 | public static final boolean INANIMATED = false; 51 | public static final int WITHOUT_MARGIN = 0; 52 | public static final int RADIUS = 12; 53 | public static final int RADIUS_MARGIN = 30; 54 | public static final int DEF_INDICATOR_UNSELECTED_COLOR = Color.WHITE; 55 | public static final int DEF_INDICATOR_SELECTED_COLOR = Color.BLACK; 56 | private WelcomeCoordinatorTouchController touchController; 57 | private WelcomeCoordinatorPageInflater pageInflater; 58 | private FrameLayout mainContentView; 59 | private List behaviors = new ArrayList<>(); 60 | private OnPageScrollListener onPageScrollListener; 61 | private int pageSelected = 0; 62 | private int indicatorColorUnselected = DEF_INDICATOR_UNSELECTED_COLOR; 63 | private int indicatorColorSelected = DEF_INDICATOR_SELECTED_COLOR; 64 | private Paint indicatorPaintUnselected; 65 | private Paint indicatorPaintSelected; 66 | private boolean showIndicators = true; 67 | private boolean scrollingEnabled = true; 68 | 69 | public WelcomeCoordinatorLayout(Context context) { 70 | super(context); 71 | initializeView(context, null); 72 | } 73 | 74 | public WelcomeCoordinatorLayout(Context context, AttributeSet attrs) { 75 | super(context, attrs); 76 | initializeView(context, attrs); 77 | } 78 | 79 | public WelcomeCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 80 | super(context, attrs, defStyleAttr); 81 | initializeView(context, attrs); 82 | } 83 | 84 | @Override 85 | protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { 86 | return true; 87 | } 88 | 89 | public void showIndicators(boolean show) { 90 | this.showIndicators = show; 91 | } 92 | 93 | public void setScrollingEnabled(boolean enabled) { 94 | this.scrollingEnabled = enabled; 95 | } 96 | 97 | @SuppressWarnings("unused") 98 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 99 | public WelcomeCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 100 | super(context, attrs, defStyleAttr, defStyleRes); 101 | initializeView(context, attrs); 102 | } 103 | 104 | public void addPage(@LayoutRes int... layoutResourceIds) { 105 | for (int i = layoutResourceIds.length - 1; i >= 0; i--) { 106 | int layoutResourceId = layoutResourceIds[i]; 107 | final View pageView = pageInflater.inflate(layoutResourceId); 108 | final List pageBehaviors = extractPageBehaviors(pageView); 109 | if (!pageBehaviors.isEmpty()) { 110 | this.behaviors.addAll(pageBehaviors); 111 | } 112 | mainContentView.addView(pageView); 113 | } 114 | if (onPageScrollListener != null) { 115 | onPageScrollListener.onPageSelected(this, 0); 116 | } 117 | requestLayout(); 118 | } 119 | 120 | private List extractPageBehaviors(View view) { 121 | List behaviors = new ArrayList<>(); 122 | if (view instanceof WelcomePageLayout) { 123 | final WelcomePageLayout pageLayout = (WelcomePageLayout)view; 124 | final List pageBehaviors = pageLayout.getBehaviors(this); 125 | if (!pageBehaviors.isEmpty()) { 126 | behaviors.addAll(pageBehaviors); 127 | } 128 | 129 | } 130 | return behaviors; 131 | } 132 | 133 | public int getNumOfPages() { 134 | int result = 0; 135 | if (mainContentView != null) { 136 | result = mainContentView.getChildCount(); 137 | } 138 | return result; 139 | } 140 | 141 | private void initializeView(Context context, AttributeSet attrs) { 142 | this.setHorizontalScrollBarEnabled(false); 143 | this.setOverScrollMode(OVER_SCROLL_NEVER); 144 | touchController = new WelcomeCoordinatorTouchController(this); 145 | pageInflater = new WelcomeCoordinatorPageInflater(this); 146 | extractAttributes(context, attrs); 147 | buildMainContentView(); 148 | attachMainContentView(); 149 | configureIndicatorColors(); 150 | } 151 | 152 | private void extractAttributes(Context context, AttributeSet attrs) { 153 | final TypedArray attributes 154 | = context.obtainStyledAttributes(attrs, R.styleable.WelcomeCoordinatorLayout); 155 | indicatorColorUnselected = attributes 156 | .getColor(R.styleable.WelcomeCoordinatorLayout_indicatorUnselected, DEF_INDICATOR_UNSELECTED_COLOR); 157 | indicatorColorSelected = attributes 158 | .getColor(R.styleable.WelcomeCoordinatorLayout_indicatorSelected, DEF_INDICATOR_SELECTED_COLOR); 159 | showIndicators = attributes 160 | .getBoolean(R.styleable.WelcomeCoordinatorLayout_showIndicators, showIndicators); 161 | scrollingEnabled = attributes 162 | .getBoolean(R.styleable.WelcomeCoordinatorLayout_scrollingEnabled, scrollingEnabled); 163 | attributes.recycle(); 164 | } 165 | 166 | private void buildMainContentView() { 167 | mainContentView = new FrameLayout(this.getContext()); 168 | mainContentView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 169 | LayoutParams.MATCH_PARENT)); 170 | mainContentView.setClipToPadding(false); 171 | mainContentView.setClipChildren(false); 172 | } 173 | 174 | private void attachMainContentView() { 175 | removeAllViews(); 176 | setClipChildren(false); 177 | addView(mainContentView); 178 | } 179 | 180 | private void configureIndicatorColors() { 181 | indicatorPaintUnselected = new Paint(); 182 | indicatorPaintUnselected.setColor(indicatorColorUnselected); 183 | indicatorPaintSelected = new Paint(); 184 | indicatorPaintSelected.setColor(indicatorColorSelected); 185 | } 186 | 187 | public void setIndicatorColorSelected(int indicatorColorSelected) { 188 | this.indicatorColorSelected = indicatorColorSelected; 189 | indicatorPaintSelected.setColor(indicatorColorSelected); 190 | } 191 | 192 | public void setIndicatorColorUnselected(int indicatorColorUnselected) { 193 | this.indicatorColorUnselected = indicatorColorUnselected; 194 | indicatorPaintUnselected.setColor(indicatorColorUnselected); 195 | } 196 | 197 | @Override 198 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 199 | for (int index = 0; index < getNumOfPages(); index++) { 200 | ViewGroup childAt = (ViewGroup) mainContentView.getChildAt(index); 201 | configurePageLayout(childAt, index); 202 | } 203 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 204 | } 205 | 206 | private void configurePageLayout(ViewGroup pageView, int position) { 207 | int coordinatorWidth = getMeasuredWidth(); 208 | int reversePosition = getNumOfPages() - 1 - position; 209 | int pageMarginLeft = (coordinatorWidth * reversePosition); 210 | int originalHeight = pageView.getLayoutParams().height; 211 | LayoutParams layoutParams = new LayoutParams(coordinatorWidth, originalHeight); 212 | layoutParams.setMargins(pageMarginLeft, WITHOUT_MARGIN, WITHOUT_MARGIN, WITHOUT_MARGIN); 213 | pageView.setLayoutParams(layoutParams); 214 | } 215 | 216 | @Override 217 | protected void dispatchDraw(Canvas canvas) { 218 | super.dispatchDraw(canvas); 219 | if (showIndicators) { 220 | drawIndicator(canvas); 221 | } 222 | } 223 | 224 | private void drawIndicator(Canvas canvas) { 225 | int centerX = (getWidth() - RADIUS)/2 + RADIUS/2; 226 | int indicatorWidth = RADIUS * 2; 227 | int indicatorAndMargin = indicatorWidth + RADIUS_MARGIN; 228 | int leftIndicators = centerX - ((getNumOfPages()-1) * indicatorAndMargin) / 2 ; 229 | int positionY = getHeight() - RADIUS - RADIUS_MARGIN; 230 | for (int i = 0; i < getNumOfPages(); i++) { 231 | int x = leftIndicators + indicatorAndMargin * i + getScrollX(); 232 | canvas.drawCircle(x, positionY, RADIUS, indicatorPaintUnselected); 233 | } 234 | float width = (float) getWidth(); 235 | float scrollProgress = getScrollX() / width; 236 | float selectedXPosition = leftIndicators + getScrollX() + scrollProgress * indicatorAndMargin; 237 | canvas.drawCircle(selectedXPosition, positionY, RADIUS, indicatorPaintSelected); 238 | } 239 | 240 | @Override 241 | public boolean onTouchEvent(MotionEvent event) { 242 | boolean touchEventCaptured = false; 243 | if (scrollingEnabled) { 244 | touchEventCaptured = touchController.onTouchEvent(event); 245 | if (!touchEventCaptured) { 246 | touchEventCaptured = super.onTouchEvent(event); 247 | } 248 | } 249 | return touchEventCaptured; 250 | } 251 | 252 | public void notifyProgressScroll(float progress, float scroll) { 253 | for (WelcomePageBehavior welcomePageBehavior : behaviors) { 254 | welcomePageBehavior.onPlaytimeChange(this, progress, scroll); 255 | } 256 | } 257 | 258 | public void setOnPageScrollListener(OnPageScrollListener onPageScrollListener) { 259 | this.onPageScrollListener = onPageScrollListener; 260 | touchController.setOnPageScrollListener(new WelcomeCoordinatorTouchController.OnPageScrollListener() { 261 | @Override 262 | public void onScrollPage(float progress) { 263 | int numOfPages = (getNumOfPages() - 1); 264 | int maximumScroll = getMeasuredWidth() * numOfPages; 265 | WelcomeCoordinatorLayout.this.onPageScrollListener.onScrollPage(WelcomeCoordinatorLayout.this, progress, maximumScroll); 266 | } 267 | 268 | @Override 269 | public void onPageSelected(int pageSelected) { 270 | WelcomeCoordinatorLayout.this.pageSelected = pageSelected; 271 | WelcomeCoordinatorLayout.this.onPageScrollListener.onPageSelected(WelcomeCoordinatorLayout.this, pageSelected); 272 | } 273 | }); 274 | } 275 | 276 | public int getPageSelected() { 277 | return pageSelected; 278 | } 279 | 280 | public void setCurrentPage(int newCurrentPage, boolean animated) { 281 | pageSelected = Math.max(0, Math.min(getNumOfPages() -1, newCurrentPage)); 282 | touchController.scrollToPage(pageSelected, animated); 283 | } 284 | 285 | public interface OnPageScrollListener { 286 | void onScrollPage(View v, float progress, float maximum); 287 | void onPageSelected(View v, int pageSelected); 288 | } 289 | } 290 | -------------------------------------------------------------------------------- /WelcomeCoordinator/src/main/java/com/redbooth/WelcomeCoordinatorPageInflater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth; 26 | 27 | import android.support.annotation.LayoutRes; 28 | import android.support.annotation.NonNull; 29 | import android.view.LayoutInflater; 30 | import android.view.View; 31 | import android.view.ViewGroup; 32 | 33 | class WelcomeCoordinatorPageInflater { 34 | private final WelcomeCoordinatorLayout view; 35 | private final LayoutInflater inflater; 36 | 37 | protected WelcomeCoordinatorPageInflater(@NonNull WelcomeCoordinatorLayout view) { 38 | this.view = view; 39 | this.inflater = LayoutInflater.from(view.getContext()); 40 | } 41 | 42 | protected View inflate(@LayoutRes int layoutResourceId) { 43 | final ViewGroup pageView = (ViewGroup)inflater.inflate(layoutResourceId, view, false); 44 | return pageView; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /WelcomeCoordinator/src/main/java/com/redbooth/WelcomeCoordinatorTouchController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth; 26 | 27 | import android.animation.Animator; 28 | import android.animation.ObjectAnimator; 29 | import android.animation.ValueAnimator; 30 | import android.os.Build; 31 | import android.view.MotionEvent; 32 | import android.view.VelocityTracker; 33 | import android.view.ViewTreeObserver; 34 | 35 | class WelcomeCoordinatorTouchController { 36 | public static final int MAX_VELOCITY = 300; 37 | public static final int CURRENT_VELOCITY = 1000; 38 | public static final long SMOOTH_SCROLL_DURATION = 300; 39 | public static final String PROPERTY_SCROLL_X = "scrollX"; 40 | private final WelcomeCoordinatorLayout view; 41 | private float iniEventX; 42 | private int currentScrollX; 43 | private int minScroll = 0; 44 | private int maxScroll = 0; 45 | private VelocityTracker velocityTracker; 46 | private ObjectAnimator smoothScrollAnimator; 47 | private OnPageScrollListener onPageScrollListener; 48 | 49 | public WelcomeCoordinatorTouchController(final WelcomeCoordinatorLayout view) { 50 | this.view = view; 51 | configureLayoutListener(); 52 | } 53 | 54 | private void configureLayoutListener() { 55 | view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 56 | @Override 57 | public void onGlobalLayout() { 58 | WelcomeCoordinatorLayout welcomeCoordinatorLayout 59 | = WelcomeCoordinatorTouchController.this.view; 60 | int pagesSteps = welcomeCoordinatorLayout.getNumOfPages() - 1; 61 | maxScroll = pagesSteps * welcomeCoordinatorLayout.getWidth(); 62 | ViewTreeObserver viewTreeObserver 63 | = welcomeCoordinatorLayout.getViewTreeObserver(); 64 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 65 | viewTreeObserver.removeOnGlobalLayoutListener(this); 66 | } else { 67 | viewTreeObserver.removeGlobalOnLayoutListener(this); 68 | } 69 | configureScrollListener(); 70 | } 71 | }); 72 | } 73 | 74 | private void configureScrollListener() { 75 | view.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { 76 | @Override 77 | public void onScrollChanged() { 78 | view.notifyProgressScroll(view.getScrollX() / (float) view.getWidth(), 79 | view.getScrollX()); 80 | } 81 | }); 82 | } 83 | 84 | protected boolean onTouchEvent(MotionEvent event) { 85 | switch (event.getAction()) { 86 | case MotionEvent.ACTION_DOWN: 87 | if (velocityTracker == null) { 88 | velocityTracker = VelocityTracker.obtain(); 89 | } else { 90 | velocityTracker.clear(); 91 | } 92 | velocityTracker.addMovement(event); 93 | currentScrollX = view.getScrollX(); 94 | iniEventX = event.getX(); 95 | break; 96 | case MotionEvent.ACTION_MOVE: 97 | setScrollX(scrollLimited(event.getX())); 98 | velocityTracker.addMovement(event); 99 | velocityTracker.computeCurrentVelocity(CURRENT_VELOCITY); 100 | break; 101 | case MotionEvent.ACTION_UP: 102 | case MotionEvent.ACTION_CANCEL: 103 | setScrollX(scrollLimited(event.getX())); 104 | velocityTracker.addMovement(event); 105 | velocityTracker.computeCurrentVelocity(CURRENT_VELOCITY); 106 | evaluateMoveToPage(); 107 | break; 108 | } 109 | return true; 110 | } 111 | 112 | private void evaluateMoveToPage() { 113 | float xVelocity = velocityTracker.getXVelocity(); 114 | currentScrollX = view.getScrollX(); 115 | moveToPagePosition(xVelocity); 116 | } 117 | 118 | private int scrollLimited(float scrollX) { 119 | int newScrollPosition = (int) (currentScrollX + iniEventX - scrollX); 120 | return Math.max(minScroll, Math.min(newScrollPosition, maxScroll)); 121 | } 122 | 123 | private void setScrollX(int value) { 124 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 125 | view.setScrollX(value); 126 | } else { 127 | view.scrollTo(value, view.getScrollY()); 128 | } 129 | if (onPageScrollListener != null) { 130 | onPageScrollListener.onScrollPage(value); 131 | } 132 | } 133 | 134 | private void moveToPagePosition(float xVelocity) { 135 | float width = view.getWidth(); 136 | int currentPage = (int) Math.floor(currentScrollX / width); 137 | float percentageOfNewPageVisible = (currentScrollX % width) / width; 138 | if (xVelocity < -MAX_VELOCITY) { 139 | scrollToPage(currentPage + 1); 140 | } else if (xVelocity > MAX_VELOCITY) { 141 | scrollToPage(currentPage); 142 | } else if (percentageOfNewPageVisible > 0.5f) { 143 | scrollToPage(currentPage + 1); 144 | } else { 145 | scrollToPage(currentPage); 146 | } 147 | } 148 | 149 | public void scrollToPage(int newCurrentPage) { 150 | scrollToPage(newCurrentPage, true); 151 | } 152 | 153 | public void scrollToPage(int newCurrentPage, boolean animated) { 154 | int width = view.getWidth(); 155 | int limitedNumPage = Math.max(0, Math.min(view.getNumOfPages() -1, newCurrentPage)); 156 | int scrollX = limitedNumPage * width; 157 | if (animated) { 158 | smoothScrollX(scrollX); 159 | } else { 160 | setScrollX(scrollX); 161 | } 162 | } 163 | 164 | private void smoothScrollX(int scrollX) { 165 | cancelScrollAnimationIfNecessary(); 166 | if (view.getScrollX() != scrollX) { 167 | smoothScrollAnimator = ObjectAnimator.ofInt(view, PROPERTY_SCROLL_X, view.getScrollX(), scrollX); 168 | smoothScrollAnimator.setDuration(SMOOTH_SCROLL_DURATION); 169 | smoothScrollAnimator.addListener(new Animator.AnimatorListener() { 170 | @Override 171 | public void onAnimationStart(Animator animation) { } 172 | 173 | @Override 174 | public void onAnimationEnd(Animator animation) { 175 | if (onPageScrollListener != null) { 176 | int width = view.getWidth(); 177 | int page = view.getScrollX() / width; 178 | int limitedNumPage = Math.max(0, Math.min(view.getNumOfPages() - 1, page)); 179 | onPageScrollListener.onPageSelected(limitedNumPage); 180 | } 181 | } 182 | 183 | @Override 184 | public void onAnimationCancel(Animator animation) { } 185 | 186 | @Override 187 | public void onAnimationRepeat(Animator animation) { } 188 | }); 189 | smoothScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 190 | @Override 191 | public void onAnimationUpdate(ValueAnimator animation) { 192 | if (onPageScrollListener != null) { 193 | onPageScrollListener.onScrollPage(view.getScrollX()); 194 | } 195 | } 196 | }); 197 | smoothScrollAnimator.start(); 198 | } 199 | } 200 | 201 | private void cancelScrollAnimationIfNecessary() { 202 | if ((smoothScrollAnimator != null) 203 | && (smoothScrollAnimator.isRunning())) { 204 | smoothScrollAnimator.cancel(); 205 | view.clearAnimation(); 206 | smoothScrollAnimator = null; 207 | } 208 | } 209 | 210 | public void setOnPageScrollListener(OnPageScrollListener onPageScrollListener) { 211 | this.onPageScrollListener = onPageScrollListener; 212 | } 213 | 214 | public interface OnPageScrollListener { 215 | void onScrollPage(float progress); 216 | void onPageSelected(int pageSelected); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /WelcomeCoordinator/src/main/java/com/redbooth/WelcomePageBehavior.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth; 26 | 27 | import android.os.Build; 28 | import android.view.View; 29 | import android.view.ViewTreeObserver; 30 | 31 | public abstract class WelcomePageBehavior { 32 | private final static int NO_DESTINY_VIEW = -1; 33 | protected WelcomeCoordinatorLayout coordinatorLayout; 34 | private View targetView; 35 | private View destinyView; 36 | private WelcomePageLayout page; 37 | 38 | protected WelcomePageLayout getPage() { 39 | return page; 40 | } 41 | 42 | protected View getTargetView() { 43 | return targetView; 44 | } 45 | 46 | protected View getDestinyView() { 47 | if (targetView != null && destinyView == null && coordinatorLayout != null) { 48 | int destinyViewId = ((WelcomePageLayout.LayoutParams)targetView.getLayoutParams()).getDestinyViewId(); 49 | if (destinyViewId != NO_DESTINY_VIEW) { 50 | destinyView = coordinatorLayout.findViewById(destinyViewId); 51 | } 52 | } 53 | return destinyView; 54 | } 55 | 56 | void setCoordinator(WelcomeCoordinatorLayout coordinator) { 57 | this.coordinatorLayout = coordinator; 58 | this.coordinatorLayout.getViewTreeObserver() 59 | .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 60 | @Override 61 | public void onGlobalLayout() { 62 | onCreate(coordinatorLayout); 63 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 64 | coordinatorLayout.getViewTreeObserver() 65 | .removeOnGlobalLayoutListener(this); 66 | } else { 67 | coordinatorLayout.getViewTreeObserver() 68 | .removeGlobalOnLayoutListener(this); 69 | } 70 | } 71 | }); 72 | } 73 | 74 | void setPage(WelcomePageLayout page) { 75 | this.page = page; 76 | } 77 | 78 | void setTarget(View target) { 79 | this.targetView = target; 80 | } 81 | 82 | protected abstract void onCreate(WelcomeCoordinatorLayout coordinator); 83 | 84 | protected abstract void onPlaytimeChange(WelcomeCoordinatorLayout coordinator, 85 | float newPlaytime, float newScrollPosition); 86 | } 87 | -------------------------------------------------------------------------------- /WelcomeCoordinator/src/main/java/com/redbooth/WelcomePageLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth; 26 | 27 | import android.annotation.TargetApi; 28 | import android.content.Context; 29 | import android.content.res.TypedArray; 30 | import android.os.Build; 31 | import android.text.TextUtils; 32 | import android.util.AttributeSet; 33 | import android.view.View; 34 | import android.view.ViewGroup; 35 | import android.widget.RelativeLayout; 36 | 37 | import com.redbooth.welcomecoordinator.R; 38 | 39 | import java.lang.reflect.Constructor; 40 | import java.util.ArrayList; 41 | import java.util.List; 42 | 43 | public class WelcomePageLayout extends RelativeLayout { 44 | public WelcomePageLayout(Context context) { 45 | super(context); 46 | } 47 | 48 | public WelcomePageLayout(Context context, AttributeSet attrs) { 49 | super(context, attrs); 50 | } 51 | 52 | public WelcomePageLayout(Context context, AttributeSet attrs, int defStyleAttr) { 53 | super(context, attrs, defStyleAttr); 54 | } 55 | 56 | @SuppressWarnings("unused") 57 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 58 | public WelcomePageLayout(Context context, AttributeSet attrs, 59 | int defStyleAttr, int defStyleRes) { 60 | super(context, attrs, defStyleAttr, defStyleRes); 61 | } 62 | 63 | @Override 64 | protected LayoutParams generateDefaultLayoutParams() { 65 | return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 66 | } 67 | 68 | @Override 69 | protected boolean checkLayoutParams(ViewGroup.LayoutParams params) { 70 | return params instanceof LayoutParams; 71 | } 72 | 73 | @Override 74 | protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams params) { 75 | return new LayoutParams(params); 76 | } 77 | 78 | @Override 79 | public LayoutParams generateLayoutParams(AttributeSet attrs) { 80 | return new LayoutParams(getContext(), attrs); 81 | } 82 | 83 | List getBehaviors(WelcomeCoordinatorLayout coordinatorLayout) { 84 | List result = new ArrayList<>(); 85 | for (int index = 0; index < getChildCount(); index++) { 86 | final View view = getChildAt(index); 87 | if (view.getLayoutParams() instanceof LayoutParams) { 88 | final LayoutParams params = (LayoutParams)view.getLayoutParams(); 89 | final WelcomePageBehavior behavior = params.getBehavior(); 90 | if (behavior != null) { 91 | behavior.setCoordinator(coordinatorLayout); 92 | behavior.setTarget(view); 93 | behavior.setPage(this); 94 | result.add(behavior); 95 | } 96 | } 97 | } 98 | return result; 99 | } 100 | 101 | public static class LayoutParams extends RelativeLayout.LayoutParams { 102 | public final static int NO_DESTINY_VIEW = -1; 103 | private int destinyViewId = NO_DESTINY_VIEW; 104 | private WelcomePageBehavior behavior; 105 | 106 | public WelcomePageBehavior getBehavior() { 107 | return behavior; 108 | } 109 | 110 | public int getDestinyViewId() { 111 | return destinyViewId; 112 | } 113 | 114 | public LayoutParams(int width, int height) { 115 | super(width, height); 116 | } 117 | 118 | public LayoutParams(ViewGroup.LayoutParams source) { 119 | super(source); 120 | } 121 | 122 | public LayoutParams(MarginLayoutParams source) { 123 | super(source); 124 | } 125 | 126 | public LayoutParams(Context context, AttributeSet attrs) { 127 | super(context, attrs); 128 | extractAttributes(context, attrs); 129 | } 130 | 131 | private void extractAttributes(Context context, AttributeSet attrs) { 132 | final TypedArray attributes = context.obtainStyledAttributes(attrs, 133 | R.styleable.WelcomePageLayout_LayoutParams); 134 | if (attributes.hasValue(R.styleable.WelcomePageLayout_LayoutParams_view_behavior)) { 135 | behavior = parseBehavior(context, attributes 136 | .getString(R.styleable.WelcomePageLayout_LayoutParams_view_behavior)); 137 | } 138 | if (attributes.hasValue(R.styleable.WelcomePageLayout_LayoutParams_destiny)) { 139 | destinyViewId = attributes 140 | .getResourceId(R.styleable.WelcomePageLayout_LayoutParams_destiny, NO_DESTINY_VIEW); 141 | } 142 | attributes.recycle(); 143 | } 144 | 145 | private WelcomePageBehavior parseBehavior(Context context, String name) { 146 | WelcomePageBehavior result = null; 147 | if (!TextUtils.isEmpty(name)) { 148 | final String fullName; 149 | if (name.startsWith(".")) { 150 | fullName = context.getPackageName() + name; 151 | } else { 152 | fullName = name; 153 | } 154 | try { 155 | Class behaviorClazz 156 | = (Class) Class.forName(fullName); 157 | final Constructor mainConstructor 158 | = behaviorClazz.getConstructor(); 159 | mainConstructor.setAccessible(true); 160 | result = mainConstructor.newInstance(); 161 | } catch (Exception e) { 162 | throw new RuntimeException("Could not inflate Behavior subclass " + fullName, e); 163 | } 164 | } 165 | return result; 166 | } 167 | 168 | @SuppressWarnings("unused") 169 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 170 | public LayoutParams(RelativeLayout.LayoutParams source) { 171 | super(source); 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /WelcomeCoordinator/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright Txus Ballesteros 2016 (@txusballesteros) 2 | # 3 | # This file is part of some open source application. 4 | # 5 | # Licensed to the Apache Software Foundation (ASF) under one 6 | # for more contributor license agreements. See the NOTICE file 7 | # distributed with this work for additional information 8 | # regarding copyright ownership. The ASF licenses this file 9 | # to you under the Apache License, Version 2.0 (the 10 | # "License"); you may not use this file except in compliance 11 | # with the License. You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, 16 | # software distributed under the License is distributed on an 17 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 | # KIND, either express or implied. See the License for the 19 | # specific language governing permissions and limitations 20 | # under the License. 21 | # 22 | # Contact: Txus Ballesteros 23 | 24 | /build 25 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | apply plugin: 'com.android.application' 26 | 27 | def globalConfiguration = rootProject.extensions.getByName("ext") 28 | 29 | android { 30 | compileSdkVersion globalConfiguration.getAt("androidCompileSdkVersion") 31 | buildToolsVersion globalConfiguration.getAt("androidBuildToolsVersion") 32 | 33 | defaultConfig { 34 | applicationId "${globalConfiguration.getAt("androidApplicationId")}.demo" 35 | minSdkVersion globalConfiguration.getAt("appMinSdkVersion") 36 | targetSdkVersion globalConfiguration.getAt("androidTargetSdkVersion") 37 | versionCode globalConfiguration.getAt("androidVersionCode") 38 | versionName globalConfiguration.getAt("androidVersionName") 39 | } 40 | 41 | compileOptions { 42 | sourceCompatibility JavaVersion.VERSION_1_7 43 | targetCompatibility JavaVersion.VERSION_1_7 44 | } 45 | 46 | buildTypes { 47 | release { 48 | minifyEnabled false 49 | } 50 | } 51 | } 52 | 53 | dependencies { 54 | def mobileDependencies = globalConfiguration.mobileDependencies 55 | compile project(':WelcomeCoordinator') 56 | compile mobileDependencies.AppCompat 57 | compile mobileDependencies.DesignLibrary 58 | compile mobileDependencies.ButterKnife 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 23 | 24 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/AnimationFillWithColor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo; 26 | 27 | import android.animation.ObjectAnimator; 28 | import android.view.View; 29 | 30 | import com.redbooth.WelcomeCoordinatorLayout; 31 | import com.redbooth.WelcomePageBehavior; 32 | 33 | @SuppressWarnings("unused") 34 | public class AnimationFillWithColor extends WelcomePageBehavior { 35 | public static final long DURATION = 10000L; 36 | public static final int INIT_PLAY_TIME = 2; 37 | private ObjectAnimator objectAnimatorY; 38 | 39 | @Override 40 | protected void onCreate(WelcomeCoordinatorLayout coordinator) { 41 | configureTranslations(); 42 | } 43 | 44 | protected void configureTranslations() { 45 | objectAnimatorY = ObjectAnimator.ofFloat(getTargetView(), View.TRANSLATION_Y, getTargetView().getHeight(), -getTargetView().getWidth()/2 - getPage().getPaddingTop()); 46 | objectAnimatorY.setDuration(DURATION); 47 | } 48 | 49 | @Override 50 | protected void onPlaytimeChange(WelcomeCoordinatorLayout coordinator, 51 | float currentPlaytime, 52 | float newScrollPosition) { 53 | if (currentPlaytime <= INIT_PLAY_TIME) { 54 | objectAnimatorY.setCurrentPlayTime(0); 55 | } else { 56 | long playTime = (long) ((currentPlaytime - INIT_PLAY_TIME) * DURATION); 57 | objectAnimatorY.setCurrentPlayTime(playTime); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/AnimationFlightTo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo; 26 | 27 | import android.animation.ObjectAnimator; 28 | import android.view.View; 29 | import android.view.animation.AccelerateInterpolator; 30 | import android.view.animation.LinearInterpolator; 31 | 32 | import com.redbooth.WelcomeCoordinatorLayout; 33 | import com.redbooth.WelcomePageBehavior; 34 | 35 | @SuppressWarnings("unused") 36 | public class AnimationFlightTo extends WelcomePageBehavior { 37 | public static final long DURATION = 10000L; 38 | public static final int INIT_TIME = 1; 39 | public static final int FINAL_TIME = 2; 40 | public static final int Y = 1; 41 | public static final int X = 0; 42 | public static final int LENGTH_LOCATION_ARRAY = 2; 43 | private ObjectAnimator alphaAnimator; 44 | private ObjectAnimator objectAnimatorY; 45 | private ObjectAnimator objectAnimatorX; 46 | private ObjectAnimator objectAnimatorScaleX; 47 | private ObjectAnimator objectAnimatorScaleY; 48 | 49 | @Override 50 | protected void onCreate(WelcomeCoordinatorLayout coordinator) { 51 | configureTranslation(); 52 | configureScale(); 53 | } 54 | 55 | private void configureTranslation() { 56 | final View targetView = getTargetView(); 57 | final View shadowView = getTargetView().findViewById(R.id.star_shadow); 58 | int[] viewLocation = new int[LENGTH_LOCATION_ARRAY]; 59 | getLeftPositionFrom(targetView, viewLocation); 60 | int[] destinyViewLocation = new int[LENGTH_LOCATION_ARRAY]; 61 | getLeftPositionFrom(getDestinyView(), destinyViewLocation); 62 | objectAnimatorY = ObjectAnimator.ofFloat(targetView, View.TRANSLATION_Y, 0, -(viewLocation[Y] - destinyViewLocation[Y])); 63 | objectAnimatorY.setInterpolator(new AccelerateInterpolator()); 64 | objectAnimatorY.setDuration(DURATION); 65 | objectAnimatorX = ObjectAnimator.ofFloat(targetView, View.TRANSLATION_X, 0, -(viewLocation[X] - destinyViewLocation[X])); 66 | objectAnimatorX.setInterpolator(new LinearInterpolator()); 67 | objectAnimatorX.setDuration(DURATION); 68 | alphaAnimator = ObjectAnimator.ofFloat(shadowView, View.ALPHA, 0, 0.4f); 69 | alphaAnimator.setInterpolator(new LinearInterpolator()); 70 | alphaAnimator.setDuration(DURATION); 71 | } 72 | 73 | private void configureScale() { 74 | View targetView = getTargetView(); 75 | float scaleXFactor = ((float) getDestinyView().getMeasuredWidth() / (float) targetView.getMeasuredWidth()); 76 | objectAnimatorScaleX = ObjectAnimator.ofFloat(targetView, View.SCALE_X, scaleXFactor); 77 | objectAnimatorScaleX.setDuration(DURATION); 78 | objectAnimatorScaleX.setInterpolator(new LinearInterpolator()); 79 | float scaleYFactor = ((float) getDestinyView().getMeasuredHeight() / (float) targetView.getMeasuredHeight()); 80 | objectAnimatorScaleY = ObjectAnimator.ofFloat(targetView, View.SCALE_Y, scaleYFactor); 81 | objectAnimatorScaleY.setDuration(DURATION); 82 | objectAnimatorScaleY.setInterpolator(new LinearInterpolator()); 83 | } 84 | 85 | private void getLeftPositionFrom(View view, int[] location) { 86 | int x = view.getLeft(); 87 | int y = view.getTop(); 88 | View parent = (View) view.getParent(); 89 | while(parent != null 90 | && !(parent instanceof WelcomeCoordinatorLayout)){ 91 | x += parent.getLeft(); 92 | y += parent.getTop(); 93 | parent = (View)parent.getParent(); 94 | } 95 | location[X] = x; 96 | location[Y] = y; 97 | } 98 | 99 | @Override 100 | protected void onPlaytimeChange(WelcomeCoordinatorLayout coordinator, 101 | float newPlaytime, 102 | float newScrollPosition) { 103 | if (newPlaytime <= INIT_TIME) { 104 | setCurrentTimeInAllAnimators(0); 105 | } else if (newPlaytime > INIT_TIME 106 | && newPlaytime <= FINAL_TIME) { 107 | long playTime = (long) ((newPlaytime - INIT_TIME) * DURATION); 108 | setCurrentTimeInAllAnimators(playTime); 109 | } else { 110 | setCurrentTimeInAllAnimators(DURATION); 111 | } 112 | } 113 | 114 | private void setCurrentTimeInAllAnimators(long playTime) { 115 | objectAnimatorY.setCurrentPlayTime(playTime); 116 | objectAnimatorX.setCurrentPlayTime(playTime); 117 | objectAnimatorScaleX.setCurrentPlayTime(playTime); 118 | objectAnimatorScaleY.setCurrentPlayTime(playTime); 119 | alphaAnimator.setCurrentPlayTime(playTime); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/AnimationLaunch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo; 26 | 27 | import android.animation.ObjectAnimator; 28 | import android.view.View; 29 | import android.view.animation.LinearInterpolator; 30 | 31 | import com.redbooth.WelcomeCoordinatorLayout; 32 | import com.redbooth.WelcomePageBehavior; 33 | 34 | @SuppressWarnings("unused") 35 | public class AnimationLaunch extends WelcomePageBehavior { 36 | public static final long DURATION = 10000L; 37 | private ObjectAnimator objectAnimatorY; 38 | private ObjectAnimator objectAnimatorX; 39 | 40 | @Override 41 | protected void onCreate(WelcomeCoordinatorLayout coordinator) { 42 | objectAnimatorY = ObjectAnimator.ofFloat(getTargetView(), View.TRANSLATION_Y, 0, -getTargetView().getTop() - getTargetView().getHeight()); 43 | objectAnimatorY.setDuration(DURATION); 44 | objectAnimatorY.setInterpolator(new LinearInterpolator()); 45 | objectAnimatorX = ObjectAnimator.ofFloat(getTargetView(), View.TRANSLATION_X, 0, coordinatorLayout.getWidth()); 46 | objectAnimatorX.setDuration(DURATION); 47 | objectAnimatorX.setInterpolator(new LinearInterpolator()); 48 | } 49 | 50 | @Override 51 | protected void onPlaytimeChange(WelcomeCoordinatorLayout coordinator, 52 | float newPlaytime, 53 | float newScrollPosition) { 54 | if (newPlaytime < 1) { 55 | long playTime = (long) (newPlaytime * DURATION); 56 | objectAnimatorY.setCurrentPlayTime(playTime); 57 | objectAnimatorX.setCurrentPlayTime(playTime); 58 | } else { 59 | objectAnimatorY.setCurrentPlayTime(1); 60 | objectAnimatorX.setCurrentPlayTime(1); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo; 26 | 27 | import android.animation.ArgbEvaluator; 28 | import android.animation.ValueAnimator; 29 | import android.content.res.Resources; 30 | import android.os.Bundle; 31 | import android.support.v4.content.res.ResourcesCompat; 32 | import android.support.v7.app.AppCompatActivity; 33 | import android.view.View; 34 | 35 | import com.redbooth.WelcomeCoordinatorLayout; 36 | import com.redbooth.demo.animators.ChatAvatarsAnimator; 37 | import com.redbooth.demo.animators.InSyncAnimator; 38 | import com.redbooth.demo.animators.RocketAvatarsAnimator; 39 | import com.redbooth.demo.animators.RocketFlightAwayAnimator; 40 | 41 | import butterknife.Bind; 42 | import butterknife.ButterKnife; 43 | import butterknife.OnClick; 44 | 45 | public class MainActivity extends AppCompatActivity { 46 | private boolean animationReady = false; 47 | private ValueAnimator backgroundAnimator; 48 | @Bind(R.id.coordinator) WelcomeCoordinatorLayout coordinatorLayout; 49 | private RocketAvatarsAnimator rocketAvatarsAnimator; 50 | private ChatAvatarsAnimator chatAvatarsAnimator; 51 | private RocketFlightAwayAnimator rocketFlightAwayAnimator; 52 | private InSyncAnimator inSyncAnimator; 53 | 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | setContentView(R.layout.activity_main); 58 | ButterKnife.bind(this); 59 | initializeListeners(); 60 | initializePages(); 61 | initializeBackgroundTransitions(); 62 | } 63 | 64 | private void initializePages() { 65 | final WelcomeCoordinatorLayout coordinatorLayout 66 | = (WelcomeCoordinatorLayout)findViewById(R.id.coordinator); 67 | coordinatorLayout.addPage(R.layout.welcome_page_1, 68 | R.layout.welcome_page_2, 69 | R.layout.welcome_page_3, 70 | R.layout.welcome_page_4); 71 | } 72 | 73 | private void initializeListeners() { 74 | coordinatorLayout.setOnPageScrollListener(new WelcomeCoordinatorLayout.OnPageScrollListener() { 75 | @Override 76 | public void onScrollPage(View v, float progress, float maximum) { 77 | if (!animationReady) { 78 | animationReady = true; 79 | backgroundAnimator.setDuration((long) maximum); 80 | } 81 | backgroundAnimator.setCurrentPlayTime((long) progress); 82 | } 83 | 84 | @Override 85 | public void onPageSelected(View v, int pageSelected) { 86 | switch (pageSelected) { 87 | case 0: 88 | if (rocketAvatarsAnimator == null) { 89 | rocketAvatarsAnimator = new RocketAvatarsAnimator(coordinatorLayout); 90 | rocketAvatarsAnimator.play(); 91 | } 92 | break; 93 | case 1: 94 | if (chatAvatarsAnimator == null) { 95 | chatAvatarsAnimator = new ChatAvatarsAnimator(coordinatorLayout); 96 | chatAvatarsAnimator.play(); 97 | } 98 | break; 99 | case 2: 100 | if (inSyncAnimator == null) { 101 | inSyncAnimator = new InSyncAnimator(coordinatorLayout); 102 | inSyncAnimator.play(); 103 | } 104 | break; 105 | case 3: 106 | if (rocketFlightAwayAnimator == null) { 107 | rocketFlightAwayAnimator = new RocketFlightAwayAnimator(coordinatorLayout); 108 | rocketFlightAwayAnimator.play(); 109 | } 110 | break; 111 | } 112 | } 113 | }); 114 | } 115 | 116 | private void initializeBackgroundTransitions() { 117 | final Resources resources = getResources(); 118 | final int colorPage1 = ResourcesCompat.getColor(resources, R.color.page1, getTheme()); 119 | final int colorPage2 = ResourcesCompat.getColor(resources, R.color.page2, getTheme()); 120 | final int colorPage3 = ResourcesCompat.getColor(resources, R.color.page3, getTheme()); 121 | final int colorPage4 = ResourcesCompat.getColor(resources, R.color.page4, getTheme()); 122 | backgroundAnimator = ValueAnimator 123 | .ofObject(new ArgbEvaluator(), colorPage1, colorPage2, colorPage3, colorPage4); 124 | backgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 125 | @Override 126 | public void onAnimationUpdate(ValueAnimator animation) { 127 | coordinatorLayout.setBackgroundColor((int) animation.getAnimatedValue()); 128 | } 129 | }); 130 | } 131 | 132 | @OnClick(R.id.skip) 133 | void skip() { 134 | coordinatorLayout.setCurrentPage(coordinatorLayout.getNumOfPages() - 1, true); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/ParallaxSubtitleBehaviour.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo; 26 | 27 | import android.animation.ObjectAnimator; 28 | import android.view.View; 29 | import android.view.animation.LinearInterpolator; 30 | import android.widget.FrameLayout; 31 | 32 | import com.redbooth.WelcomeCoordinatorLayout; 33 | import com.redbooth.WelcomePageBehavior; 34 | 35 | @SuppressWarnings("unused") 36 | public class ParallaxSubtitleBehaviour extends WelcomePageBehavior { 37 | private final static int PARALLAX_FACTOR = 4; 38 | private ObjectAnimator parallaxAnimator; 39 | 40 | @Override 41 | protected void onCreate(WelcomeCoordinatorLayout coordinator) { 42 | final FrameLayout.LayoutParams params 43 | = (FrameLayout.LayoutParams)getPage().getLayoutParams(); 44 | long startDelay; 45 | long duration; 46 | float rightTranslation; 47 | float leftTranslation; 48 | if (params.leftMargin == 0) { 49 | startDelay = 0; 50 | duration = getPage().getMeasuredWidth(); 51 | rightTranslation = 0; 52 | leftTranslation = -(duration / PARALLAX_FACTOR); 53 | } else { 54 | startDelay = (params.leftMargin - coordinator.getMeasuredWidth()); 55 | duration = (getPage().getMeasuredWidth() * 2); 56 | rightTranslation = (duration / PARALLAX_FACTOR); 57 | leftTranslation = -(duration / PARALLAX_FACTOR); 58 | } 59 | parallaxAnimator = ObjectAnimator 60 | .ofFloat(getTargetView(), View.TRANSLATION_X, rightTranslation, leftTranslation); 61 | parallaxAnimator.setInterpolator(new LinearInterpolator()); 62 | parallaxAnimator.setTarget(getTargetView()); 63 | parallaxAnimator.setStartDelay(startDelay); 64 | parallaxAnimator.setDuration(duration); 65 | } 66 | 67 | @Override 68 | protected void onPlaytimeChange(WelcomeCoordinatorLayout coordinator, 69 | float newPlaytime, 70 | float newScrollPosition) { 71 | long currentPlaytime = (long)newScrollPosition; 72 | if (newScrollPosition >= parallaxAnimator.getStartDelay()) { 73 | currentPlaytime = (long)(newScrollPosition - parallaxAnimator.getStartDelay()); 74 | } 75 | parallaxAnimator.setCurrentPlayTime(currentPlaytime); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/ParallaxTitleBehaviour.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo; 26 | 27 | import android.animation.ObjectAnimator; 28 | import android.view.View; 29 | import android.view.animation.LinearInterpolator; 30 | import android.widget.FrameLayout; 31 | 32 | import com.redbooth.WelcomeCoordinatorLayout; 33 | import com.redbooth.WelcomePageBehavior; 34 | 35 | @SuppressWarnings("unused") 36 | public class ParallaxTitleBehaviour extends WelcomePageBehavior { 37 | private final static int PARALLAX_FACTOR = 2; 38 | private ObjectAnimator parallaxAnimator; 39 | 40 | @Override 41 | protected void onCreate(WelcomeCoordinatorLayout coordinator) { 42 | final FrameLayout.LayoutParams params 43 | = (FrameLayout.LayoutParams)getPage().getLayoutParams(); 44 | long startDelay; 45 | long duration; 46 | float rightTranslation; 47 | float leftTranslation; 48 | if (params.leftMargin == 0) { 49 | startDelay = 0; 50 | duration = getPage().getMeasuredWidth(); 51 | rightTranslation = 0; 52 | leftTranslation = -(duration / PARALLAX_FACTOR); 53 | } else { 54 | startDelay = (params.leftMargin - coordinator.getMeasuredWidth()); 55 | duration = (getPage().getMeasuredWidth() * 2); 56 | rightTranslation = (duration / PARALLAX_FACTOR); 57 | leftTranslation = -(duration / PARALLAX_FACTOR); 58 | } 59 | parallaxAnimator = ObjectAnimator 60 | .ofFloat(getTargetView(), View.TRANSLATION_X, rightTranslation, leftTranslation); 61 | parallaxAnimator.setInterpolator(new LinearInterpolator()); 62 | parallaxAnimator.setTarget(getTargetView()); 63 | parallaxAnimator.setStartDelay(startDelay); 64 | parallaxAnimator.setDuration(duration); 65 | } 66 | 67 | @Override 68 | protected void onPlaytimeChange(WelcomeCoordinatorLayout coordinator, 69 | float newPlaytime, 70 | float newScrollPosition) { 71 | long currentPlaytime = (long)newScrollPosition; 72 | if (newScrollPosition >= parallaxAnimator.getStartDelay()) { 73 | currentPlaytime = (long)(newScrollPosition - parallaxAnimator.getStartDelay()); 74 | } 75 | parallaxAnimator.setCurrentPlayTime(currentPlaytime); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/RectangleWithCapCircleView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo; 26 | 27 | import android.content.Context; 28 | import android.graphics.Canvas; 29 | import android.graphics.Color; 30 | import android.graphics.Paint; 31 | import android.graphics.RectF; 32 | import android.util.AttributeSet; 33 | import android.view.View; 34 | 35 | public class RectangleWithCapCircleView extends View { 36 | private Paint paint; 37 | private RectF rectCap; 38 | private RectF rectBottom; 39 | 40 | public RectangleWithCapCircleView(Context context) { 41 | super(context); 42 | } 43 | 44 | public RectangleWithCapCircleView(Context context, AttributeSet attrs) { 45 | super(context, attrs); 46 | } 47 | 48 | public RectangleWithCapCircleView(Context context, AttributeSet attrs, int defStyleAttr) { 49 | super(context, attrs, defStyleAttr); 50 | } 51 | 52 | @Override 53 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 54 | rectCap = null; 55 | super.onMeasure(widthMeasureSpec, (int) Math.ceil(heightMeasureSpec + widthMeasureSpec)); 56 | } 57 | 58 | @Override 59 | protected void onDraw(Canvas canvas) { 60 | super.onDraw(canvas); 61 | if (rectCap == null) { 62 | rectCap = new RectF(0f, 0f, getWidth(), getWidth() + 1); 63 | rectBottom = new RectF(0.0f, (getWidth()/2) - 1, getWidth(), getHeight()); 64 | paint = new Paint(Paint.ANTI_ALIAS_FLAG); 65 | paint.setColor(Color.WHITE); 66 | } 67 | canvas.drawRect(rectBottom, paint); 68 | canvas.drawArc(rectCap, 0f, -180f, true, paint); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/animators/ChatAvatarsAnimator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo.animators; 26 | 27 | import android.animation.Animator; 28 | import android.animation.AnimatorSet; 29 | import android.animation.ObjectAnimator; 30 | import android.view.View; 31 | import android.view.animation.OvershootInterpolator; 32 | 33 | import com.redbooth.demo.R; 34 | 35 | public class ChatAvatarsAnimator { 36 | private AnimatorSet animator; 37 | private final View rootView; 38 | 39 | public ChatAvatarsAnimator(View rootView) { 40 | this.rootView = rootView; 41 | initializeAnimator(); 42 | } 43 | 44 | private void initializeAnimator() { 45 | final View avatar1 = rootView.findViewById(R.id.avatar1_page2); 46 | final View card1 = rootView.findViewById(R.id.card1_page2); 47 | final View avatar2 = rootView.findViewById(R.id.avatar2_page2); 48 | final View card2 = rootView.findViewById(R.id.card2_page2); 49 | final View star = rootView.findViewById(R.id.star); 50 | Animator avatar1Animator = getScaleAnimator(avatar1); 51 | Animator card1Animator = getFlightFromLeft(card1); 52 | Animator avatar2Animator = getScaleAnimator(avatar2); 53 | Animator card2Animator = getFlightFromRight(card2); 54 | Animator starAnimator = getScaleAndVisibilityAnimator(star); 55 | animator = new AnimatorSet(); 56 | animator.play(starAnimator).after(card2Animator); 57 | animator.play(card2Animator).after(avatar2Animator); 58 | animator.play(avatar2Animator).after(card1Animator); 59 | animator.play(card1Animator).after(avatar1Animator); 60 | } 61 | 62 | private AnimatorSet getScaleAnimator(final View targetView) { 63 | AnimatorSet animator = new AnimatorSet(); 64 | animator.setDuration(300); 65 | animator.setInterpolator(new OvershootInterpolator()); 66 | ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(targetView, View.SCALE_X, 1f); 67 | ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(targetView, View.SCALE_Y, 1f); 68 | animator.playTogether(scaleXAnimator, scaleYAnimator); 69 | return animator; 70 | } 71 | 72 | private AnimatorSet getScaleAndVisibilityAnimator(final View targetView) { 73 | AnimatorSet animator = new AnimatorSet(); 74 | animator.setDuration(300); 75 | animator.setInterpolator(new OvershootInterpolator()); 76 | ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(targetView, View.SCALE_X, 0f, 1f); 77 | ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(targetView, View.SCALE_Y, 0f, 1f); 78 | animator.playTogether(scaleXAnimator, scaleYAnimator); 79 | animator.addListener(new AnimatorListener() { 80 | @Override 81 | public void onAnimationStart(Animator animation) { 82 | targetView.setVisibility(View.VISIBLE); 83 | } 84 | }); 85 | return animator; 86 | } 87 | 88 | private AnimatorSet getFlightFromRight(final View targetView) { 89 | AnimatorSet animator = new AnimatorSet(); 90 | animator.setDuration(300); 91 | ObjectAnimator translationXAnimator = ObjectAnimator.ofFloat(targetView, View.TRANSLATION_X, 0f); 92 | animator.addListener(new AnimatorListener() { 93 | @Override 94 | public void onAnimationStart(Animator animation) { 95 | targetView.setVisibility(View.VISIBLE); 96 | } 97 | }); 98 | animator.play(translationXAnimator); 99 | return animator; 100 | } 101 | 102 | private AnimatorSet getFlightFromLeft(final View targetView) { 103 | AnimatorSet animator = new AnimatorSet(); 104 | animator.setDuration(600); 105 | ObjectAnimator translationXAnimator = ObjectAnimator.ofFloat(targetView, View.TRANSLATION_X, 0f); 106 | animator.addListener(new AnimatorListener() { 107 | @Override 108 | public void onAnimationStart(Animator animation) { 109 | targetView.setVisibility(View.VISIBLE); 110 | } 111 | }); 112 | animator.play(translationXAnimator); 113 | return animator; 114 | } 115 | 116 | public void play() { 117 | animator.start(); 118 | } 119 | 120 | public abstract class AnimatorListener implements Animator.AnimatorListener { 121 | public abstract void onAnimationStart(Animator animation); 122 | public void onAnimationEnd(Animator animation) {} 123 | public void onAnimationCancel(Animator animation) {} 124 | public void onAnimationRepeat(Animator animation) {} 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/animators/InSyncAnimator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo.animators; 26 | 27 | import android.animation.AnimatorSet; 28 | import android.animation.ObjectAnimator; 29 | import android.view.View; 30 | import android.view.animation.BounceInterpolator; 31 | import android.view.animation.LinearInterpolator; 32 | import android.view.animation.OvershootInterpolator; 33 | 34 | import com.redbooth.demo.R; 35 | 36 | public class InSyncAnimator { 37 | private AnimatorSet animator; 38 | private final View rootView; 39 | 40 | public InSyncAnimator(View rootView) { 41 | this.rootView = rootView; 42 | initializeAnimator(); 43 | } 44 | 45 | private void initializeAnimator() { 46 | final View avatarView = rootView.findViewById(R.id.avatar5); 47 | final View arrowChartMaskView = rootView.findViewById(R.id.arrow_chart_mask); 48 | final ObjectAnimator scaleXAnimator = ObjectAnimator 49 | .ofFloat(avatarView, View.SCALE_X, 0f, 1f); 50 | scaleXAnimator.setDuration(300); 51 | scaleXAnimator.setInterpolator(new OvershootInterpolator()); 52 | final ObjectAnimator scaleYAnimator = ObjectAnimator 53 | .ofFloat(avatarView, View.SCALE_Y, 0f, 1f); 54 | scaleYAnimator.setDuration(300); 55 | scaleYAnimator.setInterpolator(new OvershootInterpolator()); 56 | final ObjectAnimator maskScaleXAnimator = ObjectAnimator 57 | .ofFloat(arrowChartMaskView, View.SCALE_X, 1f, 0f); 58 | maskScaleXAnimator.setDuration(500); 59 | maskScaleXAnimator.setInterpolator(new LinearInterpolator()); 60 | animator = new AnimatorSet(); 61 | animator.play(scaleXAnimator).with(scaleYAnimator).before(maskScaleXAnimator); 62 | } 63 | 64 | public void play() { 65 | animator.start(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/animators/RocketAvatarsAnimator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo.animators; 26 | 27 | import android.animation.Animator; 28 | import android.animation.AnimatorSet; 29 | import android.animation.ObjectAnimator; 30 | import android.animation.ValueAnimator; 31 | import android.view.View; 32 | import android.view.animation.LinearInterpolator; 33 | import android.view.animation.OvershootInterpolator; 34 | 35 | import com.redbooth.demo.R; 36 | 37 | public class RocketAvatarsAnimator { 38 | private AnimatorSet animator; 39 | private Animator rocketFlameAnimator; 40 | private final View rootView; 41 | 42 | public RocketAvatarsAnimator(View rootView) { 43 | this.rootView = rootView; 44 | initializeAnimator(); 45 | } 46 | 47 | private void initializeAnimator() { 48 | final View rocketFlame = rootView.findViewById(R.id.rocket_flame); 49 | final View avatar1 = rootView.findViewById(R.id.avatar1); 50 | final View avatar2 = rootView.findViewById(R.id.avatar2); 51 | final View avatar3 = rootView.findViewById(R.id.avatar3); 52 | final View avatar4 = rootView.findViewById(R.id.avatar4); 53 | Animator avatar1Animator = getAnimator(avatar1); 54 | Animator avatar2Animator = getAnimator(avatar2); 55 | Animator avatar3Animator = getAnimator(avatar3); 56 | Animator avatar4Animator = getAnimator(avatar4); 57 | rocketFlameAnimator = getFlameAnimator(rocketFlame); 58 | animator = new AnimatorSet(); 59 | animator.setStartDelay(500); 60 | animator.play(avatar3Animator).after(avatar4Animator); 61 | animator.play(avatar2Animator).after(avatar3Animator); 62 | animator.play(avatar1Animator).after(avatar2Animator); 63 | } 64 | 65 | private Animator getAnimator(View targetView) { 66 | AnimatorSet animator = new AnimatorSet(); 67 | animator.setDuration(300); 68 | animator.setInterpolator(new OvershootInterpolator()); 69 | ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(targetView, View.SCALE_X, 1f); 70 | ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(targetView, View.SCALE_Y, 1f); 71 | animator.playTogether(scaleXAnimator, scaleYAnimator); 72 | return animator; 73 | } 74 | 75 | private Animator getFlameAnimator(View targetView) { 76 | AnimatorSet animator = new AnimatorSet(); 77 | animator.setDuration(1000); 78 | animator.setInterpolator(new LinearInterpolator()); 79 | ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(targetView, View.ALPHA, 0f, 1f, 0.5f, 1f, 0.8f, 1f); 80 | ObjectAnimator scaleAnimator = ObjectAnimator.ofFloat(targetView, View.SCALE_Y, 0.8f, 1f, 0.9f, 1f, 0.7f, 1f); 81 | alphaAnimator.setRepeatCount(ValueAnimator.INFINITE); 82 | alphaAnimator.setRepeatMode(ValueAnimator.REVERSE); 83 | scaleAnimator.setRepeatCount(ValueAnimator.INFINITE); 84 | scaleAnimator.setRepeatMode(ValueAnimator.REVERSE); 85 | animator.playTogether(alphaAnimator, scaleAnimator); 86 | return animator; 87 | } 88 | 89 | public void play() { 90 | animator.start(); 91 | rocketFlameAnimator.start(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /app/src/main/java/com/redbooth/demo/animators/RocketFlightAwayAnimator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Txus Ballesteros 2016 (@txusballesteros) 3 | * 4 | * This file is part of some open source application. 5 | * 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, 17 | * software distributed under the License is distributed on an 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 | * KIND, either express or implied. See the License for the 20 | * specific language governing permissions and limitations 21 | * under the License. 22 | * 23 | * Contact: Txus Ballesteros 24 | */ 25 | package com.redbooth.demo.animators; 26 | 27 | import android.animation.Animator; 28 | import android.animation.AnimatorSet; 29 | import android.animation.ObjectAnimator; 30 | import android.view.View; 31 | import android.view.animation.AccelerateInterpolator; 32 | import android.view.animation.DecelerateInterpolator; 33 | import android.view.animation.OvershootInterpolator; 34 | 35 | import com.redbooth.demo.R; 36 | 37 | public class RocketFlightAwayAnimator { 38 | private AnimatorSet animator; 39 | private final View rootView; 40 | 41 | public RocketFlightAwayAnimator(View rootView) { 42 | this.rootView = rootView; 43 | initializeAnimator(); 44 | } 45 | 46 | private void initializeAnimator() { 47 | final View rocket = rootView.findViewById(R.id.rocket_page4); 48 | Animator rocketScaleAnimator = getScaleAndVisibilityAnimator(rocket); 49 | Animator rocketRotationAnimator = getRotationAnimator(rocket); 50 | Animator rocketTranslationAnimator = getTranslationAnimator(rocket); 51 | animator = new AnimatorSet(); 52 | animator.setStartDelay(600); 53 | animator.playTogether(rocketScaleAnimator, rocketRotationAnimator, rocketTranslationAnimator); 54 | } 55 | 56 | private AnimatorSet getScaleAndVisibilityAnimator(final View targetView) { 57 | AnimatorSet animator = new AnimatorSet(); 58 | animator.setDuration(1000); 59 | ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(targetView, View.SCALE_X, 1f, 0f); 60 | ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(targetView, View.SCALE_Y, 1f, 0f); 61 | animator.playTogether(scaleXAnimator, scaleYAnimator); 62 | animator.addListener(new AnimatorListener() { 63 | @Override 64 | public void onAnimationStart(Animator animation) { 65 | targetView.setVisibility(View.VISIBLE); 66 | } 67 | }); 68 | return animator; 69 | } 70 | 71 | private AnimatorSet getRotationAnimator(final View targetView) { 72 | AnimatorSet animator = new AnimatorSet(); 73 | animator.setDuration(1000); 74 | animator.setInterpolator(new DecelerateInterpolator(1.5f)); 75 | ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(targetView, View.ROTATION, 0f, 45f); 76 | animator.play(scaleXAnimator); 77 | return animator; 78 | } 79 | 80 | private AnimatorSet getTranslationAnimator(final View targetView) { 81 | AnimatorSet animator = new AnimatorSet(); 82 | animator.setDuration(1000); 83 | ObjectAnimator translationXAnimator = ObjectAnimator.ofFloat(targetView, View.TRANSLATION_X, -rootView.getWidth()/2, 0f); 84 | ObjectAnimator translationYAnimator = ObjectAnimator.ofFloat(targetView, View.TRANSLATION_Y, rootView.getWidth()/2, 0f); 85 | translationYAnimator.setInterpolator(new DecelerateInterpolator(1.5f)); 86 | animator.playTogether(translationXAnimator, translationYAnimator); 87 | return animator; 88 | } 89 | 90 | public void play() { 91 | animator.start(); 92 | } 93 | 94 | public abstract class AnimatorListener implements Animator.AnimatorListener { 95 | public abstract void onAnimationStart(Animator animation); 96 | public void onAnimationEnd(Animator animation) {} 97 | public void onAnimationCancel(Animator animation) {} 98 | public void onAnimationRepeat(Animator animation) {} 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/arrow_chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/arrow_chart.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/avatar_fred.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/avatar_fred.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/avatar_jack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/avatar_jack.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/avatar_jack2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/avatar_jack2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/avatar_lucy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/avatar_lucy.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/avatar_lucy2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/avatar_lucy2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/avatar_maggie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/avatar_maggie.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/avatar_maggie2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/avatar_maggie2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/bubble_excellent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/bubble_excellent.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/bubble_finished.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/bubble_finished.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/easel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/easel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/excellent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/excellent.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/file.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/finished.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/finished.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/rocket_flame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/rocket_flame.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/rocket_large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/rocket_large.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/star_large_no_shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/txusballesteros/welcome-coordinator/1cf2d6ef34ab0815019a07626d0a3e70600b1b2e/app/src/main/res/drawable-xhdpi/star_large_no_shadow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_rocket_144dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 26 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 27 | 28 | 36 | 37 |