Repository: florent37/MaterialViewPager Branch: master Commit: e2fb22e0ad95 Files: 75 Total size: 152.1 KB Directory structure: gitextract_vckdg7ln/ ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── circle.yml ├── gradle/ │ ├── bintray-android-v1.gradle │ ├── install-v1.gradle │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── materialviewpager/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── github/ │ │ └── florent37/ │ │ └── materialviewpager/ │ │ ├── MaterialViewPager.java │ │ ├── MaterialViewPagerAnimator.java │ │ ├── MaterialViewPagerHeader.java │ │ ├── MaterialViewPagerHeaderView.java │ │ ├── MaterialViewPagerHelper.java │ │ ├── MaterialViewPagerSettings.java │ │ ├── Utils.java │ │ └── header/ │ │ ├── HeaderDesign.java │ │ ├── MaterialViewPagerHeaderDecorator.java │ │ ├── MaterialViewPagerImageHeader.java │ │ ├── MaterialViewPagerImageHelper.java │ │ └── MaterialViewPagerKenBurnsHeader.java │ └── res/ │ ├── layout/ │ │ ├── material_view_pager_imageview_header.xml │ │ ├── material_view_pager_layout.xml │ │ ├── material_view_pager_moving_header.xml │ │ ├── material_view_pager_pagertitlestrip_newstand.xml │ │ ├── material_view_pager_pagertitlestrip_standard.xml │ │ ├── material_view_pager_placeholder.xml │ │ ├── material_view_pager_viewpager.xml │ │ ├── tools_list_item_card_big.xml │ │ ├── tools_list_item_card_small.xml │ │ ├── tools_list_items.xml │ │ └── tools_material_view_pager_pagertitlestrip.xml │ └── values/ │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── ids.xml │ └── styles.xml ├── publish.sh ├── sample/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── github/ │ │ └── florent37/ │ │ └── materialviewpager/ │ │ └── sample/ │ │ ├── DrawerActivity.java │ │ ├── MainActivity.java │ │ ├── TestListViewAdapter.java │ │ ├── TestRecyclerViewAdapter.java │ │ └── fragment/ │ │ ├── RecyclerViewFragment.java │ │ └── ScrollFragment.java │ └── res/ │ ├── drawable/ │ │ └── circle.xml │ ├── layout/ │ │ ├── activity_main.xml │ │ ├── drawer.xml │ │ ├── fragment_list.xml │ │ ├── fragment_recyclerview.xml │ │ ├── fragment_scroll.xml │ │ ├── fragment_webview.xml │ │ ├── header_logo.xml │ │ ├── header_logo_2.xml │ │ ├── header_logo_full.xml │ │ ├── header_logo_text.xml │ │ ├── list_item_card_big.xml │ │ └── list_item_card_small.xml │ ├── menu/ │ │ └── menu_main.xml │ ├── values/ │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── values-w820dp/ │ └── dimens.xml └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Built application files *.apk *.ap_ # Files for the Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ # Gradle files .gradle/ build/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Log Files *.log # Android Studio Navigation editor temp files .navigation/ # Android Studio captures folder captures/ .gradle .idea *.iml **/build/* ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ MaterialViewPager ======= [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-MaterialViewPager-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/1731) [![Android Weekly](https://img.shields.io/badge/android--weekly-151-blue.svg)](http://androidweekly.net/issues/issue-151) [![CircleCI](https://circleci.com/gh/florent37/MaterialViewPager.svg?style=svg)](https://circleci.com/gh/florent37/MaterialViewPager) Material Design ViewPager easy to use library Android app on Google Play [![Build screen](https://raw.githubusercontent.com/florent37/MaterialViewPager/master/screenshots/screenshot_2_small.png)](http://youtu.be/g6tTDVceM9E) # Sample Android app on Google Play And have a look on a sample Youtube Video : [Youtube Link](http://www.youtube.com/watch?v=r95Tt6AS18c) # Download Buy Me a Coffee at ko-fi.com In your module [![Download](https://api.bintray.com/packages/florent37/maven/MaterialViewPager/images/download.svg)](https://bintray.com/florent37/maven/MaterialViewPager/_latestVersion) ```groovy compile 'com.github.florent37:materialviewpager:1.2.3' //dependencies compile 'com.flaviofaria:kenburnsview:1.0.7' compile 'com.jpardogo.materialtabstrip:library:1.1.0' compile 'com.github.bumptech.glide:glide:4.0.0' ``` # Usage Add MaterialViewPager to your activity's layout ```xml ``` with **header_logo.xml** ```xml ``` You will see on Android Studio Preview : ![alt preview](https://raw.github.com/florent37/MaterialViewPager/master/screenshots/preview_small.png) To get a beautiful screen and enable preview, you theme may follow ```xml ``` # Retrieve the MaterialViewPager You can use MaterialViewPager as an usual Android View, and get it by findViewById ```java public class MainActivity extends ActionBarActivity { private MaterialViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (MaterialViewPager) findViewById(R.id.materialViewPager); } } ``` # Customisation First choose your color and height ```xml ``` ## Set your logo ```xml ``` ### Titlebar Logo [![Video](http://share.gifyoutube.com/ygbqnA.gif)](http://youtu.be/82gvoUqXb_I) Your logo's layout must * layout_height="@dimen/materialviewpager_logoHeight" **header_logo.xml** ```xml ``` ```xml ``` ### Fading Logo [![Video](http://share.gifyoutube.com/KYb0D4.gif)](http://youtu.be/9laniARQdqg) **header_logo.xml** ```xml ``` ```xml ``` ## Toolbar Animation ## Hide Logo and Toolbar [![Video](http://share.gifyoutube.com/y5V8JX.gif)](http://youtu.be/3ElFoqVKxag) ```xml ``` ### Sticky Toolbar [![Video](http://share.gifyoutube.com/yo2oJn.gif)](http://youtu.be/3ElFoqVKxag) ```xml ``` ### Transparent Toolbar [![Video](http://share.gifyoutube.com/ywbP8k.gif)](https://youtu.be/jUVO2cozQHQ) ```xml ``` ## Header Layout You can replace the header ```xml ``` ### Moving Header Or use the default header, with a KenBurns animation ```xml ``` ### Static Header Or simply use an ImageView as header ```xml ``` ## Custom Tab Bar You can set you own tab bar, by default I provided 2 implementations ### Standard [![Video](http://share.gifyoutube.com/KdnoZX.gif)](http://youtu.be/VRinfxgewNE) ```xml ``` ### News Stand [![Video](http://share.gifyoutube.com/KeboLp.gif)](http://youtu.be/MBzK2s7HU1A) ```xml ``` ### Or create your own tab bar Create your own layout using a PagerSlidingTabStrip **my_tabs.xml** ```xml ``` **Don't forget to give it id="@id/materialviewpager_pagerTitleStrip"** ```xml ``` # Animate Header [![Video](http://share.gifyoutube.com/yABkgW.gif)](http://youtu.be/90gKwEL1j2I ) Simply add a listen to the ViewPager ```java mViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() { @Override public HeaderDesign getHeaderDesign(int page) { switch (page) { case 0: return HeaderDesign.fromColorResAndUrl( R.color.blue, "http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2014/06/wallpaper_51.jpg"); case 1: return HeaderDesign.fromColorResAndUrl( R.color.green, "https://fs01.androidpit.info/a/63/0e/android-l-wallpapers-630ea6-h900.jpg"); case 2: return HeaderDesign.fromColorResAndUrl( R.color.cyan, "http://www.droid-life.com/wp-content/uploads/2014/10/lollipop-wallpapers10.jpg"); case 3: return HeaderDesign.fromColorResAndUrl( R.color.red, "http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg"); } //execute others actions if needed (ex : modify your header logo) return null; } }); ``` Available ```java HeaderDesign.fromColorAndUrl(Color.BLUE,"http:...); HeaderDesign.fromColorResAndUrl(R.color.blue,"http:...); HeaderDesign.fromColorAndDrawable(Color.BLUE,myDrawable); HeaderDesign.fromColorResAndDrawable(R.color.blue,myDrawable); ``` # Toolbar ```java Toolbar toolbar = mViewPager.getToolbar(); if (toolbar != null) { setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayUseLogoEnabled(false); actionBar.setHomeButtonEnabled(true); } ``` # ViewPager ```java ViewPager viewPager = mViewPager.getViewPager(); viewPage.setAdapter(...); //After set an adapter to the ViewPager mViewPager.getPagerTitleStrip().setViewPager(mViewPager.getViewPager()); ``` # RecyclerView ```java mRecyclerView.addItemDecoration(new MaterialViewPagerHeaderDecorator()); mRecyclerView.setAdapter(yourAdapter); ``` # ScrollView The ScrollView must be an NestedScrollView` ```java MaterialViewPagerHelper.registerScrollView(getActivity(), mScrollView, null); ``` And include @layout/material_view_pager_placeholder` as first child ```xml ...your content... ``` # CHANGELOG ## 1.2.0 - header decorator instead of Adapter ## 1.1.3 - header is now clickable - fixed some scrolling issues ## 1.1.2 - quick scroll fix - can set a custom viewpager with app:viewpager_viewpager (the viewpager id must be id/materialviewpager_viewpager) ## 1.1.0 - orientation change fix - header image display fix - elements on header are now clickable - notifyHeaderChanged ## 1.0.8 - added attribute viewpager_disableToolbar ## 1.0.7 - fix bug on low resolutions ## 1.0.6 - added attribute transparentToolbar - added attribute animatedHeaderImage - fixed bug when page is too small to scroll - modified HeaderDesign implementation ## 1.0.5 - smoother toolbar scrolling - fixed bug with fitSystemWindow - added HeaderDesign to modify the header color & image - added displayToolbarWhenSwipe attribute ## 1.0.4 Fixed : - Orientation changed - Memory Leak - Android >2.3 with NineOldAndroid - Removed ListView usage ## 1.0.3 Fixed : Rapid scrolling results in varying Toolbar height RecyclerViewMaterialAdapter can handle a custom placeholder cells count (usefull for GridLayoutManager) ```java public RecyclerViewMaterialAdapter(RecyclerView.Adapter adapter, int placeholderSize) ``` ## 1.0.2 Added attributes ```java app:viewpager_parallaxHeaderFactor="1.5" app:viewpager_headerAdditionalHeight="20dp" ``` *parallaxHeaderFactor* Modify the speed of parallax header scroll (not the speed of KenBurns effect) *parallaxHeaderFactor* Set up the height of the header's layout displayed behind the first cards view Fixed issue when scroll down & scroll up multiples time while hideToolbarAndTitle="true" ## 1.0.1 Added attributes ```java viewpager_headerAlpha="0.6" ``` # Community Looking for contributors, feel free to fork ! Tell me if you're using my library in your application, I'll share it in this README # Dependencies * [Glide][glide] (from Bumptech) * [KenBurnsView][kenburnsview] (from flavioarfaria) * [Material PagerSlidingTabStrip][pagerslidingtitlestrip] (from jpardogo, forked from astuetz) # Credits Author: Florent Champigny [http://www.florentchampigny.com/](http://www.florentchampigny.com/) Blog : [http://www.tutos-android-france.com/](http://www.tutos-android-france.com/) Fiches Plateau Moto : [https://www.fiches-plateau-moto.fr/](https://www.fiches-plateau-moto.fr/) Android app on Google Play Follow me on Google+ Follow me on Twitter Follow me on LinkedIn License -------- Copyright 2015 florent37, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. [glide]: https://github.com/bumptech/glide [kenburnsview]: https://github.com/flavioarfaria/KenBurnsView [pagerslidingtitlestrip]: https://github.com/jpardogo/PagerSlidingTabStrip ================================================ FILE: build.gradle ================================================ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { mavenCentral() jcenter() google() maven { url "http://dl.bintray.com/jfrog/jfrog-jars" } maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1" classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' classpath 'com.github.ben-manes:gradle-versions-plugin:+' classpath 'io.fabric.tools:gradle:1.+' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } ext { minSdk = 14 sdk = 27 buildTools = "26.0.2" supportVersion = "27.1.0" libraryVersion = '1.2.3' } allprojects { repositories { jcenter() maven { url "http://dl.bintray.com/florent37/maven" } maven { url 'https://maven.fabric.io/public' } maven { url "https://maven.google.com" } google() } } ================================================ FILE: circle.yml ================================================ deployment: release: tag: /v.*/ commands: - ./gradlew :materialviewpager:bintrayUpload ================================================ FILE: gradle/bintray-android-v1.gradle ================================================ apply plugin: 'com.jfrog.bintray' version = libraryVersion task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources' } task javadoc(type: Javadoc) { source = android.sourceSets.main.java.srcDirs classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) } task javadocJar(type: Jar, dependsOn: javadoc) { classifier = 'javadoc' from javadoc.destinationDir } artifacts { //archives javadocJar archives sourcesJar } def _user = System.getenv("BINTRAY_USER") def _key = System.getenv("BINTRAY_API_KEY") def _passphrase = System.getenv("BINTRAY_PASSPHRASE") if(project.rootProject.file('local.properties').exists() && (_user == null || _user.isEmpty())){ Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) _user = properties.getProperty("bintray.user") _key = properties.getProperty("bintray.apikey"); _passphrase = properties.getProperty("bintray.gpg.password") } // Bintray bintray { user = _user key = _key configurations = ['archives'] pkg { repo = bintrayRepo name = bintrayName desc = libraryDescription userOrg = orgName websiteUrl = siteUrl vcsUrl = gitUrl licenses = allLicenses publish = true publicDownloadNumbers = true version { desc = libraryDescription gpg { sign = true //Determines whether to GPG sign the files. The default is false passphrase = _passphrase //Optional. The passphrase for GPG signing' } } } } ================================================ FILE: gradle/install-v1.gradle ================================================ apply plugin: 'com.github.dcendents.android-maven' group = publishedGroupId // Maven Group ID for the artifact install { repositories.mavenInstaller { // This generates POM.xml with proper parameters pom { project { packaging 'aar' groupId publishedGroupId artifactId artifact // Add your description here name libraryName description libraryDescription url siteUrl // Set your license licenses { license { name licenseName url licenseUrl } } developers { developer { id developerId name developerName email developerEmail } } scm { connection gitUrl developerConnection gitUrl url siteUrl } } } } } //from https://github.com/workarounds/bundler/blob/master/gradle/install-v1.gradle ================================================ FILE: gradle/wrapper/gradle-wrapper.properties ================================================ #Mon Feb 27 17:10:37 CET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip ================================================ FILE: gradle.properties ================================================ # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true ================================================ FILE: gradlew ================================================ #!/usr/bin/env bash ############################################################################## ## ## Gradle start up script for UN*X ## ############################################################################## # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS="" APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn ( ) { echo "$*" } die ( ) { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; esac # For Cygwin, ensure paths are in UNIX format before anything is touched. if $cygwin ; then [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` fi # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >&- APP_HOME="`pwd -P`" cd "$SAVED" >&- CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin, switch paths to Windows format before running java if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi i=$((i+1)) done case $i in (0) set -- ;; (1) set -- "$args0" ;; (2) set -- "$args0" "$args1" ;; (3) set -- "$args0" "$args1" "$args2" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules function splitJvmOpts() { JVM_OPTS=("$@") } eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" ================================================ FILE: gradlew.bat ================================================ @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS= set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :init @rem Get command-line arguments, handling Windowz variants if not "%OS%" == "Windows_NT" goto win9xME_args if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. set CMD_LINE_ARGS= set _SKIP=2 :win9xME_args_slurp if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* goto execute :4NT_args @rem Get arguments from the 4NT Shell from JP Software set CMD_LINE_ARGS=%$ :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% :end @rem End local scope for the variables with windows NT shell if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal :omega ================================================ FILE: materialviewpager/.gitignore ================================================ /build ================================================ FILE: materialviewpager/build.gradle ================================================ apply plugin: 'com.android.library' apply plugin: 'com.github.ben-manes.versions' android { compileSdkVersion project.sdk buildToolsVersion project.buildTools defaultConfig { minSdkVersion project.minSdk targetSdkVersion project.sdk versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile ( 'com.android.support:appcompat-v7:'+project.supportVersion, 'com.android.support:recyclerview-v7:'+project.supportVersion, 'com.android.support:support-annotations:'+project.supportVersion ) compile 'com.flaviofaria:kenburnsview:1.0.7' compile ('com.jpardogo.materialtabstrip:library:1.1.0') { exclude module: 'support-v4' } compile 'com.github.bumptech.glide:glide:4.6.1' } ext { bintrayRepo = 'maven' bintrayName = 'MaterialViewPager' orgName = 'florent37' publishedGroupId = 'com.github.florent37' libraryName = 'MaterialViewPager' artifact = 'materialviewpager' libraryDescription = 'MaterialViewPager' siteUrl = 'https://github.com/florent37/MaterialViewPager' gitUrl = 'https://github.com/florent37/MaterialViewPager.git' libraryVersion = rootProject.ext.libraryVersion developerId = 'florent37' developerName = 'Florent Champigny' developerEmail = 'champigny.florent@gmail.com' licenseName = 'The Apache Software License, Version 2.0' licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' allLicenses = ["Apache-2.0"] } apply from: rootProject.file('gradle/install-v1.gradle') apply from: rootProject.file('gradle/bintray-android-v1.gradle') ================================================ FILE: materialviewpager/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in /Users/florentchampigny/android/sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} ================================================ FILE: materialviewpager/src/main/AndroidManifest.xml ================================================ ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPager.java ================================================ package com.github.florent37.materialviewpager; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.RelativeLayout; import com.astuetz.PagerSlidingTabStrip; import com.github.florent37.materialviewpager.header.HeaderDesign; import com.github.florent37.materialviewpager.header.MaterialViewPagerImageHelper; /** * Created by florentchampigny on 28/04/15. *

* The main class of MaterialViewPager * To use in an xml layout with attributes viewpager_* *

* Display a preview with header, actual logo and fake cells */ public class MaterialViewPager extends FrameLayout implements ViewPager.OnPageChangeListener { /** * Contains all references to MatervialViewPager's header views */ protected MaterialViewPagerHeader materialViewPagerHeader; //the child toolbar protected Toolbar mToolbar; //the child viewpager protected ViewPager mViewPager; //a view used to add placeholder color below the header protected View headerBackground; //a view used to add fading color over the headerBackgroundContainer protected View toolbarLayoutBackground; //Class containing the configuration of the MaterialViewPager protected MaterialViewPagerSettings settings = new MaterialViewPagerSettings(); protected MaterialViewPager.Listener listener; int lastPosition = -1; int currentPagerState = Integer.MIN_VALUE; /** * the layout containing the header * default : add @layout/material_view_pager_default_header * with viewpager_header you can set your own layout */ private ViewGroup headerBackgroundContainer; /** * the layout containing tabs * default : add @layout/material_view_pager_pagertitlestrip_standard * with viewpager_pagerTitleStrip you can set your own layout */ private ViewGroup pagerTitleStripContainer; /** * the layout containing the viewpager, can be replaced to add your own implementation of viewpager */ private ViewGroup viewpagerContainer; //region construct /** * the layout containing logo * default : empty * with viewpager_logo you can set your own layout */ private ViewGroup logoContainer; public MaterialViewPager(Context context) { super(context); } public MaterialViewPager(Context context, AttributeSet attrs) { super(context, attrs); settings.handleAttributes(context, attrs); } public MaterialViewPager(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); settings.handleAttributes(context, attrs); } //endregion @TargetApi(Build.VERSION_CODES.LOLLIPOP) public MaterialViewPager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); settings.handleAttributes(context, attrs); } @Override protected void onRestoreInstanceState(Parcelable state) { SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState()); this.settings = ss.settings; if (headerBackground != null) { headerBackground.setBackgroundColor(this.settings.color); } MaterialViewPagerAnimator animator = MaterialViewPagerHelper.getAnimator(this.getContext()); //-1*ss.yOffset restore to 0 animator.restoreScroll(-1 * ss.yOffset, ss.settings); MaterialViewPagerHelper.register(getContext(), animator); } @Override protected Parcelable onSaveInstanceState() { Parcelable superState = super.onSaveInstanceState(); SavedState ss = new SavedState(superState); //end ss.settings = this.settings; ss.yOffset = MaterialViewPagerHelper.getAnimator(getContext()).lastYOffset; return ss; } /** * Retrieve the displayed viewpager, don't forget to use * getPagerTitleStrip().setAdapter(materialviewpager.getViewPager()) * after set an adapter * * @return the displayed viewpager */ public ViewPager getViewPager() { return mViewPager; } /** * Retrieve the displayed tabs * * @return the displayed tabs */ public PagerSlidingTabStrip getPagerTitleStrip() { return (PagerSlidingTabStrip) pagerTitleStripContainer.findViewById(R.id.materialviewpager_pagerTitleStrip); } /** * Retrieve the displayed toolbar * * @return the displayed toolbar */ public Toolbar getToolbar() { return mToolbar; } /** * Retrieve the displayed toolbar */ public void setToolbar(Toolbar toolbar) { mToolbar = toolbar; } /** * change the header displayed image with a fade * may remove Picasso */ public void setImageUrl(String imageUrl, int fadeDuration) { if (imageUrl != null) { final ImageView headerBackgroundImage = (ImageView) findViewById(R.id.materialviewpager_imageHeader); //if using MaterialViewPagerImageHeader if (headerBackgroundImage != null) { ViewCompat.setAlpha(headerBackgroundImage, settings.headerAlpha); MaterialViewPagerImageHelper.setImageUrl(headerBackgroundImage, imageUrl, fadeDuration); setImageHeaderDarkLayerAlpha(); } } } /** * change the header displayed image with a fade and an OnLoadListener * may remove Picasso */ public void setImageUrl(String imageUrl, int fadeDuration, OnImageLoadListener imageLoadListener) { if (imageLoadListener != null) { MaterialViewPagerImageHelper.setImageLoadListener(imageLoadListener); } setImageUrl(imageUrl, fadeDuration); } /** * change the header displayed image with a fade * may remove Picasso */ public void setImageDrawable(Drawable drawable, int fadeDuration) { if (drawable != null) { final ImageView headerBackgroundImage = (ImageView) findViewById(R.id.materialviewpager_imageHeader); //if using MaterialViewPagerImageHeader if (headerBackgroundImage != null) { ViewCompat.setAlpha(headerBackgroundImage, settings.headerAlpha); MaterialViewPagerImageHelper.setImageDrawable(headerBackgroundImage, drawable, fadeDuration); setImageHeaderDarkLayerAlpha(); } } } /** * Change alpha of the header image dark layer to reveal text. */ public void setImageHeaderDarkLayerAlpha() { final View headerImageDarkLayerView = findViewById(R.id.materialviewpager_headerImageDarkLayer); //if using MaterialViewPagerImageHeader if (headerImageDarkLayerView != null) { headerImageDarkLayerView.setBackgroundColor(getResources().getColor(android.R.color.black)); ViewCompat.setAlpha(headerImageDarkLayerView, settings.imageHeaderDarkLayerAlpha); } } /** * Change the header color */ public void setColor(int color, int fadeDuration) { if (MaterialViewPagerHelper.getAnimator(getContext()) != null) { MaterialViewPagerHelper.getAnimator(getContext()).setColor(color, fadeDuration * 2); } } public ViewGroup getHeaderBackgroundContainer() { return headerBackgroundContainer; } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (currentPagerState != ViewPager.SCROLL_STATE_SETTLING) { if (positionOffset >= 0.5) { onPageSelected(position + 1); } else if (positionOffset <= -0.5) { onPageSelected(position - 1); } else { onPageSelected(position); } } } public void notifyHeaderChanged() { int position = lastPosition; lastPosition = -1; onPageSelected(position); } //region ViewPagerOnPageListener @Override public void onPageSelected(int position) { if (position == lastPosition || listener == null) { return; } HeaderDesign headerDesign = listener.getHeaderDesign(position); if (headerDesign == null) { return; } int fadeDuration = 400; int color = headerDesign.getColor(); if (headerDesign.getColorRes() != 0) { color = getContext().getResources().getColor(headerDesign.getColorRes()); } if (headerDesign.getDrawable() != null) { setImageDrawable(headerDesign.getDrawable(), fadeDuration); } else { setImageUrl(headerDesign.getImageUrl(), fadeDuration); } setColor(color, fadeDuration); lastPosition = position; } @Override public void onPageScrollStateChanged(int state) { currentPagerState = state; if (settings.displayToolbarWhenSwipe) { MaterialViewPagerHelper.getAnimator(getContext()).onViewPagerPageChanged(); } } public void setMaterialViewPagerListener(Listener listener) { this.listener = listener; } @Override protected void onDetachedFromWindow() { MaterialViewPagerHelper.unregister(getContext()); listener = null; super.onDetachedFromWindow(); } @Override protected void onFinishInflate() { super.onFinishInflate(); //add @layout/material_view_pager_layout as child, containing all the MaterialViewPager views addView(LayoutInflater.from(getContext()).inflate(R.layout.material_view_pager_layout, this, false)); headerBackgroundContainer = (ViewGroup) findViewById(R.id.headerBackgroundContainer); pagerTitleStripContainer = (ViewGroup) findViewById(R.id.pagerTitleStripContainer); viewpagerContainer = (ViewGroup) findViewById(R.id.viewpager_layout); logoContainer = (ViewGroup) findViewById(R.id.logoContainer); mToolbar = (Toolbar) findViewById(R.id.toolbar); if (settings.disableToolbar) { mToolbar.setVisibility(INVISIBLE); } { //replace the viewpager ? int viewPagerLayoutId = settings.viewpagerId; if (viewPagerLayoutId != -1) { viewpagerContainer.removeAllViews(); viewpagerContainer.addView(LayoutInflater.from(getContext()).inflate(viewPagerLayoutId, viewpagerContainer, false)); } } mViewPager = (ViewPager) findViewById(R.id.materialviewpager_viewpager); mViewPager.addOnPageChangeListener(this); //inflate subviews defined in attributes { int headerId = settings.headerLayoutId; if (headerId == -1) { if (settings.animatedHeaderImage) { headerId = R.layout.material_view_pager_moving_header; } else { headerId = R.layout.material_view_pager_imageview_header; } } headerBackgroundContainer.addView(LayoutInflater.from(getContext()).inflate(headerId, headerBackgroundContainer, false)); } if (isInEditMode()) { //preview titlestrip //add fake tabs on edit mode settings.pagerTitleStripId = R.layout.tools_material_view_pager_pagertitlestrip; } if (settings.pagerTitleStripId != -1) { pagerTitleStripContainer.addView(LayoutInflater.from(getContext()).inflate(settings.pagerTitleStripId, pagerTitleStripContainer, false)); } if (settings.logoLayoutId != -1) { logoContainer.addView(LayoutInflater.from(getContext()).inflate(settings.logoLayoutId, logoContainer, false)); if (settings.logoMarginTop != 0) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) logoContainer.getLayoutParams(); layoutParams.setMargins(0, settings.logoMarginTop, 0, 0); logoContainer.setLayoutParams(layoutParams); } } headerBackground = findViewById(R.id.headerBackground); toolbarLayoutBackground = findViewById(R.id.toolbar_layout_background); initialiseHeights(); //construct the materialViewPagerHeader with subviews if (!isInEditMode()) { materialViewPagerHeader = MaterialViewPagerHeader .withToolbar(mToolbar) .withToolbarLayoutBackground(toolbarLayoutBackground) .withPagerSlidingTabStrip(pagerTitleStripContainer) .withHeaderBackground(headerBackground) .withStatusBackground(findViewById(R.id.statusBackground)) .withLogo(logoContainer); //and construct the MaterialViewPagerAnimator //attach it to the activity to enable MaterialViewPagerHeaderView.setMaterialHeight(); MaterialViewPagerHelper.register(getContext(), new MaterialViewPagerAnimator(this)); } else { //if in edit mode, add fake cardsviews View sample = LayoutInflater.from(getContext()).inflate(R.layout.tools_list_items, pagerTitleStripContainer, false); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) sample.getLayoutParams(); int marginTop = Math.round(Utils.dpToPx(settings.headerHeight + 10, getContext())); params.setMargins(0, marginTop, 0, 0); super.setLayoutParams(params); addView(sample); } } //endregion private void initialiseHeights() { if (headerBackground != null) { headerBackground.setBackgroundColor(this.settings.color); ViewGroup.LayoutParams layoutParams = headerBackground.getLayoutParams(); layoutParams.height = (int) Utils.dpToPx(this.settings.headerHeight + settings.headerAdditionalHeight, getContext()); headerBackground.setLayoutParams(layoutParams); } if (pagerTitleStripContainer != null) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) pagerTitleStripContainer.getLayoutParams(); int marginTop = (int) Utils.dpToPx(this.settings.headerHeight - 40, getContext()); layoutParams.setMargins(0, marginTop, 0, 0); pagerTitleStripContainer.setLayoutParams(layoutParams); } if (toolbarLayoutBackground != null) { ViewGroup.LayoutParams layoutParams = toolbarLayoutBackground.getLayoutParams(); layoutParams.height = (int) Utils.dpToPx(this.settings.headerHeight, getContext()); toolbarLayoutBackground.setLayoutParams(layoutParams); } } public interface Listener { HeaderDesign getHeaderDesign(int page); } public interface OnImageLoadListener { void OnImageLoad(ImageView imageView, Bitmap bitmap); } static class SavedState extends BaseSavedState { //required field that makes Parcelables from a Parcel public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public SavedState createFromParcel(Parcel in) { return new SavedState(in); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; public MaterialViewPagerSettings settings; public float yOffset; SavedState(Parcelable superState) { super(superState); } private SavedState(Parcel in) { super(in); this.settings = in.readParcelable(MaterialViewPagerSettings.class.getClassLoader()); this.yOffset = in.readFloat(); } @Override public void writeToParcel(Parcel out, int flags) { super.writeToParcel(out, flags); out.writeParcelable(this.settings, flags); out.writeFloat(this.yOffset); } } } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerAnimator.java ================================================ package com.github.florent37.materialviewpager; import android.animation.ArgbEvaluator; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; import android.os.Handler; import android.os.Looper; import android.support.v4.view.ViewCompat; import android.support.v4.widget.NestedScrollView; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import static com.github.florent37.materialviewpager.Utils.canScroll; import static com.github.florent37.materialviewpager.Utils.colorWithAlpha; import static com.github.florent37.materialviewpager.Utils.dpToPx; import static com.github.florent37.materialviewpager.Utils.getTheVisibileView; import static com.github.florent37.materialviewpager.Utils.minMax; import static com.github.florent37.materialviewpager.Utils.scrollTo; import static com.github.florent37.materialviewpager.Utils.setBackgroundColor; import static com.github.florent37.materialviewpager.Utils.setElevation; import static com.github.florent37.materialviewpager.Utils.setScale; /** * Created by florentchampigny on 24/04/15. *

* Listen to Scrollable inside MaterialViewPager * When notified scroll, dispatch the current scroll to other scrollable *

* Note : didn't want to translate the MaterialViewPager or intercept Scroll, * so added a ViewPager with scrollables containing a transparent placeholder on top *

* When scroll, animate the MaterialViewPager Header (toolbar, logo, color ...) */ public class MaterialViewPagerAnimator { private static final String TAG = "MaterialViewPager"; //duration of translate header enter animation private static final int ENTER_TOOLBAR_ANIMATION_DURATION = 300; public static Boolean ENABLE_LOG = false; //final toolbar layout elevation (if attr viewpager_enableToolbarElevation = true) public final float elevation; //max scroll which will be dispatched for all scrollable private final float scrollMax; // equals scrollMax in DP (saved to avoir convert to dp anytime I use it) private final float scrollMaxDp; float lastYOffset = -1; //the current yOffset private float lastPercent = 0; //the current Percent //contains the attributes given to MaterialViewPager from layout private MaterialViewPagerSettings settings; //list of all registered scrollers private List scrollViewList = new ArrayList<>(); //save all yOffsets of scrollables private HashMap yOffsets = new HashMap<>(); private boolean followScrollToolbarIsVisible = false; private float firstScrollValue = Float.MIN_VALUE; private boolean justToolbarAnimated = false; //intial distance between pager & toolbat private float initialDistance = -1; //contains MaterialViewPager subviews references private MaterialViewPagerHeader mHeader; //the tmp headerAnimator (not null if animating, else null) private ValueAnimator headerAnimator; MaterialViewPagerAnimator(MaterialViewPager materialViewPager) { this.settings = materialViewPager.settings; this.mHeader = materialViewPager.materialViewPagerHeader; Context context = mHeader.getContext(); // initialise the scrollMax to headerHeight, so until the first cell touch the top of the screen this.scrollMax = this.settings.headerHeight; //save in into dp once this.scrollMaxDp = Utils.dpToPx(this.scrollMax, context); //heightMaxScrollToolbar = context.getResources().getDimension(R.dimen.material_viewpager_padding_top); elevation = dpToPx(4, context); } /** * Called when a scroller(RecyclerView/ListView,ScrollView,WebView) scrolled by the user * * @param source the scroller * @param yOffset the scroller current yOffset */ private boolean onMaterialScrolled(Object source, float yOffset) { if (initialDistance == -1 || initialDistance == 0) { initialDistance = mHeader.mPagerSlidingTabStrip.getTop() - mHeader.toolbar.getBottom(); } //only if yOffset changed if (yOffset == lastYOffset) { return false; } float scrollTop = -yOffset; { //parallax scroll of the Background ImageView (the KenBurnsView) if (mHeader.headerBackground != null) { if (this.settings.parallaxHeaderFactor != 0) { ViewCompat.setTranslationY(mHeader.headerBackground, scrollTop / this.settings.parallaxHeaderFactor); } if (ViewCompat.getY(mHeader.headerBackground) >= 0) { ViewCompat.setY(mHeader.headerBackground, 0); } } } log("yOffset" + yOffset); //dispatch the new offset to all registered scrollables dispatchScrollOffset(source, minMax(0, yOffset, scrollMaxDp)); float percent = yOffset / scrollMax; log("percent1" + percent); if (percent != 0) { //distance between pager & toolbar float newDistance = ViewCompat.getY(mHeader.mPagerSlidingTabStrip) - mHeader.toolbar.getBottom(); percent = 1 - newDistance / initialDistance; log("percent2" + percent); } if (Float.isNaN(percent)) //fix for orientation change { return false; } //fix quick scroll if (percent == 0 && headerAnimator != null) { cancelHeaderAnimator(); ViewCompat.setTranslationY(mHeader.toolbarLayout, 0); } percent = minMax(0, percent, 1); { if (!settings.toolbarTransparent) { // change color of toolbar & viewpager indicator & statusBaground setColorPercent(percent); } else { if (justToolbarAnimated) { if (toolbarJoinsTabs()) { setColorPercent(1); } else if (lastPercent != percent) { animateColorPercent(0, 200); } } } lastPercent = percent; //save the percent if (mHeader.mPagerSlidingTabStrip != null) { //move the viewpager indicator //float newY = ViewCompat.getY(mHeader.mPagerSlidingTabStrip) + scrollTop; log("" + scrollTop); //mHeader.mPagerSlidingTabStrip.setTranslationY(mHeader.getToolbar().getBottom()-mHeader.mPagerSlidingTabStrip.getY()); if (scrollTop <= 0) { ViewCompat.setTranslationY(mHeader.mPagerSlidingTabStrip, scrollTop); ViewCompat.setTranslationY(mHeader.toolbarLayoutBackground, scrollTop); //when if (ViewCompat.getY(mHeader.mPagerSlidingTabStrip) < mHeader.getToolbar().getBottom()) { float ty = mHeader.getToolbar().getBottom() - mHeader.mPagerSlidingTabStrip.getTop(); ViewCompat.setTranslationY(mHeader.mPagerSlidingTabStrip, ty); ViewCompat.setTranslationY(mHeader.toolbarLayoutBackground, ty); } } } if (mHeader.mLogo != null) { //move the header logo to toolbar if (this.settings.hideLogoWithFade) { ViewCompat.setAlpha(mHeader.mLogo, 1 - percent); ViewCompat.setTranslationY(mHeader.mLogo, (mHeader.finalTitleY - mHeader.originalTitleY) * percent); } else { ViewCompat.setTranslationY(mHeader.mLogo, (mHeader.finalTitleY - mHeader.originalTitleY) * percent); ViewCompat.setTranslationX(mHeader.mLogo, (mHeader.finalTitleX - mHeader.originalTitleX) * percent); float scale = (1 - percent) * (1 - mHeader.finalScale) + mHeader.finalScale; setScale(scale, mHeader.mLogo); } } if (this.settings.hideToolbarAndTitle && mHeader.toolbarLayout != null) { boolean scrollUp = lastYOffset < yOffset; if (scrollUp) { scrollUp(yOffset); } else { scrollDown(yOffset); } } } if (headerAnimator != null && percent < 1) { cancelHeaderAnimator(); } lastYOffset = yOffset; return true; } /** * Change the color of the statusbackground, toolbar, toolbarlayout and pagertitlestrip * With a color transition animation * * @param color the final color * @param duration the transition color animation duration */ void setColor(int color, int duration) { final ValueAnimator colorAnim = ObjectAnimator.ofInt(mHeader.headerBackground, "backgroundColor", settings.color, color); colorAnim.setEvaluator(new ArgbEvaluator()); colorAnim.setDuration(duration); colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { final int animatedValue = (Integer) animation.getAnimatedValue(); int colorAlpha = colorWithAlpha(animatedValue, lastPercent); mHeader.headerBackground.setBackgroundColor(colorAlpha); mHeader.statusBackground.setBackgroundColor(colorAlpha); mHeader.toolbar.setBackgroundColor(colorAlpha); mHeader.toolbarLayoutBackground.setBackgroundColor(colorAlpha); mHeader.mPagerSlidingTabStrip.setBackgroundColor(colorAlpha); //set the new color as MaterialViewPager's color settings.color = animatedValue; } }); colorAnim.start(); } public void animateColorPercent(float percent, int duration) { final ValueAnimator valueAnimator = ValueAnimator.ofFloat(lastPercent, percent); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { setColorPercent((float) animation.getAnimatedValue()); } }); valueAnimator.setDuration(duration); valueAnimator.start(); } public void setColorPercent(float percent) { // change color of // toolbar & viewpager indicator & statusBaground setBackgroundColor( colorWithAlpha(this.settings.color, percent), mHeader.statusBackground ); if (percent >= 1) { setBackgroundColor( colorWithAlpha(this.settings.color, percent), mHeader.toolbar, mHeader.toolbarLayoutBackground, mHeader.mPagerSlidingTabStrip ); } else { setBackgroundColor( colorWithAlpha(this.settings.color, 0), mHeader.toolbar, mHeader.toolbarLayoutBackground, mHeader.mPagerSlidingTabStrip ); } if (this.settings.enableToolbarElevation && toolbarJoinsTabs()) { setElevation( (percent == 1) ? elevation : 0, mHeader.toolbar, mHeader.toolbarLayoutBackground, mHeader.mPagerSlidingTabStrip, mHeader.mLogo ); } } public int getHeaderHeight() { return this.settings.headerHeight; } /** * Register a RecyclerView to the current MaterialViewPagerAnimator * Listen to RecyclerView.OnScrollListener so give to $[onScrollListener] your RecyclerView.OnScrollListener if you already use one * For loadmore or anything else * * @param recyclerView the scrollable */ void registerRecyclerView(final RecyclerView recyclerView) { if (recyclerView != null && !scrollViewList.contains(recyclerView)) { scrollViewList.add(recyclerView); //add to the scrollable list yOffsets.put(recyclerView, recyclerView.getScrollY()); //save the initial recyclerview's yOffset (0) into hashmap //only necessary for recyclerview //listen to scroll recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { boolean firstZeroPassed; @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); int yOffset = yOffsets.get(recyclerView); if(yOffset < 0) { yOffset = 0; } yOffset += dy; yOffsets.put(recyclerView, yOffset); //save the new offset //first time you get 0, don't share it to others scrolls if (yOffset == 0 && !firstZeroPassed) { firstZeroPassed = true; return; } //only if yOffset changed if (isNewYOffset(yOffset)) { onMaterialScrolled(recyclerView, yOffset); } } }); recyclerView.post(new Runnable() { @Override public void run() { setScrollOffset(recyclerView, lastYOffset); } }); } } /** * Register a ScrollView to the current MaterialViewPagerAnimator * Listen to ObservableScrollViewCallbacks so give to $[observableScrollViewCallbacks] your ObservableScrollViewCallbacks if you already use one * For loadmore or anything else * * @param scrollView the scrollable */ void registerScrollView(final NestedScrollView scrollView) { if (scrollView != null) { scrollViewList.add(scrollView); //add to the scrollable list scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { boolean firstZeroPassed; @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { //first time you get 0, don't share it to others scrolls if (scrollY == 0 && !firstZeroPassed) { firstZeroPassed = true; return; } //only if yOffset changed if (isNewYOffset(scrollY)) { onMaterialScrolled(scrollView, scrollY); } } }); scrollView.post(new Runnable() { @Override public void run() { setScrollOffset(scrollView, lastYOffset); } }); } } void restoreScroll(final float scroll, final MaterialViewPagerSettings settings) { //try to scroll up, on a looper to wait until restored new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { if (!onMaterialScrolled(null, scroll)) { restoreScroll(scroll, settings); } } }, 100); } void onViewPagerPageChanged() { scrollDown(lastYOffset); View visibleView = getTheVisibileView(scrollViewList); if (!canScroll(visibleView)) { followScrollToolbarLayout(0); onMaterialScrolled(visibleView, 0); } } /** * When notified for scroll, dispatch it to all registered scrollables * * @param source * @param yOffset */ private void dispatchScrollOffset(Object source, float yOffset) { if (scrollViewList != null) { for (Object scroll : scrollViewList) { //do not re-scroll the source if (scroll != null && scroll != source) { setScrollOffset(scroll, yOffset); } } } } private boolean isNewYOffset(int yOffset) { if (lastYOffset == -1) { return true; } else { return yOffset != lastYOffset; } } /** * When notified for scroll, dispatch it to all registered scrollables * * @param scroll * @param yOffset */ private void setScrollOffset(Object scroll, float yOffset) { //do not re-scroll the source if (scroll != null && yOffset >= 0) { scrollTo(scroll, yOffset); //save the current yOffset of the scrollable on the yOffsets hashmap yOffsets.put(scroll, (int) yOffset); } } private void cancelHeaderAnimator() { if (headerAnimator != null) { headerAnimator.cancel(); headerAnimator = null; } } //region register scrollables private void scrollUp(float yOffset) { log("scrollUp"); followScrollToolbarLayout(yOffset); } private void log(String scrollUp) { if (ENABLE_LOG) { Log.d(TAG, scrollUp); } } private void scrollDown(float yOffset) { log("scrollDown"); if (yOffset > mHeader.toolbarLayout.getHeight() * 1.5f) { animateEnterToolbarLayout(yOffset); } else { if (headerAnimator != null) { followScrollToolbarIsVisible = true; } else { followScrollToolbarLayout(yOffset); } } } private boolean toolbarJoinsTabs() { return (mHeader.toolbar.getBottom() == mHeader.mPagerSlidingTabStrip.getTop() + ViewCompat.getTranslationY(mHeader.mPagerSlidingTabStrip)); } //endregion /** * move the toolbarlayout (containing toolbar & tabs) * following the current scroll */ private void followScrollToolbarLayout(float yOffset) { if (mHeader.toolbar.getBottom() == 0) { return; } if (toolbarJoinsTabs()) { if (firstScrollValue == Float.MIN_VALUE) { firstScrollValue = yOffset; } float translationY = firstScrollValue - yOffset; if (translationY > 0) { translationY = 0; } log("translationY " + translationY); ViewCompat.setTranslationY(mHeader.toolbarLayout, translationY); } else { ViewCompat.setTranslationY(mHeader.toolbarLayout, 0); justToolbarAnimated = false; } followScrollToolbarIsVisible = (ViewCompat.getY(mHeader.toolbarLayout) >= 0); } /** * Animate enter toolbarlayout * * @param yOffset */ private void animateEnterToolbarLayout(float yOffset) { if (!followScrollToolbarIsVisible && headerAnimator != null) { headerAnimator.cancel(); headerAnimator = null; } if (headerAnimator == null) { headerAnimator = ObjectAnimator.ofFloat(mHeader.toolbarLayout, View.TRANSLATION_Y, 0); headerAnimator.setDuration(ENTER_TOOLBAR_ANIMATION_DURATION); headerAnimator.addListener(new android.animation.AnimatorListenerAdapter() { @Override public void onAnimationEnd(android.animation.Animator animation) { super.onAnimationEnd(animation); followScrollToolbarIsVisible = true; firstScrollValue = Float.MIN_VALUE; justToolbarAnimated = true; } }); headerAnimator.start(); } } } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerHeader.java ================================================ package com.github.florent37.materialviewpager; import android.content.Context; import android.support.v4.view.ViewCompat; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.ViewTreeObserver; import android.support.v4.view.ViewCompat; import static com.github.florent37.materialviewpager.Utils.dpToPx; /** * Created by florentchampigny on 25/04/15. * A class containing references to views inside MaterialViewPager's header */ public class MaterialViewPagerHeader { protected Context context; protected View toolbarLayout; protected Toolbar toolbar; protected View mPagerSlidingTabStrip; protected View toolbarLayoutBackground; protected View headerBackground; protected View statusBackground; protected View mLogo; //positions used to animate views during scroll public float finalTabsY; public float finalTitleY; public float finalTitleHeight; public float finalTitleX; public float originalTitleY; public float originalTitleHeight; public float originalTitleX; public float finalScale; private MaterialViewPagerHeader(Toolbar toolbar) { this.toolbar = toolbar; this.context = toolbar.getContext(); this.toolbarLayout = (View) toolbar.getParent(); } public static MaterialViewPagerHeader withToolbar(Toolbar toolbar) { return new MaterialViewPagerHeader(toolbar); } public Context getContext() { return context; } public MaterialViewPagerHeader withPagerSlidingTabStrip(View pagerSlidingTabStrip) { this.mPagerSlidingTabStrip = pagerSlidingTabStrip; mPagerSlidingTabStrip.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { finalTabsY = dpToPx(-2, context); mPagerSlidingTabStrip.getViewTreeObserver().removeOnPreDrawListener(this); return false; } }); return this; } public MaterialViewPagerHeader withHeaderBackground(View headerBackground) { this.headerBackground = headerBackground; return this; } public MaterialViewPagerHeader withStatusBackground(View statusBackground) { this.statusBackground = statusBackground; return this; } public MaterialViewPagerHeader withToolbarLayoutBackground(View toolbarLayoutBackground) { this.toolbarLayoutBackground = toolbarLayoutBackground; return this; } public int getStatusBarHeight(Context context) { int result = 0; int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = context.getResources().getDimensionPixelSize(resourceId); } return result; } public MaterialViewPagerHeader withLogo(View logo) { this.mLogo = logo; //when logo get a height, initialise initial & final logo positions toolbarLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { //rotation fix, if not set, originalTitleY = Na ViewCompat.setTranslationY(mLogo,0); ViewCompat.setTranslationX(mLogo, 0); originalTitleY = ViewCompat.getY(mLogo); originalTitleX = ViewCompat.getX(mLogo); originalTitleHeight = mLogo.getHeight(); finalTitleHeight = dpToPx(21, context); //the final scale of the logo finalScale = finalTitleHeight / originalTitleHeight; finalTitleY = (toolbar.getPaddingTop() + toolbar.getHeight()) / 2 - finalTitleHeight / 2 - (1 - finalScale) * finalTitleHeight; //(mLogo.getWidth()/2) *(1-finalScale) is the margin left added by the scale() on the logo //when logo scaledown, the content stay in center, so we have to anually remove the left padding finalTitleX = dpToPx(52f, context) - (mLogo.getWidth() / 2) * (1 - finalScale); toolbarLayout.getViewTreeObserver().removeOnPreDrawListener(this); return false; } }); return this; } public Toolbar getToolbar() { return toolbar; } public View getHeaderBackground() { return headerBackground; } public View getStatusBackground() { return statusBackground; } public View getLogo() { return mLogo; } } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerHeaderView.java ================================================ package com.github.florent37.materialviewpager; import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; /** * Created by florentchampigny on 26/04/15. * A placeholder view used to add a transparent padding on top of a Scroller * RecyclerView : use RecyclerViewMaterialAdapter * ListView : use ListViewMaterialAdapter (smoother if use RecyclerView) * ScrollView : add a MaterialViewPagerHeaderView on top of your ScrollView (with LinearLayout vertical) */ public class MaterialViewPagerHeaderView extends View { public MaterialViewPagerHeaderView(Context context) { super(context); } public MaterialViewPagerHeaderView(Context context, AttributeSet attrs) { super(context, attrs); } public MaterialViewPagerHeaderView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public MaterialViewPagerHeaderView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } private void setMaterialHeight() { //get the MaterialViewPagerAnimator attached to this activity //to retrieve the declared header height //and set it as current view height (+10dp margin) MaterialViewPagerAnimator animator = MaterialViewPagerHelper.getAnimator(getContext()); if (animator != null) { ViewGroup.LayoutParams params = getLayoutParams(); params.height = Math.round(Utils.dpToPx(animator.getHeaderHeight() + 10, getContext())); super.setLayoutParams(params); } } @Override protected void onFinishInflate() { super.onFinishInflate(); if (!isInEditMode()) { getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { setMaterialHeight(); getViewTreeObserver().removeOnPreDrawListener(this); return false; } }); } } } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerHelper.java ================================================ package com.github.florent37.materialviewpager; import android.app.Activity; import android.content.Context; import android.support.v4.widget.NestedScrollView; import android.support.v7.widget.RecyclerView; import java.util.concurrent.ConcurrentHashMap; /** * Created by florentchampigny on 25/04/15. *

* MaterialViewPagerHelper attach a MaterialViewPagerAnimator to an activity * You can use MaterialViewPagerHelper to retrieve MaterialViewPagerAnimator from context * Or register a scrollable to the current activity's MaterialViewPagerAnimator */ public class MaterialViewPagerHelper { private static ConcurrentHashMap hashMap = new ConcurrentHashMap<>(); /** * Register an MaterialViewPagerAnimator attached to an activity into the ConcurrentHashMap * * @param context the context * @param animator the current MaterialViewPagerAnimator */ static void register(Context context, MaterialViewPagerAnimator animator) { hashMap.put(context, animator); } static void unregister(Context context) { if (context != null) { hashMap.remove(context); } } /** * Register a RecyclerView to the current MaterialViewPagerAnimator * Listen to RecyclerView.OnScrollListener so give to $[onScrollListener] your RecyclerView.OnScrollListener if you already use one * For loadmore or anything else * * @param context current context * @param recyclerView the scrollable */ public static void registerRecyclerView(Context context, RecyclerView recyclerView) { if (context != null && hashMap.containsKey(context)) { final MaterialViewPagerAnimator animator = hashMap.get(context); if (animator != null) { animator.registerRecyclerView(recyclerView); } } } /** * Register a ScrollView to the current MaterialViewPagerAnimator * Listen to ObservableScrollViewCallbacks so give to $[observableScrollViewCallbacks] your ObservableScrollViewCallbacks if you already use one * For loadmore or anything else * * @param context current context * @param mScrollView the scrollable */ public static void registerScrollView(Context context, NestedScrollView mScrollView) { if (context != null && hashMap.containsKey(context)) { final MaterialViewPagerAnimator animator = hashMap.get(context); if (animator != null) { animator.registerScrollView(mScrollView); } } } /** * Retrieve the current MaterialViewPagerAnimator used in this context (Activity) * * @param context the context * @return current MaterialViewPagerAnimator */ public static MaterialViewPagerAnimator getAnimator(Context context) { return hashMap.get(context); } } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerSettings.java ================================================ package com.github.florent37.materialviewpager; import android.content.Context; import android.content.res.TypedArray; import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; import static com.github.florent37.materialviewpager.Utils.pxToDp; /** * Created by florentchampigny on 29/04/15. *

* Save attributes given to MaterialViewPager from layout */ public class MaterialViewPagerSettings implements Parcelable { //attributes are protected and can be used by class from the same package //com.github.florent37.materialviewpager public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public MaterialViewPagerSettings createFromParcel(Parcel source) { return new MaterialViewPagerSettings(source); } public MaterialViewPagerSettings[] newArray(int size) { return new MaterialViewPagerSettings[size]; } }; int headerLayoutId; int pagerTitleStripId; int viewpagerId; int logoLayoutId; int logoMarginTop; int headerAdditionalHeight; int headerHeight; int headerHeightPx; int color; float headerAlpha; float parallaxHeaderFactor; float imageHeaderDarkLayerAlpha; boolean hideToolbarAndTitle; boolean hideLogoWithFade; boolean enableToolbarElevation; boolean displayToolbarWhenSwipe; boolean toolbarTransparent; boolean animatedHeaderImage; boolean disableToolbar; //region parcelable public MaterialViewPagerSettings() { } private MaterialViewPagerSettings(Parcel in) { this.headerLayoutId = in.readInt(); this.pagerTitleStripId = in.readInt(); this.viewpagerId = in.readInt(); this.logoLayoutId = in.readInt(); this.logoMarginTop = in.readInt(); this.headerAdditionalHeight = in.readInt(); this.headerHeight = in.readInt(); this.headerHeightPx = in.readInt(); this.color = in.readInt(); this.headerAlpha = in.readFloat(); this.imageHeaderDarkLayerAlpha = in.readFloat(); this.parallaxHeaderFactor = in.readFloat(); this.hideToolbarAndTitle = in.readByte() != 0; this.hideLogoWithFade = in.readByte() != 0; this.enableToolbarElevation = in.readByte() != 0; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(this.headerLayoutId); dest.writeInt(this.pagerTitleStripId); dest.writeInt(this.viewpagerId); dest.writeInt(this.logoLayoutId); dest.writeInt(this.logoMarginTop); dest.writeInt(this.headerAdditionalHeight); dest.writeInt(this.headerHeight); dest.writeInt(this.headerHeightPx); dest.writeInt(this.color); dest.writeFloat(this.headerAlpha); dest.writeFloat(this.imageHeaderDarkLayerAlpha); dest.writeFloat(this.parallaxHeaderFactor); dest.writeByte(hideToolbarAndTitle ? (byte) 1 : (byte) 0); dest.writeByte(hideLogoWithFade ? (byte) 1 : (byte) 0); dest.writeByte(enableToolbarElevation ? (byte) 1 : (byte) 0); } /** * Retrieve attributes from the MaterialViewPager * * @param context * @param attrs */ void handleAttributes(Context context, AttributeSet attrs) { try { TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.MaterialViewPager); { headerLayoutId = styledAttrs.getResourceId(R.styleable.MaterialViewPager_viewpager_header, -1); } { pagerTitleStripId = styledAttrs.getResourceId(R.styleable.MaterialViewPager_viewpager_pagerTitleStrip, -1); if (pagerTitleStripId == -1) { pagerTitleStripId = R.layout.material_view_pager_pagertitlestrip_standard; } } { viewpagerId = styledAttrs.getResourceId(R.styleable.MaterialViewPager_viewpager_viewpager, -1); } { logoLayoutId = styledAttrs.getResourceId(R.styleable.MaterialViewPager_viewpager_logo, -1); logoMarginTop = styledAttrs.getDimensionPixelSize(R.styleable.MaterialViewPager_viewpager_logoMarginTop, 0); } { color = styledAttrs.getColor(R.styleable.MaterialViewPager_viewpager_color, 0); } { headerHeightPx = styledAttrs.getDimensionPixelOffset(R.styleable.MaterialViewPager_viewpager_headerHeight, 200); headerHeight = Math.round(pxToDp(headerHeightPx, context)); //convert to dp } { headerAdditionalHeight = styledAttrs.getDimensionPixelOffset(R.styleable.MaterialViewPager_viewpager_headerAdditionalHeight, 60); } { headerAlpha = styledAttrs.getFloat(R.styleable.MaterialViewPager_viewpager_headerAlpha, 0.5f); } { imageHeaderDarkLayerAlpha = styledAttrs.getFloat(R.styleable.MaterialViewPager_viewpager_imageHeaderDarkLayerAlpha, 0.0f); } { parallaxHeaderFactor = styledAttrs.getFloat(R.styleable.MaterialViewPager_viewpager_parallaxHeaderFactor, 1.5f); parallaxHeaderFactor = Math.max(parallaxHeaderFactor, 1); //min=1 } { hideToolbarAndTitle = styledAttrs.getBoolean(R.styleable.MaterialViewPager_viewpager_hideToolbarAndTitle, false); hideLogoWithFade = styledAttrs.getBoolean(R.styleable.MaterialViewPager_viewpager_hideLogoWithFade, false); } { enableToolbarElevation = styledAttrs.getBoolean(R.styleable.MaterialViewPager_viewpager_enableToolbarElevation, false); } { displayToolbarWhenSwipe = styledAttrs.getBoolean(R.styleable.MaterialViewPager_viewpager_displayToolbarWhenSwipe, false); } { toolbarTransparent = styledAttrs.getBoolean(R.styleable.MaterialViewPager_viewpager_transparentToolbar, false); } { animatedHeaderImage = styledAttrs.getBoolean(R.styleable.MaterialViewPager_viewpager_animatedHeaderImage, true); } { disableToolbar = styledAttrs.getBoolean(R.styleable.MaterialViewPager_viewpager_disableToolbar, false); } styledAttrs.recycle(); } catch (Exception e) { e.printStackTrace(); } } //endregion } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/Utils.java ================================================ package com.github.florent37.materialviewpager; import android.content.Context; import android.graphics.Color; import android.graphics.Rect; import android.support.v4.view.ViewCompat; import android.support.v4.widget.NestedScrollView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.StaggeredGridLayoutManager; import android.view.View; import android.webkit.WebView; import android.widget.ListView; import android.widget.ScrollView; import android.support.v4.view.ViewCompat; import java.util.List; /** * Created by florentchampigny on 24/04/15. */ public class Utils { /** * convert dp to px */ public static float dpToPx(float dp, Context context) { return dp * context.getResources().getDisplayMetrics().density; } /** * convert px to dp */ static float pxToDp(float px, Context context) { return px / context.getResources().getDisplayMetrics().density; } /* * Create a color from [$color].RGB and then add an alpha with 255*[$percent] */ static int colorWithAlpha(int color, float percent) { int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); int alpha = Math.round(percent * 255); return Color.argb(alpha, r, g, b); } static float minMax(float min, float value, float max) { value = Math.min(value, max); value = Math.max(min, value); return value; } /** * modify the scale of multiples views * * @param scale the new scale * @param views */ static void setScale(float scale, View... views) { for (View view : views) { if (view != null) { ViewCompat.setScaleX(view, scale); ViewCompat.setScaleY(view, scale); } } } /** * modify the elevation of multiples views * * @param elevation the new elevation * @param views */ static void setElevation(float elevation, View... views) { for (View view : views) { if (view != null) { ViewCompat.setElevation(view, elevation); } } } /** * modify the backgroundcolor of multiples views * * @param color the new backgroundcolor * @param views */ static void setBackgroundColor(int color, View... views) { for (View view : views) { if (view != null) { view.setBackgroundColor(color); } } } static boolean canScroll(View view) { if (view instanceof ScrollView) { ScrollView scrollView = (ScrollView) view; View child = scrollView.getChildAt(0); if (child != null) { int childHeight = child.getHeight(); return scrollView.getHeight() < childHeight + scrollView.getPaddingTop() + scrollView.getPaddingBottom(); } return false; } else if (view instanceof RecyclerView) { RecyclerView recyclerView = (RecyclerView) view; int yOffset = recyclerView.computeVerticalScrollOffset(); return yOffset != 0; } return true; } public static void scrollTo(Object scroll, float yOffset) { if (scroll instanceof RecyclerView) { //RecyclerView.scrollTo : UnsupportedOperationException //Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset //Have to be instanceOf RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager) final RecyclerView.LayoutManager layoutManager = ((RecyclerView) scroll).getLayoutManager(); if (layoutManager instanceof LinearLayoutManager) { LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager; linearLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset); } else if (layoutManager instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager; staggeredGridLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset); } } else if (scroll instanceof NestedScrollView) { ((NestedScrollView) scroll).scrollTo(0, (int) yOffset); } } static View getTheVisibileView(List viewList) { Rect scrollBounds = new Rect(); int listSize = viewList.size(); for (int i = 0; i < listSize; ++i) { View view = viewList.get(i); if (view != null) { view.getHitRect(scrollBounds); if (view.getLocalVisibleRect(scrollBounds)) { return view; } } } return null; } } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/header/HeaderDesign.java ================================================ package com.github.florent37.materialviewpager.header; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.annotation.ColorRes; /** * Created by florentchampigny on 10/06/15. */ public class HeaderDesign { protected int color; protected int colorRes; protected String imageUrl; protected Drawable drawable; private HeaderDesign() { } public static HeaderDesign fromColorAndUrl(@ColorInt int color, String imageUrl) { HeaderDesign headerDesign = new HeaderDesign(); headerDesign.color = color; headerDesign.imageUrl = imageUrl; return headerDesign; } public static HeaderDesign fromColorResAndUrl(@ColorRes int colorRes, String imageUrl) { HeaderDesign headerDesign = new HeaderDesign(); headerDesign.colorRes = colorRes; headerDesign.imageUrl = imageUrl; return headerDesign; } public static HeaderDesign fromColorAndDrawable(@ColorInt int color, Drawable drawable) { HeaderDesign headerDesign = new HeaderDesign(); headerDesign.drawable = drawable; headerDesign.color = color; return headerDesign; } public static HeaderDesign fromColorResAndDrawable(@ColorRes int colorRes, Drawable drawable) { HeaderDesign headerDesign = new HeaderDesign(); headerDesign.colorRes = colorRes; headerDesign.drawable = drawable; return headerDesign; } public int getColor() { return color; } public int getColorRes() { return colorRes; } public String getImageUrl() { return imageUrl; } public Drawable getDrawable() { return drawable; } } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/header/MaterialViewPagerHeaderDecorator.java ================================================ package com.github.florent37.materialviewpager.header; import android.content.Context; import android.graphics.Rect; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.StaggeredGridLayoutManager; import android.view.View; import com.github.florent37.materialviewpager.MaterialViewPagerAnimator; import com.github.florent37.materialviewpager.MaterialViewPagerHelper; import com.github.florent37.materialviewpager.Utils; /** * Created by florentchampigny on 27/05/2016. */ public class MaterialViewPagerHeaderDecorator extends RecyclerView.ItemDecoration { boolean registered = false; @Override public void getItemOffsets(Rect outRect, View view, RecyclerView recyclerView, RecyclerView.State state) { final RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(view); final Context context = recyclerView.getContext(); if(!registered) { MaterialViewPagerHelper.registerRecyclerView(context, recyclerView); registered = true; } int headerCells = 1; //don't work with stagged RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if(layoutManager instanceof GridLayoutManager){ GridLayoutManager gridLayoutManager = (GridLayoutManager)layoutManager; headerCells = gridLayoutManager.getSpanCount(); } MaterialViewPagerAnimator animator = MaterialViewPagerHelper.getAnimator(context); if (animator != null) { if (holder.getAdapterPosition() < headerCells) { outRect.top = Math.round(Utils.dpToPx(animator.getHeaderHeight() + 10, context)); } } } } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/header/MaterialViewPagerImageHeader.java ================================================ package com.github.florent37.materialviewpager.header; import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import com.flaviofaria.kenburnsview.KenBurnsView; /** * Created by florentchampigny on 29/04/15. * The MaterialViewPager animated Header * Using com.flaviofaria.kenburnsview.KenBurnsView * https://github.com/flavioarfaria/KenBurnsView */ public class MaterialViewPagerImageHeader extends KenBurnsView { //region construct public MaterialViewPagerImageHeader(Context context) { super(context); } public MaterialViewPagerImageHeader(Context context, AttributeSet attrs) { super(context, attrs); } public MaterialViewPagerImageHeader(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } //endregion /** * change the image with a fade * * @param urlImage * @param fadeDuration TODO : remove Picasso */ public void setImageUrl(final String urlImage, final int fadeDuration) { MaterialViewPagerImageHelper.setImageUrl(this, urlImage, fadeDuration); } /** * change the image with a fade * * @param drawable * @param fadeDuration */ public void setImageDrawable(final Drawable drawable, final int fadeDuration) { MaterialViewPagerImageHelper.setImageDrawable(this, drawable, fadeDuration); } } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/header/MaterialViewPagerImageHelper.java ================================================ package com.github.florent37.materialviewpager.header; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Looper; import android.support.annotation.Nullable; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPropertyAnimatorListenerAdapter; import android.view.View; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.widget.ImageView; import com.bumptech.glide.Glide; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; import com.github.florent37.materialviewpager.MaterialViewPager; import android.os.Handler; /** * Created by florentchampigny on 12/06/15. */ public class MaterialViewPagerImageHelper { private static MaterialViewPager.OnImageLoadListener imageLoadListener; /** * change the image with a fade * * @param urlImage * @param fadeDuration TODO : remove Picasso */ public static void setImageUrl(final ImageView imageView, final String urlImage, final int fadeDuration) { final float alpha = ViewCompat.getAlpha(imageView); final ImageView viewToAnimate = imageView; //fade to alpha=0 fadeOut(viewToAnimate, fadeDuration, new ViewPropertyAnimatorListenerAdapter() { @Override public void onAnimationEnd(View view) { super.onAnimationEnd(view); //change the image when alpha=0 Glide.with(imageView.getContext()).load(urlImage) .apply(new RequestOptions().centerCrop()) .listener(new RequestListener() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { //then fade to alpha=1 new Handler(Looper.getMainLooper()) {}.post(new Runnable(){ @Override public void run(){ fadeIn(viewToAnimate, alpha, fadeDuration, new ViewPropertyAnimatorListenerAdapter()); if (imageLoadListener != null) { imageLoadListener.OnImageLoad(imageView, ((BitmapDrawable) imageView.getDrawable()).getBitmap()); } } }); return false; } }) .into(viewToAnimate); } }); } public static void fadeOut(View view, int fadeDuration, ViewPropertyAnimatorListenerAdapter listener) { //fade to alpha=0 ViewCompat.animate(view) .alpha(0) .setDuration(fadeDuration) .withLayer() .setInterpolator(new DecelerateInterpolator()) .setListener(listener); } public static void fadeIn(View view, float alpha, int fadeDuration, ViewPropertyAnimatorListenerAdapter listener) { //fade to alpha=0 ViewCompat.animate(view) .alpha(alpha) .setDuration(fadeDuration) .withLayer() .setInterpolator(new AccelerateInterpolator()) .setListener(listener); } /** * change the image with a fade * * @param drawable * @param fadeDuration */ public static void setImageDrawable(final ImageView imageView, final Drawable drawable, final int fadeDuration) { final float alpha = ViewCompat.getAlpha(imageView); final ImageView viewToAnimate = imageView; fadeOut(viewToAnimate, fadeDuration, new ViewPropertyAnimatorListenerAdapter() { @Override public void onAnimationEnd(View view) { super.onAnimationEnd(view); //change the image when alpha=0 imageView.setImageDrawable(drawable); //then fade to alpha=1 fadeIn(viewToAnimate, alpha, fadeDuration, new ViewPropertyAnimatorListenerAdapter()); } }); } public static void setImageLoadListener(MaterialViewPager.OnImageLoadListener imageLoadListener) { MaterialViewPagerImageHelper.imageLoadListener = imageLoadListener; } } ================================================ FILE: materialviewpager/src/main/java/com/github/florent37/materialviewpager/header/MaterialViewPagerKenBurnsHeader.java ================================================ package com.github.florent37.materialviewpager.header; import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import com.flaviofaria.kenburnsview.KenBurnsView; /** * Created by florentchampigny on 29/04/15. * The MaterialViewPager animated Header * Using com.flaviofaria.kenburnsview.KenBurnsView * https://github.com/flavioarfaria/KenBurnsView */ public class MaterialViewPagerKenBurnsHeader extends KenBurnsView { //region construct public MaterialViewPagerKenBurnsHeader(Context context) { super(context); } public MaterialViewPagerKenBurnsHeader(Context context, AttributeSet attrs) { super(context, attrs); } public MaterialViewPagerKenBurnsHeader(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } //endregion /** * change the image with a fade * * @param urlImage * @param fadeDuration TODO : remove Picasso */ public void setImageUrl(final String urlImage, final int fadeDuration) { MaterialViewPagerImageHelper.setImageUrl(this, urlImage, fadeDuration); } /** * change the image with a fade * * @param drawable * @param fadeDuration */ public void setImageDrawable(final Drawable drawable, final int fadeDuration) { MaterialViewPagerImageHelper.setImageDrawable(this, drawable, fadeDuration); } } ================================================ FILE: materialviewpager/src/main/res/layout/material_view_pager_imageview_header.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/layout/material_view_pager_layout.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/layout/material_view_pager_moving_header.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/layout/material_view_pager_pagertitlestrip_newstand.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/layout/material_view_pager_pagertitlestrip_standard.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/layout/material_view_pager_placeholder.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/layout/material_view_pager_viewpager.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/layout/tools_list_item_card_big.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/layout/tools_list_item_card_small.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/layout/tools_list_items.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/layout/tools_material_view_pager_pagertitlestrip.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/values/attrs.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/values/colors.xml ================================================ #303F9F #4CAF50 #009688 #673AB7 #F44336 #00BCD4 #CDDC39 @color/blue @color/blue @color/blue @color/blue @android:color/black @android:color/white ================================================ FILE: materialviewpager/src/main/res/values/dimens.xml ================================================ 10dp 8dp 35dp ================================================ FILE: materialviewpager/src/main/res/values/ids.xml ================================================ ================================================ FILE: materialviewpager/src/main/res/values/styles.xml ================================================ ================================================ FILE: publish.sh ================================================ ./gradlew clean :materialviewpager:install :materialviewpager:bintrayUpload ================================================ FILE: sample/.gitignore ================================================ /build material_view_pager_keystore.jks keyInfos.properties fabric.properties ================================================ FILE: sample/build.gradle ================================================ apply plugin: 'com.android.application' apply plugin: 'io.fabric' android { compileSdkVersion project.sdk buildToolsVersion project.buildTools defaultConfig { minSdkVersion project.minSdk targetSdkVersion project.sdk versionCode 4 versionName "1.0" } File signFile = project.file('keyInfos.properties') if (signFile.exists()) { Properties properties = new Properties() properties.load(new FileInputStream(signFile)) signingConfigs { release { storeFile file(project.file(properties['keystore.filename'])) storePassword properties['keystore.password'] keyAlias properties['keystore.alias'] keyPassword properties['keystore.password'] } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' if (signFile.exists()) signingConfig signingConfigs.release } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile 'com.android.support:appcompat-v7:'+project.supportVersion compile 'com.android.support:cardview-v7:'+project.supportVersion compile 'com.jakewharton:butterknife:8.1.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0' //compile ('com.github.florent37:materialviewpager:1.0.6@aar'){ // transitive=true //} compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') { transitive = true; } compile project(':materialviewpager') } ================================================ FILE: sample/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in /Users/florentchampigny/android/sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} ================================================ FILE: sample/src/main/AndroidManifest.xml ================================================ ================================================ FILE: sample/src/main/java/com/github/florent37/materialviewpager/sample/DrawerActivity.java ================================================ package com.github.florent37.materialviewpager.sample; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import com.crashlytics.android.Crashlytics; import io.fabric.sdk.android.Fabric; /** * Created by florentchampigny on 27/05/2016. */ public class DrawerActivity extends AppCompatActivity { private DrawerLayout mDrawer; private ActionBarDrawerToggle mDrawerToggle; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!BuildConfig.DEBUG) { Fabric.with(this, new Crashlytics()); } } @Override protected void onStart() { super.onStart(); mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, 0, 0); mDrawer.setDrawerListener(mDrawerToggle); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayUseLogoEnabled(false); actionBar.setHomeButtonEnabled(true); } } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); mDrawerToggle.syncState(); } @Override public boolean onOptionsItemSelected(MenuItem item) { return mDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item); } } ================================================ FILE: sample/src/main/java/com/github/florent37/materialviewpager/sample/MainActivity.java ================================================ package com.github.florent37.materialviewpager.sample; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.widget.Toast; import com.crashlytics.android.Crashlytics; import com.github.florent37.materialviewpager.MaterialViewPager; import com.github.florent37.materialviewpager.header.HeaderDesign; import com.github.florent37.materialviewpager.sample.fragment.RecyclerViewFragment; import butterknife.BindView; import butterknife.ButterKnife; import io.fabric.sdk.android.Fabric; public class MainActivity extends DrawerActivity { @BindView(R.id.materialViewPager) MaterialViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setTitle(""); ButterKnife.bind(this); final Toolbar toolbar = mViewPager.getToolbar(); if (toolbar != null) { setSupportActionBar(toolbar); } mViewPager.getViewPager().setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { switch (position % 4) { //case 0: // return RecyclerViewFragment.newInstance(); //case 1: // return RecyclerViewFragment.newInstance(); //case 2: // return WebViewFragment.newInstance(); default: return RecyclerViewFragment.newInstance(); } } @Override public int getCount() { return 4; } @Override public CharSequence getPageTitle(int position) { switch (position % 4) { case 0: return "Selection"; case 1: return "Actualités"; case 2: return "Professionnel"; case 3: return "Divertissement"; } return ""; } }); mViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() { @Override public HeaderDesign getHeaderDesign(int page) { switch (page) { case 0: return HeaderDesign.fromColorResAndUrl( R.color.green, "http://phandroid.s3.amazonaws.com/wp-content/uploads/2014/06/android_google_moutain_google_now_1920x1080_wallpaper_Wallpaper-HD_2560x1600_www.paperhi.com_-640x400.jpg"); case 1: return HeaderDesign.fromColorResAndUrl( R.color.blue, "http://www.hdiphonewallpapers.us/phone-wallpapers/540x960-1/540x960-mobile-wallpapers-hd-2218x5ox3.jpg"); case 2: return HeaderDesign.fromColorResAndUrl( R.color.cyan, "http://www.droid-life.com/wp-content/uploads/2014/10/lollipop-wallpapers10.jpg"); case 3: return HeaderDesign.fromColorResAndUrl( R.color.red, "http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg"); } //execute others actions if needed (ex : modify your header logo) return null; } }); mViewPager.getViewPager().setOffscreenPageLimit(mViewPager.getViewPager().getAdapter().getCount()); mViewPager.getPagerTitleStrip().setViewPager(mViewPager.getViewPager()); final View logo = findViewById(R.id.logo_white); if (logo != null) { logo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mViewPager.notifyHeaderChanged(); Toast.makeText(getApplicationContext(), "Yes, the title is clickable", Toast.LENGTH_SHORT).show(); } }); } } } ================================================ FILE: sample/src/main/java/com/github/florent37/materialviewpager/sample/TestListViewAdapter.java ================================================ package com.github.florent37.materialviewpager.sample; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import java.util.List; /** * Created by florentchampigny on 24/04/15. */ public class TestListViewAdapter extends ArrayAdapter { static final int TYPE_HEADER = 0; static final int TYPE_CELL = 1; public TestListViewAdapter(Context context, List objects) { super(context, 0, objects); } @Override public int getItemViewType(int position) { switch (position) { case 0: return TYPE_HEADER; default: return TYPE_CELL; } } @Override public int getViewTypeCount() { return 2; } @Override public View getView(int position, View convertView, ViewGroup parent) { if(convertView == null) { switch (getItemViewType(position)) { case TYPE_HEADER: { convertView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.tools_list_item_card_big, parent, false); } break; case TYPE_CELL: { convertView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.tools_list_item_card_small, parent, false); } break; } } return convertView; } } ================================================ FILE: sample/src/main/java/com/github/florent37/materialviewpager/sample/TestRecyclerViewAdapter.java ================================================ package com.github.florent37.materialviewpager.sample; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.List; /** * Created by florentchampigny on 24/04/15. */ public class TestRecyclerViewAdapter extends RecyclerView.Adapter { List contents; static final int TYPE_HEADER = 0; static final int TYPE_CELL = 1; public TestRecyclerViewAdapter(List contents) { this.contents = contents; } @Override public int getItemViewType(int position) { switch (position) { case 0: return TYPE_HEADER; default: return TYPE_CELL; } } @Override public int getItemCount() { return contents.size(); } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = null; switch (viewType) { case TYPE_HEADER: { view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.list_item_card_big, parent, false); return new RecyclerView.ViewHolder(view) { }; } case TYPE_CELL: { view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.list_item_card_small, parent, false); return new RecyclerView.ViewHolder(view) { }; } } return null; } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { switch (getItemViewType(position)) { case TYPE_HEADER: break; case TYPE_CELL: break; } } } ================================================ FILE: sample/src/main/java/com/github/florent37/materialviewpager/sample/fragment/RecyclerViewFragment.java ================================================ package com.github.florent37.materialviewpager.sample.fragment; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator; import com.github.florent37.materialviewpager.sample.R; import com.github.florent37.materialviewpager.sample.TestRecyclerViewAdapter; import java.util.ArrayList; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; /** * Created by florentchampigny on 24/04/15. */ public class RecyclerViewFragment extends Fragment { private static final boolean GRID_LAYOUT = false; private static final int ITEM_COUNT = 100; @BindView(R.id.recyclerView) RecyclerView mRecyclerView; public static RecyclerViewFragment newInstance() { return new RecyclerViewFragment(); } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_recyclerview, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ButterKnife.bind(this, view); final List items = new ArrayList<>(); for (int i = 0; i < ITEM_COUNT; ++i) { items.add(new Object()); } //setup materialviewpager if (GRID_LAYOUT) { mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2)); } else { mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); } mRecyclerView.setHasFixedSize(true); //Use this now mRecyclerView.addItemDecoration(new MaterialViewPagerHeaderDecorator()); mRecyclerView.setAdapter(new TestRecyclerViewAdapter(items)); } } ================================================ FILE: sample/src/main/java/com/github/florent37/materialviewpager/sample/fragment/ScrollFragment.java ================================================ package com.github.florent37.materialviewpager.sample.fragment; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.widget.NestedScrollView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.github.florent37.materialviewpager.MaterialViewPagerHelper; import com.github.florent37.materialviewpager.sample.R; import butterknife.BindView; import butterknife.ButterKnife; /** * Created by florentchampigny on 24/04/15. */ public class ScrollFragment extends Fragment { @BindView(R.id.scrollView) NestedScrollView mScrollView; public static ScrollFragment newInstance() { return new ScrollFragment(); } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_scroll, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ButterKnife.bind(this, view); MaterialViewPagerHelper.registerScrollView(getActivity(), mScrollView); } } ================================================ FILE: sample/src/main/res/drawable/circle.xml ================================================ ================================================ FILE: sample/src/main/res/layout/activity_main.xml ================================================ ================================================ FILE: sample/src/main/res/layout/drawer.xml ================================================ ================================================ FILE: sample/src/main/res/layout/fragment_list.xml ================================================ ================================================ FILE: sample/src/main/res/layout/fragment_recyclerview.xml ================================================ ================================================ FILE: sample/src/main/res/layout/fragment_scroll.xml ================================================ ================================================ FILE: sample/src/main/res/layout/fragment_webview.xml ================================================ ================================================ FILE: sample/src/main/res/layout/header_logo.xml ================================================ ================================================ FILE: sample/src/main/res/layout/header_logo_2.xml ================================================ ================================================ FILE: sample/src/main/res/layout/header_logo_full.xml ================================================ ================================================ FILE: sample/src/main/res/layout/header_logo_text.xml ================================================ ================================================ FILE: sample/src/main/res/layout/list_item_card_big.xml ================================================ ================================================ FILE: sample/src/main/res/layout/list_item_card_small.xml ================================================ ================================================ FILE: sample/src/main/res/menu/menu_main.xml ================================================ ================================================ FILE: sample/src/main/res/values/colors.xml ================================================ #303F9F @color/blue @color/blue @color/blue @color/blue @android:color/black @android:color/white ================================================ FILE: sample/src/main/res/values/dimens.xml ================================================ 10dp 8dp ================================================ FILE: sample/src/main/res/values/strings.xml ================================================ Material View Pager Hello world! Settings ================================================ FILE: sample/src/main/res/values/styles.xml ================================================ ================================================ FILE: sample/src/main/res/values-w820dp/dimens.xml ================================================ 64dp ================================================ FILE: settings.gradle ================================================ include ':materialviewpager', ':sample'