diff --git a/.gitignore b/.gitignore
index 27dce785..89676dd8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,8 +2,6 @@
*.apk
*.ap_
-.idea/workspace.xml
-
# Files for the Dalvik VM
*.dex
@@ -17,7 +15,6 @@ gen/
# Gradle files
.gradle/
build/
-/*/build/
# Local configuration file (sdk path, etc)
local.properties
@@ -27,3 +24,14 @@ proguard/
# Log Files
*.log
+
+# Android Studio Navigation editor temp files
+.navigation/
+
+# Android Studio captures folder
+captures/
+
+.gradle
+.idea
+*.iml
+**/build/*
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 058c87cc..26f59804 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -3,10 +3,24 @@
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 47662492..5d199810 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,8 @@
+
+
+
@@ -34,7 +37,7 @@
-
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index ad2b2424..d104611d 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -3,6 +3,9 @@
+
+
+
\ No newline at end of file
diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml
deleted file mode 100644
index 922003b8..00000000
--- a/.idea/scopes/scope_settings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 35eb1ddf..94a25f7f 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/MaterialViewPager.iml b/MaterialViewPager.iml
index 02342f05..9c5f8acd 100644
--- a/MaterialViewPager.iml
+++ b/MaterialViewPager.iml
@@ -7,16 +7,6 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/README.md b/README.md
index 5d36ff0b..cb6dea21 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,7 @@ And have a look on a sample Youtube Video : [Youtube Link](http://www.youtube.co
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.1.3@aar'){
+compile ('com.github.florent37:materialviewpager:1.2.0@aar'){
transitive = true
}
```
@@ -441,6 +441,15 @@ Sample :
##RecyclerView
+### LinearLayoutManager / GridLayoutManager
+
+```java
+mRecyclerView.setAdapter(new MaterialViewPagerHeaderDecorator());
+mRecyclerView.setAdapter(yourAdapter);
+```
+
+### StaggedLayoutManager
+
From your fragment
```java
mAdapter = new RecyclerViewMaterialAdapter(new ***Adapter(mList));
@@ -501,6 +510,9 @@ And must include @layout/material_view_pager_placeholder as first child
#CHANGELOG
+##1.2.0
+- header decorator instead of Adapter
+
##1.1.3
- header is now clickable
- fixed some scrolling issues
diff --git a/build.gradle b/build.gradle
index 3c8242b7..9bed12bb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,38 +4,33 @@ buildscript {
repositories {
mavenCentral()
jcenter()
- maven {
- url "http://dl.bintray.com/jfrog/jfrog-jars"
- }
+ maven { url "http://dl.bintray.com/jfrog/jfrog-jars" }
+ maven { url 'https://maven.fabric.io/public' }
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.2.3'
- classpath 'com.github.dcendents:android-maven-plugin:1.2'
- classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1"
- classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
+ classpath 'com.android.tools.build:gradle:2.1.0'
+ classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
+ classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
+ 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{
- ANDROID_BUILD_MIN_SDK_VERSION=10
- ANDROID_BUILD_TARGET_SDK_VERSION=22
- ANDROID_BUILD_TOOLS_VERSION='22.0.0'
- ANDROID_BUILD_SDK_VERSION=22
-
- SUPPORT_VERSION='22.2.1'
-
- MAVEN_VERSION='1.1.3'
+ext {
+ minSdk = 10
+ sdk = 23
+ buildTools = "23.0.3"
+ supportVersion = "23.3.0"
+ libraryVersion = '1.2.0'
}
allprojects {
repositories {
jcenter()
- maven {
- url "http://dl.bintray.com/florent37/maven"
- }
+ maven { url "http://dl.bintray.com/florent37/maven" }
+ maven { url 'https://maven.fabric.io/public' }
}
}
diff --git a/gradle/bintray-android-v1.gradle b/gradle/bintray-android-v1.gradle
new file mode 100644
index 00000000..0101dd55
--- /dev/null
+++ b/gradle/bintray-android-v1.gradle
@@ -0,0 +1,52 @@
+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
+}
+
+// Bintray
+Properties properties = new Properties()
+properties.load(project.rootProject.file('local.properties').newDataInputStream())
+
+bintray {
+ user = properties.getProperty("bintray.user")
+ key = properties.getProperty("bintray.apikey")
+
+ 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 = properties.getProperty("bintray.gpg.password")
+ //Optional. The passphrase for GPG signing'
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/gradle/bintray-java-v1.gradle b/gradle/bintray-java-v1.gradle
new file mode 100644
index 00000000..67025d75
--- /dev/null
+++ b/gradle/bintray-java-v1.gradle
@@ -0,0 +1,49 @@
+apply plugin: 'com.jfrog.bintray'
+
+version = libraryVersion
+
+task sourcesJar(type: Jar) {
+ from sourceSets.main.allSource
+ classifier = 'sources'
+}
+
+task javadocJar(type: Jar, dependsOn: javadoc) {
+ classifier = 'javadoc'
+ from javadoc.destinationDir
+}
+artifacts {
+ archives javadocJar
+ archives sourcesJar
+}
+
+// Bintray
+Properties properties = new Properties()
+properties.load(project.rootProject.file('local.properties').newDataInputStream())
+
+bintray {
+ user = properties.getProperty("bintray.user")
+ key = properties.getProperty("bintray.apikey")
+
+ configurations = ['archives']
+ pkg {
+ repo = bintrayRepo
+ name = bintrayName
+ desc = libraryDescription
+ userOrg = orgName
+ websiteUrl = siteUrl
+ vcsUrl = gitUrl
+ licenses = ['Apache-2.0']
+ publish = true
+ publicDownloadNumbers = true
+ version {
+ desc = libraryDescription
+ gpg {
+ sign = true //Determines whether to GPG sign the files. The default is false
+ passphrase = properties.getProperty("bintray.gpg.password")
+ //Optional. The passphrase for GPG signing'
+ }
+ }
+ }
+}
+
+//from https://github.com/workarounds/bundler/blob/master/gradle/bintray-java-v1.gradle
\ No newline at end of file
diff --git a/gradle/install-v1.gradle b/gradle/install-v1.gradle
new file mode 100644
index 00000000..79980d1d
--- /dev/null
+++ b/gradle/install-v1.gradle
@@ -0,0 +1,44 @@
+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
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 0c71e760..d5705170 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
diff --git a/materialviewpager/build.gradle b/materialviewpager/build.gradle
index b8c1d62f..addb842d 100644
--- a/materialviewpager/build.gradle
+++ b/materialviewpager/build.gradle
@@ -1,18 +1,13 @@
-apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.library'
-apply plugin: 'com.github.dcendents.android-maven'
-apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.ben-manes.versions'
-version = project.MAVEN_VERSION
-
android {
- compileSdkVersion project.ANDROID_BUILD_SDK_VERSION
- buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
+ compileSdkVersion project.sdk
+ buildToolsVersion project.buildTools
defaultConfig {
- minSdkVersion project.ANDROID_BUILD_MIN_SDK_VERSION
- targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION
+ minSdkVersion project.minSdk
+ targetSdkVersion project.sdk
versionCode 1
versionName "1.0"
}
@@ -28,110 +23,47 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile (
- 'com.android.support:appcompat-v7:'+project.SUPPORT_VERSION,
- 'com.android.support:support-v4:'+project.SUPPORT_VERSION,
- 'com.android.support:recyclerview-v7:'+project.SUPPORT_VERSION,
- 'com.android.support:cardview-v7:'+project.SUPPORT_VERSION,
- 'com.android.support:support-annotations:'+project.SUPPORT_VERSION
+ 'com.android.support:appcompat-v7:'+project.supportVersion,
+ 'com.android.support:support-v4:'+project.supportVersion,
+ 'com.android.support:recyclerview-v7:'+project.supportVersion,
+ 'com.android.support:cardview-v7:'+project.supportVersion,
+ 'com.android.support:support-annotations:'+project.supportVersion
)
compile 'com.nineoldandroids:library:2.4.0'
- compile 'com.flaviofaria:kenburnsview:1.0.6'
+ compile 'com.flaviofaria:kenburnsview:1.0.7'
compile 'com.jpardogo.materialtabstrip:library:1.1.0'
- compile 'com.github.ksoichiro:android-observablescrollview:1.5.2'
- compile 'com.squareup.picasso:picasso:2.5.2'
+ compile 'com.github.ksoichiro:android-observablescrollview:1.6.0'
+ compile 'com.github.bumptech.glide:glide:3.7.0'
}
+ext {
+ bintrayRepo = 'maven'
+ bintrayName = 'MaterialViewPager'
+ orgName = 'florent37'
-//https://github.com/danielemaddaluno/gradle-jcenter-publish
-
-// ./gradlew install bintrayUpload
-
-
-def siteUrl = 'https://github.com/florent37/MaterialViewPager' // Homepage URL of the library
-def gitUrl = 'https://github.com/florent37/MaterialViewPager.git' // Git repository URL
-group = "com.github.florent37" // Maven Group ID for the artifact
+ publishedGroupId = 'com.github.florent37'
+ libraryName = 'MaterialViewPager'
+ artifact = 'materialviewpager'
+ libraryDescription = 'MaterialViewPager'
-install {
- repositories.mavenInstaller {
- // This generates POM.xml with proper parameters
- pom {
- project {
- packaging 'aar'
+ siteUrl = 'https://github.com/florent37/MaterialViewPager'
+ gitUrl = 'https://github.com/florent37/MaterialViewPager.git'
- // Add your description here
- name 'MaterialViewPager'
- description = ''
- url siteUrl
+ libraryVersion = rootProject.ext.libraryVersion
- // Set your license
- licenses {
- license {
- name 'The Apache Software License, Version 2.0'
- url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
- }
- }
- developers {
- developer {
- id 'florent37'
- name 'Florent Champigny'
- email 'champigny.florent@gmail.com'
- }
- }
- scm {
- connection gitUrl
- developerConnection gitUrl
- url siteUrl
-
- }
- }
- }
- }
-}
+ developerId = 'florent37'
+ developerName = 'Florent Champigny'
+ developerEmail = 'champigny.florent@gmail.com'
-task sourcesJar(type: Jar) {
- from android.sourceSets.main.java.srcDirs
- classifier = 'sources'
+ licenseName = 'The Apache Software License, Version 2.0'
+ licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+ allLicenses = ["Apache-2.0"]
}
-artifacts {
- archives sourcesJar
+if (project.rootProject.file('local.properties').exists()) {
+ apply from: rootProject.file('gradle/install-v1.gradle')
+ apply from: rootProject.file('gradle/bintray-android-v1.gradle')
}
-
-Properties properties = new Properties()
-File f = new File("local.properties")
-if(f.exists()) {
- properties.load(project.rootProject.file('local.properties').newDataInputStream())
-}
-
-// https://github.com/bintray/gradle-bintray-plugin
-bintray {
-
- user = properties.getProperty("bintray.user")
- key = properties.getProperty("bintray.apikey")
-
- configurations = ['archives']
- pkg {
- repo = "maven"
- // it is the name that appears in bintray when logged
- name = "MaterialViewPager"
- websiteUrl = siteUrl
- vcsUrl = gitUrl
- licenses = ["Apache-2.0"]
- publish = true
- version {
- gpg {
- sign = true //Determines whether to GPG sign the files. The default is false
- passphrase = properties.getProperty("bintray.gpg.password") //Optional. The passphrase for GPG signing'
- }
-// mavenCentralSync {
-// sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
-// user = properties.getProperty("bintray.oss.user") //OSS user token
-// password = properties.getProperty("bintray.oss.password") //OSS user password
-// close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
-// }
- }
- }
-}
\ No newline at end of file
diff --git a/materialviewpager/materialviewpager.iml b/materialviewpager/materialviewpager.iml
index c2ae7bb9..a323cf64 100644
--- a/materialviewpager/materialviewpager.iml
+++ b/materialviewpager/materialviewpager.iml
@@ -1,5 +1,5 @@
-
+
@@ -12,10 +12,7 @@
@@ -29,7 +26,7 @@
-
+
@@ -37,13 +34,13 @@
-
+
-
+
@@ -51,6 +48,15 @@
+
+
+
+
+
+
+
+
+
@@ -58,6 +64,7 @@
+
@@ -65,47 +72,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
-
+
-
+
-
-
+
+
-
-
-
-
+
-
-
-
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPager.java b/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPager.java
index 18d79ad8..ee24e609 100644
--- a/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPager.java
+++ b/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPager.java
@@ -20,7 +20,7 @@
import com.astuetz.PagerSlidingTabStrip;
import com.github.florent37.materialviewpager.header.HeaderDesign;
import com.github.florent37.materialviewpager.header.MaterialViewPagerImageHelper;
-import com.nineoldandroids.view.ViewHelper;
+import android.support.v4.view.ViewCompat;
/**
* Created by florentchampigny on 28/04/15.
@@ -32,26 +32,40 @@
*/
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;
/**
* 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
@@ -59,30 +73,6 @@ public class MaterialViewPager extends FrameLayout implements ViewPager.OnPageCh
*/
private ViewGroup logoContainer;
- /**
- * 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;
-
- //region construct
-
public MaterialViewPager(Context context) {
super(context);
}
@@ -97,132 +87,41 @@ public MaterialViewPager(Context context, AttributeSet attrs, int 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);
}
- //endregion
-
-
- @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));
- }
+ protected void onRestoreInstanceState(Parcelable state) {
+ SavedState ss = (SavedState) state;
+ super.onRestoreInstanceState(ss.getSuperState());
- 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);
- }
+ this.settings = ss.settings;
+ if (headerBackground != null) {
+ headerBackground.setBackgroundColor(this.settings.color);
}
- 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);
+ MaterialViewPagerAnimator animator = MaterialViewPagerHelper.getAnimator(this.getContext());
- addView(sample);
- }
+ //-1*ss.yOffset restore to 0
+ animator.restoreScroll(-1 * ss.yOffset, ss.settings);
+ MaterialViewPagerHelper.register(getContext(), animator);
}
- private void initialiseHeights() {
- if (headerBackground != null) {
- headerBackground.setBackgroundColor(this.settings.color);
+ @Override
+ protected Parcelable onSaveInstanceState() {
+ Parcelable superState = super.onSaveInstanceState();
- 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);
- }
+ SavedState ss = new SavedState(superState);
+ //end
+ ss.settings = this.settings;
+ ss.yOffset = MaterialViewPagerHelper.getAnimator(getContext()).lastYOffset;
+
+ return ss;
}
/**
@@ -247,18 +146,18 @@ public PagerSlidingTabStrip getPagerTitleStrip() {
/**
* Retrieve the displayed toolbar
+ *
+ * @return the displayed toolbar
*/
- public void setToolbar(Toolbar toolbar) {
- mToolbar = toolbar;
+ public Toolbar getToolbar() {
+ return mToolbar;
}
/**
* Retrieve the displayed toolbar
- *
- * @return the displayed toolbar
*/
- public Toolbar getToolbar() {
- return mToolbar;
+ public void setToolbar(Toolbar toolbar) {
+ mToolbar = toolbar;
}
/**
@@ -270,7 +169,7 @@ public void setImageUrl(String imageUrl, int fadeDuration) {
final ImageView headerBackgroundImage = (ImageView) findViewById(R.id.materialviewpager_imageHeader);
//if using MaterialViewPagerImageHeader
if (headerBackgroundImage != null) {
- ViewHelper.setAlpha(headerBackgroundImage, settings.headerAlpha);
+ ViewCompat.setAlpha(headerBackgroundImage, settings.headerAlpha);
MaterialViewPagerImageHelper.setImageUrl(headerBackgroundImage, imageUrl, fadeDuration);
setImageHeaderDarkLayerAlpha();
}
@@ -282,12 +181,12 @@ public void setImageUrl(String imageUrl, int fadeDuration) {
* may remove Picasso
*/
public void setImageUrl(String imageUrl, int fadeDuration, OnImageLoadListener imageLoadListener) {
- if (imageLoadListener != null)
+ if (imageLoadListener != null) {
MaterialViewPagerImageHelper.setImageLoadListener(imageLoadListener);
+ }
setImageUrl(imageUrl, fadeDuration);
}
-
/**
* change the header displayed image with a fade
* may remove Picasso
@@ -297,7 +196,7 @@ public void setImageDrawable(Drawable drawable, int fadeDuration) {
final ImageView headerBackgroundImage = (ImageView) findViewById(R.id.materialviewpager_imageHeader);
//if using MaterialViewPagerImageHeader
if (headerBackgroundImage != null) {
- ViewHelper.setAlpha(headerBackgroundImage, settings.headerAlpha);
+ ViewCompat.setAlpha(headerBackgroundImage, settings.headerAlpha);
MaterialViewPagerImageHelper.setImageDrawable(headerBackgroundImage, drawable, fadeDuration);
setImageHeaderDarkLayerAlpha();
}
@@ -312,7 +211,7 @@ public void setImageHeaderDarkLayerAlpha() {
//if using MaterialViewPagerImageHeader
if (headerImageDarkLayerView != null) {
headerImageDarkLayerView.setBackgroundColor(getResources().getColor(android.R.color.black));
- ViewHelper.setAlpha(headerImageDarkLayerView, settings.imageHeaderDarkLayerAlpha);
+ ViewCompat.setAlpha(headerImageDarkLayerView, settings.imageHeaderDarkLayerAlpha);
}
}
@@ -320,46 +219,15 @@ public void setImageHeaderDarkLayerAlpha() {
* Change the header color
*/
public void setColor(int color, int fadeDuration) {
- if (MaterialViewPagerHelper.getAnimator(getContext()) != null)
+ if (MaterialViewPagerHelper.getAnimator(getContext()) != null) {
MaterialViewPagerHelper.getAnimator(getContext()).setColor(color, fadeDuration * 2);
- }
-
- @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;
- }
-
- @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);
+ }
}
public ViewGroup getHeaderBackgroundContainer() {
return headerBackgroundContainer;
}
- //region ViewPagerOnPageListener
-
- int lastPosition = -1;
-
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (positionOffset >= 0.5) {
@@ -377,14 +245,18 @@ public void notifyHeaderChanged() {
onPageSelected(position);
}
+ //region ViewPagerOnPageListener
+
@Override
public void onPageSelected(int position) {
- if (position == lastPosition || listener == null)
+ if (position == lastPosition || listener == null) {
return;
+ }
HeaderDesign headerDesign = listener.getHeaderDesign(position);
- if (headerDesign == null)
+ if (headerDesign == null) {
return;
+ }
int fadeDuration = 400;
int color = headerDesign.getColor();
@@ -410,9 +282,152 @@ public void onPageScrollStateChanged(int state) {
}
}
+ 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;
@@ -432,30 +447,6 @@ public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(this.settings, flags);
out.writeFloat(this.yOffset);
}
-
- //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 void setMaterialViewPagerListener(Listener listener) {
- this.listener = listener;
- }
-
- public interface Listener {
- HeaderDesign getHeaderDesign(int page);
- }
-
- public interface OnImageLoadListener {
- void OnImageLoad(ImageView imageView, Bitmap bitmap);
}
}
diff --git a/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerAnimator.java b/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerAnimator.java
index 8d8a4373..368746bb 100644
--- a/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerAnimator.java
+++ b/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerAnimator.java
@@ -18,7 +18,7 @@
import com.nineoldandroids.animation.ArgbEvaluator;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.animation.ValueAnimator;
-import com.nineoldandroids.view.ViewHelper;
+import android.support.v4.view.ViewCompat;
import java.util.ArrayList;
import java.util.HashMap;
@@ -36,65 +36,49 @@
/**
* 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 = MaterialViewPagerAnimator.class.getSimpleName();
-
- public static Boolean ENABLE_LOG = true;
-
- private Context context;
-
- //contains MaterialViewPager subviews references
- private MaterialViewPagerHeader mHeader;
-
//duration of translate header enter animation
private static final int ENTER_TOOLBAR_ANIMATION_DURATION = 600;
-
- //reference to the current MaterialViewPager
- protected MaterialViewPager materialViewPager;
-
+ public static Boolean ENABLE_LOG = true;
//final toolbar layout elevation (if attr viewpager_enableToolbarElevation = true)
public final float elevation;
-
//max scroll which will be dispatched for all scrollable
public final float scrollMax;
-
// equals scrollMax in DP (saved to avoir convert to dp anytime I use it)
public final float scrollMaxDp;
-
+ //reference to the current MaterialViewPager
+ protected MaterialViewPager materialViewPager;
protected float lastYOffset = -1; //the current yOffset
protected float lastPercent = 0; //the current Percent
-
//contains the attributes given to MaterialViewPager from layout
protected MaterialViewPagerSettings settings;
-
//list of all registered scrollers
protected List scrollViewList = new ArrayList<>();
-
//save all yOffsets of scrollables
protected HashMap