From e4f657af85546757a3c9f70688692546eeeff838 Mon Sep 17 00:00:00 2001 From: florent37 Date: Sun, 13 Sep 2015 14:18:37 +0200 Subject: [PATCH] added option to replace the viewpager --- .idea/libraries/appcompat_v7_22_2_1.xml | 7 ++++++- .idea/libraries/cardview_v7_22_2_1.xml | 4 +++- .idea/libraries/circleimageview_1_3_0.xml | 3 +++ .idea/libraries/materialviewpager_1_1_1.xml | 3 +++ .idea/libraries/recyclerview_v7_22_2_1.xml | 4 +++- .idea/libraries/support_v4_22_2_1.xml | 7 ++++++- README.md | 4 ++++ build.gradle | 2 +- materialviewpager/materialviewpager.iml | 2 +- .../materialviewpager/MaterialViewPager.java | 19 ++++++++++++++++++- .../MaterialViewPagerAnimator.java | 1 + .../MaterialViewPagerSettings.java | 6 ++++++ .../res/layout/material_view_pager_layout.xml | 10 +++++++--- .../layout/material_view_pager_viewpager.xml | 6 ++++++ .../src/main/res/values/attrs.xml | 1 + materialviewpager/src/main/res/values/ids.xml | 1 + .../materialviewpagercontroller.iml | 2 +- sample/sample.iml | 2 +- 18 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 materialviewpager/src/main/res/layout/material_view_pager_viewpager.xml diff --git a/.idea/libraries/appcompat_v7_22_2_1.xml b/.idea/libraries/appcompat_v7_22_2_1.xml index 1b9a3b42..3fd60afd 100644 --- a/.idea/libraries/appcompat_v7_22_2_1.xml +++ b/.idea/libraries/appcompat_v7_22_2_1.xml @@ -1,10 +1,15 @@ + + + - + + + \ No newline at end of file diff --git a/.idea/libraries/cardview_v7_22_2_1.xml b/.idea/libraries/cardview_v7_22_2_1.xml index 7c2cb6ba..a06563f0 100644 --- a/.idea/libraries/cardview_v7_22_2_1.xml +++ b/.idea/libraries/cardview_v7_22_2_1.xml @@ -5,6 +5,8 @@ - + + + \ No newline at end of file diff --git a/.idea/libraries/circleimageview_1_3_0.xml b/.idea/libraries/circleimageview_1_3_0.xml index 597015f3..f190e249 100644 --- a/.idea/libraries/circleimageview_1_3_0.xml +++ b/.idea/libraries/circleimageview_1_3_0.xml @@ -1,5 +1,8 @@ + + + diff --git a/.idea/libraries/materialviewpager_1_1_1.xml b/.idea/libraries/materialviewpager_1_1_1.xml index 4d9c96db..a0048ee0 100644 --- a/.idea/libraries/materialviewpager_1_1_1.xml +++ b/.idea/libraries/materialviewpager_1_1_1.xml @@ -1,5 +1,8 @@ + + + diff --git a/.idea/libraries/recyclerview_v7_22_2_1.xml b/.idea/libraries/recyclerview_v7_22_2_1.xml index eaae5604..4c638463 100644 --- a/.idea/libraries/recyclerview_v7_22_2_1.xml +++ b/.idea/libraries/recyclerview_v7_22_2_1.xml @@ -5,6 +5,8 @@ - + + + \ No newline at end of file diff --git a/.idea/libraries/support_v4_22_2_1.xml b/.idea/libraries/support_v4_22_2_1.xml index 96cbfbe0..c45b85ba 100644 --- a/.idea/libraries/support_v4_22_2_1.xml +++ b/.idea/libraries/support_v4_22_2_1.xml @@ -1,11 +1,16 @@ + + + - + + + \ No newline at end of file diff --git a/README.md b/README.md index 50397999..a7bbcf56 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build.gradle b/build.gradle index ad085511..c9f3eb44 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ ext{ SUPPORT_VERSION='22.2.1' - MAVEN_VERSION='1.1.1' + MAVEN_VERSION='1.1.2' } allprojects { diff --git a/materialviewpager/materialviewpager.iml b/materialviewpager/materialviewpager.iml index 7ac2adff..e529fb12 100644 --- a/materialviewpager/materialviewpager.iml +++ b/materialviewpager/materialviewpager.iml @@ -1,5 +1,5 @@ - + 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 38c9c399..18d79ad8 100644 --- a/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPager.java +++ b/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPager.java @@ -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 @@ -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); @@ -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; 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 8db180b5..8eb15793 100644 --- a/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerAnimator.java +++ b/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerAnimator.java @@ -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); diff --git a/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerSettings.java b/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerSettings.java index a824ea7a..a8786f9f 100644 --- a/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerSettings.java +++ b/materialviewpager/src/main/java/com/github/florent37/materialviewpager/MaterialViewPagerSettings.java @@ -20,6 +20,7 @@ public class MaterialViewPagerSettings implements Parcelable { protected int headerLayoutId; protected int pagerTitleStripId; + protected int viewpagerId; protected int logoLayoutId; protected int logoMarginTop; @@ -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); @@ -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); @@ -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(); diff --git a/materialviewpager/src/main/res/layout/material_view_pager_layout.xml b/materialviewpager/src/main/res/layout/material_view_pager_layout.xml index a62bf08f..18b8c66c 100644 --- a/materialviewpager/src/main/res/layout/material_view_pager_layout.xml +++ b/materialviewpager/src/main/res/layout/material_view_pager_layout.xml @@ -26,10 +26,14 @@ - + android:layout_height="match_parent"> + + + + + \ No newline at end of file diff --git a/materialviewpager/src/main/res/values/attrs.xml b/materialviewpager/src/main/res/values/attrs.xml index cedd249c..08c24f01 100644 --- a/materialviewpager/src/main/res/values/attrs.xml +++ b/materialviewpager/src/main/res/values/attrs.xml @@ -5,6 +5,7 @@ + diff --git a/materialviewpager/src/main/res/values/ids.xml b/materialviewpager/src/main/res/values/ids.xml index fb5566a8..369adf72 100644 --- a/materialviewpager/src/main/res/values/ids.xml +++ b/materialviewpager/src/main/res/values/ids.xml @@ -3,4 +3,5 @@ + \ No newline at end of file diff --git a/materialviewpagercontroller/materialviewpagercontroller.iml b/materialviewpagercontroller/materialviewpagercontroller.iml index 27be55ec..ef792925 100644 --- a/materialviewpagercontroller/materialviewpagercontroller.iml +++ b/materialviewpagercontroller/materialviewpagercontroller.iml @@ -1,5 +1,5 @@ - + diff --git a/sample/sample.iml b/sample/sample.iml index 8c185a47..7c940ff2 100644 --- a/sample/sample.iml +++ b/sample/sample.iml @@ -100,8 +100,8 @@ - +