├── .circleci └── config.yml ├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── ToxicBakery │ │ └── viewpager │ │ └── transforms │ │ └── example │ │ └── MainActivity.kt │ └── res │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── layout │ ├── activity_main.xml │ └── fragment_main.xml │ └── values │ ├── strings.xml │ └── style.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── detekt.yml ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── ToxicBakery │ │ └── viewpager │ │ └── transforms │ │ ├── ABaseTransformer.kt │ │ ├── AccordionTransformer.kt │ │ ├── BackgroundToForegroundTransformer.kt │ │ ├── CubeInTransformer.kt │ │ ├── CubeOutTransformer.kt │ │ ├── DefaultTransformer.kt │ │ ├── DepthPageTransformer.kt │ │ ├── DrawerTransformer.kt │ │ ├── FlipHorizontalTransformer.kt │ │ ├── FlipVerticalTransformer.kt │ │ ├── ForegroundToBackgroundTransformer.kt │ │ ├── RotateDownTransformer.kt │ │ ├── RotateUpTransformer.kt │ │ ├── ScaleInOutTransformer.kt │ │ ├── StackTransformer.kt │ │ ├── TabletTransformer.kt │ │ ├── ZoomInTransformer.kt │ │ ├── ZoomOutSlideTransformer.kt │ │ └── ZoomOutTransformer.kt │ └── res │ └── .gitignore ├── maven.keystore.gpg ├── publish.gradle └── settings.gradle /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | defaults: &defaults 2 | working_directory: ~/repo 3 | docker: 4 | - image: toxicbakery/alpine-glibc-android:release-1.3.4 5 | environment: 6 | TERM: dumb 7 | 8 | version: 2 9 | jobs: 10 | build: 11 | <<: *defaults 12 | steps: 13 | - checkout 14 | - run: 15 | name: Execute Gradle 16 | command: | 17 | echo "org.gradle.parallel=false" >> gradle.properties 18 | echo "org.gradle.daemon=false" >> gradle.properties 19 | echo "org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -Dfile.encoding=UTF-8" >> gradle.properties 20 | 21 | # Only deploy master and tags, only tags are pushed as releases to OSS. Forks never attempt deploy 22 | if [ -z "$CIRCLE_PR_REPONAME" ] && { [ "master" = "$CIRCLE_BRANCH" ] || [ ! -z "$CIRCLE_TAG" ]; }; then 23 | echo "signing.keyId=${SIGNING_KEY}" >> "gradle.properties" 24 | echo "signing.password=${SIGNING_PASSWORD}" >> "gradle.properties" 25 | echo "signing.secretKeyRingFile=../maven.keystore" >> "gradle.properties" 26 | gpg --cipher-algo AES256 --yes --batch --passphrase=$ENC_FILE_KEY maven.keystore.gpg 27 | # Build and deploy 28 | ./gradlew build dokkaGhPages publish 29 | else 30 | # Regular Build 31 | ./gradlew build 32 | fi 33 | 34 | # Codecov report for non forked work 35 | if [ -z "$CIRCLE_PR_REPONAME" ]; then 36 | bash <(curl -s https://codecov.io/bash) 37 | fi 38 | 39 | # Github Pages for master non forked work 40 | if [ -z "$CIRCLE_PR_REPONAME" ] && [ "master" = "$CIRCLE_BRANCH" ]; then 41 | git config --global user.email $GH_EMAIL 42 | git config --global user.name $GH_NAME 43 | cp -r .circleci library/build/gh-pages/.circleci 44 | cd library/build/gh-pages 45 | git init 46 | git checkout --orphan gh-pages 47 | git add -A 48 | git commit -m "Automated deployment of ${CIRCLE_BRANCH} ${CIRCLE_SHA1}" --allow-empty 49 | git push -q https://${GH_PERSONAL_TOKEN}@github.com/ToxicBakery/${CIRCLE_PROJECT_REPONAME}.git gh-pages --force 50 | fi 51 | 52 | workflows: 53 | version: 2 54 | build: 55 | jobs: 56 | - build: 57 | context: Sonatype 58 | filters: 59 | tags: 60 | only: /.*/ 61 | branches: 62 | ignore: 63 | - gh-pages 64 | 65 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | /*/build/ 3 | build/ 4 | 5 | # Crashlytics configuations 6 | com_crashlytics_export_strings.xml 7 | 8 | # Local configuration file (sdk path, etc) 9 | local.properties 10 | 11 | # Gradle generated files 12 | .gradle/ 13 | 14 | # Signing files 15 | .signing/ 16 | 17 | # User-specific configurations 18 | .idea 19 | *.iml 20 | 21 | # OS-specific files 22 | .DS_Store 23 | .DS_Store? 24 | ._* 25 | .Spotlight-V100 26 | .Trashes 27 | ehthumbs.db 28 | Thumbs.db -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014 Toxic Bakery 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![CircleCI](https://circleci.com/gh/ToxicBakery/ViewPagerTransforms.svg?style=svg)](https://circleci.com/gh/ToxicBakery/ViewPagerTransforms) 2 | [![License](https://img.shields.io/badge/license-Apache%202.0%20License-blue.svg)](https://github.com/ToxicBakery/ViewPagerTransforms/blob/master/LICENSE) 3 | [![Maven Central](https://img.shields.io/maven-metadata/v/https/oss.sonatype.org/content/repositories/releases/com/ToxicBakery/viewpager/transforms/view-pager-transforms/maven-metadata.xml.svg)](https://oss.sonatype.org/content/repositories/releases/com/ToxicBakery/viewpager/transforms/view-pager-transforms) 4 | 5 | ViewPagerTransforms 6 | =================== 7 | 8 | Library containing common animations needed for transforming ViewPager scrolling on Android v13+. This library is a rewrite of the [JazzyViewPager](https://github.com/jfeinstein10/JazzyViewPager) library and owes credit of the animation concepts directly to its source. The purpose of this rewrite is to provide an easier to use and extend implementation of ViewPager animations. 9 | 10 | ![Demo](http://i.imgur.com/rvhE2ns.gif) 11 | 12 | # Getting Started (Gradle / Android Studio) 13 | 14 | Add gradle dependency to your application. 15 | ```gradle 16 | implementation 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:2.0.24' 17 | ``` 18 | 19 | After configuration, instantiate the transformer animation you wish to use and set it as the [page transformer](https://developer.android.com/reference/android/support/v4/view/ViewPager.html#setpagetransformer_1). 20 | 21 | ```java 22 | // Reference (or instantiate) a ViewPager instance and apply a transformer 23 | pager = (ViewPager) findViewById(R.id.container); 24 | pager.setAdapter(mAdapter); 25 | pager.setPageTransformer(true, new RotateUpTransformer()); 26 | ``` 27 | 28 | # Creating Custom Transforms 29 | 30 | All ViewPagerTransform implementations extend [ABaseTransformer](https://github.com/ToxicBakery/ViewPagerTransforms/blob/master/library/src/main/java/com/ToxicBakery/viewpager/transforms/ABaseTransformer.java) providing useful hooks improving readability of animations and basic functionality important when switching between animations. [ABaseTransformer](https://github.com/ToxicBakery/ViewPagerTransforms/blob/master/library/src/main/java/com/ToxicBakery/viewpager/transforms/ABaseTransformer.java) provides three lifecycle hooks and two flags for default handling of hiding offscreen fragments and mimicking the default paging functionality of the ViewPager. 31 | 32 | * [onPreTransform(View view, float position)](https://github.com/ToxicBakery/ViewPagerTransforms/blob/master/library/src/main/java/com/ToxicBakery/viewpager/transforms/ABaseTransformer.java#L85) 33 | * Default implementation resets the animation state of the fragment to defaults that will place it on the screen if its position permits. 34 | * [onTransform(View view, float position)](https://github.com/ToxicBakery/ViewPagerTransforms/blob/master/library/src/main/java/com/ToxicBakery/viewpager/transforms/ABaseTransformer.java#L33) 35 | * Animations should perform all or most of their work inside this callback. 36 | * [onPostTransform(View view, float position)](https://github.com/ToxicBakery/ViewPagerTransforms/blob/master/library/src/main/java/com/ToxicBakery/viewpager/transforms/ABaseTransformer.java#L116) 37 | * Default implementation does nothing. This provides a logical location for any additional work to be done that is not directly related to the animation. 38 | 39 | ## Building 40 | This project is built with Gradle using the Gradle Wrapper script. 41 | 42 | ```bash 43 | ./gradlew build 44 | ``` 45 | 46 | ## Creating Local Versions 47 | You can modify this project and create local packages with via the maven publish plugin used in the build scripts. 48 | 49 | ```bash 50 | ./gradlew publishToMavenLocal 51 | ``` 52 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.application' 18 | apply plugin: 'kotlin-android' 19 | 20 | repositories { 21 | maven { 22 | url "https://oss.sonatype.org/content/repositories/snapshots" 23 | } 24 | maven { 25 | url "https://oss.sonatype.org/content/repositories/releases" 26 | } 27 | } 28 | 29 | android { 30 | compileSdkVersion android_target_sdk 31 | buildToolsVersion = android_build_tools_version 32 | 33 | defaultConfig { 34 | applicationId "com.ToxicBakery.viewpager.transforms" 35 | minSdkVersion 14 36 | targetSdkVersion android_target_sdk 37 | versionCode 1 38 | versionName "1.0" 39 | } 40 | 41 | buildTypes { 42 | release { 43 | minifyEnabled false 44 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 45 | } 46 | } 47 | 48 | lintOptions { 49 | abortOnError false 50 | } 51 | 52 | testOptions { 53 | animationsDisabled true 54 | unitTests { 55 | returnDefaultValues = true 56 | includeAndroidResources = true 57 | } 58 | } 59 | 60 | dexOptions { 61 | // Skip pre-dexing when running on CI 62 | preDexLibraries = !isCi 63 | javaMaxHeapSize maxDexHeap 64 | } 65 | } 66 | 67 | dependencies { 68 | implementation "com.android.support:appcompat-v7:$android_support_version" 69 | implementation "com.android.support:support-v4:$android_support_version" 70 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 71 | implementation project(':library') 72 | } 73 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\android/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | 21 | 22 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/ToxicBakery/viewpager/transforms/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms.example 18 | 19 | import android.os.Bundle 20 | import android.support.v4.app.Fragment 21 | import android.support.v4.app.FragmentManager 22 | import android.support.v4.app.FragmentStatePagerAdapter 23 | import android.support.v4.view.ViewPager 24 | import android.support.v4.view.ViewPager.PageTransformer 25 | import android.support.v7.app.AppCompatActivity 26 | import android.support.v7.widget.AppCompatSpinner 27 | import android.view.LayoutInflater 28 | import android.view.View 29 | import android.view.ViewGroup 30 | import android.widget.AdapterView 31 | import android.widget.ArrayAdapter 32 | import android.widget.TextView 33 | import com.ToxicBakery.viewpager.transforms.* 34 | 35 | class MainActivity : AppCompatActivity() { 36 | 37 | private var selectedClassIndex: Int = 0 38 | private lateinit var pager: ViewPager 39 | 40 | override fun onCreate(savedInstanceState: Bundle?) { 41 | super.onCreate(savedInstanceState) 42 | 43 | setContentView(R.layout.activity_main) 44 | setSupportActionBar(findViewById(R.id.toolbar)) 45 | 46 | selectedClassIndex = savedInstanceState?.getInt(KEY_SELECTED_CLASS) ?: 0 47 | 48 | pager = findViewById(R.id.container) 49 | pager.adapter = PageAdapter(supportFragmentManager) 50 | pager.currentItem = savedInstanceState?.getInt(KEY_SELECTED_PAGE) ?: 0 51 | 52 | title = "" 53 | 54 | findViewById(R.id.spinner).apply { 55 | adapter = ArrayAdapter( 56 | applicationContext, 57 | android.R.layout.simple_list_item_1, 58 | android.R.id.text1, 59 | TRANSFORM_CLASSES) 60 | setSelection(selectedClassIndex) 61 | onItemSelectedListener = object : AdapterView.OnItemSelectedListener { 62 | override fun onNothingSelected(parent: AdapterView<*>?) = Unit 63 | 64 | override fun onItemSelected( 65 | parent: AdapterView<*>, 66 | view: View?, 67 | position: Int, 68 | id: Long) = selectPage(position) 69 | } 70 | } 71 | } 72 | 73 | public override fun onSaveInstanceState(outState: Bundle) { 74 | super.onSaveInstanceState(outState) 75 | outState.putInt(KEY_SELECTED_CLASS, selectedClassIndex) 76 | outState.putInt(KEY_SELECTED_PAGE, pager.currentItem) 77 | } 78 | 79 | private fun selectPage(position: Int) { 80 | selectedClassIndex = position 81 | pager.setPageTransformer(true, TRANSFORM_CLASSES[position].clazz.newInstance()) 82 | } 83 | 84 | class PlaceholderFragment : Fragment() { 85 | 86 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 87 | val position = arguments!!.getInt(EXTRA_POSITION) 88 | val textViewPosition = inflater.inflate(R.layout.fragment_main, container, false) as TextView 89 | textViewPosition.text = position.toString() 90 | textViewPosition.setBackgroundColor(COLORS[position - 1]) 91 | 92 | return textViewPosition 93 | } 94 | 95 | companion object { 96 | private const val EXTRA_POSITION = "EXTRA_POSITION" 97 | private val COLORS = intArrayOf(-0xcc4a1b, -0x559934, -0x663400, -0x44cd, -0xbbbc) 98 | 99 | fun newInstance(position: Int) = PlaceholderFragment().apply { 100 | arguments = Bundle().apply { 101 | putInt(PlaceholderFragment.EXTRA_POSITION, position) 102 | } 103 | } 104 | } 105 | 106 | } 107 | 108 | private class PageAdapter internal constructor(fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) { 109 | 110 | override fun getItem(position: Int): Fragment = 111 | PlaceholderFragment.newInstance(position + 1) 112 | 113 | override fun getCount(): Int { 114 | return 5 115 | } 116 | 117 | } 118 | 119 | class TransformerItem( 120 | val clazz: Class, 121 | val title: String = clazz.simpleName 122 | ) { 123 | override fun toString(): String = title 124 | } 125 | 126 | companion object { 127 | private const val KEY_SELECTED_PAGE = "KEY_SELECTED_PAGE" 128 | private const val KEY_SELECTED_CLASS = "KEY_SELECTED_CLASS" 129 | 130 | private val TRANSFORM_CLASSES: List = listOf( 131 | TransformerItem(DefaultTransformer::class.java), 132 | TransformerItem(AccordionTransformer::class.java), 133 | TransformerItem(BackgroundToForegroundTransformer::class.java), 134 | TransformerItem(CubeInTransformer::class.java), 135 | TransformerItem(CubeOutTransformer::class.java), 136 | TransformerItem(DepthPageTransformer::class.java), 137 | TransformerItem(FlipHorizontalTransformer::class.java), 138 | TransformerItem(FlipVerticalTransformer::class.java), 139 | TransformerItem(ForegroundToBackgroundTransformer::class.java), 140 | TransformerItem(RotateDownTransformer::class.java), 141 | TransformerItem(RotateUpTransformer::class.java), 142 | TransformerItem(ScaleInOutTransformer::class.java), 143 | TransformerItem(StackTransformer::class.java), 144 | TransformerItem(TabletTransformer::class.java), 145 | TransformerItem(ZoomInTransformer::class.java), 146 | TransformerItem(ZoomOutSlideTransformer::class.java), 147 | TransformerItem(ZoomOutTransformer::class.java), 148 | TransformerItem(DrawerTransformer::class.java) 149 | ) 150 | 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ToxicBakery/ViewPagerTransforms/2c3ffe13c43467d5d0ae2ec5e2bcd95c6391817d/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 28 | 29 | 33 | 34 | 35 | 36 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_main.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | ViewPagerTransforms Example 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/values/style.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 22 | 23 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 18 | 19 | buildscript { 20 | ext.android_target_sdk = 28 21 | ext.android_build_tools_version = '28.0.3' 22 | 23 | ext.kotlin_version = '1.3.50' 24 | ext.jacoco_version = '0.8.1' 25 | ext.dokka_version = '0.9.17' 26 | 27 | ext.android_support_version = '28.0.0' 28 | 29 | repositories { 30 | google() 31 | jcenter() 32 | } 33 | dependencies { 34 | classpath 'com.android.tools.build:gradle:3.5.1' 35 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 36 | classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version" 37 | classpath 'digital.wup:android-maven-publish:3.6.2' 38 | classpath "org.jacoco:org.jacoco.core:$jacoco_version" 39 | } 40 | } 41 | 42 | ext { 43 | tagName = System.getenv('CIRCLE_TAG') 44 | isTag = tagName != null && !tagName.isEmpty() 45 | buildNumber = System.getenv('CIRCLE_BUILD_NUM') ?: "0" 46 | isCi = buildNumber != "0" 47 | maxDexHeap = "2g" 48 | } 49 | 50 | subprojects { 51 | group 'com.ToxicBakery.viewpager.transforms' 52 | version "2.0.${buildNumber}" + (isTag ? "" : "-SNAPSHOT") 53 | 54 | repositories { 55 | google() 56 | mavenCentral() 57 | jcenter() 58 | } 59 | } 60 | 61 | task clean(type: Delete) { 62 | delete rootProject.buildDir 63 | } 64 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014 Toxic Bakery 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | POM_NAME=ViewPagerTransforms 18 | POM_ARTIFACT_ID=view-pager-transforms 19 | POM_PACKAGING=aar 20 | POM_DESCRIPTION=Library containing common animations needed for transforming ViewPager scrolling on Android v13+ 21 | POM_URL=https://github.com/ToxicBakery/ViewPagerTransforms 22 | POM_SCM_URL=https://github.com/ToxicBakery/ViewPagerTransforms.git 23 | POM_SCM_CONNECTION=scm:git@github.com:ToxicBakery/ViewPagerTransforms.git 24 | POM_SCM_DEV_CONNECTION=scm:git@github.com:ToxicBakery/ViewPagerTransforms.git 25 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 26 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 27 | POM_LICENCE_DIST=repo 28 | POM_DEVELOPER_ID=toxicbakery 29 | POM_DEVELOPER_NAME=Ian Thomas 30 | POM_DEVELOPER_EMAIL=toxicbakery@gmail.com 31 | POM_DEVELOPER_ORGANIZATION=Toxic Bakery 32 | POM_DEVELOPER_ORGANIZATION_URL=https://github.com/ToxicBakery 33 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ToxicBakery/ViewPagerTransforms/2c3ffe13c43467d5d0ae2ec5e2bcd95c6391817d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Nov 02 19:53:49 CET 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | id("io.gitlab.arturbosch.detekt").version("1.0.0-RC12") 19 | } 20 | 21 | apply plugin: 'com.android.library' 22 | apply plugin: 'kotlin-android' 23 | 24 | repositories { 25 | google() 26 | jcenter() 27 | mavenCentral() 28 | } 29 | 30 | android { 31 | compileSdkVersion android_target_sdk 32 | buildToolsVersion = android_build_tools_version 33 | 34 | defaultConfig { 35 | minSdkVersion 14 36 | targetSdkVersion android_target_sdk 37 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 38 | } 39 | 40 | buildTypes { 41 | debug { 42 | testCoverageEnabled true 43 | } 44 | release { 45 | minifyEnabled false 46 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 47 | } 48 | } 49 | 50 | lintOptions { 51 | abortOnError false 52 | } 53 | 54 | testOptions { 55 | animationsDisabled true 56 | unitTests { 57 | returnDefaultValues = true 58 | includeAndroidResources = true 59 | } 60 | } 61 | 62 | dexOptions { 63 | // Skip pre-dexing when running on CI 64 | preDexLibraries = !isCi 65 | javaMaxHeapSize maxDexHeap 66 | } 67 | } 68 | 69 | dependencies { 70 | implementation "com.android.support:support-v4:$android_support_version" 71 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 72 | } 73 | 74 | detekt { 75 | input = files("src/main/java") 76 | config = files("$projectDir/detekt.yml") 77 | parallel = true 78 | reports { 79 | xml.enabled = false 80 | html { 81 | enabled = true 82 | destination = file("build/reports/detekt/detekt.html") 83 | } 84 | } 85 | } 86 | check.dependsOn('detekt') 87 | 88 | apply from: "${rootDir}/publish.gradle" 89 | 90 | task dokkaGhPages(type: org.jetbrains.dokka.gradle.DokkaAndroidTask) { 91 | outputFormat = 'html' 92 | outputDirectory = "$buildDir/gh-pages" 93 | sourceDirs = files('src/main/java') 94 | skipEmptyPackages = true 95 | skipDeprecated = false 96 | noStdlibLink = false 97 | } 98 | 99 | task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaAndroidTask) { 100 | outputFormat = 'javadoc' 101 | outputDirectory = "$buildDir/javadoc" 102 | sourceDirs = files('src/main/java') 103 | skipEmptyPackages = true 104 | skipDeprecated = false 105 | noStdlibLink = false 106 | } 107 | -------------------------------------------------------------------------------- /library/detekt.yml: -------------------------------------------------------------------------------- 1 | autoCorrect: true 2 | failFast: false 3 | 4 | test-pattern: # Configure exclusions for test sources 5 | active: true 6 | patterns: # Test file regexes 7 | - '.*/test/.*' 8 | - '.*Test.kt' 9 | - '.*Spec.kt' 10 | exclude-rule-sets: 11 | - 'comments' 12 | exclude-rules: 13 | - 'NamingRules' 14 | - 'WildcardImport' 15 | - 'MagicNumber' 16 | - 'MaxLineLength' 17 | - 'LateinitUsage' 18 | - 'StringLiteralDuplication' 19 | - 'SpreadOperator' 20 | - 'TooManyFunctions' 21 | - 'ForEachOnRange' 22 | - 'FunctionMaxLength' 23 | - 'TooGenericExceptionCaught' 24 | 25 | build: 26 | maxIssues: 0 27 | weights: 28 | # complexity: 2 29 | # LongParameterList: 1 30 | # style: 1 31 | # comments: 1 32 | 33 | processors: 34 | active: true 35 | exclude: 36 | # - 'FunctionCountProcessor' 37 | # - 'PropertyCountProcessor' 38 | # - 'ClassCountProcessor' 39 | # - 'PackageCountProcessor' 40 | # - 'KtFileCountProcessor' 41 | 42 | console-reports: 43 | active: true 44 | exclude: 45 | # - 'ProjectStatisticsReport' 46 | # - 'ComplexityReport' 47 | # - 'NotificationReport' 48 | # - 'FindingsReport' 49 | # - 'BuildFailureReport' 50 | 51 | comments: 52 | active: true 53 | CommentOverPrivateFunction: 54 | active: false 55 | CommentOverPrivateProperty: 56 | active: false 57 | EndOfSentenceFormat: 58 | active: false 59 | endOfSentenceFormat: ([.?!][ \t\n\r\f<])|([.?!]$) 60 | UndocumentedPublicClass: 61 | active: false 62 | searchInNestedClass: true 63 | searchInInnerClass: true 64 | searchInInnerObject: true 65 | searchInInnerInterface: true 66 | UndocumentedPublicFunction: 67 | active: false 68 | 69 | complexity: 70 | active: true 71 | ComplexCondition: 72 | active: true 73 | threshold: 4 74 | ComplexInterface: 75 | active: false 76 | threshold: 10 77 | includeStaticDeclarations: false 78 | ComplexMethod: 79 | active: true 80 | threshold: 10 81 | ignoreSingleWhenExpression: false 82 | ignoreSimpleWhenEntries: false 83 | LabeledExpression: 84 | active: false 85 | ignoredLabels: "" 86 | LargeClass: 87 | active: true 88 | threshold: 150 89 | LongMethod: 90 | active: true 91 | threshold: 20 92 | LongParameterList: 93 | active: true 94 | threshold: 6 95 | ignoreDefaultParameters: false 96 | MethodOverloading: 97 | active: false 98 | threshold: 6 99 | NestedBlockDepth: 100 | active: true 101 | threshold: 4 102 | StringLiteralDuplication: 103 | active: false 104 | threshold: 3 105 | ignoreAnnotation: true 106 | excludeStringsWithLessThan5Characters: true 107 | ignoreStringsRegex: '$^' 108 | TooManyFunctions: 109 | active: true 110 | thresholdInFiles: 11 111 | thresholdInClasses: 11 112 | thresholdInInterfaces: 11 113 | thresholdInObjects: 11 114 | thresholdInEnums: 11 115 | ignoreDeprecated: false 116 | ignorePrivate: false 117 | 118 | empty-blocks: 119 | active: true 120 | EmptyCatchBlock: 121 | active: true 122 | allowedExceptionNameRegex: "^(_|(ignore|expected).*)" 123 | EmptyClassBlock: 124 | active: true 125 | EmptyDefaultConstructor: 126 | active: true 127 | EmptyDoWhileBlock: 128 | active: true 129 | EmptyElseBlock: 130 | active: true 131 | EmptyFinallyBlock: 132 | active: true 133 | EmptyForBlock: 134 | active: true 135 | EmptyFunctionBlock: 136 | active: true 137 | ignoreOverriddenFunctions: false 138 | EmptyIfBlock: 139 | active: true 140 | EmptyInitBlock: 141 | active: true 142 | EmptyKtFile: 143 | active: true 144 | EmptySecondaryConstructor: 145 | active: true 146 | EmptyWhenBlock: 147 | active: true 148 | EmptyWhileBlock: 149 | active: true 150 | 151 | exceptions: 152 | active: true 153 | ExceptionRaisedInUnexpectedLocation: 154 | active: false 155 | methodNames: 'toString,hashCode,equals,finalize' 156 | InstanceOfCheckForException: 157 | active: false 158 | NotImplementedDeclaration: 159 | active: false 160 | PrintStackTrace: 161 | active: false 162 | RethrowCaughtException: 163 | active: false 164 | ReturnFromFinally: 165 | active: false 166 | SwallowedException: 167 | active: false 168 | ignoredExceptionTypes: 'InterruptedException,NumberFormatException,ParseException,MalformedURLException' 169 | ThrowingExceptionFromFinally: 170 | active: false 171 | ThrowingExceptionInMain: 172 | active: false 173 | ThrowingExceptionsWithoutMessageOrCause: 174 | active: false 175 | exceptions: 'IllegalArgumentException,IllegalStateException,IOException' 176 | ThrowingNewInstanceOfSameException: 177 | active: false 178 | TooGenericExceptionCaught: 179 | active: true 180 | exceptionNames: 181 | - ArrayIndexOutOfBoundsException 182 | - Error 183 | - Exception 184 | - IllegalMonitorStateException 185 | - NullPointerException 186 | - IndexOutOfBoundsException 187 | - RuntimeException 188 | - Throwable 189 | allowedExceptionNameRegex: "^(_|(ignore|expected).*)" 190 | TooGenericExceptionThrown: 191 | active: true 192 | exceptionNames: 193 | - Error 194 | - Exception 195 | - Throwable 196 | - RuntimeException 197 | 198 | formatting: 199 | active: true 200 | android: false 201 | autoCorrect: true 202 | ChainWrapping: 203 | active: true 204 | autoCorrect: true 205 | CommentSpacing: 206 | active: true 207 | autoCorrect: true 208 | Filename: 209 | active: true 210 | FinalNewline: 211 | active: true 212 | autoCorrect: true 213 | ImportOrdering: 214 | active: true 215 | autoCorrect: true 216 | Indentation: 217 | active: true 218 | autoCorrect: true 219 | indentSize: 4 220 | continuationIndentSize: 4 221 | MaximumLineLength: 222 | active: true 223 | maxLineLength: 120 224 | ModifierOrdering: 225 | active: true 226 | autoCorrect: true 227 | NoBlankLineBeforeRbrace: 228 | active: true 229 | autoCorrect: true 230 | NoConsecutiveBlankLines: 231 | active: true 232 | autoCorrect: true 233 | NoEmptyClassBody: 234 | active: true 235 | autoCorrect: true 236 | NoItParamInMultilineLambda: 237 | active: true 238 | NoLineBreakAfterElse: 239 | active: true 240 | autoCorrect: true 241 | NoLineBreakBeforeAssignment: 242 | active: true 243 | autoCorrect: true 244 | NoMultipleSpaces: 245 | active: true 246 | autoCorrect: true 247 | NoSemicolons: 248 | active: true 249 | autoCorrect: true 250 | NoTrailingSpaces: 251 | active: true 252 | autoCorrect: true 253 | NoUnitReturn: 254 | active: true 255 | autoCorrect: true 256 | NoUnusedImports: 257 | active: true 258 | autoCorrect: true 259 | NoWildcardImports: 260 | active: true 261 | autoCorrect: true 262 | PackageName: 263 | active: true 264 | autoCorrect: true 265 | ParameterListWrapping: 266 | active: true 267 | autoCorrect: true 268 | indentSize: 4 269 | SpacingAroundColon: 270 | active: true 271 | autoCorrect: true 272 | SpacingAroundComma: 273 | active: true 274 | autoCorrect: true 275 | SpacingAroundCurly: 276 | active: true 277 | autoCorrect: true 278 | SpacingAroundKeyword: 279 | active: true 280 | autoCorrect: true 281 | SpacingAroundOperators: 282 | active: true 283 | autoCorrect: true 284 | SpacingAroundParens: 285 | active: true 286 | autoCorrect: true 287 | SpacingAroundRangeOperator: 288 | active: true 289 | autoCorrect: true 290 | StringTemplate: 291 | active: true 292 | autoCorrect: true 293 | 294 | naming: 295 | active: true 296 | ClassNaming: 297 | active: true 298 | classPattern: '[A-Z$][a-zA-Z0-9$]*' 299 | ConstructorParameterNaming: 300 | active: true 301 | parameterPattern: '[a-z][A-Za-z0-9]*' 302 | privateParameterPattern: '[a-z][A-Za-z0-9]*' 303 | excludeClassPattern: '$^' 304 | EnumNaming: 305 | active: true 306 | enumEntryPattern: '^[A-Z][_a-zA-Z0-9]*' 307 | ForbiddenClassName: 308 | active: false 309 | forbiddenName: '' 310 | FunctionMaxLength: 311 | active: false 312 | maximumFunctionNameLength: 30 313 | FunctionMinLength: 314 | active: false 315 | minimumFunctionNameLength: 3 316 | FunctionNaming: 317 | active: true 318 | functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' 319 | excludeClassPattern: '$^' 320 | ignoreOverridden: true 321 | FunctionParameterNaming: 322 | active: true 323 | parameterPattern: '[a-z][A-Za-z0-9]*' 324 | excludeClassPattern: '$^' 325 | ignoreOverriddenFunctions: true 326 | MatchingDeclarationName: 327 | active: true 328 | MemberNameEqualsClassName: 329 | active: false 330 | ignoreOverriddenFunction: true 331 | ObjectPropertyNaming: 332 | active: true 333 | constantPattern: '[A-Za-z][_A-Za-z0-9]*' 334 | propertyPattern: '[A-Za-z][_A-Za-z0-9]*' 335 | privatePropertyPattern: '(_)?[A-Za-z][_A-Za-z0-9]*' 336 | PackageNaming: 337 | active: false 338 | packagePattern: '^[a-z]+(\.[a-z][a-z0-9]*)*$' 339 | TopLevelPropertyNaming: 340 | active: true 341 | constantPattern: '[A-Z][_A-Z0-9]*' 342 | propertyPattern: '[A-Za-z][_A-Za-z0-9]*' 343 | privatePropertyPattern: '(_)?[A-Za-z][A-Za-z0-9]*' 344 | VariableMaxLength: 345 | active: false 346 | maximumVariableNameLength: 64 347 | VariableMinLength: 348 | active: false 349 | minimumVariableNameLength: 1 350 | VariableNaming: 351 | active: true 352 | variablePattern: '[a-z][A-Za-z0-9]*' 353 | privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' 354 | excludeClassPattern: '$^' 355 | ignoreOverridden: true 356 | 357 | performance: 358 | active: true 359 | ArrayPrimitive: 360 | active: false 361 | ForEachOnRange: 362 | active: true 363 | SpreadOperator: 364 | active: true 365 | UnnecessaryTemporaryInstantiation: 366 | active: true 367 | 368 | potential-bugs: 369 | active: true 370 | DuplicateCaseInWhenExpression: 371 | active: true 372 | EqualsAlwaysReturnsTrueOrFalse: 373 | active: false 374 | EqualsWithHashCodeExist: 375 | active: true 376 | ExplicitGarbageCollectionCall: 377 | active: true 378 | InvalidRange: 379 | active: false 380 | IteratorHasNextCallsNextMethod: 381 | active: false 382 | IteratorNotThrowingNoSuchElementException: 383 | active: false 384 | LateinitUsage: 385 | active: false 386 | excludeAnnotatedProperties: "" 387 | ignoreOnClassesPattern: "" 388 | UnconditionalJumpStatementInLoop: 389 | active: false 390 | UnreachableCode: 391 | active: true 392 | UnsafeCallOnNullableType: 393 | active: false 394 | UnsafeCast: 395 | active: false 396 | UselessPostfixExpression: 397 | active: false 398 | WrongEqualsTypeParameter: 399 | active: false 400 | 401 | style: 402 | active: true 403 | CollapsibleIfStatements: 404 | active: false 405 | DataClassContainsFunctions: 406 | active: false 407 | conversionFunctionPrefix: 'to' 408 | EqualsNullCall: 409 | active: false 410 | EqualsOnSignatureLine: 411 | active: false 412 | ExplicitItLambdaParameter: 413 | active: false 414 | ExpressionBodySyntax: 415 | active: false 416 | includeLineWrapping: false 417 | ForbiddenComment: 418 | active: true 419 | values: 'TODO:,FIXME:,STOPSHIP:' 420 | ForbiddenImport: 421 | active: false 422 | imports: '' 423 | ForbiddenVoid: 424 | active: false 425 | FunctionOnlyReturningConstant: 426 | active: false 427 | ignoreOverridableFunction: true 428 | excludedFunctions: 'describeContents' 429 | LoopWithTooManyJumpStatements: 430 | active: false 431 | maxJumpCount: 1 432 | MagicNumber: 433 | active: true 434 | ignoreNumbers: '-1,0,1,2,0.5,-0.5,0.25,90,-90,180,-180' 435 | ignoreHashCodeFunction: true 436 | ignorePropertyDeclaration: false 437 | ignoreConstantDeclaration: true 438 | ignoreCompanionObjectPropertyDeclaration: true 439 | ignoreAnnotation: false 440 | ignoreNamedArgument: true 441 | ignoreEnums: false 442 | MandatoryBracesIfStatements: 443 | active: false 444 | MaxLineLength: 445 | active: true 446 | maxLineLength: 120 447 | excludePackageStatements: true 448 | excludeImportStatements: true 449 | excludeCommentStatements: false 450 | MayBeConst: 451 | active: false 452 | ModifierOrder: 453 | active: true 454 | NestedClassesVisibility: 455 | active: false 456 | NewLineAtEndOfFile: 457 | active: true 458 | NoTabs: 459 | active: false 460 | OptionalAbstractKeyword: 461 | active: true 462 | OptionalUnit: 463 | active: false 464 | OptionalWhenBraces: 465 | active: false 466 | PreferToOverPairSyntax: 467 | active: false 468 | ProtectedMemberInFinalClass: 469 | active: false 470 | RedundantVisibilityModifierRule: 471 | active: false 472 | ReturnCount: 473 | active: true 474 | max: 2 475 | excludedFunctions: "equals" 476 | excludeLabeled: false 477 | excludeReturnFromLambda: true 478 | SafeCast: 479 | active: true 480 | SerialVersionUIDInSerializableClass: 481 | active: false 482 | SpacingBetweenPackageAndImports: 483 | active: false 484 | ThrowsCount: 485 | active: true 486 | max: 2 487 | TrailingWhitespace: 488 | active: false 489 | UnnecessaryAbstractClass: 490 | active: false 491 | excludeAnnotatedClasses: "dagger.Module" 492 | UnnecessaryApply: 493 | active: false 494 | UnnecessaryInheritance: 495 | active: false 496 | UnnecessaryLet: 497 | active: false 498 | UnnecessaryParentheses: 499 | active: false 500 | UntilInsteadOfRangeTo: 501 | active: false 502 | UnusedImports: 503 | active: false 504 | UnusedPrivateClass: 505 | active: false 506 | UnusedPrivateMember: 507 | active: false 508 | allowedNames: "(_|ignored|expected|serialVersionUID)" 509 | UseDataClass: 510 | active: false 511 | excludeAnnotatedClasses: "" 512 | UtilityClassWithPublicConstructor: 513 | active: false 514 | VarCouldBeVal: 515 | active: false 516 | WildcardImport: 517 | active: true 518 | excludeImports: 'java.util.*,kotlinx.android.synthetic.*' -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:/android/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/ABaseTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.support.v4.view.ViewPager.PageTransformer 20 | import android.view.View 21 | 22 | abstract class ABaseTransformer : PageTransformer { 23 | 24 | /** 25 | * Indicates if the default animations of the view pager should be used. 26 | * 27 | * @return 28 | */ 29 | protected open val isPagingEnabled: Boolean 30 | get() = false 31 | 32 | /** 33 | * Called each [.transformPage]. 34 | * 35 | * @param page 36 | * Apply the transformation to this page 37 | * @param position 38 | * Position of page relative to the current front-and-center position of the pager. 0 is front and 39 | * center. 1 is one full page position to the right, and -1 is one page position to the left. 40 | */ 41 | protected abstract fun onTransform(page: View, position: Float) 42 | 43 | /** 44 | * Apply a property transformation to the given page. For most use cases, this method should not be overridden. 45 | * Instead use [.transformPage] to perform typical transformations. 46 | * 47 | * @param page 48 | * Apply the transformation to this page 49 | * @param position 50 | * Position of page relative to the current front-and-center position of the pager. 0 is front and 51 | * center. 1 is one full page position to the right, and -1 is one page position to the left. 52 | */ 53 | override fun transformPage(page: View, position: Float) { 54 | val clampedPosition = clampPosition(position) 55 | onPreTransform(page, clampedPosition) 56 | onTransform(page, clampedPosition) 57 | onPostTransform(page, clampedPosition) 58 | } 59 | 60 | /** 61 | * Clamp the position. This step is required for some Android 4 devices. 62 | *

63 | * The position is dependant on the range of the ViewPager and whether it supports infinite scrolling in both 64 | * directions. 65 | * 66 | * On some devices it returns the position as NaN, so we set 0 as the fallback value 67 | * 68 | * @param position Position of page relative to the current front-and-center position of the pager. 69 | * @return A value between -1 and 1 70 | */ 71 | private fun clampPosition(position: Float): Float { 72 | return when { 73 | position < -1f -> -1f 74 | position > 1f -> 1f 75 | position.isNaN() -> 0f 76 | else -> position 77 | } 78 | } 79 | 80 | /** 81 | * If the position offset of a fragment is less than negative one or greater than one, returning true will set the 82 | * fragment alpha to 0f. Otherwise fragment alpha is always defaulted to 1f. 83 | * 84 | * @return 85 | */ 86 | protected open fun hideOffscreenPages(): Boolean { 87 | return true 88 | } 89 | 90 | /** 91 | * Called each [.transformPage] before {[.onTransform]. 92 | * 93 | * 94 | * The default implementation attempts to reset all view properties. This is useful when toggling transforms that do 95 | * not modify the same page properties. For instance changing from a transformation that applies rotation to a 96 | * transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied 97 | * alpha. 98 | * 99 | * @param page 100 | * Apply the transformation to this page 101 | * @param position 102 | * Position of page relative to the current front-and-center position of the pager. 0 is front and 103 | * center. 1 is one full page position to the right, and -1 is one page position to the left. 104 | */ 105 | protected open fun onPreTransform(page: View, position: Float) { 106 | val width = page.width.toFloat() 107 | 108 | page.rotationX = 0f 109 | page.rotationY = 0f 110 | page.rotation = 0f 111 | page.scaleX = 1f 112 | page.scaleY = 1f 113 | page.pivotX = 0f 114 | page.pivotY = 0f 115 | page.translationY = 0f 116 | page.translationX = if (isPagingEnabled) 0f else -width * position 117 | 118 | if (hideOffscreenPages()) { 119 | page.alpha = if (position <= -1f || position >= 1f) 0f else 1f 120 | page.isEnabled = false 121 | } else { 122 | page.isEnabled = true 123 | page.alpha = 1f 124 | } 125 | } 126 | 127 | /** 128 | * Called each [.transformPage] after [.onTransform]. 129 | * 130 | * @param page 131 | * Apply the transformation to this page 132 | * @param position 133 | * Position of page relative to the current front-and-center position of the pager. 0 is front and 134 | * center. 1 is one full page position to the right, and -1 is one page position to the left. 135 | */ 136 | protected open fun onPostTransform(page: View, position: Float) {} 137 | 138 | companion object { 139 | 140 | /** 141 | * Same as [Math.min] without double casting, zero closest to infinity handling, or NaN support. 142 | * 143 | * @param value 144 | * @param min 145 | * @return 146 | */ 147 | @JvmStatic 148 | protected fun min(value: Float, min: Float): Float { 149 | return if (value < min) min else value 150 | } 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/AccordionTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class AccordionTransformer : ABaseTransformer() { 22 | 23 | override fun onTransform(page: View, position: Float) { 24 | page.pivotX = if (position < 0) 0f else page.width.toFloat() 25 | page.scaleX = if (position < 0) 1f + position else 1f - position 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/BackgroundToForegroundTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class BackgroundToForegroundTransformer : ABaseTransformer() { 22 | 23 | override fun onTransform(page: View, position: Float) { 24 | val height = page.height.toFloat() 25 | val width = page.width.toFloat() 26 | val scale = min(if (position < 0) 1f else Math.abs(1f - position), 0.5f) 27 | 28 | page.scaleX = scale 29 | page.scaleY = scale 30 | page.pivotX = width * 0.5f 31 | page.pivotY = height * 0.5f 32 | page.translationX = if (position < 0) width * position else -width * position * 0.25f 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/CubeInTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class CubeInTransformer : ABaseTransformer() { 22 | 23 | public override val isPagingEnabled: Boolean 24 | get() = true 25 | 26 | override fun onTransform(page: View, position: Float) { 27 | // Rotate the fragment on the left or right edge 28 | page.pivotX = if (position > 0) 0f else page.width.toFloat() 29 | page.pivotY = 0f 30 | page.rotationY = -90f * position 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/CubeOutTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class CubeOutTransformer @JvmOverloads constructor( 22 | private val distanceMultiplier: Int = 20 23 | ) : ABaseTransformer() { 24 | 25 | public override val isPagingEnabled: Boolean 26 | get() = true 27 | 28 | override fun onTransform(page: View, position: Float) { 29 | page.cameraDistance = (page.width * distanceMultiplier).toFloat() 30 | page.pivotX = if (position < 0f) page.width.toFloat() else 0f 31 | page.pivotY = page.height * 0.5f 32 | page.rotationY = 90f * position 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/DefaultTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class DefaultTransformer : ABaseTransformer() { 22 | 23 | public override val isPagingEnabled: Boolean 24 | get() = true 25 | 26 | override fun onTransform(page: View, position: Float) {} 27 | 28 | } 29 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/DepthPageTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class DepthPageTransformer : ABaseTransformer() { 22 | 23 | override val isPagingEnabled: Boolean 24 | get() = true 25 | 26 | override fun onTransform(page: View, position: Float) { 27 | if (position <= 0f) { 28 | page.translationX = 0f 29 | page.scaleX = 1f 30 | page.scaleY = 1f 31 | } else if (position <= 1f) { 32 | val scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position)) 33 | page.alpha = 1 - position 34 | page.pivotY = 0.5f * page.height 35 | page.translationX = page.width * -position 36 | page.scaleX = scaleFactor 37 | page.scaleY = scaleFactor 38 | } 39 | } 40 | 41 | companion object { 42 | private const val MIN_SCALE = 0.75f 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/DrawerTransformer.kt: -------------------------------------------------------------------------------- 1 | package com.ToxicBakery.viewpager.transforms 2 | 3 | import android.view.View 4 | 5 | /** 6 | * Created by dkzwm on 2017/3/2. 7 | * 8 | * @author dkzwm 9 | */ 10 | open class DrawerTransformer : ABaseTransformer() { 11 | 12 | override fun onTransform(page: View, position: Float) { 13 | if (position <= 0) page.translationX = 0f 14 | else if (position <= 1) page.translationX = -page.width / 2 * position 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/FlipHorizontalTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class FlipHorizontalTransformer : ABaseTransformer() { 22 | 23 | override fun onTransform(page: View, position: Float) { 24 | val rotation = 180f * position 25 | 26 | page.alpha = if (rotation > 90f || rotation < -90f) 0f else 1f 27 | page.pivotX = page.width * 0.5f 28 | page.pivotY = page.height * 0.5f 29 | page.rotationY = rotation 30 | } 31 | 32 | override fun onPostTransform(page: View, position: Float) { 33 | super.onPostTransform(page, position) 34 | 35 | //resolve problem: new page can't handle click event! 36 | page.visibility = if (position > -0.5f && position < 0.5f) View.VISIBLE else View.INVISIBLE 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/FlipVerticalTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class FlipVerticalTransformer : ABaseTransformer() { 22 | 23 | override fun onTransform(page: View, position: Float) { 24 | val rotation = -180f * position 25 | 26 | page.alpha = if (rotation > 90f || rotation < -90f) 0f else 1f 27 | page.pivotX = page.width * 0.5f 28 | page.pivotY = page.height * 0.5f 29 | page.rotationX = rotation 30 | } 31 | 32 | override fun onPostTransform(page: View, position: Float) { 33 | super.onPostTransform(page, position) 34 | page.visibility = if (position > -0.5f && position < 0.5f) View.VISIBLE else View.INVISIBLE 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/ForegroundToBackgroundTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class ForegroundToBackgroundTransformer : ABaseTransformer() { 22 | 23 | override fun onTransform(page: View, position: Float) { 24 | val height = page.height.toFloat() 25 | val width = page.width.toFloat() 26 | val scale = min(if (position > 0) 1f else Math.abs(1f + position), 0.5f) 27 | 28 | page.scaleX = scale 29 | page.scaleY = scale 30 | page.pivotX = width * 0.5f 31 | page.pivotY = height * 0.5f 32 | page.translationX = if (position > 0) width * position else -width * position * 0.25f 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/RotateDownTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class RotateDownTransformer : ABaseTransformer() { 22 | 23 | override val isPagingEnabled: Boolean 24 | get() = true 25 | 26 | override fun onTransform(page: View, position: Float) { 27 | val width = page.width.toFloat() 28 | val height = page.height.toFloat() 29 | val rotation = ROT_MOD * position 30 | 31 | page.pivotX = width * 0.5f 32 | page.pivotY = height 33 | page.rotation = rotation 34 | } 35 | 36 | companion object { 37 | private const val ROT_MOD = 18.75f 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/RotateUpTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class RotateUpTransformer : ABaseTransformer() { 22 | 23 | override val isPagingEnabled: Boolean 24 | get() = true 25 | 26 | override fun onTransform(page: View, position: Float) { 27 | val width = page.width.toFloat() 28 | val rotation = ROT_MOD * position 29 | 30 | page.pivotX = width * 0.5f 31 | page.pivotY = 0f 32 | page.translationX = 0f 33 | page.rotation = rotation 34 | } 35 | 36 | companion object { 37 | private const val ROT_MOD = -15f 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/ScaleInOutTransformer.kt: -------------------------------------------------------------------------------- 1 | package com.ToxicBakery.viewpager.transforms 2 | 3 | import android.view.View 4 | 5 | open class ScaleInOutTransformer : ABaseTransformer() { 6 | 7 | override fun onTransform(page: View, position: Float) { 8 | page.pivotX = (if (position < 0) 0 else page.width).toFloat() 9 | page.pivotY = page.height / 2f 10 | val scale = if (position < 0) 1f + position else 1f - position 11 | page.scaleX = scale 12 | page.scaleY = scale 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/StackTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class StackTransformer : ABaseTransformer() { 22 | 23 | override fun onTransform(page: View, position: Float) { 24 | page.translationX = if (position < 0) 0f else -page.width * position 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/TabletTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.graphics.Camera 20 | import android.graphics.Matrix 21 | import android.view.View 22 | 23 | open class TabletTransformer : ABaseTransformer() { 24 | 25 | override fun onTransform(page: View, position: Float) { 26 | val rotation = if (position < 0) ROT_MOD else -ROT_MOD 27 | val rotationY = rotation * Math.abs(position) 28 | 29 | page.translationX = getOffsetXForRotation(rotationY, page.width, page.height) 30 | page.pivotX = page.width * 0.5f 31 | page.pivotY = 0f 32 | page.rotationY = rotationY 33 | } 34 | 35 | companion object { 36 | private val OFFSET_MATRIX = Matrix() 37 | private val OFFSET_CAMERA = Camera() 38 | private val OFFSET_TEMP_FLOAT = FloatArray(2) 39 | private const val ROT_MOD = 30f 40 | 41 | protected fun getOffsetXForRotation(degrees: Float, width: Int, height: Int): Float { 42 | OFFSET_MATRIX.reset() 43 | OFFSET_CAMERA.save() 44 | OFFSET_CAMERA.rotateY(Math.abs(degrees)) 45 | OFFSET_CAMERA.getMatrix(OFFSET_MATRIX) 46 | OFFSET_CAMERA.restore() 47 | 48 | OFFSET_MATRIX.preTranslate(-width * 0.5f, -height * 0.5f) 49 | OFFSET_MATRIX.postTranslate(width * 0.5f, height * 0.5f) 50 | OFFSET_TEMP_FLOAT[0] = width.toFloat() 51 | OFFSET_TEMP_FLOAT[1] = height.toFloat() 52 | OFFSET_MATRIX.mapPoints(OFFSET_TEMP_FLOAT) 53 | return (width - OFFSET_TEMP_FLOAT[0]) * if (degrees > 0.0f) 1.0f else -1.0f 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/ZoomInTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class ZoomInTransformer : ABaseTransformer() { 22 | 23 | override fun onTransform(page: View, position: Float) { 24 | val scale = if (position < 0) position + 1f else Math.abs(1f - position) 25 | page.scaleX = scale 26 | page.scaleY = scale 27 | page.pivotX = page.width * 0.5f 28 | page.pivotY = page.height * 0.5f 29 | page.alpha = if (position < -1f || position > 1f) 0f else 1f - (scale - 1f) 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/ZoomOutSlideTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class ZoomOutSlideTransformer : ABaseTransformer() { 22 | 23 | override fun onTransform(page: View, position: Float) { 24 | if (position >= -1 || position <= 1) { 25 | // Modify the default slide transition to shrink the page as well 26 | val height = page.height.toFloat() 27 | val width = page.width.toFloat() 28 | val scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)) 29 | val vertMargin = height * (1 - scaleFactor) / 2 30 | val horzMargin = width * (1 - scaleFactor) / 2 31 | 32 | // Center vertically 33 | page.pivotY = 0.5f * height 34 | page.pivotX = 0.5f * width 35 | 36 | page.translationX = 37 | if (position < 0) horzMargin - vertMargin / 2 38 | else -horzMargin + vertMargin / 2 39 | 40 | // Scale the page down (between MIN_SCALE and 1) 41 | page.scaleX = scaleFactor 42 | page.scaleY = scaleFactor 43 | 44 | // Fade the page relative to its size. 45 | page.alpha = MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA) 46 | } 47 | } 48 | 49 | companion object { 50 | private const val MIN_SCALE = 0.85f 51 | private const val MIN_ALPHA = 0.5f 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /library/src/main/java/com/ToxicBakery/viewpager/transforms/ZoomOutTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ToxicBakery.viewpager.transforms 18 | 19 | import android.view.View 20 | 21 | open class ZoomOutTransformer : ABaseTransformer() { 22 | 23 | override fun onTransform(page: View, position: Float) { 24 | val scale = 1f + Math.abs(position) 25 | page.scaleX = scale 26 | page.scaleY = scale 27 | page.pivotX = page.width * 0.5f 28 | page.pivotY = page.height * 0.5f 29 | page.alpha = if (position < -1f || position > 1f) 0f else 1f - (scale - 1f) 30 | if (position == -1f) page.translationX = (page.width * -1).toFloat() 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /library/src/main/res/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ToxicBakery/ViewPagerTransforms/2c3ffe13c43467d5d0ae2ec5e2bcd95c6391817d/library/src/main/res/.gitignore -------------------------------------------------------------------------------- /maven.keystore.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ToxicBakery/ViewPagerTransforms/2c3ffe13c43467d5d0ae2ec5e2bcd95c6391817d/maven.keystore.gpg -------------------------------------------------------------------------------- /publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'org.jetbrains.dokka-android' 2 | apply plugin: 'digital.wup.android-maven-publish' 3 | apply plugin: 'signing' 4 | apply plugin: 'jacoco' 5 | 6 | jacoco { 7 | toolVersion = '0.8.1' 8 | } 9 | 10 | tasks.withType(Test) { 11 | jacoco.includeNoLocationClasses = true 12 | } 13 | 14 | task jacocoTestReport(type: JacocoReport) { 15 | group = "Reporting" 16 | description = "Combine code coverage to unified report." 17 | 18 | reports { 19 | xml.enabled = true 20 | html.enabled = true 21 | } 22 | 23 | def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] 24 | def debugTree = fileTree(dir: "${project.buildDir}/intermediates/javac/debug/compileDebugJavaWithJavac/classes", excludes: fileFilter) 25 | def mainSrc = "${project.projectDir}/src/main/java" 26 | def ecSrc = fileTree(dir: "$project.buildDir", include: "**/*.ec") 27 | def execSrc = fileTree(dir: "$project.buildDir", include: "**/*.exec") 28 | 29 | doFirst { 30 | def files = files([ecSrc, execSrc]).files 31 | println "Creating Jacoco Report for ${files.size()} coverage files" 32 | files.each { file -> println file } 33 | } 34 | 35 | sourceDirectories = files([mainSrc]) 36 | classDirectories = files([debugTree]) 37 | executionData = files([ecSrc, execSrc]) 38 | } 39 | 40 | dokka { 41 | outputFormat = 'javadoc' 42 | outputDirectory = "$buildDir/javadoc" 43 | sourceDirs = files('src/main/java') 44 | skipEmptyPackages = true 45 | skipDeprecated = false 46 | noStdlibLink = false 47 | } 48 | 49 | task dokkaJar(type: Jar, dependsOn: dokka) { 50 | classifier = 'javadoc' 51 | from "$buildDir/javadoc" 52 | } 53 | 54 | task androidSourcesJar(type: Jar) { 55 | classifier = 'sources' 56 | from android.sourceSets.main.java.srcDirs 57 | } 58 | 59 | publishing { 60 | publications { 61 | mavenAar(MavenPublication) { 62 | from components.android 63 | groupId group 64 | artifactId POM_ARTIFACT_ID 65 | version version 66 | 67 | artifact dokkaJar 68 | artifact androidSourcesJar 69 | 70 | pom.withXml { 71 | def root = asNode() 72 | 73 | root.children().last() + { 74 | resolveStrategy = DELEGATE_FIRST 75 | 76 | description POM_DESCRIPTION 77 | name POM_NAME 78 | url POM_URL 79 | scm { 80 | url POM_SCM_URL 81 | connection POM_SCM_CONNECTION 82 | developerConnection POM_SCM_DEV_CONNECTION 83 | } 84 | licenses { 85 | license { 86 | name POM_LICENCE_NAME 87 | url POM_LICENCE_URL 88 | distribution POM_LICENCE_DIST 89 | } 90 | } 91 | developers { 92 | developer { 93 | id POM_DEVELOPER_ID 94 | name POM_DEVELOPER_NAME 95 | email POM_DEVELOPER_EMAIL 96 | organization POM_DEVELOPER_ORGANIZATION 97 | organizationUrl POM_DEVELOPER_ORGANIZATION_URL 98 | } 99 | } 100 | } 101 | } 102 | } 103 | } 104 | 105 | repositories { 106 | def releaseUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 107 | def snapshotUrl = "https://oss.sonatype.org/content/repositories/snapshots" 108 | 109 | maven { 110 | url !version.contains("SNAPSHOT") ? releaseUrl : snapshotUrl 111 | credentials { 112 | username System.getenv('SONATYPE_USERNAME') ?: "" 113 | password System.getenv('SONATYPE_PASSWORD') ?: "" 114 | } 115 | } 116 | } 117 | } 118 | 119 | signing { 120 | required false 121 | sign publishing.publications 122 | } 123 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Toxic Bakery 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | include ':app', ':library' 18 | --------------------------------------------------------------------------------