Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
1.0.5 README
Browse files Browse the repository at this point in the history
  • Loading branch information
florent37 committed Jun 10, 2015
1 parent 1812459 commit 5dd0d9f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 56 deletions.
84 changes: 33 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,71 +300,47 @@ Create your own layout using a PagerSlidingTabStrip

[![Video](http://share.gifyoutube.com/yABkgW.gif)](http://youtu.be/90gKwEL1j2I )

Simply listen to the ViewPager Page Change and modify the header's **color and image**
Simply add a listen to the ViewPager

```java
//it's a sample ViewPagerAdapter
mViewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

int oldPosition = -1;

@Override
public Fragment getItem(int position) {
return RecyclerViewFragment.newInstance();
}

@Override
public int getCount() {
return 4;
}

@Override
public CharSequence getPageTitle(int position) {
return "Tab "+position;
}

//called when the current page has changed
mViewPager.setMaterialViewPagerListener(new MaterialViewPager.MaterialViewPagerListener() {
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
super.setPrimaryItem(container, position, object);

//only if position changed
if(position == oldPosition)
return;
oldPosition = position;

int color = 0;
String imageUrl = "";
switch (position){
public HeaderDesign getHeaderDesign(int page) {
switch (page) {
case 0:
imageUrl = "http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2014/06/wallpaper_51.jpg";
color = getResources().getColor(R.color.blue);
break;
return HeaderDesign.fromColorResAndUrl(
R.color.blue,
"http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2014/06/wallpaper_51.jpg");
case 1:
imageUrl = "https://fs01.androidpit.info/a/63/0e/android-l-wallpapers-630ea6-h900.jpg";
color = getResources().getColor(R.color.green);
break;
return HeaderDesign.fromColorResAndUrl(
R.color.green,
"https://fs01.androidpit.info/a/63/0e/android-l-wallpapers-630ea6-h900.jpg");
case 2:
imageUrl = "http://www.droid-life.com/wp-content/uploads/2014/10/lollipop-wallpapers10.jpg";
color = getResources().getColor(R.color.cyan);
break;
return HeaderDesign.fromColorResAndUrl(
R.color.cyan,
"http://www.droid-life.com/wp-content/uploads/2014/10/lollipop-wallpapers10.jpg");
case 3:
imageUrl = "http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg";
color = getResources().getColor(R.color.red);
break;
return HeaderDesign.fromColorResAndUrl(
R.color.red,
"http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg");
}

final int fadeDuration = 400;

//change header's color and image
mViewPager.setImageUrl(imageUrl,fadeDuration);
mViewPager.setColor(color,fadeDuration);
//execute others actions if needed (ex : modify your header logo)

return null;
}

});
```

Available

```java
HeaderDesign.fromColorAndUrl(Color.BLUE,"http:...);
HeaderDesign.fromColorResAndUrl(R.color.blue,"http:...);
HeaderDesign.fromColorAndDrawable(Color.BLUE,myDrawable);
HeaderDesign.fromColorResAndDrawable(R.color.blue,myDrawable);
```

#Toolbar

```java
Expand Down Expand Up @@ -495,6 +471,12 @@ MaterialViewPagerHelper.registerWebView(getActivity(), mWebView, null);

#CHANGELOG

##1.0.5
- smoother toolbar scrolling
- fixed bug with fitSystemWindow
- added HeaderDesign to modify the header color & image
- added displayToolbarWhenSwipe attribute

##1.0.4
Fixed :

Expand Down
3 changes: 2 additions & 1 deletion materialviewpager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ dependencies {
'com.android.support:appcompat-v7:22.2.0',
'com.android.support:support-v4:22.2.0',
'com.android.support:recyclerview-v7:22.2.0',
'com.android.support:cardview-v7:22.2.0'
'com.android.support:cardview-v7:22.2.0',
'com.android.support:support-annotations:22.2.0'
)

compile 'com.nineoldandroids:library:2.4.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.florent37.materialviewpager;

import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;

/**
* Created by florentchampigny on 10/06/15.
Expand All @@ -14,28 +16,28 @@ public class HeaderDesign {
private HeaderDesign() {
}

public static HeaderDesign fromColorAndUrl(int color, String imageUrl) {
public static HeaderDesign fromColorAndUrl(@ColorInt int color, String imageUrl) {
HeaderDesign headerDesign = new HeaderDesign();
headerDesign.color = color;
headerDesign.imageUrl = imageUrl;
return headerDesign;
}

public static HeaderDesign fromColorResAndUrl(int colorRes, String imageUrl) {
public static HeaderDesign fromColorResAndUrl(@ColorRes int colorRes, String imageUrl) {
HeaderDesign headerDesign = new HeaderDesign();
headerDesign.colorRes = colorRes;
headerDesign.imageUrl = imageUrl;
return headerDesign;
}

public static HeaderDesign fromColorAndDrawable(int color, Drawable drawable) {
public static HeaderDesign fromColorAndDrawable(@ColorInt int color, Drawable drawable) {
HeaderDesign headerDesign = new HeaderDesign();
headerDesign.drawable = drawable;
headerDesign.color = color;
return headerDesign;
}

public static HeaderDesign fromColorResAndDrawable(int colorRes, String imageUrl) {
public static HeaderDesign fromColorResAndDrawable(@ColorRes int colorRes, String imageUrl) {
HeaderDesign headerDesign = new HeaderDesign();
headerDesign.colorRes = colorRes;
headerDesign.imageUrl = imageUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public HeaderDesign getHeaderDesign(int page) {
R.color.red,
"http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg");
}

//execute others actions if needed (ex : modify your header logo)

return null;
}
});
Expand Down

0 comments on commit 5dd0d9f

Please sign in to comment.