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

Commit

Permalink
added option to replace the viewpager
Browse files Browse the repository at this point in the history
  • Loading branch information
florent37 committed Sep 13, 2015
1 parent 10f539a commit e4f657a
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 12 deletions.
7 changes: 6 additions & 1 deletion .idea/libraries/appcompat_v7_22_2_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/libraries/cardview_v7_22_2_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/libraries/circleimageview_1_3_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/libraries/materialviewpager_1_1_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/libraries/recyclerview_v7_22_2_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion .idea/libraries/support_v4_22_2_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ And must include @layout/material_view_pager_placeholder as first child

#CHANGELOG

##1.1.2
- quick scroll fix
- can set a custom viewpager with app:viewpager_viewpager (the viewpager id must be id/materialviewpager_viewpager)

##1.1.0
- orientation change fix
- header image display fix
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ext{

SUPPORT_VERSION='22.2.1'

MAVEN_VERSION='1.1.1'
MAVEN_VERSION='1.1.2'
}

allprojects {
Expand Down
2 changes: 1 addition & 1 deletion materialviewpager/materialviewpager.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":materialviewpager" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.github.florent37" external.system.module.version="1.1.1" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":materialviewpager" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.github.florent37" external.system.module.version="1.1.2" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public class MaterialViewPager extends FrameLayout implements ViewPager.OnPageCh
*/
private ViewGroup pagerTitleStripContainer;


/**
* the layout containing the viewpager, can be replaced to add your own implementation of viewpager
*/
private ViewGroup viewpagerContainer;

/**
* the layout containing logo
* default : empty
Expand Down Expand Up @@ -116,12 +122,22 @@ protected void onFinishInflate() {

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);
mViewPager = (ViewPager) findViewById(R.id.viewPager);

{ //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);

Expand All @@ -138,6 +154,7 @@ protected void onFinishInflate() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public boolean onMaterialScrolled(Object source, float yOffset) {
if(Float.isNaN(percent)) //fix for orientation change
return false;

//fix quick scroll
if(percent == 0 && headerAnimator != null) {
cancelHeaderAnimator();
ViewHelper.setTranslationY(mHeader.toolbarLayout,0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class MaterialViewPagerSettings implements Parcelable {

protected int headerLayoutId;
protected int pagerTitleStripId;
protected int viewpagerId;

protected int logoLayoutId;
protected int logoMarginTop;
Expand Down Expand Up @@ -58,6 +59,9 @@ protected void handleAttributes(Context context, AttributeSet attrs){
if(pagerTitleStripId == -1)
pagerTitleStripId = R.layout.material_view_pager_pagertitlestrip_standard;
}
{
viewpagerId = styledAttrs.getResourceId(R.styleable.MaterialViewPager_viewpager_viewpager, -1);
}
{
logoLayoutId = styledAttrs.getResourceId(R.styleable.MaterialViewPager_viewpager_logo, -1);
logoMarginTop = styledAttrs.getDimensionPixelSize(R.styleable.MaterialViewPager_viewpager_logoMarginTop, 0);
Expand Down Expand Up @@ -118,6 +122,7 @@ public int describeContents() {
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.headerLayoutId);
dest.writeInt(this.pagerTitleStripId);
dest.writeInt(this.viewpagerId);
dest.writeInt(this.logoLayoutId);
dest.writeInt(this.logoMarginTop);
dest.writeInt(this.headerAdditionalHeight);
Expand All @@ -138,6 +143,7 @@ public MaterialViewPagerSettings() {
private MaterialViewPagerSettings(Parcel in) {
this.headerLayoutId = in.readInt();
this.pagerTitleStripId = in.readInt();
this.viewpagerId = in.readInt();
this.logoLayoutId = in.readInt();
this.logoMarginTop = in.readInt();
this.headerAdditionalHeight = in.readInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@

</FrameLayout>

<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
<FrameLayout
android:id="@+id/viewpager_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="match_parent">

<include layout="@layout/material_view_pager_viewpager"/>

</FrameLayout>

<RelativeLayout
android:id="@+id/toolbar_layout"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
android:id="@id/materialviewpager_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" />
1 change: 1 addition & 0 deletions materialviewpager/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<attr name="viewpager_header" format="reference"/>
<attr name="viewpager_logo" format="reference"/>
<attr name="viewpager_pagerTitleStrip" format="reference"/>
<attr name="viewpager_viewpager" format="reference"/>
<attr name="viewpager_logoMarginTop" format="dimension"/>
<attr name="viewpager_color" format="color"/>
<attr name="viewpager_headerHeight" format="dimension"/>
Expand Down
1 change: 1 addition & 0 deletions materialviewpager/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<item type="id" name="materialviewpager_pagerTitleStrip" />
<item type="id" name="materialviewpager_imageHeader" />
<item type="id" name="materialviewpager_headerImageDarkLayer" />
<item type="id" name="materialviewpager_viewpager" />
</resources>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":materialviewpagercontroller" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.github.florent37" external.system.module.version="1.1.1" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":materialviewpagercontroller" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.github.florent37" external.system.module.version="1.1.2" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down
2 changes: 1 addition & 1 deletion sample/sample.iml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
<orderEntry type="library" exported="" name="answers-1.2.2" level="project" />
<orderEntry type="library" exported="" name="crashlytics-2.4.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-22.2.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />
<orderEntry type="library" exported="" name="fabric-1.3.4" level="project" />
Expand Down

0 comments on commit e4f657a

Please sign in to comment.