├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── layout │ │ │ │ ├── fragment_fragment4.xml │ │ │ │ ├── view_toolbar.xml │ │ │ │ ├── list_test_item.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── fragment_fragment1.xml │ │ │ │ ├── fragment_fragment3.xml │ │ │ │ └── fragment_fragment2.xml │ │ │ └── values-w820dp │ │ │ │ └── dimens.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── loopeer │ │ │ └── android │ │ │ └── librarys │ │ │ └── pullswitcher │ │ │ ├── TestPagerAdapter.java │ │ │ ├── MainActivity.java │ │ │ ├── TestSwitcherAdapter.java │ │ │ ├── TestCustomFooterView.java │ │ │ ├── TestFragment2Scroll.java │ │ │ ├── TestRecyclerAdapter.java │ │ │ ├── TestFragment3ViewPager.java │ │ │ ├── TestFragment4.java │ │ │ ├── TestFragment1Recycler.java │ │ │ └── DividerItemDecoration.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── loopeer │ │ │ └── android │ │ │ └── librarys │ │ │ └── pullswitcher │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── loopeer │ │ └── android │ │ └── librarys │ │ └── pullswitcher │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── pullswitcherview ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── integers.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── strings.xml │ │ │ ├── anim │ │ │ │ ├── in_from_top.xml │ │ │ │ ├── in_from_bottom.xml │ │ │ │ ├── out_to_top.xml │ │ │ │ └── out_to_bottom.xml │ │ │ └── values-zh │ │ │ │ └── strings.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── loopeer │ │ │ │ └── android │ │ │ │ └── librarys │ │ │ │ ├── Footer.java │ │ │ │ ├── Header.java │ │ │ │ ├── SwitchListener.java │ │ │ │ ├── SwitcherHolder.java │ │ │ │ ├── HeaderFooter.java │ │ │ │ ├── SwitcherAdapter.java │ │ │ │ ├── DefaultHeader.java │ │ │ │ ├── DefaultFooter.java │ │ │ │ ├── SwitcherHolderImpl.java │ │ │ │ ├── SwitchFragmentAdapter.java │ │ │ │ ├── PullIndicator.java │ │ │ │ └── PullSwitchView.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── loopeer │ │ │ └── android │ │ │ └── librarys │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── loopeer │ │ └── android │ │ └── librarys │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── screenshot └── screenshot.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradlew.bat ├── gradlew └── README.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /pullswitcherview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':pullswitcherview' 2 | -------------------------------------------------------------------------------- /screenshot/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/PullSwitcher/HEAD/screenshot/screenshot.gif -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PullSwitcher 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/PullSwitcher/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/PullSwitcher/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/PullSwitcher/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/PullSwitcher/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/PullSwitcher/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/PullSwitcher/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /pullswitcherview/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 300 5 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/java/com/loopeer/android/librarys/Footer.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 2 | 3 | public interface Footer extends HeaderFooter { 4 | 5 | 6 | 7 | } 8 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/java/com/loopeer/android/librarys/Header.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 2 | 3 | public interface Header extends HeaderFooter { 4 | 5 | 6 | 7 | } 8 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #B8B8B8 5 | 6 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/java/com/loopeer/android/librarys/SwitchListener.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 2 | 3 | public interface SwitchListener { 4 | 5 | void onPagePause(); 6 | void onPageResume(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Oct 29 22:30:14 CST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 7 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/java/com/loopeer/android/librarys/SwitcherHolder.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 2 | 3 | public interface SwitcherHolder { 4 | 5 | void onNextPage(); 6 | void onPrePage(); 7 | boolean isLastPage(); 8 | boolean isFirstPage(); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 12dp 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | #777777 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_fragment4.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/java/com/loopeer/android/librarys/HeaderFooter.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 2 | 3 | public interface HeaderFooter { 4 | 5 | void onMoveStart(int currentPosY, int startSwitchOffset, CharSequence string); 6 | 7 | void onCanStartSwitch(int currentPosY, int startSwitchOffset, CharSequence string); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/res/anim/in_from_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_toolbar.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/res/anim/in_from_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/res/anim/out_to_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/res/anim/out_to_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /pullswitcherview/src/test/java/com/loopeer/android/librarys/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/list_test_item.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/test/java/com/loopeer/android/librarys/pullswitcher/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.pullswitcher; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /pullswitcherview/src/main/res/values-zh/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 继续下拉返回上一页 4 | 松手返回上一页 5 | 继续上拉进入下一页 6 | 松手进入下一页 7 | 已经是第一页了 8 | 没有更多页面了 9 | 10 | 11 | -------------------------------------------------------------------------------- /pullswitcherview/src/androidTest/java/com/loopeer/android/librarys/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 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 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/loopeer/android/librarys/pullswitcher/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.pullswitcher; 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 | } -------------------------------------------------------------------------------- /pullswitcherview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | keep pull down to go back 4 | Let go back 5 | keep pull up to go next page 6 | Let go to next page 7 | Already first one 8 | No more 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/java/com/loopeer/android/librarys/SwitcherAdapter.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 2 | 3 | import android.view.ViewGroup; 4 | 5 | public abstract class SwitcherAdapter { 6 | 7 | private SwitcherHolder switcherHolder; 8 | 9 | public abstract void replaceItem(ViewGroup container, int prePosition, int newPosition); 10 | 11 | public abstract int getCount(); 12 | 13 | public void setOnPageChangeListener(SwitcherHolder holder) { 14 | this.switcherHolder = holder; 15 | } 16 | 17 | public SwitcherHolder getSwitcherHolder() { 18 | return switcherHolder; 19 | } 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /app/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 /Users/todou/Library/Android/sdk/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 | -------------------------------------------------------------------------------- /pullswitcherview/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 /Users/todou/Library/Android/sdk/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 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/loopeer/android/librarys/pullswitcher/TestPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.pullswitcher; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | 7 | public class TestPagerAdapter extends FragmentPagerAdapter { 8 | 9 | public TestPagerAdapter(FragmentManager fm) { 10 | super(fm); 11 | } 12 | 13 | @Override 14 | public Fragment getItem(int position) { 15 | return TestFragment4.newInstance(); 16 | } 17 | 18 | @Override 19 | public int getCount() { 20 | return 4; 21 | } 22 | 23 | @Override 24 | public CharSequence getPageTitle(int position) { 25 | return "Tab: " + (position + 1); 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_fragment1.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.loopeer.android.librarys.pullswitcher" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.0' 26 | compile 'com.android.support:design:23.1.0' 27 | compile 'com.android.support:recyclerview-v7:23.1.0' 28 | compile project(':pullswitcherview') 29 | // compile 'com.loopeer.library:pullswitcherview:1.0.6' 30 | } 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Specific files to exclude 2 | dist 3 | com_crashlytics_export_strings.xml 4 | keys.xml 5 | #*.keystore 6 | 7 | ### Android 8 | ########### 9 | # built application files 10 | *.apk 11 | *.ap_ 12 | 13 | # files for the dex VM 14 | *.dex 15 | 16 | # Java class files 17 | *.class 18 | 19 | # generated files 20 | bin/ 21 | gen/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | gradle.properties 26 | keystore.properties 27 | 28 | ### Mac 29 | .DS_store 30 | 31 | ### Linux 32 | ######### 33 | !.gitignore 34 | *~ 35 | 36 | ### Windows 37 | ############ 38 | # Windows image file caches 39 | Thumbs.db 40 | ehthumbs.db 41 | 42 | # Folder config file 43 | Desktop.ini 44 | 45 | # Recycle Bin used on file shares 46 | $RECYCLE.BIN/ 47 | 48 | ### IntelliJ 49 | *.iml 50 | *.ipr 51 | *.iws 52 | .idea/ 53 | 54 | ### Gradle 55 | .gradle/ 56 | build/ 57 | out/ 58 | 59 | #Maven 60 | target 61 | release.properties 62 | pom.xml.* 63 | 64 | ### AppEngine 65 | google_generated/ 66 | datanucleus.log -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_fragment3.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 19 | 20 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/loopeer/android/librarys/pullswitcher/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.pullswitcher; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.FrameLayout; 6 | 7 | import com.loopeer.android.librarys.SwitcherAdapter; 8 | import com.loopeer.android.librarys.SwitcherHolderImpl; 9 | 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | private FrameLayout containerLayout; 14 | private SwitcherAdapter adapter; 15 | private SwitcherHolderImpl mSwitchHolder; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | 22 | containerLayout = (FrameLayout) findViewById(R.id.container); 23 | 24 | mSwitchHolder = new SwitcherHolderImpl(containerLayout); 25 | adapter = new TestSwitcherAdapter(getSupportFragmentManager()); 26 | mSwitchHolder.setAdapter(adapter); 27 | } 28 | 29 | @Override 30 | public void onBackPressed() { 31 | mSwitchHolder.doBack(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/loopeer/android/librarys/pullswitcher/TestSwitcherAdapter.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.pullswitcher; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | 6 | import com.loopeer.android.librarys.SwitchFragmentAdapter; 7 | 8 | public class TestSwitcherAdapter extends SwitchFragmentAdapter { 9 | 10 | public TestSwitcherAdapter(FragmentManager fm) { 11 | super(fm); 12 | } 13 | 14 | @Override 15 | public Fragment getItem(int position) { 16 | Fragment fragment; 17 | switch (position) { 18 | case 0: 19 | fragment = TestFragment1Recycler.newInstance(getSwitcherHolder()); 20 | break; 21 | case 1: 22 | fragment = TestFragment2Scroll.newInstance(getSwitcherHolder()); 23 | break; 24 | case 2: 25 | fragment = TestFragment3ViewPager.newInstance(getSwitcherHolder()); 26 | break; 27 | default: 28 | fragment = null; 29 | } 30 | return fragment; 31 | } 32 | 33 | @Override 34 | public int getCount() { 35 | return 3; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/loopeer/android/librarys/pullswitcher/TestCustomFooterView.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.pullswitcher; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.Gravity; 6 | import android.widget.TextView; 7 | 8 | import com.loopeer.android.librarys.Footer; 9 | 10 | public class TestCustomFooterView extends TextView implements Footer{ 11 | 12 | public TestCustomFooterView(Context context) { 13 | this(context, null); 14 | } 15 | 16 | public TestCustomFooterView(Context context, AttributeSet attrs) { 17 | this(context, attrs, 0); 18 | } 19 | 20 | public TestCustomFooterView(Context context, AttributeSet attrs, int defStyleAttr) { 21 | super(context, attrs, defStyleAttr); 22 | setPadding(20, 20, 20, 20); 23 | setGravity(Gravity.CENTER); 24 | } 25 | 26 | @Override 27 | public void onMoveStart(int currentPosY, int startSwitchOffset, CharSequence string) { 28 | setText("Test custom footer text onMoveStart"); 29 | } 30 | 31 | @Override 32 | public void onCanStartSwitch(int currentPosY, int startSwitchOffset, CharSequence string) { 33 | setText("Test custom footer text onCanStartSwitch"); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/loopeer/android/librarys/pullswitcher/TestFragment2Scroll.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.pullswitcher; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.loopeer.android.librarys.PullSwitchView; 11 | import com.loopeer.android.librarys.SwitcherHolder; 12 | 13 | public class TestFragment2Scroll extends Fragment { 14 | 15 | private SwitcherHolder switcherHolder; 16 | 17 | public static TestFragment2Scroll newInstance(SwitcherHolder switcherHolder) { 18 | TestFragment2Scroll testFragment = new TestFragment2Scroll(); 19 | testFragment.switcherHolder = switcherHolder; 20 | return testFragment; 21 | } 22 | 23 | @Nullable 24 | @Override 25 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 26 | return inflater.inflate(R.layout.fragment_fragment2, container, false); 27 | } 28 | 29 | @Override 30 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 31 | super.onViewCreated(view, savedInstanceState); 32 | 33 | PullSwitchView pullSwitchView = (PullSwitchView) view.findViewById(R.id.switcher); 34 | pullSwitchView.setSwitcherHolder(switcherHolder); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/java/com/loopeer/android/librarys/DefaultHeader.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 2 | 3 | import android.content.Context; 4 | import android.support.v4.content.ContextCompat; 5 | import android.util.AttributeSet; 6 | import android.view.Gravity; 7 | import android.widget.TextView; 8 | 9 | public class DefaultHeader extends TextView implements Header { 10 | 11 | public DefaultHeader(Context context) { 12 | this(context, null); 13 | } 14 | 15 | public DefaultHeader(Context context, AttributeSet attrs) { 16 | this(context, attrs, 0); 17 | } 18 | 19 | public DefaultHeader(Context context, AttributeSet attrs, int defStyleAttr) { 20 | super(context, attrs, defStyleAttr); 21 | 22 | init(context, attrs, defStyleAttr); 23 | } 24 | 25 | private void init(Context context, AttributeSet attrs, int defStyleAttr) { 26 | setGravity(Gravity.CENTER); 27 | int padding = getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin); 28 | setPadding(padding, padding, padding, padding); 29 | setTextColor(ContextCompat.getColor(context, R.color.switcher_color_hint)); 30 | } 31 | 32 | 33 | @Override 34 | public void onMoveStart(int currentPosY, int startSwitchOffset, CharSequence string) { 35 | setText(string); 36 | } 37 | 38 | @Override 39 | public void onCanStartSwitch(int currentPosY, int startSwitchOffset, CharSequence string) { 40 | setText(string); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/loopeer/android/librarys/pullswitcher/TestRecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.pullswitcher; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | public class TestRecyclerAdapter extends RecyclerView.Adapter { 10 | private String[] mDataset; 11 | 12 | 13 | public static class ViewHolder extends RecyclerView.ViewHolder { 14 | public TextView mTextView; 15 | 16 | public ViewHolder(View v) { 17 | super(v); 18 | mTextView = (TextView) v; 19 | } 20 | } 21 | 22 | public TestRecyclerAdapter(String[] myDataset) { 23 | mDataset = myDataset; 24 | } 25 | 26 | // Create new views (invoked by the layout manager) 27 | @Override 28 | public TestRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, 29 | int viewType) { 30 | // create a new view 31 | View v = LayoutInflater.from(parent.getContext()) 32 | .inflate(R.layout.list_test_item, parent, false); 33 | 34 | ViewHolder vh = new ViewHolder(v); 35 | return vh; 36 | } 37 | 38 | @Override 39 | public void onBindViewHolder(ViewHolder holder, int position) { 40 | holder.mTextView.setText(mDataset[position]); 41 | 42 | } 43 | 44 | @Override 45 | public int getItemCount() { 46 | return mDataset.length; 47 | } 48 | } -------------------------------------------------------------------------------- /pullswitcherview/src/main/java/com/loopeer/android/librarys/DefaultFooter.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 2 | 3 | import android.content.Context; 4 | import android.support.v4.content.ContextCompat; 5 | import android.util.AttributeSet; 6 | import android.view.Gravity; 7 | import android.widget.TextView; 8 | 9 | public class DefaultFooter extends TextView implements Footer { 10 | private static final String TAG = "DefaultFooter"; 11 | 12 | public DefaultFooter(Context context) { 13 | this(context, null); 14 | } 15 | 16 | public DefaultFooter(Context context, AttributeSet attrs) { 17 | this(context, attrs, 0); 18 | } 19 | 20 | public DefaultFooter(Context context, AttributeSet attrs, int defStyleAttr) { 21 | super(context, attrs, defStyleAttr); 22 | 23 | init(context, attrs, defStyleAttr); 24 | } 25 | 26 | private void init(Context context, AttributeSet attrs, int defStyleAttr) { 27 | setGravity(Gravity.CENTER); 28 | int padding = getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin); 29 | setPadding(padding, padding, padding, padding); 30 | setTextColor(ContextCompat.getColor(context, R.color.switcher_color_hint)); 31 | } 32 | 33 | @Override 34 | public void onMoveStart(int currentPosY, int startSwitchOffset, final CharSequence string) { 35 | setText(string.toString()); 36 | } 37 | 38 | @Override 39 | public void onCanStartSwitch(int currentPosY, int startSwitchOffset, final CharSequence string) { 40 | setText(string.toString()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/loopeer/android/librarys/pullswitcher/TestFragment3ViewPager.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.pullswitcher; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.design.widget.TabLayout; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.view.ViewPager; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import com.loopeer.android.librarys.PullSwitchView; 13 | import com.loopeer.android.librarys.SwitcherHolder; 14 | 15 | public class TestFragment3ViewPager extends Fragment { 16 | 17 | private SwitcherHolder switcherHolder; 18 | private PullSwitchView pullSwitchView; 19 | 20 | private TestPagerAdapter mAdapter; 21 | private ViewPager mViewpager; 22 | private TabLayout mTabs; 23 | 24 | public static TestFragment3ViewPager newInstance(SwitcherHolder switcherHolder) { 25 | TestFragment3ViewPager testFragment = new TestFragment3ViewPager(); 26 | testFragment.switcherHolder = switcherHolder; 27 | return testFragment; 28 | } 29 | 30 | @Nullable 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 33 | return inflater.inflate(R.layout.fragment_fragment3, container, false); 34 | } 35 | 36 | @Override 37 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 38 | super.onViewCreated(view, savedInstanceState); 39 | 40 | initSwitchView(view); 41 | initPagerTabs(view); 42 | } 43 | 44 | private void initPagerTabs(View view) { 45 | mViewpager = (ViewPager) view.findViewById(R.id.viewpager); 46 | mTabs = (TabLayout) view.findViewById(R.id.tabs); 47 | mAdapter = new TestPagerAdapter(getChildFragmentManager()); 48 | mViewpager.setAdapter(mAdapter); 49 | mTabs.setupWithViewPager(mViewpager); 50 | } 51 | 52 | private void initSwitchView(View view) { 53 | pullSwitchView = (PullSwitchView) view.findViewById(R.id.switcher); 54 | pullSwitchView.setSwitcherHolder(switcherHolder); 55 | pullSwitchView.disableWhenHorizontalMove(true); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /pullswitcherview/src/main/java/com/loopeer/android/librarys/SwitcherHolderImpl.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys; 2 | 3 | import android.app.Activity; 4 | import android.view.ViewGroup; 5 | 6 | 7 | public class SwitcherHolderImpl implements SwitcherHolder { 8 | 9 | private ViewGroup mContainer; 10 | private SwitcherAdapter mAdapter; 11 | private int mPreCurrentItem; 12 | private int mCurItem; // Index of currently displayed page. 13 | 14 | public SwitcherHolderImpl(ViewGroup mContainer) { 15 | this.mContainer = mContainer; 16 | } 17 | 18 | public void setAdapter(SwitcherAdapter adapter) { 19 | mAdapter = adapter; 20 | mPreCurrentItem = 0; 21 | adapter.setOnPageChangeListener(this); 22 | setCurrentItem(0); 23 | } 24 | 25 | public void setCurrentItem(int i) { 26 | mCurItem = i; 27 | if (mCurItem == mPreCurrentItem && mCurItem != 0) return; 28 | mAdapter.replaceItem(mContainer, mPreCurrentItem, mCurItem); 29 | mAdapter.setOnPageChangeListener(this); 30 | mPreCurrentItem = i; 31 | } 32 | 33 | public int getCurrentPosition() { 34 | return mCurItem; 35 | } 36 | 37 | public void nextPage() { 38 | if (mCurItem == mAdapter.getCount() - 1) return; 39 | mPreCurrentItem = mCurItem++; 40 | nextPage(mCurItem); 41 | } 42 | 43 | public void nextPage(int position) { 44 | setCurrentItem(position); 45 | } 46 | 47 | public void prePage() { 48 | if (mCurItem == 0) return; 49 | mPreCurrentItem = mCurItem --; 50 | prePage(mCurItem); 51 | } 52 | 53 | private void prePage(int position) { 54 | setCurrentItem(position); 55 | } 56 | 57 | @Override 58 | public void onNextPage() { 59 | nextPage(); 60 | } 61 | 62 | @Override 63 | public void onPrePage() { 64 | prePage(); 65 | } 66 | 67 | @Override 68 | public boolean isLastPage() { 69 | return mCurItem == mAdapter.getCount() - 1; 70 | } 71 | 72 | @Override 73 | public boolean isFirstPage() { 74 | return mCurItem == 0; 75 | } 76 | 77 | public void doBack() { 78 | if (mCurItem == 0) { 79 | ((Activity) mContainer.getContext()).finish(); 80 | } else { 81 | onPrePage(); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_fragment2.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 20 | 21 | 25 | 26 | 30 | 31 | 36 | 37 | 38 | 39 | 44 | 45 | 49 | 50 | 55 | 56 | 57 |