├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── demo ├── .gitignore ├── MagicHeaderViewPager_demo.jks ├── apk │ └── MagicHeaderViewPager_demo_1.0.apk ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── culiu │ │ └── mhvp │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── culiu │ │ └── mhvp │ │ └── demo │ │ ├── APP.java │ │ ├── AbsDemoFragment.java │ │ ├── DemoActivity.java │ │ ├── DemoConfig.java │ │ ├── DemoGridFragment.java │ │ ├── DemoListFragment.java │ │ ├── DemoPagerAdapter.java │ │ ├── DemoPullToRefreshGridFragment.java │ │ ├── DemoPullToRefreshListFragment.java │ │ ├── DemoPullToRefreshScrollFragment.java │ │ ├── DemoScrollFragment.java │ │ ├── RandomPic.java │ │ └── WelcomeActivity.java │ └── res │ ├── drawable-xxhdpi │ ├── bg_1.jpg │ ├── bg_10.jpg │ ├── bg_11.jpg │ ├── bg_12.jpg │ ├── bg_13.jpg │ ├── bg_2.jpg │ ├── bg_3.jpg │ ├── bg_4.jpg │ ├── bg_5.jpg │ ├── bg_6.jpg │ ├── bg_7.jpg │ ├── bg_8.jpg │ └── bg_9.jpg │ ├── drawable │ ├── bg_btn_welcome.xml │ └── ptr_loading_bg.png │ ├── layout │ ├── activity_mhvp_demo.xml │ ├── activity_welcome.xml │ ├── fragment_list.xml │ ├── fragment_pulltorefresh_list.xml │ ├── fragment_pulltorefresh_scrollview.xml │ ├── fragment_scrollview.xml │ ├── header_custom_layout.xml │ ├── item_grid_fragment.xml │ ├── item_list_fragment.xml │ ├── layout_tabs1.xml │ └── pull_to_refresh_header_vertical.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── doc └── README.md ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties ├── mhvp-core ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── culiu │ │ └── mhvp │ │ └── core │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── culiu │ │ └── mhvp │ │ └── core │ │ ├── InnerListView.java │ │ ├── InnerScrollView.java │ │ ├── InnerScroller.java │ │ ├── InnerScrollerContainer.java │ │ ├── MagicHeaderUtils.java │ │ ├── MagicHeaderViewPager.java │ │ ├── OuterPagerAdapter.java │ │ ├── OuterScroller.java │ │ ├── ScrollableViewPager.java │ │ ├── layout │ │ ├── SizeSensitiveLinearLayout.java │ │ └── TranslatableLinearLayout.java │ │ ├── specialview │ │ └── InnerSpecialViewHelper.java │ │ ├── tabs │ │ ├── GridViewWithHeaderBaseAdapter.java │ │ └── com │ │ │ └── astuetz │ │ │ └── PagerSlidingTabStrip.java │ │ └── util │ │ └── IntegerVariable.java │ └── res │ ├── drawable │ └── background_tab.xml │ ├── layout │ └── mhvp_layout.xml │ └── values │ ├── colors.xml │ ├── ids.xml │ ├── psts_attr.xml │ └── strings.xml ├── mhvp-integrated-ptr ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── culiu │ │ └── mhvp │ │ └── integrated │ │ └── ptr │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── culiu │ │ └── mhvp │ │ └── integrated │ │ └── ptr │ │ ├── PullToRefreshInnerListView.java │ │ ├── PullToRefreshInnerScrollView.java │ │ └── pulltorefresh │ │ ├── ILoadingLayout.java │ │ ├── IPullToRefresh.java │ │ ├── LoadingLayoutProxy.java │ │ ├── OverscrollHelper.java │ │ ├── PullToRefreshAdapterViewBase.java │ │ ├── PullToRefreshBase.java │ │ └── internal │ │ ├── EmptyViewMethodAccessor.java │ │ ├── FlipLoadingLayout.java │ │ ├── IndicatorLayout.java │ │ ├── LoadingLayout.java │ │ ├── RotateLoadingLayout.java │ │ ├── Utils.java │ │ └── ViewCompat.java │ └── res │ ├── anim │ ├── slide_in_from_bottom.xml │ ├── slide_in_from_top.xml │ ├── slide_out_to_bottom.xml │ └── slide_out_to_top.xml │ ├── drawable-xhdpi │ ├── default_ptr_flip.png │ └── default_ptr_rotate.png │ ├── drawable │ ├── indicator_bg_bottom.xml │ └── indicator_bg_top.xml │ ├── layout │ └── default_pull_to_refresh_header_vertical.xml │ └── values │ ├── dimens.xml │ ├── ids.xml │ ├── ptr_arrays.xml │ ├── ptr_attr.xml │ └── strings.xml ├── pics ├── 1.gif ├── 2.gif ├── 3.gif ├── 4.gif ├── 5.gif ├── 6.gif ├── 7.gif └── 8.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | #built application files 2 | #*.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | #local.properties 17 | 18 | # Windows thumbnail db 19 | Thumbs.db 20 | 21 | # OSX files 22 | .DS_Store 23 | 24 | # Eclipse project files 25 | .classpath 26 | .project 27 | 28 | # Android Studio 29 | *.iml 30 | .idea 31 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 32 | .gradle 33 | build/ 34 | /captures 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | This project is archived. 3 | 4 | # MagicHeaderViewPager 5 | HeaderViewPager with a header can be fixed and many scrollable Fragments (listFragments, gridFragments and ScrollFragments) inside. 6 | 7 | # Introduction 8 | ### 0. Example 9 | **0.1、Simply immobilizing tabs and keeping locaiton** 10 | 11 | ![](https://raw.githubusercontent.com/XavierSAndroid/MagicHeaderViewPager/master/pics/1.gif) 12 |
13 |
14 | 15 | **0.2、Support large Header taller than screen** 16 | 17 | ![](https://raw.githubusercontent.com/XavierSAndroid/MagicHeaderViewPager/master/pics/2.gif) 18 |
19 |
20 | 21 | **0.3、Support Mixed ListView items and their heights need not be the same** 22 | 23 | ![](https://raw.githubusercontent.com/XavierSAndroid/MagicHeaderViewPager/master/pics/3.gif) 24 |
25 |
26 | 27 | **0.4、Combined with pull to refresh** 28 | 29 | ![](https://raw.githubusercontent.com/XavierSAndroid/MagicHeaderViewPager/master/pics/4.gif) 30 |
31 |
32 | 33 | **0.5、Magic header can be drag down as you like. The header and inner ListView(ScrollView) can respond touch respctively** 34 | 35 | ![](https://raw.githubusercontent.com/XavierSAndroid/MagicHeaderViewPager/master/pics/5.gif) 36 |
37 |
38 | 39 | **0.6、Inner Scroller(ListView、GridView、ScrollView) can be scrolled even if content is null, and the empty content can be customized to improve user experience** 40 | 41 | ![](https://raw.githubusercontent.com/XavierSAndroid/MagicHeaderViewPager/master/pics/6.gif) 42 |
43 |
44 | 45 | **0.7、Dispatch touch event as expected** 46 | 47 | ![](https://raw.githubusercontent.com/XavierSAndroid/MagicHeaderViewPager/master/pics/7.gif) 48 |
49 |
50 | 51 | **0.8、Example of height auto completion: empty content colored green, and auto completion colored blue** 52 | 53 | ![](https://raw.githubusercontent.com/XavierSAndroid/MagicHeaderViewPager/master/pics/8.gif) 54 |
55 |
56 | 57 | ### 1. Dependency 58 | 59 | Add the following lines to your build.gradle for pure MagicHeaderViewPager. 60 | ```Java 61 | dependencies { 62 | compile 'com.culiu.android:mhvp-core:2.1.2@aar' 63 | } 64 | ``` 65 | 66 | For using integrated Pull-To-Refresh: 67 | ```Java 68 | dependencies { 69 | compile 'com.culiu.android:mhvp-core:2.1.2@aar' 70 | compile 'com.culiu.android:mhvp-integrated-ptr:2.1.2@aar' 71 | } 72 | ``` 73 | 74 | For more details, see [Guide](https://github.com/XavierSAndroid/MagicHeaderViewPager/tree/master/doc) or [Demo](https://github.com/XavierSAndroid/MagicHeaderViewPager/tree/master/demo). 75 | 76 | # Developed By 77 | 78 | * Xavier S -   79 | * https://github.com/XavierSAndroid   https://github.com/CuliuDev 80 | 81 | # License 82 | 83 | Copyright (c) 2015 [Xavier-S](mailto:X.S.Xavier.S@gmail.com) 84 | 85 | Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) 86 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.0.0-alpha1' 9 | 10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' 11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /demo/MagicHeaderViewPager_demo.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/MagicHeaderViewPager_demo.jks -------------------------------------------------------------------------------- /demo/apk/MagicHeaderViewPager_demo_1.0.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/apk/MagicHeaderViewPager_demo_1.0.apk -------------------------------------------------------------------------------- /demo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | android { 3 | compileSdkVersion 21 4 | buildToolsVersion '23.0.2' 5 | 6 | defaultConfig { 7 | applicationId "com.culiu.mhvp" 8 | minSdkVersion 7 9 | targetSdkVersion 21 10 | versionCode 57 11 | versionName "3.3" 12 | } 13 | 14 | signingConfigs { 15 | myConfig { 16 | storeFile file("MagicHeaderViewPager_demo.jks") 17 | storePassword "123456" 18 | keyAlias "com.culiu.mhvp" 19 | keyPassword "123456" 20 | } 21 | } 22 | 23 | buildTypes { 24 | release { 25 | signingConfig signingConfigs.myConfig 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | 31 | lintOptions { 32 | abortOnError false 33 | } 34 | 35 | } 36 | task clearApk(type: Delete) { 37 | delete '../apk/' + POM_ARTIFACT_ID + '_' + VERSION_NAME + '.apk' 38 | } 39 | task makeApk(type: Copy) { 40 | from('build/outputs/apk/') 41 | into('apk/') 42 | include("demo-release.apk") 43 | rename("demo-release.apk", POM_ARTIFACT_ID + '_' + VERSION_NAME + '.apk') 44 | } 45 | makeApk.dependsOn(clearApk, build) 46 | 47 | // local dependencies 48 | dependencies { 49 | compile project(':mhvp-integrated-ptr') 50 | } 51 | 52 | // remote dependencies 53 | //dependencies { 54 | // compile 'com.android.support:support-v4:21.0.3' 55 | // compile 'com.culiu.android:mhvp-core:2.1.2@aar' 56 | // compile 'com.culiu.android:mhvp-integrated-ptr:2.1.2@aar' 57 | //} -------------------------------------------------------------------------------- /demo/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=MagicHeaderViewPager 2 | VERSION_NAME=demo_1.0 -------------------------------------------------------------------------------- /demo/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 /Applications/eclipse-ADT/android-sdk-macosxs/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 | -------------------------------------------------------------------------------- /demo/src/androidTest/java/com/culiu/mhvp/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/APP.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | /** 7 | * @author Xavier-S 8 | * @date 2015.11.27 20:09 9 | */ 10 | public class APP extends Application { 11 | 12 | private static APP mApplication; 13 | 14 | private static Context mApplicationContext; 15 | 16 | @Override 17 | public void onCreate() { 18 | super.onCreate(); 19 | synchronized(APP.this) { 20 | mApplicationContext = getApplicationContext(); 21 | mApplication = this; 22 | } 23 | } 24 | 25 | @Override 26 | public Context getApplicationContext() { 27 | return mApplicationContext; 28 | } 29 | 30 | public static APP getInstance() { 31 | return mApplication; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/AbsDemoFragment.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.app.Activity; 4 | import android.os.Handler; 5 | import android.support.v4.app.Fragment; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.LinearLayout; 10 | 11 | import com.culiu.mhvp.R; 12 | import com.culiu.mhvp.core.InnerScrollerContainer; 13 | import com.culiu.mhvp.core.OuterScroller; 14 | import com.culiu.mhvp.integrated.ptr.pulltorefresh.PullToRefreshBase; 15 | 16 | /** 17 | * @author Xavier-S 18 | * 19 | * Extracted codes for demo. In you practice, there's no need to 20 | * create an AbsFragment to extend it. Just let your fragment 21 | * implement InnerScrollerContainer. It's ok and good enough. 22 | * 23 | * @date 2015.11.12 11:20 24 | */ 25 | public abstract class AbsDemoFragment extends Fragment implements InnerScrollerContainer, PullToRefreshBase.OnRefreshListener2 { 26 | 27 | /************* InnerScrollerContainer interface **************/ 28 | 29 | protected OuterScroller mOuterScroller; 30 | protected int mIndex; 31 | @Override 32 | public void setOuterScroller(OuterScroller outerScroller, int myPosition) { 33 | if(outerScroller == mOuterScroller && myPosition == mIndex) { 34 | return; 35 | } 36 | mOuterScroller = outerScroller; 37 | mIndex = myPosition; 38 | 39 | if(getInnerScroller() != null) { 40 | getInnerScroller().register2Outer(mOuterScroller, mIndex); 41 | } 42 | } 43 | /************* InnerScrollerContainer interface End **************/ 44 | 45 | 46 | 47 | /****************************** Test code ******************************/ 48 | /** 49 | * Emulate http asynchronous loading 50 | */ 51 | protected void requestData() { 52 | new Handler().postDelayed(new Runnable() { 53 | @Override 54 | public void run() { 55 | onResponse(); 56 | } 57 | }, 1500); 58 | } 59 | 60 | public abstract void onResponse(); 61 | 62 | @Override 63 | public void onAttach(Activity activity) { 64 | super.onAttach(activity); 65 | } 66 | 67 | /** 68 | * After pull to refresh, add a random picture 69 | */ 70 | public View addRandomPic() { 71 | 72 | ImageView iv = new ImageView(getActivity()); 73 | iv.setScaleType(ImageView.ScaleType.FIT_XY); 74 | iv.setImageResource(RandomPic.getInstance().getPicResId()); 75 | iv.setAdjustViewBounds(true); 76 | 77 | LinearLayout.LayoutParams lpIv = new LinearLayout.LayoutParams( 78 | LinearLayout.LayoutParams.MATCH_PARENT, 79 | ViewGroup.LayoutParams.WRAP_CONTENT 80 | ); 81 | 82 | LinearLayout ll = new LinearLayout(getActivity()); 83 | ll.addView(iv, lpIv); 84 | getInnerScroller().addHeaderView(ll); 85 | 86 | return ll; 87 | } 88 | 89 | View tempChild = null; 90 | 91 | @Override 92 | public void onPullDownToRefresh(PullToRefreshBase refreshView) { 93 | // Update the whole state, and forbidden touch 94 | getInnerScroller().onRefresh(true); 95 | 96 | new Handler().postDelayed(new Runnable() { 97 | @Override 98 | public void run() { 99 | // Return to normal state 100 | getInnerScroller().onRefresh(false); 101 | // Test code 102 | switch (WelcomeActivity.demoType) { 103 | case Pull_to_add_Magic_Header_Mixed: 104 | case Pull_to_add_Magic_Header_Mixed_Complicated_header: 105 | if (getActivity() instanceof DemoActivity) { 106 | ((DemoActivity) getActivity()).addRandomPic(); 107 | } 108 | break; 109 | case Pull_to_add_Inner_Header_Mixed: 110 | addRandomPic(); 111 | break; 112 | default: 113 | // nothing 114 | break; 115 | } 116 | if (getInnerScroller().getReceiveView() instanceof PullToRefreshBase) { 117 | ((PullToRefreshBase)getInnerScroller().getReceiveView()).onRefreshComplete(); 118 | } 119 | } 120 | }, 2000); 121 | } 122 | 123 | @Override 124 | public void onPullUpToRefresh(PullToRefreshBase refreshView) { 125 | } 126 | /****************************** Test code End ******************************/ 127 | } 128 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/DemoActivity.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.graphics.Color; 4 | import android.graphics.drawable.Drawable; 5 | import android.os.Bundle; 6 | import android.support.v4.app.FragmentActivity; 7 | import android.support.v4.view.ViewPager; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Button; 12 | import android.widget.HorizontalScrollView; 13 | import android.widget.ImageView; 14 | import android.widget.LinearLayout; 15 | import android.widget.Toast; 16 | 17 | import com.culiu.mhvp.R; 18 | import com.culiu.mhvp.core.MagicHeaderUtils; 19 | import com.culiu.mhvp.core.MagicHeaderViewPager; 20 | import com.culiu.mhvp.core.tabs.com.astuetz.PagerSlidingTabStrip; 21 | 22 | public class DemoActivity extends FragmentActivity { 23 | 24 | public static final String TAG = "sz[mhvp-demo]"; 25 | 26 | private MagicHeaderViewPager mMagicHeaderViewPager; 27 | private DemoPagerAdapter mPagerAdapter; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_mhvp_demo); 33 | 34 | 35 | /* TODO: Initialize MagicHeaderViewPager. Override initTabsArea() to initialize tabs or stable area. */ 36 | mMagicHeaderViewPager = new MagicHeaderViewPager(this) { 37 | @Override 38 | protected void initTabsArea(LinearLayout container) { 39 | //You can customize your tabStrip or stable area here 40 | ViewGroup tabsArea = (ViewGroup) LayoutInflater.from(DemoActivity.this).inflate(R.layout.layout_tabs1, null); 41 | 42 | // TODO: Set height of stable area manually, then it can be calculated. 43 | LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 44 | MagicHeaderUtils.dp2px(DemoActivity.this, 48)); 45 | container.addView(tabsArea, lp); 46 | 47 | // some style 48 | PagerSlidingTabStrip pagerSlidingTabStrip = (PagerSlidingTabStrip) tabsArea.findViewById(R.id.tabs); 49 | pagerSlidingTabStrip.setTextColor(Color.BLACK); 50 | pagerSlidingTabStrip.setBackgroundColor(Color.WHITE); 51 | 52 | // TODO: These two methods must be called to let magicHeaderViewPager know who is stable area and tabs. 53 | setTabsArea(tabsArea); 54 | setPagerSlidingTabStrip(pagerSlidingTabStrip); 55 | } 56 | }; 57 | // Note: Cuz tabs or stable area of each ViewPager may not 58 | // the same. So it's abstract for developers to override. 59 | 60 | //TODO: Just add MagicHeaderViewPager into your Layout. MATCH_PARENT-MATCH_PARENT is recommended. 61 | LinearLayout mhvpParent = (LinearLayout) findViewById(R.id.mhvp_parent); 62 | LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( 63 | LinearLayout.LayoutParams.MATCH_PARENT, 64 | LinearLayout.LayoutParams.MATCH_PARENT 65 | ); 66 | mhvpParent.addView(mMagicHeaderViewPager, lp); 67 | 68 | // TODO: Use an OuterPagerAdapter as FragmentPagerAdapter 69 | mPagerAdapter = new DemoPagerAdapter(getSupportFragmentManager()); 70 | 71 | // TODO: Use this method instead of those of PagerSlidingTabStrip or ViewPager. 72 | mMagicHeaderViewPager.setPagerAdapter(mPagerAdapter); 73 | 74 | // call this if needed 75 | mMagicHeaderViewPager.setTabOnPageChangeListener(new ViewPager.OnPageChangeListener() { 76 | @Override 77 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 78 | } 79 | 80 | @Override 81 | public void onPageSelected(int position) { 82 | } 83 | 84 | @Override 85 | public void onPageScrollStateChanged(int state) { 86 | } 87 | }); 88 | 89 | // Then you can do anything like before:) 90 | 91 | // add your custom Header content 92 | initCustomHeader(); 93 | 94 | } 95 | 96 | 97 | /************************************************************ 98 | **** Test code **** 99 | ************************************************************/ 100 | 101 | private void initCustomHeader() { 102 | if (WelcomeActivity.demoType != DemoConfig.DemoType.Pull_to_add_Magic_Header_Mixed_Complicated_header) { 103 | // Simply add a picture 104 | addRandomPic(); 105 | } else { 106 | // Example: add a custom Layout 107 | 108 | View customLayout = LayoutInflater.from(this).inflate(R.layout.header_custom_layout, null); 109 | Button btn = ((Button) customLayout.findViewById(R.id.button)); 110 | btn.setOnClickListener(new View.OnClickListener() { 111 | @Override 112 | public void onClick(View v) { 113 | Toast.makeText(DemoActivity.this, "btn Clicked", Toast.LENGTH_SHORT).show(); 114 | } 115 | }); 116 | mMagicHeaderViewPager.addHeaderView(customLayout); 117 | 118 | HorizontalScrollView sv = new HorizontalScrollView(this); 119 | LinearLayout ll = new LinearLayout(this); 120 | ll.setOrientation(LinearLayout.HORIZONTAL); 121 | for (int i = 5; i > 0; i--) { 122 | ImageView iv = new ImageView(this); 123 | iv.setScaleType(ImageView.ScaleType.FIT_XY); 124 | iv.setImageResource(RandomPic.getInstance().getPicResId()); 125 | ll.addView(iv, new LinearLayout.LayoutParams(MagicHeaderUtils.getScreenWidth(this), (int) (MagicHeaderUtils.getScreenWidth(this)*.66f))); 126 | } 127 | sv.addView(ll, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 128 | mMagicHeaderViewPager.addHeaderView(sv); 129 | } 130 | } 131 | 132 | /** 133 | * Add a random picture 134 | */ 135 | public void addRandomPic() { 136 | ImageView iv = new ImageView(this); 137 | iv.setScaleType(ImageView.ScaleType.FIT_XY); 138 | Drawable drawable = getResources().getDrawable(RandomPic.getInstance().getPicResId()); 139 | iv.setImageDrawable(drawable); 140 | int height = MagicHeaderUtils.getHeightWhenFullWidth(this, drawable); 141 | mMagicHeaderViewPager.addHeaderView(iv, height); 142 | } 143 | 144 | /************************************************************ 145 | **** Test code End **** 146 | ************************************************************/ 147 | } 148 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/DemoConfig.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.graphics.Color; 4 | 5 | import com.culiu.mhvp.R; 6 | 7 | /** 8 | * @author Xavier-S 9 | * @date 2015.11.19 11:55 10 | */ 11 | public interface DemoConfig { 12 | 13 | /** 14 | * Demo子页面对应的类型 15 | */ 16 | enum DemoType { 17 | Only_ListView, 18 | Only_Scrollview, Only_GridView, Not_Pullable_Mixed, 19 | Pull_to_add_Inner_Header_Mixed, Pull_to_add_Magic_Header_Mixed, 20 | Pull_to_add_Magic_Header_Mixed_Complicated_header 21 | } 22 | 23 | 24 | /** 25 | * 用配色帮助理解 26 | */ 27 | boolean ENABLE_COLOR = true; 28 | 29 | /** 30 | * 空白内容的颜色 31 | */ 32 | int COLOR_EMPTY_CONTENT = Color.TRANSPARENT; 33 | 34 | /** 35 | * 自动补全(内容)的颜色 36 | */ 37 | int COLOR_CONTENT_AUTO_COMPLETION = Color.TRANSPARENT; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/DemoGridFragment.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | 9 | import com.culiu.mhvp.R; 10 | import com.culiu.mhvp.core.MagicHeaderUtils; 11 | import com.culiu.mhvp.core.tabs.GridViewWithHeaderBaseAdapter; 12 | 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Created by Xavier-S on 15/7/23. 17 | */ 18 | public class DemoGridFragment extends DemoListFragment { 19 | 20 | /** 21 | * Using LinearLayout in ListView items to realize 22 | * gridView result. 23 | */ 24 | protected void initAdapter() { 25 | if (mListItems == null) { 26 | mListItems = new ArrayList(); 27 | } 28 | mAdapter = new GridViewWithHeaderBaseAdapter(getActivity()) { 29 | @Override 30 | protected void setPaddingAndMargin(View leftView, View rightView, int culumn) { 31 | super.setPaddingAndMargin(leftView, rightView, culumn); 32 | int _5dp = MagicHeaderUtils.dp2px(getActivity(), 5f); 33 | leftView.setPadding(_5dp, 0, _5dp / 2, 0); 34 | rightView.setPadding(_5dp / 2, 0, _5dp, 0); 35 | } 36 | 37 | @Override 38 | public int getItemCount() { 39 | return mListItems.size(); 40 | } 41 | 42 | @Override 43 | protected View getItemView(int position, View convertView, ViewGroup parent) { 44 | if (convertView == null) { 45 | convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_grid_fragment, null); 46 | } 47 | ImageView iv = (ImageView) convertView.findViewById(R.id.iv); 48 | TextView tv = (TextView) convertView.findViewById(R.id.tv); 49 | iv.setImageResource(getItem(position).getDrawableResId()); 50 | tv.setText(getItem(position).getTitle()); 51 | return convertView; 52 | } 53 | 54 | @Override 55 | public Item getItem(int position) { 56 | return mListItems.get(position); 57 | } 58 | 59 | @Override 60 | public long getItemId(int position) { 61 | return 0; 62 | } 63 | }; 64 | ((GridViewWithHeaderBaseAdapter) mAdapter).setNumColumns(2); 65 | mListView.setAdapter(mAdapter); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/DemoListFragment.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.graphics.Color; 4 | import android.graphics.drawable.ColorDrawable; 5 | import android.os.Bundle; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.BaseAdapter; 10 | import android.widget.ImageView; 11 | import android.widget.LinearLayout; 12 | import android.widget.TextView; 13 | 14 | import com.culiu.mhvp.R; 15 | import com.culiu.mhvp.core.InnerListView; 16 | import com.culiu.mhvp.core.InnerScroller; 17 | import com.culiu.mhvp.core.MagicHeaderUtils; 18 | 19 | import java.util.ArrayList; 20 | 21 | /** 22 | * Created by Xavier-S on 15/7/23. 23 | */ 24 | public class DemoListFragment extends AbsDemoFragment { 25 | 26 | /************* InnerScrollerContainer interface **************/ 27 | protected InnerListView mListView; 28 | 29 | /** 30 | * TODO: make sure through this method, can get your InnerScroller(InnerListView) in your fragment. 31 | * @return 32 | */ 33 | @Override 34 | public InnerScroller getInnerScroller() { 35 | return mListView; 36 | } 37 | 38 | @Override 39 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 40 | if (mListView != null && viewThis != null) { 41 | if (viewThis.getParent() != null) { 42 | ((ViewGroup) viewThis.getParent()).removeView(viewThis); 43 | } 44 | return viewThis; 45 | } 46 | viewThis = inflater.inflate(R.layout.fragment_list, null); 47 | 48 | // TODO: Be sure have put PullToRefreshInnerListView or InnerListView in your layout and its height match parent or align parent's top. 49 | mListView = (InnerListView) viewThis.findViewById(R.id.listView); 50 | 51 | mListView.setSelector(new ColorDrawable(Color.TRANSPARENT)); 52 | mListView.setDividerHeight(0); 53 | 54 | // TODO: Every time listView initialized, don't forget to call registerToOuter. 55 | mListView.register2Outer(mOuterScroller, mIndex); 56 | 57 | // Demo: Use color to mark special areas. 58 | if(DemoConfig.ENABLE_COLOR) { 59 | // Optional: Customize empty content 60 | View colorView = new View(getActivity()); 61 | colorView.setBackgroundColor(DemoConfig.COLOR_EMPTY_CONTENT); 62 | mListView.setCustomEmptyView(colorView); 63 | mListView.setCustomEmptyViewHeight(ViewGroup.LayoutParams.MATCH_PARENT, 0); 64 | 65 | // Demo: color its auto completion area 66 | mListView.setContentAutoCompletionColor(DemoConfig.COLOR_CONTENT_AUTO_COMPLETION); 67 | } 68 | 69 | // Two ways to load data: 1. initAdapter(); then notifyDataSetChanged(); 2. requestData(); then initAdapter(); 70 | // demonstrate the 2nd way 71 | requestData(); 72 | 73 | return viewThis; 74 | } 75 | 76 | /************* InnerScrollerContainer interface End **************/ 77 | 78 | 79 | /*********************** Test data ***********************/ 80 | 81 | protected ArrayList mListItems; 82 | 83 | public class Item { 84 | private String title; 85 | private int drawableResId; 86 | 87 | public Item(String title, int drawableResId) { 88 | this.title = title; 89 | this.drawableResId = drawableResId; 90 | } 91 | 92 | public String getTitle() { 93 | return title; 94 | } 95 | 96 | public void setTitle(String title) { 97 | this.title = title; 98 | } 99 | 100 | public int getDrawableResId() { 101 | return drawableResId; 102 | } 103 | 104 | public void setDrawableResId(int drawableResId) { 105 | this.drawableResId = drawableResId; 106 | } 107 | } 108 | 109 | 110 | protected BaseAdapter mAdapter; 111 | 112 | @Override 113 | public void onCreate(Bundle savedInstanceState) { 114 | super.onCreate(savedInstanceState); 115 | } 116 | 117 | public void onResponse() { 118 | if(getActivity() == null || getActivity().isFinishing()) { 119 | return; 120 | } 121 | 122 | if (mListItems == null) { 123 | mListItems = new ArrayList(); 124 | } 125 | for (int i = 1; i <= 15; i++) { 126 | mListItems.add(new Item("list: " + (mIndex + 1) + "'s item " + i, RandomPic.getInstance().getPicResId())); 127 | } 128 | 129 | initAdapter(); 130 | } 131 | 132 | 133 | protected void initAdapter() { 134 | if (mListItems == null) { 135 | mListItems = new ArrayList(); 136 | } 137 | 138 | mAdapter = new BaseAdapter( 139 | 140 | ) { 141 | @Override 142 | public int getCount() { 143 | return mListItems.size(); 144 | } 145 | 146 | @Override 147 | public Item getItem(int position) { 148 | return mListItems.get(position); 149 | } 150 | 151 | @Override 152 | public long getItemId(int position) { 153 | return 0; 154 | } 155 | 156 | int picHeight = (int) (MagicHeaderUtils.getScreenWidth(getActivity()) * 0.68f); 157 | 158 | @Override 159 | public View getView(int position, View convertView, ViewGroup parent) { 160 | if (convertView == null) { 161 | convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_list_fragment, null); 162 | } 163 | ImageView iv = (ImageView) convertView.findViewById(R.id.iv); 164 | TextView tv = (TextView) convertView.findViewById(R.id.tv); 165 | iv.setImageResource(mListItems.get(position).getDrawableResId()); 166 | tv.setText(getItem(position).getTitle()); 167 | 168 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) iv.getLayoutParams(); 169 | if (lp.height != picHeight) { 170 | lp.height = picHeight; 171 | iv.setLayoutParams(lp); 172 | } 173 | 174 | return convertView; 175 | } 176 | }; 177 | mListView.setAdapter(mAdapter); 178 | } 179 | 180 | protected View viewThis; 181 | } 182 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/DemoPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | import android.view.ViewGroup; 7 | 8 | import com.culiu.mhvp.core.InnerScrollerContainer; 9 | import com.culiu.mhvp.core.OuterPagerAdapter; 10 | import com.culiu.mhvp.core.OuterScroller; 11 | 12 | /** 13 | * @author Xavier-S 14 | * @date 2015.10.08 20:33 15 | */ 16 | public class DemoPagerAdapter extends FragmentPagerAdapter implements OuterPagerAdapter{ 17 | 18 | 19 | /**** OuterPagerAdapter methods ****/ 20 | private OuterScroller mOuterScroller; 21 | 22 | @Override 23 | public void setOuterScroller(OuterScroller outerScroller) { 24 | mOuterScroller = outerScroller; 25 | } 26 | 27 | @Override 28 | public Object instantiateItem(ViewGroup container, int position) { 29 | // TODO: Make sure to put codes below in your PagerAdapter's instantiateItem() 30 | // cuz Fragment has some weird life cycle. 31 | InnerScrollerContainer fragment = 32 | (InnerScrollerContainer) super.instantiateItem(container, position); 33 | 34 | if (null != mOuterScroller) { 35 | fragment.setOuterScroller(mOuterScroller, position); 36 | } 37 | return fragment; 38 | } 39 | /**** OuterPagerAdapter methods End ****/ 40 | 41 | 42 | /************************ Test data *********************/ 43 | public DemoPagerAdapter(FragmentManager fm) { 44 | super(fm); 45 | } 46 | 47 | protected CharSequence[] mTitles = {"page 1", "page 2", "page 3", "page 4"/*, "page 5", "page 6"*/}; 48 | 49 | @Override 50 | public CharSequence getPageTitle(int position) { 51 | return mTitles[position]; 52 | } 53 | 54 | @Override 55 | public int getCount() { 56 | return mTitles.length; 57 | } 58 | 59 | @Override 60 | public final Fragment getItem(int position) { 61 | Fragment fragment; 62 | 63 | switch (WelcomeActivity.demoType) { 64 | case Only_ListView: 65 | fragment = new DemoListFragment(); 66 | break; 67 | case Only_GridView: 68 | fragment = new DemoGridFragment(); 69 | break; 70 | case Only_Scrollview: 71 | fragment = new DemoScrollFragment(); 72 | break; 73 | case Not_Pullable_Mixed: 74 | fragment = getMixedFragment(position); 75 | break; 76 | case Pull_to_add_Inner_Header_Mixed: 77 | case Pull_to_add_Magic_Header_Mixed: 78 | case Pull_to_add_Magic_Header_Mixed_Complicated_header: 79 | fragment = getMixedPullableFragment(position); 80 | break; 81 | default: 82 | fragment = new DemoGridFragment(); 83 | break; 84 | } 85 | return fragment; 86 | } 87 | 88 | private Fragment getMixedFragment(int position) { 89 | switch (position % 3) { 90 | case 0: 91 | return new DemoListFragment(); 92 | case 1: 93 | return new DemoGridFragment(); 94 | case 2: 95 | return new DemoScrollFragment(); 96 | default: 97 | return new DemoGridFragment(); 98 | } 99 | } 100 | 101 | private Fragment getMixedPullableFragment(int position) { 102 | switch (position % 3) { 103 | case 0: 104 | return new DemoPullToRefreshListFragment(); 105 | case 1: 106 | return new DemoPullToRefreshScrollFragment(); 107 | case 2: 108 | return new DemoPullToRefreshGridFragment(); 109 | default: 110 | return new DemoPullToRefreshGridFragment(); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/DemoPullToRefreshGridFragment.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | 9 | import com.culiu.mhvp.R; 10 | import com.culiu.mhvp.core.MagicHeaderUtils; 11 | import com.culiu.mhvp.core.tabs.GridViewWithHeaderBaseAdapter; 12 | 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Created by Xavier-S on 15/7/23. 17 | */ 18 | public class DemoPullToRefreshGridFragment extends DemoPullToRefreshListFragment { 19 | 20 | protected void initAdapter() { 21 | if (mListItems == null) { 22 | mListItems = new ArrayList(); 23 | } 24 | 25 | /** 26 | * Using LinearLayout in ListView items to realize 27 | * gridView result. 28 | */ 29 | mAdapter = new GridViewWithHeaderBaseAdapter(getActivity()) { 30 | 31 | @Override 32 | protected void setPaddingAndMargin(View leftView, View rightView, int culumn) { 33 | super.setPaddingAndMargin(leftView, rightView, culumn); 34 | int _5dp = MagicHeaderUtils.dp2px(getActivity(), 5f); 35 | leftView.setPadding(_5dp, 0, _5dp / 2, 0); 36 | rightView.setPadding(_5dp / 2, 0, _5dp, 0); 37 | } 38 | 39 | @Override 40 | public int getItemCount() { 41 | return mListItems.size(); 42 | } 43 | 44 | @Override 45 | protected View getItemView(int position, View convertView, ViewGroup parent) { 46 | if (convertView == null) { 47 | convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_grid_fragment, null); 48 | } 49 | ImageView iv = (ImageView) convertView.findViewById(R.id.iv); 50 | TextView tv = (TextView) convertView.findViewById(R.id.tv); 51 | iv.setImageResource(mListItems.get(position).getDrawableResId()); 52 | tv.setText(getItem(position).getTitle()); 53 | return convertView; 54 | } 55 | 56 | @Override 57 | public Item getItem(int position) { 58 | return mListItems.get(position); 59 | } 60 | 61 | @Override 62 | public long getItemId(int position) { 63 | return 0; 64 | } 65 | }; 66 | ((GridViewWithHeaderBaseAdapter) mAdapter).setNumColumns(2); 67 | mListView.setAdapter(mAdapter); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/DemoPullToRefreshListFragment.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.graphics.Color; 4 | import android.graphics.drawable.ColorDrawable; 5 | import android.os.Bundle; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.BaseAdapter; 10 | import android.widget.ImageView; 11 | import android.widget.LinearLayout; 12 | import android.widget.TextView; 13 | 14 | import com.culiu.mhvp.R; 15 | import com.culiu.mhvp.core.MagicHeaderUtils; 16 | import com.culiu.mhvp.integrated.ptr.PullToRefreshInnerListView; 17 | 18 | import java.util.ArrayList; 19 | 20 | /** 21 | * Created by Xavier-S on 15/7/23. 22 | */ 23 | public class DemoPullToRefreshListFragment extends DemoListFragment { 24 | 25 | public static final String TAG = "sz[InnerPullToRefresh]"; 26 | 27 | protected PullToRefreshInnerListView mPullToRefreshListView; 28 | 29 | @Override 30 | public void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | } 33 | 34 | protected View viewThis; 35 | 36 | @Override 37 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 38 | if (mListView != null && viewThis != null) { 39 | if (viewThis.getParent() != null) { 40 | ((ViewGroup) viewThis.getParent()).removeView(viewThis); 41 | } 42 | return viewThis; 43 | } 44 | viewThis = inflater.inflate(R.layout.fragment_pulltorefresh_list, null); 45 | 46 | // TODO: Be sure have put PullToRefreshInnerListView or InnerListView in your layout and its height match parent or align parent's top. 47 | mPullToRefreshListView = (PullToRefreshInnerListView) viewThis.findViewById(R.id.pull_refresh_inner_listview); 48 | 49 | // Set refreshing scale. You may change it or delete it if needed. 50 | mPullToRefreshListView.setScaleRefreshing(0.568f); 51 | 52 | if(mPullToRefreshListView!=null) { 53 | mPullToRefreshListView.setOnRefreshListener(this); 54 | } 55 | 56 | mListView = mPullToRefreshListView.getRefreshableView(); 57 | 58 | mListView.setSelector(new ColorDrawable(Color.TRANSPARENT)); 59 | mListView.setDividerHeight(0); 60 | 61 | // TODO: Every time listView initialized, don't forget to call registerToOuter. 62 | mListView.register2Outer(mOuterScroller, mIndex); 63 | 64 | // Demo: Use color to mark special areas. 65 | if(DemoConfig.ENABLE_COLOR) { 66 | // Optional: Customize empty content 67 | View colorView = new View(getActivity()); 68 | colorView.setBackgroundColor(DemoConfig.COLOR_EMPTY_CONTENT); 69 | mListView.setCustomEmptyView(colorView); 70 | mListView.setCustomEmptyViewHeight(ViewGroup.LayoutParams.MATCH_PARENT, -1000); 71 | 72 | // Demo: color its auto completion area 73 | mListView.setContentAutoCompletionColor(DemoConfig.COLOR_CONTENT_AUTO_COMPLETION); 74 | } 75 | 76 | // Two ways to load data: 1. initAdapter(); then notifyDataSetChanged(); 2. requestData(); then initAdapter(); 77 | // demonstrate the 2nd way 78 | requestData(); 79 | 80 | return viewThis; 81 | } 82 | 83 | /************* InnerScrollerContainer interface End **************/ 84 | 85 | 86 | /*********************** Test data ***********************/ 87 | 88 | protected void initAdapter() { 89 | if (mListItems == null) { 90 | mListItems = new ArrayList(); 91 | } 92 | 93 | mAdapter = new BaseAdapter( 94 | 95 | ) { 96 | @Override 97 | public int getCount() { 98 | return mListItems.size(); 99 | } 100 | 101 | @Override 102 | public Item getItem(int position) { 103 | return mListItems.get(position); 104 | } 105 | 106 | @Override 107 | public long getItemId(int position) { 108 | return 0; 109 | } 110 | 111 | int picHeight = (int) (MagicHeaderUtils.getScreenWidth(getActivity()) * 0.68f); 112 | 113 | @Override 114 | public View getView(int position, View convertView, ViewGroup parent) { 115 | if (convertView == null) { 116 | convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_list_fragment, null); 117 | } 118 | ImageView iv = (ImageView) convertView.findViewById(R.id.iv); 119 | TextView tv = (TextView) convertView.findViewById(R.id.tv); 120 | iv.setImageResource(getItem(position).getDrawableResId()); 121 | tv.setText(getItem(position).getTitle()); 122 | 123 | if (iv.getLayoutParams() != null) { 124 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) iv.getLayoutParams(); 125 | if (lp.height != picHeight) { 126 | lp.height = picHeight; 127 | iv.setLayoutParams(lp); 128 | } 129 | } 130 | return convertView; 131 | } 132 | }; 133 | mPullToRefreshListView.setAdapter(mAdapter); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/DemoPullToRefreshScrollFragment.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.os.Bundle; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import com.culiu.mhvp.R; 9 | import com.culiu.mhvp.integrated.ptr.PullToRefreshInnerScrollView; 10 | 11 | /** 12 | * @author Xavier-S 13 | * @date 2015.11.09 14:07 14 | */ 15 | public class DemoPullToRefreshScrollFragment extends DemoScrollFragment { 16 | 17 | 18 | protected PullToRefreshInnerScrollView mPullToRefreshScrollView; 19 | 20 | public static final String TAG = "sz[InnerPullToRefresh]"; 21 | 22 | @Override 23 | public void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | } 26 | 27 | protected View viewThis; 28 | 29 | 30 | @Override 31 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 32 | if (mScrollView != null && viewThis != null) { 33 | if (viewThis.getParent() != null) { 34 | ((ViewGroup) viewThis.getParent()).removeView(viewThis); 35 | } 36 | return viewThis; 37 | } 38 | viewThis = inflater.inflate(R.layout.fragment_pulltorefresh_scrollview, null); 39 | 40 | // TODO: Be sure have put PullToRefreshInnerScrollView or InnerScrollView in your layout. ensure your ListView's height match parent or align parent's top. 41 | mPullToRefreshScrollView = (PullToRefreshInnerScrollView) viewThis.findViewById(R.id.pull_refresh_inner_scrollview); 42 | 43 | // Set refreshing scale. You may change it or delete it if you need. 44 | mPullToRefreshScrollView.setScaleRefreshing(0.568f); 45 | 46 | if(mPullToRefreshScrollView!=null) { 47 | mPullToRefreshScrollView.setOnRefreshListener(this); 48 | } 49 | 50 | mScrollView = mPullToRefreshScrollView.getRefreshableView(); 51 | 52 | // TODO: Every time listView initialized, don't forget to call registerToOuter. 53 | mScrollView.register2Outer(mOuterScroller, mIndex); 54 | 55 | // Demo: Use color to mark special areas. 56 | if(DemoConfig.ENABLE_COLOR) { 57 | // Optional: Customize empty content 58 | View colorView = new View(getActivity()); 59 | colorView.setBackgroundColor(DemoConfig.COLOR_EMPTY_CONTENT); 60 | mScrollView.setCustomEmptyView(colorView); 61 | mScrollView.setCustomEmptyViewHeight(ViewGroup.LayoutParams.MATCH_PARENT, -300); 62 | 63 | // Demo: color its auto completion area 64 | mScrollView.setContentAutoCompletionColor(DemoConfig.COLOR_CONTENT_AUTO_COMPLETION); 65 | } 66 | 67 | requestData(); 68 | 69 | tempChild = addRandomPic(); 70 | 71 | return viewThis; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/DemoScrollFragment.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.LinearLayout; 10 | import android.widget.TextView; 11 | 12 | import com.culiu.mhvp.R; 13 | import com.culiu.mhvp.core.InnerScrollView; 14 | import com.culiu.mhvp.core.InnerScroller; 15 | import com.culiu.mhvp.core.MagicHeaderUtils; 16 | 17 | /** 18 | * @author Xavier-S 19 | * @date 2015.11.09 14:07 20 | */ 21 | public class DemoScrollFragment extends AbsDemoFragment { 22 | 23 | /************* InnerScrollerContainer interface **************/ 24 | protected InnerScrollView mScrollView; 25 | 26 | /** 27 | * TODO: make sure through this method, can get your InnerScroller(InnerListView) in your fragment. 28 | * @return 29 | */ 30 | @Override 31 | public InnerScroller getInnerScroller() { 32 | return mScrollView; 33 | } 34 | 35 | protected View viewThis; 36 | 37 | @Override 38 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 39 | if (mScrollView != null && viewThis != null) { 40 | if (viewThis.getParent() != null) { 41 | ((ViewGroup) viewThis.getParent()).removeView(viewThis); 42 | } 43 | return viewThis; 44 | } 45 | viewThis = inflater.inflate(R.layout.fragment_scrollview, null); 46 | 47 | // TODO: Be sure have put PullToRefreshInnerScrollView or InnerScrollView in your layout and its height match parent or align parent's top. 48 | mScrollView = (InnerScrollView) viewThis.findViewById(R.id.inner_scrollview); 49 | 50 | // TODO: Every time scrollview initialized, don't forget to call registerToOuter. 51 | mScrollView.register2Outer(mOuterScroller, mIndex); 52 | 53 | // Demo: Use color to mark special areas. 54 | if(DemoConfig.ENABLE_COLOR) { 55 | // Optional: Customize empty content 56 | View colorView = new View(getActivity()); 57 | colorView.setBackgroundColor(DemoConfig.COLOR_EMPTY_CONTENT); 58 | mScrollView.setCustomEmptyView(colorView); 59 | mScrollView.setCustomEmptyViewHeight(ViewGroup.LayoutParams.MATCH_PARENT, -300); 60 | 61 | // Demo: color its auto completion area 62 | mScrollView.setContentAutoCompletionColor(DemoConfig.COLOR_CONTENT_AUTO_COMPLETION); 63 | } 64 | 65 | requestData(); 66 | 67 | return viewThis; 68 | } 69 | 70 | /************* InnerScrollerContainer interface End **************/ 71 | 72 | 73 | /*********************** Test data ***********************/ 74 | 75 | private TextView tv; 76 | 77 | @Override 78 | public void onCreate(Bundle savedInstanceState) { 79 | super.onCreate(savedInstanceState); 80 | } 81 | 82 | public void onResponse() { 83 | 84 | if(getActivity() == null || getActivity().isFinishing()) { 85 | return; 86 | } 87 | 88 | initContent(); 89 | } 90 | 91 | 92 | LinearLayout mContentLinearLayout; 93 | 94 | private void initContent() { 95 | mScrollView.clearContent(); 96 | 97 | if (getActivity() == null) { 98 | return; 99 | } 100 | 101 | mContentLinearLayout = new LinearLayout(getActivity()); 102 | mContentLinearLayout.setOrientation(LinearLayout.VERTICAL); 103 | 104 | // picture 105 | ImageView iv = new ImageView(getActivity()); 106 | iv.setImageResource(RandomPic.getInstance().getPicResId()); 107 | iv.setAdjustViewBounds(true); 108 | int _5dp = MagicHeaderUtils.dp2px(getActivity(), 5f); 109 | iv.setPadding(_5dp, 0, _5dp, _5dp); 110 | mContentLinearLayout.addView(iv, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 111 | 112 | // Text data 113 | tv = new TextView(getActivity()); 114 | tv.setText(getString(R.string.text_3_kingdoms_chapter_1)); 115 | tv.setTextSize(20); 116 | tv.setTextColor(Color.parseColor("#2c3e50")); 117 | tv.setLineSpacing(0, 1.2f); 118 | tv.setPadding(_5dp, _5dp, _5dp, 0); 119 | mContentLinearLayout.addView(tv, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); 120 | 121 | mScrollView.setContentView(mContentLinearLayout); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/RandomPic.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | import com.culiu.mhvp.R; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | import java.util.List; 8 | import java.util.Random; 9 | 10 | /** 11 | * @author Xavier-S 12 | * @date 2015.11.27 20:02 13 | */ 14 | public class RandomPic { 15 | 16 | private RandomPic() { 17 | random = new Random(); 18 | mIntList = new ArrayList(); 19 | } 20 | 21 | public static RandomPic getInstance() { 22 | return Nested.instance; 23 | } 24 | 25 | private static class Nested { 26 | private static RandomPic instance = new RandomPic(); 27 | } 28 | 29 | /** 30 | * 获得随机drawable图片资源id 31 | * 32 | * @return 33 | */ 34 | public int getPicResId() { 35 | if (mIntList.size() == 0) { 36 | Collections.addAll(mIntList, picIds); 37 | } 38 | int index = random.nextInt(mIntList.size()); 39 | int result = mIntList.get(index); 40 | mIntList.remove(index); 41 | return result; 42 | } 43 | 44 | private Random random; 45 | private List mIntList; 46 | 47 | Integer[] picIds = new Integer[]{R.drawable.bg_1, R.drawable.bg_2, R.drawable.bg_3, R.drawable.bg_4, 48 | R.drawable.bg_5, R.drawable.bg_6, R.drawable.bg_7, R.drawable.bg_8, R.drawable.bg_9, 49 | R.drawable.bg_10, R.drawable.bg_11, R.drawable.bg_12, R.drawable.bg_13}; 50 | } 51 | -------------------------------------------------------------------------------- /demo/src/main/java/com/culiu/mhvp/demo/WelcomeActivity.java: -------------------------------------------------------------------------------- 1 | package com.culiu.mhvp.demo; 2 | 3 | 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | 9 | import com.culiu.mhvp.R; 10 | 11 | /** 12 | * Created by Xavier-S on 15/7/26. 13 | */ 14 | public class WelcomeActivity extends Activity { 15 | 16 | static DemoConfig.DemoType demoType; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | 22 | setContentView(R.layout.activity_welcome); 23 | } 24 | 25 | public void onClick(View view) { 26 | switch (view.getId()) { 27 | case R.id.btn_pure_listview: 28 | // Only ListView 29 | demoType = DemoConfig.DemoType.Only_ListView; 30 | break; 31 | case R.id.btn_pure_scrollview: 32 | // Only ScrollView 33 | demoType = DemoConfig.DemoType.Only_Scrollview; 34 | break; 35 | case R.id.btn_pure_gridview: 36 | // Only GridView 37 | demoType = DemoConfig.DemoType.Only_GridView; 38 | break; 39 | case R.id.btn_mix_innerscroller: 40 | // 混合,不可下拉刷新 41 | demoType = DemoConfig.DemoType.Not_Pullable_Mixed; 42 | break; 43 | case R.id.btn_pull_to_add_inner_header: 44 | // Mixed,pull to add an inner header 45 | demoType = DemoConfig.DemoType.Pull_to_add_Inner_Header_Mixed; 46 | break; 47 | case R.id.btn_pull_to_add_magic_header: 48 | // Mixed,pull to add an outer header (content in Magic Header) 49 | demoType = DemoConfig.DemoType.Pull_to_add_Magic_Header_Mixed; 50 | break; 51 | case R.id.btn_pull_to_add_magic_header_complicated_header: 52 | // Mixed,pull to add an outer header (content in Magic Header); header default to complicated layout 53 | demoType = DemoConfig.DemoType.Pull_to_add_Magic_Header_Mixed_Complicated_header; 54 | break; 55 | default: 56 | //nothing 57 | break; 58 | } 59 | startActivity(new Intent(this, DemoActivity.class)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_1.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_10.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_11.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_12.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_13.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_2.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_3.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_4.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_5.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_6.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_7.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_8.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/bg_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable-xxhdpi/bg_9.jpg -------------------------------------------------------------------------------- /demo/src/main/res/drawable/bg_btn_welcome.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ptr_loading_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XAVlER-S/MagicHeaderViewPager/790213fbc796e3a8d7ec97b55217e40172ebae54/demo/src/main/res/drawable/ptr_loading_bg.png -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_mhvp_demo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 12 | 13 | 20 | 21 | 30 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_welcome.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 |