├── sample ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-xhdpi │ │ │ │ └── bg_image.png │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── drawable-v21 │ │ │ │ ├── white.xml │ │ │ │ └── selectable.xml │ │ │ ├── drawable │ │ │ │ ├── selectable.xml │ │ │ │ └── white.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── menu │ │ │ │ └── menu_main.xml │ │ │ └── layout │ │ │ │ ├── text_binder.xml │ │ │ │ ├── tab_viewpager_fragment.xml │ │ │ │ ├── main_activity.xml │ │ │ │ ├── image_fab_activity.xml │ │ │ │ └── tab_viewpager_activity.xml │ │ ├── java │ │ │ └── jp │ │ │ │ └── satorufujiwara │ │ │ │ └── scrolling │ │ │ │ └── sample │ │ │ │ ├── SampleViewType.java │ │ │ │ ├── Constants.java │ │ │ │ ├── behavior │ │ │ │ ├── TitleBehavior.java │ │ │ │ ├── OverlayViewBehavior.java │ │ │ │ └── FabBehavior.java │ │ │ │ ├── util │ │ │ │ ├── FragmentPagerItem.java │ │ │ │ └── FragmentPagerItemAdapter.java │ │ │ │ ├── TextBinder.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── TabViewPagerFragment.java │ │ │ │ ├── TabViewPagerActivity.java │ │ │ │ └── ImageFabActivity.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── jp │ │ └── hollywist │ │ └── binder │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── library ├── .gitignore ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── res │ │ │ └── values │ │ │ │ └── attrs.xml │ │ └── java │ │ │ └── jp │ │ │ └── satorufujiwara │ │ │ └── scrolling │ │ │ ├── behavior │ │ │ ├── ParallaxBehavior.java │ │ │ ├── ScrollBehavior.java │ │ │ ├── ScrollFadingBehavior.java │ │ │ ├── ScrollUntilBehavior.java │ │ │ └── ExitUntilCollapsedBehavior.java │ │ │ ├── Behavior.java │ │ │ ├── Utils.java │ │ │ ├── BehaviorDispatcher.java │ │ │ ├── MaterialScrollingLayout.java │ │ │ ├── RecyclerViewHolder.java │ │ │ └── MaterialScrollingViewPager.java │ └── androidTest │ │ └── java │ │ └── jp │ │ └── satorufujiwara │ │ └── scrolling │ │ └── ApplicationTest.java ├── proguard-rules.pro ├── android-artifacts.gradle ├── build.gradle └── bintray-publish.gradle ├── settings.gradle ├── arts ├── imagefab.gif ├── viewpager.gif └── viewpager_land.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':library', ':sample' 2 | -------------------------------------------------------------------------------- /arts/imagefab.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/material-scrolling/HEAD/arts/imagefab.gif -------------------------------------------------------------------------------- /arts/viewpager.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/material-scrolling/HEAD/arts/viewpager.gif -------------------------------------------------------------------------------- /arts/viewpager_land.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/material-scrolling/HEAD/arts/viewpager_land.gif -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/material-scrolling/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/bg_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/material-scrolling/HEAD/sample/src/main/res/drawable-xhdpi/bg_image.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/material-scrolling/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/material-scrolling/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/material-scrolling/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/material-scrolling/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #fff 4 | #1e000000 5 | #27000000 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v21/white.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/selectable.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/SampleViewType.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample; 2 | 3 | import jp.satorufujiwara.binder.ViewType; 4 | 5 | public enum SampleViewType implements ViewType { 6 | TEXT; 7 | 8 | @Override 9 | public int viewType() { 10 | return ordinal(); 11 | } 12 | } -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v21/selectable.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Thumbs.db 3 | 4 | # gradle files 5 | .gradle 6 | 7 | # Intellij project files 8 | .idea 9 | *.iml 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | obj/ 15 | apk/ 16 | target/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 156dp 7 | 156dp 8 | 9 | -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/jp/hollywist/binder/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package jp.hollywist.binder; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | 11 | public ApplicationTest() { 12 | super(Application.class); 13 | } 14 | } -------------------------------------------------------------------------------- /library/src/androidTest/java/jp/satorufujiwara/scrolling/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | 11 | public ApplicationTest() { 12 | super(Application.class); 13 | } 14 | } -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/text_binder.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/tab_viewpager_fragment.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Scrolling Sample 3 | 4 | Hello world! 5 | 6 | Search 7 | Settings 8 | 9 | 10 | 11 | NEXUS 12 | XPERIA 13 | GALAXY 14 | AQUOS 15 | MOTO 16 | 17 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/Constants.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample; 2 | 3 | 4 | public class Constants { 5 | 6 | public static String[] ANDROID_VERSIONS = new String[]{ 7 | "Marshmallow", 8 | "Lollipop", 9 | "KitKat", 10 | "Jelly Bean", 11 | "Ice Cream Sandwich", 12 | "Honeycomb", 13 | "Gingerbread", 14 | "Froyo", 15 | "Eclair", 16 | "Donut", 17 | "Cupcake", 18 | "Banana Bread", 19 | "Apple Pie" 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/white.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/behavior/ParallaxBehavior.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.behavior; 2 | 3 | import android.support.v4.view.ViewCompat; 4 | import android.view.View; 5 | 6 | public class ParallaxBehavior extends ScrollBehavior { 7 | 8 | private final float parallaxRate; 9 | 10 | public ParallaxBehavior() { 11 | this(1.5f); 12 | } 13 | 14 | public ParallaxBehavior(final float parallaxRate) { 15 | this.parallaxRate = parallaxRate; 16 | } 17 | 18 | @Override 19 | protected void computeTranslation(final View target, final int scrollY, final int y) { 20 | ViewCompat.setTranslationY(target, -scrollY / parallaxRate); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /adt-bundle-mac/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /adt-bundle-mac/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/behavior/ScrollBehavior.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.behavior; 2 | 3 | import android.support.v4.view.ViewCompat; 4 | import android.view.View; 5 | 6 | import jp.satorufujiwara.scrolling.Behavior; 7 | 8 | public class ScrollBehavior extends Behavior { 9 | 10 | public ScrollBehavior() { 11 | } 12 | 13 | @Override 14 | protected void onScrolled(final View target, final int scrollY, final int dy) { 15 | computeTranslation(target, scrollY, dy); 16 | } 17 | 18 | protected void computeTranslation(final View target, final int scrollY, final int dy) { 19 | ViewCompat.setTranslationY(target, -Math.min(scrollY, getFlexibleHeight())); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /library/android-artifacts.gradle: -------------------------------------------------------------------------------- 1 | task androidJavadocs(type: Javadoc) { 2 | source = android.sourceSets.main.java.srcDirs 3 | ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar" 4 | classpath += files(ext.androidJar) 5 | } 6 | 7 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 8 | classifier = 'javadoc' 9 | from androidJavadocs.destinationDir 10 | } 11 | 12 | task androidSourcesJar(type: Jar) { 13 | classifier = 'sources' 14 | from android.sourceSets.main.java.sourceFiles 15 | } 16 | 17 | task androidJar(type: Jar) { 18 | from 'build/intermediates/classes/release' 19 | } 20 | 21 | artifacts { 22 | archives androidSourcesJar 23 | archives androidJavadocsJar 24 | archives androidJar 25 | } -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/behavior/TitleBehavior.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample.behavior; 2 | 3 | import android.content.res.Resources; 4 | import android.support.v4.view.ViewCompat; 5 | import android.view.View; 6 | 7 | import jp.satorufujiwara.scrolling.Behavior; 8 | import jp.satorufujiwara.scrolling.sample.R; 9 | 10 | public class TitleBehavior extends Behavior { 11 | 12 | private final int scrollLimitHeight; 13 | 14 | public TitleBehavior(Resources r) { 15 | scrollLimitHeight = r.getDimensionPixelOffset(R.dimen.title_scroll_height); 16 | } 17 | 18 | @Override 19 | protected void onScrolled(View target, int scrollY, int dy) { 20 | ViewCompat.setTranslationY(target, -Math.min(scrollY, scrollLimitHeight)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/Behavior.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling; 2 | 3 | import android.view.View; 4 | 5 | import com.github.ksoichiro.android.observablescrollview.ScrollState; 6 | 7 | public abstract class Behavior { 8 | 9 | private int flexibleHeight; 10 | 11 | void setFlexibleHeight(final int flexibleHeight) { 12 | this.flexibleHeight = flexibleHeight; 13 | } 14 | 15 | protected void onAttached(final View target) { 16 | 17 | } 18 | 19 | protected int getFlexibleHeight() { 20 | return flexibleHeight; 21 | } 22 | 23 | protected void onScrolled(final View target, final int scrollY, final int dy) { 24 | 25 | } 26 | 27 | protected void onDownMotionEvent() { 28 | 29 | } 30 | 31 | protected void onUpOrCancelMotionEvent(final ScrollState scrollState) { 32 | 33 | } 34 | 35 | protected void onGlobalLayout(final View target) { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/behavior/ScrollFadingBehavior.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.behavior; 2 | 3 | import android.view.View; 4 | 5 | import jp.satorufujiwara.scrolling.Behavior; 6 | 7 | public class ScrollFadingBehavior extends Behavior { 8 | 9 | private int targetTop = 0; 10 | 11 | @Override 12 | protected void onScrolled(final View target, final int scrollY, final int dy) { 13 | computeTranslation(target, scrollY, dy); 14 | } 15 | 16 | @Override 17 | protected void onGlobalLayout(final View target) { 18 | targetTop = target.getTop(); 19 | } 20 | 21 | 22 | protected void computeTranslation(final View target, final int scrollY, final int y) { 23 | target.setTranslationY(-Math.min(scrollY, getFlexibleHeight())); 24 | if (targetTop != 0) { 25 | target.setAlpha(Math.max(0.0f, Math.min(1.0f, 1.0f - (float) y / (float) targetTop))); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | COMPILE_SDK_VERSION=23 2 | BUILD_TOOLS_VERSION=23.0.1 3 | MIN_SDK_VERSION=9 4 | TARGET_SDK_VERSION=23 5 | 6 | SUPPORT_APP_COMPAT_VERSION=23.2.1 7 | 8 | VERSION_NAME=1.2.1 9 | VERSION_CODE=1 10 | GROUP=jp.satorufujiwara 11 | ARTIFACT_ID=material-scrolling 12 | 13 | POM_DESCRIPTION=Android library for material scrolling techniques. 14 | POM_URL=https://github.com/satorufujiwara/material-scrolling 15 | POM_SCM_URL=git@github.com:satorufujiwara/material-scrolling.git 16 | POM_SCM_CONNECTION=scm:git@github.com:satorufujiwara/material-scrolling.git 17 | POM_SCM_DEV_CONNECTION=scm:git@github.com:satorufujiwara/material-scrolling.git 18 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 19 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 20 | POM_LICENCE_DIST=repo 21 | POM_DEVELOPER_ID=satorufujiwara 22 | POM_DEVELOPER_NAME=satorufujiwara 23 | POM_DEVELOPER_EMAIL=holly.wist@gmail.com 24 | ISSUE_URL=https://github.com/satorufujiwara/material-scrolling/issues 25 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/main_activity.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 16 | 17 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/Utils.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | import com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView; 7 | 8 | final class Utils { 9 | 10 | private Utils() { 11 | 12 | } 13 | 14 | static ObservableRecyclerView findRecyclerView(final View view) { 15 | if (view instanceof ObservableRecyclerView) { 16 | return (ObservableRecyclerView) view; 17 | } 18 | if (!(view instanceof ViewGroup)) { 19 | return null; 20 | } 21 | ViewGroup group = (ViewGroup) view; 22 | int count = group.getChildCount(); 23 | for (int i = 0; i < count; i++) { 24 | ObservableRecyclerView child = findRecyclerView(group.getChildAt(i)); 25 | if (child != null) { 26 | return child; 27 | } 28 | } 29 | return null; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/behavior/ScrollUntilBehavior.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.behavior; 2 | 3 | import android.support.v4.view.ViewCompat; 4 | import android.view.View; 5 | 6 | import jp.satorufujiwara.scrolling.Behavior; 7 | 8 | public class ScrollUntilBehavior extends Behavior { 9 | 10 | private final int until; 11 | private int targetHeight = 0; 12 | 13 | public ScrollUntilBehavior(final int until) { 14 | this.until = until; 15 | } 16 | 17 | @Override 18 | protected void onGlobalLayout(final View target) { 19 | targetHeight = target.getHeight(); 20 | } 21 | 22 | @Override 23 | protected void onScrolled(final View target, final int scrollY, final int dy) { 24 | computeTranslation(target, scrollY, dy); 25 | } 26 | 27 | protected void computeTranslation(final View target, final int scrollY, final int dy) { 28 | ViewCompat.setTranslationY(target, -Math.min(scrollY, getFlexibleHeight() - targetHeight - until)); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/behavior/OverlayViewBehavior.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample.behavior; 2 | 3 | import android.graphics.Color; 4 | import android.support.v4.view.ViewCompat; 5 | import android.view.View; 6 | 7 | import jp.satorufujiwara.scrolling.Behavior; 8 | 9 | public class OverlayViewBehavior extends Behavior { 10 | 11 | private final int until; 12 | 13 | public OverlayViewBehavior(final int until) { 14 | this.until = until; 15 | } 16 | 17 | @Override 18 | protected void onScrolled(View target, int scrollY, int dy) { 19 | final int movingHeight = getFlexibleHeight() - until; 20 | ViewCompat.setTranslationY(target, -Math.min(scrollY, movingHeight)); 21 | if (scrollY >= movingHeight) { 22 | target.setBackgroundColor(Color.rgb(33, 33, 33)); 23 | } else { 24 | final int alpha = 255 * scrollY / movingHeight; 25 | target.setBackgroundColor(Color.argb(alpha, 33, 33, 33)); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/behavior/ExitUntilCollapsedBehavior.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.behavior; 2 | 3 | import android.view.View; 4 | 5 | import jp.satorufujiwara.scrolling.Behavior; 6 | 7 | public class ExitUntilCollapsedBehavior extends Behavior { 8 | 9 | private final int pushUpOffset; 10 | private int targetHeight = 0; 11 | 12 | public ExitUntilCollapsedBehavior() { 13 | this(0); 14 | } 15 | 16 | public ExitUntilCollapsedBehavior(final int pushUpHeight) { 17 | pushUpOffset = pushUpHeight; 18 | } 19 | 20 | @Override 21 | protected void onGlobalLayout(final View target) { 22 | targetHeight = target.getHeight(); 23 | } 24 | 25 | @Override 26 | protected void onScrolled(final View target, final int scrollY, final int dy) { 27 | computeTranslation(target, scrollY); 28 | } 29 | 30 | protected void computeTranslation(final View target, final int y) { 31 | final int h = getFlexibleHeight() - targetHeight - pushUpOffset; 32 | if (y < h) { 33 | target.setTranslationY(0); 34 | return; 35 | } 36 | target.setTranslationY(-y + h); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion COMPILE_SDK_VERSION as int 5 | buildToolsVersion BUILD_TOOLS_VERSION 6 | 7 | defaultConfig { 8 | applicationId "jp.satorufujiwara.scrolling.sample" 9 | minSdkVersion MIN_SDK_VERSION as int 10 | targetSdkVersion TARGET_SDK_VERSION as int 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | compile project(':library') 26 | compile 'com.github.ksoichiro:android-observablescrollview:1.5.2' 27 | 28 | compile "com.android.support:appcompat-v7:$SUPPORT_APP_COMPAT_VERSION" 29 | compile "com.android.support:design:$SUPPORT_APP_COMPAT_VERSION" 30 | compile "com.android.support:recyclerview-v7:$SUPPORT_APP_COMPAT_VERSION" 31 | compile "com.android.support:cardview-v7:$SUPPORT_APP_COMPAT_VERSION" 32 | 33 | compile 'jp.satorufujiwara:recyclerview-binder:1.2.0' 34 | compile 'com.ogaclejapan.smarttablayout:library:1.4.2@aar' 35 | compile 'com.jakewharton:butterknife:6.1.0' 36 | } 37 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 27 | 28 | 29 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/util/FragmentPagerItem.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample.util; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | 7 | public class FragmentPagerItem { 8 | 9 | private final String mTitle; 10 | private final Class mFragmentClass; 11 | private final Bundle mArgs; 12 | 13 | protected FragmentPagerItem(final String title, final Class f, 14 | final Bundle args) { 15 | mTitle = title; 16 | mFragmentClass = f; 17 | mArgs = args; 18 | } 19 | 20 | public static FragmentPagerItem create(final String title, 21 | final Class fragmentClass) { 22 | return create(title, fragmentClass, new Bundle()); 23 | } 24 | 25 | public static FragmentPagerItem create(final String title, 26 | final Class fragmentClass, 27 | final Bundle args) { 28 | return new FragmentPagerItem(title, fragmentClass, args); 29 | } 30 | 31 | public CharSequence getPagerTitle() { 32 | return mTitle; 33 | } 34 | 35 | public Fragment newInstance(final Context context) { 36 | return Fragment.instantiate(context, mFragmentClass.getName(), mArgs); 37 | } 38 | 39 | public Bundle getArgs() { 40 | return mArgs; 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/TextBinder.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample; 2 | 3 | import android.app.Activity; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import jp.satorufujiwara.binder.recycler.RecyclerBinder; 9 | 10 | public class TextBinder extends RecyclerBinder { 11 | 12 | private final String text; 13 | private final View.OnClickListener listener; 14 | 15 | public TextBinder(Activity activity, String text, View.OnClickListener listener) { 16 | super(activity, SampleViewType.TEXT); 17 | this.text = text; 18 | this.listener = listener; 19 | } 20 | 21 | @Override 22 | public int layoutResId() { 23 | return R.layout.text_binder; 24 | } 25 | 26 | @Override 27 | public RecyclerView.ViewHolder onCreateViewHolder(View v) { 28 | return new ViewHolder(v); 29 | } 30 | 31 | @Override 32 | public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { 33 | final ViewHolder holder = (ViewHolder) viewHolder; 34 | holder.textView.setText(text); 35 | holder.textView.setOnClickListener(listener); 36 | } 37 | 38 | static class ViewHolder extends RecyclerView.ViewHolder { 39 | 40 | TextView textView = (TextView) itemView; 41 | 42 | ViewHolder(View view) { 43 | super(view); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/behavior/FabBehavior.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample.behavior; 2 | 3 | import android.content.res.Resources; 4 | import android.support.v4.view.ViewCompat; 5 | import android.view.View; 6 | 7 | import jp.satorufujiwara.scrolling.Behavior; 8 | import jp.satorufujiwara.scrolling.sample.R; 9 | 10 | public class FabBehavior extends Behavior { 11 | 12 | private int targetHeight = 0; 13 | 14 | private final int startScalingHeight; 15 | 16 | public FabBehavior(Resources r) { 17 | startScalingHeight = r.getDimensionPixelOffset(R.dimen.fab_scaling_height); 18 | } 19 | 20 | protected void onGlobalLayout(View target) { 21 | targetHeight = target.getHeight(); 22 | } 23 | 24 | @Override 25 | protected void onScrolled(View target, int scrollY, int dy) { 26 | final int movingHeight = getFlexibleHeight() - targetHeight; 27 | ViewCompat.setTranslationY(target, -Math.min(scrollY, movingHeight)); 28 | if (scrollY >= movingHeight) { 29 | ViewCompat.setScaleX(target, 0.0f); 30 | ViewCompat.setScaleY(target, 0.0f); 31 | } else if (scrollY >= startScalingHeight) { 32 | final float scale = 1.0f - (scrollY - startScalingHeight) * 1.0f / (movingHeight 33 | - startScalingHeight); 34 | ViewCompat.setScaleX(target, scale); 35 | ViewCompat.setScaleY(target, scale); 36 | } else { 37 | ViewCompat.setScaleX(target, 1.0f); 38 | ViewCompat.setScaleY(target, 1.0f); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | repositories { 4 | mavenCentral() 5 | } 6 | 7 | android { 8 | compileSdkVersion COMPILE_SDK_VERSION as int 9 | buildToolsVersion BUILD_TOOLS_VERSION 10 | 11 | defaultConfig { 12 | minSdkVersion MIN_SDK_VERSION as int 13 | targetSdkVersion TARGET_SDK_VERSION as int 14 | versionName project.version 15 | } 16 | lintOptions { 17 | abortOnError false 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | compile fileTree(dir: 'libs', include: ['*.jar']) 30 | compile "com.android.support:appcompat-v7:$SUPPORT_APP_COMPAT_VERSION" 31 | compile "com.android.support:recyclerview-v7:$SUPPORT_APP_COMPAT_VERSION" 32 | compile 'com.github.ksoichiro:android-observablescrollview:1.6.0' 33 | 34 | } 35 | 36 | android.libraryVariants.all { variant -> 37 | if (variant.buildType.isDebuggable()) { 38 | return; // Skip debug builds. 39 | } 40 | task("javadoc${variant.name.capitalize()}", type: Javadoc) { 41 | description "Generates Javadoc for $variant.name." 42 | source = variant.javaCompile.source 43 | ext.androidJar = System.getenv("ANDROID_HOME") + 44 | "/platforms/${android.compileSdkVersion}/android.jar" 45 | classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) 46 | } 47 | 48 | task("bundleJavadoc${variant.name.capitalize()}", type: Jar) { 49 | description "Bundles Javadoc into zip for $variant.name." 50 | classifier = "javadoc" 51 | from tasks["javadoc${variant.name.capitalize()}"] 52 | } 53 | } 54 | 55 | apply from: 'android-artifacts.gradle' 56 | apply from: 'bintray-publish.gradle' 57 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.support.v7.widget.Toolbar; 8 | import android.view.View; 9 | 10 | import butterknife.ButterKnife; 11 | import butterknife.InjectView; 12 | import jp.satorufujiwara.binder.Section; 13 | import jp.satorufujiwara.binder.recycler.RecyclerBinderAdapter; 14 | 15 | 16 | public class MainActivity extends AppCompatActivity { 17 | 18 | @InjectView(R.id.recyclerView) 19 | RecyclerView recyclerView; 20 | @InjectView(R.id.toolBar) 21 | Toolbar toolBar; 22 | 23 | RecyclerBinderAdapter adapter = new RecyclerBinderAdapter<>(); 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.main_activity); 29 | ButterKnife.inject(this); 30 | setSupportActionBar(toolBar); 31 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 32 | recyclerView.setAdapter(adapter); 33 | 34 | adapter.add(MainSection.CONTENTS, new TextBinder(this, 35 | "Tab + ViewPager", new View.OnClickListener() { 36 | @Override 37 | public void onClick(View v) { 38 | startActivity(TabViewPagerActivity.newIntent(MainActivity.this)); 39 | } 40 | })); 41 | 42 | adapter.add(MainSection.CONTENTS, new TextBinder(this, 43 | "Image + FAB", new View.OnClickListener() { 44 | @Override 45 | public void onClick(View v) { 46 | startActivity(ImageFabActivity.newIntent(MainActivity.this)); 47 | } 48 | })); 49 | 50 | } 51 | 52 | enum MainSection implements Section { 53 | CONTENTS 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /library/bintray-publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'com.jfrog.bintray' 3 | 4 | publishing { 5 | publications { 6 | mavenJava(MavenPublication) { 7 | groupId GROUP 8 | version VERSION_NAME 9 | artifactId ARTIFACT_ID 10 | artifact "build/outputs/aar/library-release.aar" 11 | // artifact androidJar 12 | artifact androidJavadocsJar 13 | artifact androidSourcesJar 14 | pom.withXml { 15 | Node root = asNode() 16 | root.appendNode('name', ARTIFACT_ID) 17 | root.appendNode('description', POM_DESCRIPTION) 18 | root.appendNode('url', POM_URL) 19 | 20 | def issues = root.appendNode('issueManagement') 21 | issues.appendNode('system', 'github') 22 | issues.appendNode('url', ISSUE_URL) 23 | 24 | def scm = root.appendNode('scm') 25 | scm.appendNode('url', POM_SCM_URL) 26 | scm.appendNode('connection', POM_SCM_CONNECTION) 27 | scm.appendNode('developerConnection', POM_SCM_DEV_CONNECTION) 28 | 29 | def license = root.appendNode('licenses').appendNode('license') 30 | license.appendNode('name', POM_LICENCE_NAME) 31 | license.appendNode('url', POM_LICENCE_URL) 32 | license.appendNode('distribution', POM_LICENCE_DIST) 33 | } 34 | } 35 | } 36 | } 37 | 38 | def getBintrayUserProperty() { 39 | return hasProperty('bintrayUser') ? bintrayUser : "" 40 | } 41 | 42 | def getBintrayApiKeyProperty() { 43 | return hasProperty('bintrayApiKey') ? bintrayApiKey : "" 44 | } 45 | 46 | bintray { 47 | user = bintrayUserProperty 48 | key = bintrayApiKeyProperty 49 | publications = ['mavenJava'] 50 | 51 | dryRun = false 52 | publish = false 53 | pkg { 54 | repo = 'maven' 55 | name = ARTIFACT_ID 56 | licenses = ['Apache-2.0'] 57 | labels = ['android'] 58 | 59 | version { 60 | name = VERSION_NAME 61 | vcsTag = VERSION_NAME 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/TabViewPagerFragment.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import jp.satorufujiwara.binder.Section; 16 | import jp.satorufujiwara.binder.recycler.RecyclerBinderAdapter; 17 | 18 | public class TabViewPagerFragment extends Fragment { 19 | 20 | public static TabViewPagerFragment newInstance() { 21 | return new TabViewPagerFragment(); 22 | } 23 | 24 | @InjectView(R.id.recyclerView) 25 | RecyclerView recyclerView; 26 | 27 | private final RecyclerBinderAdapter adapter 28 | = new RecyclerBinderAdapter<>(); 29 | 30 | @Override 31 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 32 | @Nullable Bundle savedInstanceState) { 33 | final View v = inflater.inflate(R.layout.tab_viewpager_fragment, container, false); 34 | ButterKnife.inject(this, v); 35 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); 36 | recyclerView.setAdapter(adapter); 37 | return v; 38 | } 39 | 40 | @Override 41 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 42 | super.onViewCreated(view, savedInstanceState); 43 | final Activity activity = getActivity(); 44 | for (String name : Constants.ANDROID_VERSIONS) { 45 | adapter.add(TabViewPagerSection.CONTENTS, 46 | new TextBinder(activity, name, new View.OnClickListener() { 47 | @Override 48 | public void onClick(View v) { 49 | 50 | } 51 | })); 52 | } 53 | } 54 | 55 | enum TabViewPagerSection implements Section { 56 | CONTENTS 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/image_fab_activity.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 17 | 18 | 23 | 28 | 29 | 39 | 40 | 48 | 49 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/BehaviorDispatcher.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling; 2 | 3 | 4 | import com.github.ksoichiro.android.observablescrollview.ScrollState; 5 | 6 | import android.os.Build; 7 | import android.support.v4.util.ArrayMap; 8 | import android.view.View; 9 | import android.view.ViewTreeObserver; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public class BehaviorDispatcher { 15 | 16 | private final List targets = new ArrayList<>(); 17 | private final ArrayMap behaviors = new ArrayMap<>(); 18 | private int flexibleHeight; 19 | 20 | public BehaviorDispatcher() { 21 | } 22 | 23 | public void setFlexibleHeight(final int flexibleHeight) { 24 | this.flexibleHeight = flexibleHeight; 25 | for (Behavior behavior : behaviors.values()) { 26 | behavior.setFlexibleHeight(flexibleHeight); 27 | } 28 | } 29 | 30 | private final ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener 31 | = new ViewTreeObserver.OnGlobalLayoutListener() { 32 | @Override 33 | public void onGlobalLayout() { 34 | for (View target : targets) { 35 | behaviors.get(target).onGlobalLayout(target); 36 | } 37 | } 38 | }; 39 | 40 | public void onAttachedToWindow(final View view) { 41 | view.getViewTreeObserver().addOnGlobalLayoutListener(globalLayoutListener); 42 | } 43 | 44 | public void onDetachedFromWindow(final View view) { 45 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 46 | view.getViewTreeObserver().removeGlobalOnLayoutListener(globalLayoutListener); 47 | } else { 48 | view.getViewTreeObserver().removeOnGlobalLayoutListener(globalLayoutListener); 49 | } 50 | } 51 | 52 | public void addBehavior(final View target, final Behavior behavior) { 53 | targets.add(target); 54 | behavior.setFlexibleHeight(flexibleHeight); 55 | behaviors.put(target, behavior); 56 | behavior.onAttached(target); 57 | } 58 | 59 | void onScrolled(int scrollY, int dy) { 60 | for (View target : targets) { 61 | behaviors.get(target).onScrolled(target, scrollY, dy); 62 | } 63 | } 64 | 65 | void onDownMotionEvent() { 66 | for (View target : targets) { 67 | behaviors.get(target).onDownMotionEvent(); 68 | } 69 | } 70 | 71 | void onUpOrCancelMotionEvent(ScrollState scrollState) { 72 | for (View target : targets) { 73 | behaviors.get(target).onUpOrCancelMotionEvent(scrollState); 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/tab_viewpager_activity.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 17 | 18 | 25 | 26 | 30 | 31 | 56 | 57 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/TabViewPagerActivity.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample; 2 | 3 | import com.ogaclejapan.smarttablayout.SmartTabLayout; 4 | 5 | import android.app.Activity; 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.support.v7.app.ActionBar; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.support.v7.widget.Toolbar; 11 | import android.view.View; 12 | import android.widget.ImageView; 13 | 14 | import butterknife.ButterKnife; 15 | import butterknife.InjectView; 16 | import jp.satorufujiwara.scrolling.MaterialScrollingViewPager; 17 | import jp.satorufujiwara.scrolling.behavior.ExitUntilCollapsedBehavior; 18 | import jp.satorufujiwara.scrolling.behavior.ParallaxBehavior; 19 | import jp.satorufujiwara.scrolling.behavior.ScrollUntilBehavior; 20 | import jp.satorufujiwara.scrolling.sample.behavior.OverlayViewBehavior; 21 | import jp.satorufujiwara.scrolling.sample.util.FragmentPagerItemAdapter; 22 | 23 | public class TabViewPagerActivity extends AppCompatActivity { 24 | 25 | @InjectView(R.id.toolBar) 26 | Toolbar toolBar; 27 | 28 | @InjectView(R.id.bgImage) 29 | ImageView bgImage; 30 | 31 | @InjectView(R.id.tabLayout) 32 | SmartTabLayout tabLayout; 33 | 34 | @InjectView(R.id.overlayView) 35 | View overlayView; 36 | 37 | @InjectView(R.id.viewpager) 38 | MaterialScrollingViewPager viewPager; 39 | 40 | public static Intent newIntent(Activity activity) { 41 | return new Intent(activity, TabViewPagerActivity.class); 42 | } 43 | 44 | @Override 45 | protected void onCreate(Bundle savedInstanceState) { 46 | super.onCreate(savedInstanceState); 47 | setContentView(R.layout.tab_viewpager_activity); 48 | ButterKnife.inject(this); 49 | setTitle(""); 50 | setSupportActionBar(toolBar); 51 | final ActionBar ab = getSupportActionBar(); 52 | ab.setDisplayHomeAsUpEnabled(true); 53 | FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter.Builder(this) 54 | .add(R.string.tab1, TabViewPagerFragment.class) 55 | .add(R.string.tab2, TabViewPagerFragment.class) 56 | .add(R.string.tab3, TabViewPagerFragment.class) 57 | .add(R.string.tab4, TabViewPagerFragment.class) 58 | .add(R.string.tab5, TabViewPagerFragment.class) 59 | .build(); 60 | viewPager.setAdapter(adapter); 61 | tabLayout.setViewPager(viewPager); 62 | viewPager.addBehavior(bgImage, new ParallaxBehavior()); 63 | viewPager.addBehavior(tabLayout, new ScrollUntilBehavior(0)); 64 | viewPager.addBehavior(overlayView, new OverlayViewBehavior(dp(48))); 65 | viewPager.addBehavior(toolBar, new ExitUntilCollapsedBehavior(dp(48))); 66 | } 67 | 68 | public int dp(final int dp) { 69 | return (int) (dp * getResources().getDisplayMetrics().density); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/MaterialScrollingLayout.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling; 2 | 3 | import com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView; 4 | 5 | import android.content.Context; 6 | import android.content.res.TypedArray; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.FrameLayout; 11 | 12 | public class MaterialScrollingLayout extends FrameLayout { 13 | 14 | private int flexibleHeight; 15 | private final BehaviorDispatcher behaviorDispatcher = new BehaviorDispatcher(); 16 | private RecyclerViewHolder recyclerViewHolder; 17 | 18 | public MaterialScrollingLayout(final Context context) { 19 | this(context, null, 0); 20 | } 21 | 22 | public MaterialScrollingLayout(final Context context, final AttributeSet attrs) { 23 | this(context, attrs, 0); 24 | } 25 | 26 | public MaterialScrollingLayout(final Context context, final AttributeSet attrs, 27 | final int defStyleAttr) { 28 | super(context, attrs, defStyleAttr); 29 | int flexibleHeight = 0; 30 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ms_MaterialScrolling); 31 | flexibleHeight = a.getDimensionPixelSize( 32 | R.styleable.ms_MaterialScrolling_ms_flexible_height, flexibleHeight); 33 | a.recycle(); 34 | this.flexibleHeight = flexibleHeight; 35 | behaviorDispatcher.setFlexibleHeight(flexibleHeight); 36 | } 37 | 38 | @Override 39 | protected void onAttachedToWindow() { 40 | super.onAttachedToWindow(); 41 | behaviorDispatcher.onAttachedToWindow(this); 42 | } 43 | 44 | @Override 45 | protected void onDetachedFromWindow() { 46 | behaviorDispatcher.onDetachedFromWindow(this); 47 | super.onDetachedFromWindow(); 48 | } 49 | 50 | @Override 51 | public void addView(final View child, final int index, final ViewGroup.LayoutParams params) { 52 | super.addView(child, index, params); 53 | ObservableRecyclerView recyclerView = Utils.findRecyclerView(child); 54 | if (recyclerView == null) { 55 | return; 56 | } 57 | recyclerViewHolder = new RecyclerViewHolder(recyclerView, behaviorDispatcher); 58 | recyclerViewHolder.setFlexibleHeight(flexibleHeight); 59 | recyclerViewHolder.setIsDispatchScroll(true); 60 | } 61 | 62 | @Override 63 | public void removeView(final View view) { 64 | recyclerViewHolder.setIsDispatchScroll(false); 65 | recyclerViewHolder = null; 66 | super.removeView(view); 67 | } 68 | 69 | public void addBehavior(final View target, final Behavior behavior) { 70 | behaviorDispatcher.addBehavior(target, behavior); 71 | } 72 | 73 | public void setFlexibleHeight(final int flexibleHeight) { 74 | this.flexibleHeight = flexibleHeight; 75 | behaviorDispatcher.setFlexibleHeight(flexibleHeight); 76 | recyclerViewHolder.setFlexibleHeight(flexibleHeight); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/RecyclerViewHolder.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling; 2 | 3 | 4 | import com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView; 5 | import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks; 6 | import com.github.ksoichiro.android.observablescrollview.ScrollState; 7 | 8 | import android.support.v7.widget.LinearLayoutManager; 9 | 10 | public class RecyclerViewHolder { 11 | 12 | private final ObservableRecyclerView recyclerView; 13 | private final BehaviorDispatcher behaviorDispatcher; 14 | private int flexibleHeight; 15 | private boolean isDispatchScroll = true; 16 | private boolean isDirty = true; 17 | private int preScrollY = 0; 18 | private int scrollY = 0; 19 | 20 | public RecyclerViewHolder(final ObservableRecyclerView recyclerView, 21 | final BehaviorDispatcher behaviorDispatcher) { 22 | this.recyclerView = recyclerView; 23 | this.recyclerView.setClipToPadding(false); 24 | this.behaviorDispatcher = behaviorDispatcher; 25 | recyclerView.setScrollViewCallbacks(new OnScrollDelegate(this)); 26 | } 27 | 28 | public void setFlexibleHeight(final int flexibleHeight) { 29 | this.flexibleHeight = flexibleHeight; 30 | recyclerView.setPadding(0, flexibleHeight, 0, 0); 31 | } 32 | 33 | public void setIsDispatchScroll(final boolean enable) { 34 | isDispatchScroll = enable; 35 | } 36 | 37 | public int getScrollY() { 38 | return isDirty ? scrollY : recyclerView.getCurrentScrollY() + flexibleHeight; 39 | } 40 | 41 | public void scrollTo(final int y) { 42 | isDirty = true; 43 | scrollY = y; 44 | final LinearLayoutManager lm = ((LinearLayoutManager) recyclerView.getLayoutManager()); 45 | lm.scrollToPositionWithOffset(0, -y); 46 | } 47 | 48 | void onScrolled(final int y) { 49 | isDirty = false; 50 | if (!isDispatchScroll) { 51 | return; 52 | } 53 | scrollY = y + flexibleHeight; 54 | behaviorDispatcher.onScrolled(scrollY, scrollY - preScrollY); 55 | preScrollY = scrollY; 56 | } 57 | 58 | void onDownMotionEvent() { 59 | if (!isDispatchScroll) { 60 | return; 61 | } 62 | behaviorDispatcher.onDownMotionEvent(); 63 | } 64 | 65 | void onUpOrCancelMotionEvent(final ScrollState scrollState) { 66 | if (!isDispatchScroll) { 67 | return; 68 | } 69 | behaviorDispatcher.onUpOrCancelMotionEvent(scrollState); 70 | } 71 | 72 | static class OnScrollDelegate implements ObservableScrollViewCallbacks { 73 | 74 | private final RecyclerViewHolder delegate; 75 | 76 | private OnScrollDelegate(final RecyclerViewHolder delegate) { 77 | this.delegate = delegate; 78 | } 79 | 80 | @Override 81 | public void onScrollChanged(final int scrollY, final boolean b, final boolean b1) { 82 | delegate.onScrolled(scrollY); 83 | } 84 | 85 | @Override 86 | public void onDownMotionEvent() { 87 | delegate.onDownMotionEvent(); 88 | } 89 | 90 | @Override 91 | public void onUpOrCancelMotionEvent(final ScrollState scrollState) { 92 | delegate.onUpOrCancelMotionEvent(scrollState); 93 | } 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/ImageFabActivity.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.design.widget.FloatingActionButton; 7 | import android.support.v7.app.ActionBar; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.support.v7.widget.Toolbar; 12 | import android.view.View; 13 | import android.widget.ImageView; 14 | import android.widget.TextView; 15 | 16 | import butterknife.ButterKnife; 17 | import butterknife.InjectView; 18 | import jp.satorufujiwara.binder.Section; 19 | import jp.satorufujiwara.binder.recycler.RecyclerBinderAdapter; 20 | import jp.satorufujiwara.scrolling.MaterialScrollingLayout; 21 | import jp.satorufujiwara.scrolling.behavior.ParallaxBehavior; 22 | import jp.satorufujiwara.scrolling.sample.behavior.FabBehavior; 23 | import jp.satorufujiwara.scrolling.sample.behavior.OverlayViewBehavior; 24 | import jp.satorufujiwara.scrolling.sample.behavior.TitleBehavior; 25 | 26 | public class ImageFabActivity extends AppCompatActivity { 27 | 28 | private static final String TAG = "MaterialScrollingLayout"; 29 | 30 | @InjectView(R.id.toolBar) 31 | Toolbar toolBar; 32 | 33 | @InjectView(R.id.bgImage) 34 | ImageView bgImage; 35 | 36 | @InjectView(R.id.overlayView) 37 | View overlayView; 38 | 39 | @InjectView(R.id.titleText) 40 | TextView titleText; 41 | 42 | @InjectView(R.id.fab) 43 | FloatingActionButton fab; 44 | 45 | @InjectView(R.id.recyclerView) 46 | RecyclerView recyclerView; 47 | 48 | @InjectView(R.id.materialScrollingLayout) 49 | MaterialScrollingLayout scrollingLayout; 50 | 51 | private final RecyclerBinderAdapter adapter 52 | = new RecyclerBinderAdapter<>(); 53 | 54 | public static Intent newIntent(Activity activity) { 55 | return new Intent(activity, ImageFabActivity.class); 56 | } 57 | 58 | @Override 59 | protected void onCreate(Bundle savedInstanceState) { 60 | super.onCreate(savedInstanceState); 61 | setContentView(R.layout.image_fab_activity); 62 | ButterKnife.inject(this); 63 | setTitle(""); 64 | setSupportActionBar(toolBar); 65 | final ActionBar ab = getSupportActionBar(); 66 | ab.setDisplayHomeAsUpEnabled(true); 67 | 68 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 69 | recyclerView.setAdapter(adapter); 70 | titleText.setText("New York"); 71 | 72 | scrollingLayout.addBehavior(bgImage, new ParallaxBehavior()); 73 | scrollingLayout.addBehavior(overlayView, new OverlayViewBehavior(dp(56))); 74 | scrollingLayout.addBehavior(titleText, new TitleBehavior(getResources())); 75 | scrollingLayout.addBehavior(fab, new FabBehavior(getResources())); 76 | 77 | for (String name : Constants.ANDROID_VERSIONS) { 78 | adapter.add(ImageFabSection.CONTENTS, 79 | new TextBinder(this, name, new View.OnClickListener() { 80 | @Override 81 | public void onClick(View v) { 82 | 83 | } 84 | })); 85 | } 86 | 87 | } 88 | 89 | 90 | enum ImageFabSection implements Section { 91 | CONTENTS 92 | } 93 | 94 | public int dp(final int dp) { 95 | return (int) (dp * getResources().getDisplayMetrics().density); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /sample/src/main/java/jp/satorufujiwara/scrolling/sample/util/FragmentPagerItemAdapter.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling.sample.util; 2 | 3 | import com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView; 4 | 5 | import android.content.Context; 6 | import android.os.Bundle; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v4.app.FragmentActivity; 9 | import android.support.v4.app.FragmentManager; 10 | import android.support.v4.app.FragmentPagerAdapter; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | 14 | import java.util.ArrayList; 15 | import java.util.HashMap; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | import jp.satorufujiwara.scrolling.MaterialScrollingViewPager; 20 | import jp.satorufujiwara.scrolling.sample.R; 21 | 22 | public class FragmentPagerItemAdapter extends FragmentPagerAdapter implements 23 | MaterialScrollingViewPager.ContainRecyclerViewPagerAdapter { 24 | 25 | @SuppressWarnings("unused") 26 | private static final String TAG = FragmentPagerItemAdapter.class.getSimpleName(); 27 | 28 | private final Context mContext; 29 | private final List mItems; 30 | private final Map mPageReferenceMap; 31 | private OnInstantiateFragmentListener mListener; 32 | 33 | private FragmentPagerItemAdapter(final Context context, final FragmentManager fm, 34 | final List items) { 35 | super(fm); 36 | mContext = context; 37 | mItems = items; 38 | mPageReferenceMap = new HashMap<>(); 39 | } 40 | 41 | @Override 42 | public Object instantiateItem(final ViewGroup container, final int position) { 43 | final Fragment f = (Fragment) super.instantiateItem(container, position); 44 | mPageReferenceMap.put(position, f); 45 | if (mListener != null) { 46 | mListener.onInstantiate(position, f, mItems.get(position).getArgs()); 47 | } 48 | return f; 49 | } 50 | 51 | @Override 52 | public Fragment getItem(final int position) { 53 | return mItems.get(position).newInstance(mContext); 54 | } 55 | 56 | @Override 57 | public void destroyItem(final ViewGroup container, final int position, final Object object) { 58 | super.destroyItem(container, position, object); 59 | mPageReferenceMap.remove(position); 60 | } 61 | 62 | @Override 63 | public int getCount() { 64 | return mItems.size(); 65 | } 66 | 67 | public Fragment getFragment(final int position) { 68 | return mPageReferenceMap.get(position); 69 | } 70 | 71 | @Override 72 | public CharSequence getPageTitle(final int position) { 73 | return mItems.get(position).getPagerTitle(); 74 | } 75 | 76 | @Override 77 | public ObservableRecyclerView getRecyclerView(int position) { 78 | final Fragment f = getFragment(position); 79 | if (f == null) { 80 | return null; 81 | } 82 | final View v = f.getView(); 83 | return v == null ? null : (ObservableRecyclerView) v.findViewById(R.id.recyclerView); 84 | } 85 | 86 | public void setOnInstantiateFragmentListener(final OnInstantiateFragmentListener l) { 87 | mListener = l; 88 | } 89 | 90 | public interface OnInstantiateFragmentListener { 91 | 92 | void onInstantiate(final int position, final Fragment fragment, final Bundle args); 93 | 94 | } 95 | 96 | public static class Builder { 97 | 98 | private final FragmentActivity mActivity; 99 | private final List mItems; 100 | 101 | public Builder(final FragmentActivity activity) { 102 | mActivity = activity; 103 | mItems = new ArrayList<>(); 104 | } 105 | 106 | public Builder add(final FragmentPagerItem item) { 107 | mItems.add(item); 108 | return this; 109 | } 110 | 111 | public Builder add(final int titleResId, final Class clazz) { 112 | return add(FragmentPagerItem.create(mActivity.getString(titleResId), clazz)); 113 | } 114 | 115 | public Builder add(final int titleResId, final Class clazz, 116 | final Bundle args) { 117 | return add(FragmentPagerItem.create(mActivity.getString(titleResId), clazz, args)); 118 | } 119 | 120 | public FragmentPagerItemAdapter build() { 121 | return new FragmentPagerItemAdapter(mActivity, mActivity.getSupportFragmentManager(), 122 | mItems); 123 | } 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | material-scrolling 2 | === 3 | [![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) 4 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-material--scrolling-green.svg?style=flat)](https://android-arsenal.com/details/1/2529) 5 | [![Download](https://api.bintray.com/packages/satorufujiwara/maven/material-scrolling/images/download.svg)](https://bintray.com/satorufujiwara/maven/material-scrolling/_latestVersion) 6 | 7 | 8 | Android library for [material scrolling techniques](http://www.google.com/design/spec/patterns/scrolling-techniques.html). 9 | 10 | ![ViewPager](/arts/viewpager.gif) ![ImageFab](/arts/imagefab.gif) 11 | 12 | ![ViewPagerLand](/arts/viewpager_land.gif) 13 | 14 | # Features 15 | * Easily implement [material scrolling techniques](http://www.google.com/design/spec/patterns/scrolling-techniques.html) with RecyclerView. 16 | * Customize the behavior while scrolling. 17 | * Support RecyclerView in ViewPager. 18 | 19 | # Usage 20 | 21 | (For a working implementation of this project see the [sample](./sample).) 22 | 23 | ## MaterialScrollingLayout 24 | 25 | Layout `ObservableRecyclerView` inside of `MaterialScrollingLayout`. 26 | 27 | ```xml 28 | 36 | 37 | 42 | 43 | 44 | ``` 45 | `ms_flexible_height`is height from `RecyclerView`s top to `RecyclerView`'s first item. 46 | 47 | And call `MaterialScrollingLayout.addBehavior(View, Behavior)` in Activity or Fragment. 48 | 49 | First argument is target `View`. 50 | Second argument is `View`'s behavior while scrolling. 51 | 52 | ```java 53 | materialScrollingLayout.addBehavior(bgImageView, new ParallaxBehavior()); 54 | materialScrollingLayout.addBehavior(titleTextView, new ScrollingBehavior()); 55 | materialScrollingLayout.addBehavior(fabView, new FabBehavior(getResources())); 56 | ``` 57 | 58 | `FabBehavior` is customized `Behavior`. 59 | If you want customize behavior, create class that extends 'Behavior'. 60 | 61 | ```java 62 | public class TitleBehavior extends Behavior { 63 | 64 | private final int scrollLimitHeight; 65 | 66 | public TitleBehavior(Resources r) { 67 | scrollLimitHeight = r.getDimensionPixelOffset(R.dimen.title_scroll_height); 68 | } 69 | 70 | @Override 71 | protected void onScrolled(View target, int scrollY, int dy) { 72 | ViewCompat.setTranslationY(target, -Math.min(scrollY, scrollLimitHeight)); 73 | } 74 | } 75 | ``` 76 | 77 | ## MaterialViewPager 78 | 79 | If you want to use with `ViewPager`, use `MaterialViewPager`. 80 | 81 | And PagerAdapter must imptelement `MaterialScrollingViewPager.ContainRecyclerViewPagerAdapter`. 82 | 83 | ```xml 84 | 91 | ``` 92 | 93 | And call `MaterialScrollingViewPager.addBehavior(View, Behavior)` in Activity or Fragment. 94 | 95 | # Gradle 96 | 97 | ```groovy 98 | repositories { 99 | jcenter() 100 | } 101 | dependencies { 102 | compile 'jp.satorufujiwara:material-scrolling:1.2.1' 103 | compile 'com.github.ksoichiro:android-observablescrollview:1.6.0' 104 | } 105 | ``` 106 | 107 | # Developed By 108 | 109 | Satoru Fujiwara (satorufujiwara) 110 | * Twitter [satorufujiwara](https://twitter.com/satorufujiwara) 111 | * holly.wist@gmail.com 112 | 113 | Other Projects 114 | * [recyclerview-binder](https://github.com/satorufujiwara/recyclerview-binder) 115 | * Android Library for RecyclerView to manage order of items and multiple view types. 116 | * [lighthttp](https://github.com/satorufujiwara/lighthttp) 117 | * Lightweitht HTTP client for Android 118 | 119 | # Dependencies 120 | 121 | * Library 122 | * [Android-ObservableScrollView](https://github.com/ksoichiro/Android-ObservableScrollView) 123 | 124 | * Sample 125 | * [recyclerview-binder](https://github.com/satorufujiwara/recyclerview-binder) 126 | * [SmartTabLayout](https://github.com/ogaclejapan/SmartTabLayout) 127 | 128 | 129 | License 130 | ------- 131 | Copyright 2015 Satoru Fujiwara 132 | 133 | Licensed under the Apache License, Version 2.0 (the "License"); 134 | you may not use this file except in compliance with the License. 135 | You may obtain a copy of the License at 136 | 137 | http://www.apache.org/licenses/LICENSE-2.0 138 | 139 | Unless required by applicable law or agreed to in writing, software 140 | distributed under the License is distributed on an "AS IS" BASIS, 141 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 142 | See the License for the specific language governing permissions and 143 | limitations under the License. 144 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /library/src/main/java/jp/satorufujiwara/scrolling/MaterialScrollingViewPager.java: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.scrolling; 2 | 3 | import com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView; 4 | 5 | import android.content.Context; 6 | import android.content.res.TypedArray; 7 | import android.support.v4.util.ArrayMap; 8 | import android.support.v4.view.PagerAdapter; 9 | import android.support.v4.view.ViewPager; 10 | import android.util.AttributeSet; 11 | import android.view.MotionEvent; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | 15 | import java.util.Map; 16 | 17 | public class MaterialScrollingViewPager extends ViewPager { 18 | 19 | private final ArrayMap recyclerViews = new ArrayMap<>(); 20 | private final Map holders = new ArrayMap<>(); 21 | private final BehaviorDispatcher behaviorDispatcher = new BehaviorDispatcher(); 22 | private int flexibleHeight; 23 | private int baseHeight; 24 | private RecyclerViewHolder activeHolder; 25 | private boolean isFirst = true; 26 | 27 | private final OnPageChangeListener onPageChangeListener = new OnPageChangeListener() { 28 | @Override 29 | public void onPageScrolled(final int position, final float positionOffset, 30 | final int positionOffsetPixels) { 31 | // no op 32 | } 33 | 34 | @Override 35 | public void onPageSelected(final int position) { 36 | final ObservableRecyclerView recyclerView = findRecyclerViewFrom(position); 37 | if (recyclerView == null) { 38 | return; 39 | } 40 | for (RecyclerViewHolder holder : holders.values()) { 41 | holder.setIsDispatchScroll(false); 42 | } 43 | behaviorDispatcher.onScrolled(activeHolder.getScrollY(), 0); 44 | activeHolder = holders.get(recyclerView); 45 | activeHolder.setIsDispatchScroll(true); 46 | } 47 | 48 | @Override 49 | public void onPageScrollStateChanged(final int state) { 50 | findFirstActiveRecyclerView(); 51 | if (state == SCROLL_STATE_IDLE) { 52 | return; 53 | } 54 | final int activeScrollY = activeHolder.getScrollY(); 55 | for (Map.Entry item : holders.entrySet()) { 56 | final RecyclerViewHolder holder = item.getValue(); 57 | if (holder == activeHolder) { 58 | continue; 59 | } 60 | final int scrollY = holder.getScrollY(); 61 | if (activeScrollY >= flexibleHeight - baseHeight 62 | && scrollY >= flexibleHeight - baseHeight) { 63 | continue; 64 | } 65 | holder.scrollTo(Math.min(activeScrollY, flexibleHeight - baseHeight)); 66 | } 67 | } 68 | }; 69 | 70 | public MaterialScrollingViewPager(final Context context) { 71 | this(context, null); 72 | } 73 | 74 | public MaterialScrollingViewPager(final Context context, final AttributeSet attrs) { 75 | super(context, attrs); 76 | int flexibleHeight = 0; 77 | int baseHeight = 0; 78 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ms_MaterialScrolling); 79 | flexibleHeight = a.getDimensionPixelSize( 80 | R.styleable.ms_MaterialScrolling_ms_flexible_height, flexibleHeight); 81 | baseHeight = a.getDimensionPixelSize( 82 | R.styleable.ms_MaterialScrolling_ms_base_height, baseHeight); 83 | a.recycle(); 84 | this.flexibleHeight = flexibleHeight; 85 | this.baseHeight = baseHeight; 86 | behaviorDispatcher.setFlexibleHeight(flexibleHeight); 87 | } 88 | 89 | @Override 90 | protected void onAttachedToWindow() { 91 | super.onAttachedToWindow(); 92 | behaviorDispatcher.onAttachedToWindow(this); 93 | addOnPageChangeListener(onPageChangeListener); 94 | } 95 | 96 | @Override 97 | protected void onDetachedFromWindow() { 98 | removeOnPageChangeListener(onPageChangeListener); 99 | behaviorDispatcher.onDetachedFromWindow(this); 100 | super.onDetachedFromWindow(); 101 | } 102 | 103 | @Override 104 | public void addView(final View child, final int index, final ViewGroup.LayoutParams params) { 105 | super.addView(child, index, params); 106 | ObservableRecyclerView recyclerView = Utils.findRecyclerView(child); 107 | if (recyclerView == null) { 108 | return; 109 | } 110 | RecyclerViewHolder holder = new RecyclerViewHolder(recyclerView, behaviorDispatcher); 111 | holder.setFlexibleHeight(flexibleHeight); 112 | recyclerViews.put(child, recyclerView); 113 | holders.put(recyclerView, holder); 114 | } 115 | 116 | @Override 117 | public void removeView(final View view) { 118 | if (recyclerViews.containsKey(view)) { 119 | holders.remove(recyclerViews.get(view)); 120 | recyclerViews.remove(view); 121 | } 122 | super.removeView(view); 123 | } 124 | 125 | @Override 126 | public void setAdapter(final PagerAdapter adapter) { 127 | super.setAdapter(adapter); 128 | setOffscreenPageLimit(getAdapter().getCount()); 129 | } 130 | 131 | @Override 132 | public boolean onInterceptTouchEvent(MotionEvent ev) { 133 | findFirstActiveRecyclerView(); 134 | return super.onInterceptTouchEvent(ev); 135 | } 136 | 137 | public void addBehavior(final View target, final Behavior behavior) { 138 | behaviorDispatcher.addBehavior(target, behavior); 139 | } 140 | 141 | public void setFlexibleHeight(final int flexibleHeight) { 142 | this.flexibleHeight = flexibleHeight; 143 | behaviorDispatcher.setFlexibleHeight(flexibleHeight); 144 | for (RecyclerViewHolder holder : holders.values()) { 145 | holder.setFlexibleHeight(flexibleHeight); 146 | } 147 | } 148 | 149 | public void setBaseHeight(final int baseHeight) { 150 | this.baseHeight = baseHeight; 151 | } 152 | 153 | private void findFirstActiveRecyclerView() { 154 | if (!isFirst) { 155 | return; 156 | } 157 | final RecyclerViewHolder holder = holders.get(findRecyclerViewFrom(getCurrentItem())); 158 | if (holder != null) { 159 | holder.setIsDispatchScroll(true); 160 | activeHolder = holder; 161 | } 162 | isFirst = false; 163 | } 164 | 165 | private ObservableRecyclerView findRecyclerViewFrom(final int position) { 166 | final PagerAdapter adapter = getAdapter(); 167 | if (adapter instanceof ContainRecyclerViewPagerAdapter) { 168 | return ((ContainRecyclerViewPagerAdapter) adapter).getRecyclerView(position); 169 | } 170 | return null; 171 | } 172 | 173 | public interface ContainRecyclerViewPagerAdapter { 174 | 175 | ObservableRecyclerView getRecyclerView(final int position); 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------