├── .gitignore
├── README.md
├── README_CH.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── cn
│ │ └── youngkaaa
│ │ └── yviewpagerdemo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── cn
│ │ │ └── youngkaaa
│ │ │ └── yviewpagerdemo
│ │ │ ├── BannerActivity.java
│ │ │ ├── FragmentInner.java
│ │ │ ├── GallaryViewPager.java
│ │ │ ├── MainActivity.java
│ │ │ └── YViewPager1.java
│ └── res
│ │ ├── drawable
│ │ ├── circle_normal.xml
│ │ ├── circle_selected.xml
│ │ ├── image2.jpg
│ │ ├── jay_fantexi.jpg
│ │ ├── jay_jay.jpg
│ │ └── logo.jpg
│ │ ├── layout
│ │ ├── activity_banner.xml
│ │ ├── activity_gallary_view_pager.xml
│ │ ├── activity_main.xml
│ │ └── fragment_inner.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
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── cn
│ └── youngkaaa
│ └── yviewpagerdemo
│ └── ExampleUnitTest.java
├── build.gradle
├── gif
├── horizontal.gif
└── vertical.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screens
├── record.gif
└── record_circle.gif
├── settings.gradle
└── yviewpager
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── cn
│ └── youngkaaa
│ └── yviewpager
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── cn
│ │ └── youngkaaa
│ │ └── yviewpager
│ │ ├── YFragmentPagerAdapter.java
│ │ ├── YFragmentStatePagerAdapter.java
│ │ ├── YPagerAdapter.java
│ │ └── YViewPager.java
└── res
│ └── values
│ ├── attrs.xml
│ └── strings.xml
└── test
└── java
└── cn
└── youngkaaa
└── yviewpager
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | .idea
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 支持水平方向上滑动和竖直方向上的滑动,直接修改的官方提供的`ViewPager`的源码,注入了方向判断,使用起来和官方的`ViewPager`基本一样,还有监听事件也是一样的,支持`setOffscreenPageLimit()`可以放心滑动,以及`TabLayout`等。
2 |
3 |
4 | 开源地址:[https://github.com/open-android/ViewPager](https://github.com/open-android/ViewPager "开源项目地址")
5 |
6 |
7 | 
8 |
9 | 
10 |
11 | * 详细的使用方法在DEMO里面都演示啦,如果你觉得这个库还不错,请赏我一颗star吧~~~
12 |
13 | * 欢迎关注微信公众号、长期为您推荐优秀博文、开源项目、视频
14 |
15 | 
16 |
17 | ## 使用步骤
18 |
19 | ### 1. 在project的build.gradle添加如下代码(如下图)
20 |
21 | allprojects {
22 | repositories {
23 | ...
24 | maven { url "https://jitpack.io" }
25 | }
26 | }
27 |
28 |
29 | 
30 |
31 |
32 |
33 | ### 2. 在Module的build.gradle添加依赖
34 |
35 | compile 'com.github.open-android:ViewPager:0.1.0'
36 |
37 |
38 |
39 |
40 | ### 3.在xml复制如下代码
41 | ```
42 |
47 | ```
48 |
49 | 就像上面这样,只需要设置`app:orientation`属性,该属性可选值为:`vertical`和`horizontal`,分别代表竖直方向上滑动和水平方向上滑动。
50 |
51 | ### 也可以使用java代码
52 |
53 | ```
54 | mViewPager.setDirection(YViewPager.VERTICAL);
55 |
56 | mViewPager.setDirection(YViewPager.HORIZONTAL);
57 |
58 | ```
59 |
60 | 具体意思同上
61 | 注意,推荐在XML里面设置方向,请切记。
62 |
63 | ### 使用的ViewPager的适配器的时候需要继承YFragmentPagerAdapter
64 | ```
65 | class FragmentAdapter extends YFragmentPagerAdapter {
66 |
67 | public FragmentAdapter(FragmentManager fm) {
68 | super(fm);
69 | }
70 |
71 | @Override
72 | public Fragment getItem(int position) {
73 | return mFragments.get(position);
74 | }
75 |
76 | @Override
77 | public int getCount() {
78 | return mFragments.size();
79 | }
80 |
81 |
82 | }
83 |
84 | ```
85 |
86 |
--------------------------------------------------------------------------------
/README_CH.md:
--------------------------------------------------------------------------------
1 | 支持水平方向上滑动和竖直方向上的滑动,直接修改的官方提供的`ViewPager`的源码,注入了方向判断,使用起来和官方的`ViewPager`基本一样,还有监听事件也是一样的,支持`setOffscreenPageLimit()`可以放心滑动,以及`TabLayout`等。
2 |
3 |
4 | 开源地址:[https://github.com/open-android/ViewPager](https://github.com/open-android/ViewPager "开源项目地址")
5 |
6 |
7 | 
8 |
9 | 
10 |
11 | * 详细的使用方法在DEMO里面都演示啦,如果你觉得这个库还不错,请赏我一颗star吧~~~
12 |
13 | * 欢迎关注微信公众号、长期为您推荐优秀博文、开源项目、视频
14 |
15 | 
16 |
17 | ## 使用步骤
18 |
19 | ### 1. 在project的build.gradle添加如下代码(如下图)
20 |
21 | allprojects {
22 | repositories {
23 | ...
24 | maven { url "https://jitpack.io" }
25 | }
26 | }
27 |
28 |
29 | 
30 |
31 |
32 |
33 | ### 2. 在Module的build.gradle添加依赖
34 |
35 | compile 'com.github.open-android:ViewPager:0.1.0'
36 |
37 |
38 |
39 |
40 | ### 3.在xml复制如下代码
41 | ```
42 |
47 | ```
48 |
49 | 就像上面这样,只需要设置`app:orientation`属性,该属性可选值为:`vertical`和`horizontal`,分别代表竖直方向上滑动和水平方向上滑动。
50 |
51 | ### 也可以使用java代码
52 |
53 | ```
54 | mViewPager.setDirection(YViewPager.VERTICAL);
55 |
56 | mViewPager.setDirection(YViewPager.HORIZONTAL);
57 |
58 | ```
59 |
60 | 具体意思同上
61 | 注意,推荐在XML里面设置方向,请切记。
62 |
63 | ### 使用的ViewPager的适配器的时候需要继承YFragmentPagerAdapter
64 | ```
65 | class FragmentAdapter extends YFragmentPagerAdapter {
66 |
67 | public FragmentAdapter(FragmentManager fm) {
68 | super(fm);
69 | }
70 |
71 | @Override
72 | public Fragment getItem(int position) {
73 | return mFragments.get(position);
74 | }
75 |
76 | @Override
77 | public int getCount() {
78 | return mFragments.size();
79 | }
80 |
81 |
82 | }
83 |
84 | ```
85 |
86 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle/
2 | .idea/
3 | */build/
4 | build/
5 | gradle/
6 | local.properties
7 | *.iml
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 | defaultConfig {
7 | applicationId "cn.youngkaaa.yviewpagerdemo"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
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 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.0.0'
28 | testCompile 'junit:junit:4.12'
29 | compile project(path: ':yviewpager')
30 | }
31 |
--------------------------------------------------------------------------------
/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 H:\Android_SDK\adt-bundle-windows-x86_64-20131030\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/androidTest/java/cn/youngkaaa/yviewpagerdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpagerdemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("cn.youngkaaa.yviewpagerdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/youngkaaa/yviewpagerdemo/BannerActivity.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpagerdemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.view.ViewPager;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.util.Log;
7 | import android.view.Gravity;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.ImageView;
11 | import android.widget.LinearLayout;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import cn.youngkaaa.yviewpager.YPagerAdapter;
17 | import cn.youngkaaa.yviewpager.YViewPager;
18 |
19 | public class BannerActivity extends AppCompatActivity {
20 | private static final String TAG = "BannerActivity";
21 | private YViewPager mYViewPager;
22 | private LinearLayout mLinearIndicator;
23 | private List mImageViews;
24 | private int mTotalCount = 0;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_banner);
30 | mYViewPager = (YViewPager) findViewById(R.id.viewpager1);
31 | mLinearIndicator = (LinearLayout) findViewById(R.id.linearIndicator);
32 |
33 | initImgs();
34 |
35 | // setIndicator(0);
36 |
37 | mYViewPager.setAdapter(new ImagePagerAdapter());
38 |
39 | mYViewPager.setCurrentItem(0);
40 |
41 | mYViewPager.addOnPageChangeListener(new YViewPager.OnPageChangeListener() {
42 | @Override
43 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
44 |
45 | }
46 |
47 | @Override
48 | public void onPageSelected(int position) {
49 | setIndicator(position%mImageViews.size());
50 | Log.d(TAG,"POSITION=====>"+mYViewPager.getCurrentItem());
51 | }
52 |
53 | @Override
54 | public void onPageScrollStateChanged(int state) {
55 |
56 | }
57 | });
58 |
59 |
60 | }
61 |
62 | private void setIndicator(int pos) {
63 | mLinearIndicator.removeAllViews();
64 | for (int i = 0; i < mImageViews.size(); i++) {
65 | int resId = i == pos ? R.drawable.circle_selected : R.drawable.circle_normal;
66 | ImageView indicator = new ImageView(this);
67 | indicator.setImageResource(resId);
68 | LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(68, 68);
69 | indicator.setLayoutParams(lp);
70 | mLinearIndicator.addView(indicator);
71 | }
72 | }
73 |
74 |
75 | private void initImgs() {
76 | mImageViews = new ArrayList<>();
77 |
78 | ViewPager.LayoutParams lp = new ViewPager.LayoutParams();
79 | lp.gravity = Gravity.LEFT;
80 |
81 | ImageView imageView1 = new ImageView(this);
82 | imageView1.setImageResource(R.drawable.jay_fantexi);
83 | imageView1.setScaleType(ImageView.ScaleType.CENTER_CROP);
84 |
85 | ImageView imageView2 = new ImageView(this);
86 | imageView2.setImageResource(R.drawable.jay_jay);
87 | imageView2.setScaleType(ImageView.ScaleType.CENTER_CROP);
88 |
89 | ImageView imageView3 = new ImageView(this);
90 | imageView3.setImageResource(R.drawable.logo);
91 | imageView3.setScaleType(ImageView.ScaleType.CENTER_CROP);
92 |
93 | ImageView imageView4 = new ImageView(this);
94 | imageView4.setImageResource(R.drawable.image2);
95 | imageView4.setScaleType(ImageView.ScaleType.CENTER_CROP);
96 |
97 | ImageView imageView5 = new ImageView(this);
98 | imageView5.setImageResource(R.drawable.jay_jay);
99 | imageView5.setScaleType(ImageView.ScaleType.CENTER_CROP);
100 |
101 | ImageView imageView6 = new ImageView(this);
102 | imageView6.setImageResource(R.drawable.logo);
103 | imageView6.setScaleType(ImageView.ScaleType.CENTER_CROP);
104 |
105 | imageView1.setLayoutParams(lp);
106 | imageView2.setLayoutParams(lp);
107 | imageView3.setLayoutParams(lp);
108 | imageView4.setLayoutParams(lp);
109 | imageView5.setLayoutParams(lp);
110 | imageView6.setLayoutParams(lp);
111 |
112 | mImageViews.add(imageView1);
113 | mImageViews.add(imageView2);
114 | mImageViews.add(imageView3);
115 | mImageViews.add(imageView4);
116 | mImageViews.add(imageView5);
117 | mImageViews.add(imageView6);
118 | }
119 |
120 | class ImagePagerAdapter extends YPagerAdapter {
121 | @Override
122 | public Object instantiateItem(ViewGroup container, int position) {
123 | // Log.d(TAG,"############instantiateItem() start############");
124 | // Log.d(TAG, "position=>" + position);
125 | View img = mImageViews.get(position);
126 | container.addView(img);
127 | // Log.d(TAG,"############instantiateItem() end############");
128 | return img;
129 | }
130 |
131 | @Override
132 | public int getCount() {
133 | return mImageViews.size();
134 | }
135 |
136 | @Override
137 | public boolean isViewFromObject(View view, Object object) {
138 | return view == object;
139 | }
140 |
141 | @Override
142 | public void destroyItem(ViewGroup container, int position, Object object) {
143 | container.removeView((View) object);
144 | }
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/youngkaaa/yviewpagerdemo/FragmentInner.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpagerdemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.DrawableRes;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by : youngkaaa on 2017/2/22.
15 | * Contact me : 645326280@qq.com
16 | */
17 |
18 | public class FragmentInner extends Fragment {
19 | public static final String KEY_TITLE="KEY_TITLE";
20 | public static final String KEY_IMG="KEY_IMG";
21 | private TextView mTextView;
22 | private ImageView mImageView;
23 | @Nullable
24 | @Override
25 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
26 | View rootView=inflater.inflate(R.layout.fragment_inner,container,false);
27 | mTextView= (TextView) rootView.findViewById(R.id.tv1);
28 | mImageView= (ImageView) rootView.findViewById(R.id.img1);
29 | return rootView;
30 | }
31 |
32 | public static FragmentInner newInstance(String title, @DrawableRes int res){
33 | Bundle bundle=new Bundle();
34 | bundle.putString(KEY_TITLE,title);
35 | bundle.putInt(KEY_IMG,res);
36 | FragmentInner fragment=new FragmentInner();
37 | fragment.setArguments(bundle);
38 | return fragment;
39 | }
40 |
41 | @Override
42 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
43 | super.onActivityCreated(savedInstanceState);
44 | Bundle arguments = getArguments();
45 | mTextView.setText(arguments.getString(KEY_TITLE));
46 | mImageView.setImageResource(arguments.getInt(KEY_IMG));
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/youngkaaa/yviewpagerdemo/GallaryViewPager.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpagerdemo;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.os.Bundle;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | import cn.youngkaaa.yviewpager.YFragmentPagerAdapter;
12 | import cn.youngkaaa.yviewpager.YViewPager;
13 |
14 | public class GallaryViewPager extends AppCompatActivity {
15 | private YViewPager mViewPager;
16 | private List mFragments;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_gallary_view_pager);
22 | mViewPager= (YViewPager) findViewById(R.id.viewPagerGallary);
23 | initData();
24 |
25 | mViewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager()));
26 | mViewPager.setPageMargin(18);
27 | mViewPager.setOffscreenPageLimit(2);
28 | }
29 |
30 | private void initData() {
31 | mFragments=new ArrayList<>();
32 | FragmentInner fragmentInner1=FragmentInner.newInstance("fragment1",R.drawable.jay_jay);
33 | FragmentInner fragmentInner2=FragmentInner.newInstance("fragment2",R.drawable.jay_fantexi);
34 | FragmentInner fragmentInner3=FragmentInner.newInstance("fragment3",R.drawable.image2);
35 | FragmentInner fragmentInner4=FragmentInner.newInstance("fragment4",R.drawable.logo);
36 | FragmentInner fragmentInner5=FragmentInner.newInstance("fragment5",R.drawable.jay_jay);
37 | FragmentInner fragmentInner6=FragmentInner.newInstance("fragment6",R.drawable.image2);
38 | mFragments.add(fragmentInner1);
39 | mFragments.add(fragmentInner2);
40 | mFragments.add(fragmentInner3);
41 | mFragments.add(fragmentInner4);
42 | mFragments.add(fragmentInner5);
43 | mFragments.add(fragmentInner6);
44 | }
45 |
46 | class FragmentAdapter extends YFragmentPagerAdapter {
47 |
48 | public FragmentAdapter(FragmentManager fm) {
49 | super(fm);
50 | }
51 |
52 | @Override
53 | public Fragment getItem(int position) {
54 | return mFragments.get(position);
55 | }
56 |
57 | @Override
58 | public int getCount() {
59 | return mFragments.size();
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/youngkaaa/yviewpagerdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpagerdemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.app.FragmentManager;
6 | import android.support.v4.view.ViewPager;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.util.Log;
9 | import android.view.Gravity;
10 | import android.view.View;
11 | import android.widget.Button;
12 | import android.widget.ImageView;
13 | import android.widget.LinearLayout;
14 | import android.widget.TextView;
15 |
16 | import java.util.ArrayList;
17 | import java.util.List;
18 |
19 | import cn.youngkaaa.yviewpager.YFragmentPagerAdapter;
20 | import cn.youngkaaa.yviewpager.YViewPager;
21 |
22 | public class MainActivity extends AppCompatActivity {
23 |
24 | private static final String TAG = "MainActivity";
25 | private YViewPager mViewPager;
26 | private List mImageViews;
27 | private LinearLayout lTopCircleIndicator;
28 | private int mPosition;
29 | private boolean isEdgeSwipe;
30 | private int mLastPos;
31 | private List mFragments;
32 | private TextView mTextView;
33 | private int mCurrentItem=0;
34 | private Button mButtonHorizontal;
35 | private Button mButtonVertical;
36 | private int mCurrentPos=0;
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_main);
41 | mViewPager = (YViewPager) findViewById(R.id.viewpager);
42 | mTextView= (TextView) findViewById(R.id.numIndicator);
43 | mButtonHorizontal= (Button) findViewById(R.id.btnHorizontal);
44 | mButtonVertical= (Button) findViewById(R.id.btnVertical);
45 | initData();
46 |
47 | mViewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager()));
48 |
49 | mViewPager.setPageMargin(10);
50 | mViewPager.addOnPageChangeListener(new YViewPager.OnPageChangeListener() {
51 | @Override
52 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
53 | Log.d(TAG, "onPageScrolled() position=>" + position + ",positionOffset=>" + positionOffset +
54 | ",positionOffsetPixels=>" + positionOffsetPixels);
55 | }
56 |
57 | @Override
58 | public void onPageSelected(int position) {
59 | Log.d(TAG, "onPageSelected() position=>" + position);
60 | setIndicators(position);
61 | }
62 |
63 | @Override
64 | public void onPageScrollStateChanged(int state) {
65 | Log.d(TAG, "onPageScrollStateChanged() state=>"+state);
66 | }
67 | });
68 |
69 | mButtonHorizontal.setOnClickListener(new View.OnClickListener() {
70 | @Override
71 | public void onClick(View view) {
72 | mViewPager.setDirection(YViewPager.HORIZONTAL);
73 | }
74 | });
75 | mButtonVertical.setOnClickListener(new View.OnClickListener() {
76 | @Override
77 | public void onClick(View view) {
78 | mViewPager.setDirection(YViewPager.VERTICAL);
79 | }
80 | });
81 | }
82 |
83 | private void initData() {
84 | mFragments=new ArrayList<>();
85 | FragmentInner fragmentInner1=FragmentInner.newInstance("fragment1",R.drawable.jay_jay);
86 | FragmentInner fragmentInner2=FragmentInner.newInstance("fragment2",R.drawable.jay_fantexi);
87 | FragmentInner fragmentInner3=FragmentInner.newInstance("fragment3",R.drawable.image2);
88 | FragmentInner fragmentInner4=FragmentInner.newInstance("fragment4",R.drawable.logo);
89 | FragmentInner fragmentInner5=FragmentInner.newInstance("fragment5",R.drawable.jay_jay);
90 | FragmentInner fragmentInner6=FragmentInner.newInstance("fragment6",R.drawable.image2);
91 | mFragments.add(fragmentInner1);
92 | mFragments.add(fragmentInner2);
93 | mFragments.add(fragmentInner3);
94 | mFragments.add(fragmentInner4);
95 | mFragments.add(fragmentInner5);
96 | mFragments.add(fragmentInner6);
97 | setIndicators(mCurrentPos);
98 | }
99 |
100 | private void setIndicators(int position) {
101 | mTextView.setText(position+1+"/"+mFragments.size());
102 | }
103 |
104 | private void initImages() {
105 | mImageViews = new ArrayList<>();
106 |
107 | ViewPager.LayoutParams lp=new ViewPager.LayoutParams();
108 | lp.gravity= Gravity.LEFT;
109 |
110 | ImageView imageView1 = new ImageView(this);
111 | imageView1.setImageResource(R.drawable.jay_fantexi);
112 | imageView1.setScaleType(ImageView.ScaleType.CENTER_CROP);
113 |
114 | ImageView imageView2 = new ImageView(this);
115 | imageView2.setImageResource(R.drawable.jay_jay);
116 | imageView2.setScaleType(ImageView.ScaleType.CENTER_CROP);
117 |
118 | ImageView imageView3 = new ImageView(this);
119 | imageView3.setImageResource(R.drawable.image2);
120 | imageView3.setScaleType(ImageView.ScaleType.CENTER_CROP);
121 |
122 | ImageView imageView4 = new ImageView(this);
123 | imageView4.setImageResource(R.drawable.jay_jay);
124 | imageView4.setScaleType(ImageView.ScaleType.CENTER_CROP);
125 |
126 | ImageView imageView5 = new ImageView(this);
127 | imageView5.setImageResource(R.drawable.logo);
128 | imageView5.setScaleType(ImageView.ScaleType.CENTER_CROP);
129 |
130 | imageView1.setLayoutParams(lp);
131 | imageView2.setLayoutParams(lp);
132 | imageView3.setLayoutParams(lp);
133 | imageView4.setLayoutParams(lp);
134 | imageView5.setLayoutParams(lp);
135 |
136 | mImageViews.add(imageView1);
137 | mImageViews.add(imageView2);
138 | mImageViews.add(imageView3);
139 | mImageViews.add(imageView4);
140 | mImageViews.add(imageView5);
141 | }
142 |
143 | class FragmentAdapter extends YFragmentPagerAdapter {
144 |
145 | public FragmentAdapter(FragmentManager fm) {
146 | super(fm);
147 | }
148 |
149 | @Override
150 | public Fragment getItem(int position) {
151 | return mFragments.get(position);
152 | }
153 |
154 | @Override
155 | public int getCount() {
156 | return mFragments.size();
157 | }
158 |
159 |
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_selected.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/image2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/app/src/main/res/drawable/image2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/jay_fantexi.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/app/src/main/res/drawable/jay_fantexi.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/jay_jay.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/app/src/main/res/drawable/jay_jay.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/app/src/main/res/drawable/logo.jpg
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_banner.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_gallary_view_pager.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
17 |
18 |
19 |
20 |
32 |
33 |
40 |
41 |
48 |
49 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_inner.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | @color/colorAccent
4 | @color/colorAccent
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | YViewPagerDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/cn/youngkaaa/yviewpagerdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpagerdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/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.2.2'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/gif/horizontal.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/gif/horizontal.gif
--------------------------------------------------------------------------------
/gif/vertical.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/gif/vertical.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 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.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/screens/record.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/screens/record.gif
--------------------------------------------------------------------------------
/screens/record_circle.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ViewPager/71effd0b909b767f449741adf7f36a54bcb074a3/screens/record_circle.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':yviewpager'
2 |
--------------------------------------------------------------------------------
/yviewpager/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle/
2 | .idea/
3 | */build/
4 | build/
5 | gradle/
6 | local.properties
7 | *.iml
--------------------------------------------------------------------------------
/yviewpager/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 | group='com.github.open-android'//itcastsh:github账号
5 | version = "0.1.1"
6 |
7 | android {
8 | compileSdkVersion 25
9 | buildToolsVersion "25.0.0"
10 | resourcePrefix "yviewpager" //这个随便填
11 | defaultConfig {
12 | minSdkVersion 15
13 | targetSdkVersion 25
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
18 |
19 | }
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | compile fileTree(dir: 'libs', include: ['*.jar'])
30 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
31 | exclude group: 'com.android.support', module: 'support-annotations'
32 | })
33 | compile 'com.android.support:appcompat-v7:25.0.0'
34 | testCompile 'junit:junit:4.12'
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/yviewpager/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 H:\Android_SDK\adt-bundle-windows-x86_64-20131030\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 |
--------------------------------------------------------------------------------
/yviewpager/src/androidTest/java/cn/youngkaaa/yviewpager/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpager;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("cn.youngkaaa.yviewpager.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/yviewpager/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/yviewpager/src/main/java/cn/youngkaaa/yviewpager/YFragmentPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpager;
2 |
3 |
4 | /*
5 | * Copyright (C) 2011 The Android Open Source Project
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | import android.os.Parcelable;
21 | import android.support.v4.app.Fragment;
22 | import android.support.v4.app.FragmentManager;
23 | import android.support.v4.app.FragmentTransaction;
24 | import android.util.Log;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 |
28 | /**
29 | * Implementation of PagerAdapter that
30 | * represents each page as a Fragment that is persistently
31 | * kept in the fragment manager as long as the user can return to the page.
32 | *
33 | *
This version of the pager is best for use when there are a handful of
34 | * typically more static fragments to be paged through, such as a set of tabs.
35 | * The fragment of each page the user visits will be kept in memory, though its
36 | * view hierarchy may be destroyed when not visible. This can result in using
37 | * a significant amount of memory since fragment instances can hold on to an
38 | * arbitrary amount of state. For larger sets of pages, consider
39 | * FragmentStatePagerAdapter
40 | *
41 | *
When using YFragmentPagerAdapter the host ViewPager must have a
42 | * valid ID set.
43 | *
44 | *
Subclasses only need to implement getItem(int)
45 | * and getCount() to have a working adapter.
46 | *
47 | *
Here is an example implementation of a pager containing fragments of
48 | * lists:
49 | *
50 | *
51 | *
52 | *
The R.layout.fragment_pager resource of the top-level fragment is:
53 | *
54 | *
55 | *
56 | *
The R.layout.fragment_pager_list resource containing each
57 | * individual fragment's layout is:
58 | *
59 | *
60 | */
61 |
62 |
63 | /**
64 | * Created by : youngkaaa on 2017/2/22.
65 | * Contact me : 645326280@qq.com
66 | */
67 | public abstract class YFragmentPagerAdapter extends YPagerAdapter {
68 | private static final String TAG = "YFragmentPagerAdapter";
69 | private static final boolean DEBUG = false;
70 |
71 | private final FragmentManager mFragmentManager;
72 | private FragmentTransaction mCurTransaction = null;
73 | private Fragment mCurrentPrimaryItem = null;
74 |
75 | public YFragmentPagerAdapter(FragmentManager fm) {
76 | mFragmentManager = fm;
77 | }
78 |
79 | /**
80 | * Return the Fragment associated with a specified position.
81 | */
82 | public abstract Fragment getItem(int position);
83 |
84 | @Override
85 | public void startUpdate(ViewGroup container) {
86 | if (container.getId() == View.NO_ID) {
87 | throw new IllegalStateException("ViewPager with adapter " + this
88 | + " requires a view id");
89 | }
90 | }
91 |
92 | @Override
93 | public Object instantiateItem(ViewGroup container, int position) {
94 | if (mCurTransaction == null) {
95 | mCurTransaction = mFragmentManager.beginTransaction();
96 | }
97 |
98 | final long itemId = getItemId(position);
99 |
100 | // Do we already have this fragment?
101 | String name = makeFragmentName(container.getId(), itemId);
102 | Fragment fragment = mFragmentManager.findFragmentByTag(name);
103 | if (fragment != null) {
104 | if (DEBUG) Log.v(TAG, "Attaching item #" + itemId + ": f=" + fragment);
105 | mCurTransaction.attach(fragment);
106 | } else {
107 | fragment = getItem(position);
108 | if (DEBUG) Log.v(TAG, "Adding item #" + itemId + ": f=" + fragment);
109 | mCurTransaction.add(container.getId(), fragment,
110 | makeFragmentName(container.getId(), itemId));
111 | }
112 | if (fragment != mCurrentPrimaryItem) {
113 | fragment.setMenuVisibility(false);
114 | fragment.setUserVisibleHint(false);
115 | }
116 |
117 | return fragment;
118 | }
119 |
120 | @Override
121 | public void destroyItem(ViewGroup container, int position, Object object) {
122 | if (mCurTransaction == null) {
123 | mCurTransaction = mFragmentManager.beginTransaction();
124 | }
125 | if (DEBUG) Log.v(TAG, "Detaching item #" + getItemId(position) + ": f=" + object
126 | + " v=" + ((Fragment)object).getView());
127 | mCurTransaction.detach((Fragment)object);
128 | }
129 |
130 | @Override
131 | public void setPrimaryItem(ViewGroup container, int position, Object object) {
132 | Fragment fragment = (Fragment)object;
133 | if (fragment != mCurrentPrimaryItem) {
134 | if (mCurrentPrimaryItem != null) {
135 | mCurrentPrimaryItem.setMenuVisibility(false);
136 | mCurrentPrimaryItem.setUserVisibleHint(false);
137 | }
138 | if (fragment != null) {
139 | fragment.setMenuVisibility(true);
140 | fragment.setUserVisibleHint(true);
141 | }
142 | mCurrentPrimaryItem = fragment;
143 | }
144 | }
145 |
146 | @Override
147 | public void finishUpdate(ViewGroup container) {
148 | if (mCurTransaction != null) {
149 | mCurTransaction.commitNowAllowingStateLoss();
150 | mCurTransaction = null;
151 | }
152 | }
153 |
154 | @Override
155 | public boolean isViewFromObject(View view, Object object) {
156 | return ((Fragment)object).getView() == view;
157 | }
158 |
159 | @Override
160 | public Parcelable saveState() {
161 | return null;
162 | }
163 |
164 | @Override
165 | public void restoreState(Parcelable state, ClassLoader loader) {
166 | }
167 |
168 | /**
169 | * Return a unique identifier for the item at the given position.
170 | *
171 | *
The default implementation returns the given position.
172 | * Subclasses should override this method if the positions of items can change.
173 | *
174 | * @param position Position within this adapter
175 | * @return Unique identifier for the item at position
176 | */
177 | public long getItemId(int position) {
178 | return position;
179 | }
180 |
181 | private static String makeFragmentName(int viewId, long id) {
182 | return "android:switcher:" + viewId + ":" + id;
183 | }
184 | }
185 |
186 |
--------------------------------------------------------------------------------
/yviewpager/src/main/java/cn/youngkaaa/yviewpager/YFragmentStatePagerAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpager;
2 |
3 | import android.os.Bundle;
4 | import android.os.Parcelable;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentManager;
7 | import android.support.v4.app.FragmentPagerAdapter;
8 | import android.support.v4.app.FragmentTransaction;
9 | import android.support.v4.view.PagerAdapter;
10 | import android.util.Log;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 |
14 | import java.util.ArrayList;
15 |
16 | /**
17 | * Created by : youngkaaa on 2017/2/22.
18 | * Contact me : 645326280@qq.com
19 | */
20 |
21 | /*
22 | * Copyright (C) 2011 The Android Open Source Project
23 | *
24 | * Licensed under the Apache License, Version 2.0 (the "License");
25 | * you may not use this file except in compliance with the License.
26 | * You may obtain a copy of the License at
27 | *
28 | * http://www.apache.org/licenses/LICENSE-2.0
29 | *
30 | * Unless required by applicable law or agreed to in writing, software
31 | * distributed under the License is distributed on an "AS IS" BASIS,
32 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 | * See the License for the specific language governing permissions and
34 | * limitations under the License.
35 | */
36 |
37 |
38 | /**
39 | * Implementation of PagerAdapter that
40 | * uses a Fragment to manage each page. This class also handles
41 | * saving and restoring of fragment's state.
42 | *
This version of the pager is more useful when there are a large number
43 | * of pages, working more like a list view. When pages are not visible to
44 | * the user, their entire fragment may be destroyed, only keeping the saved
45 | * state of that fragment. This allows the pager to hold on to much less
46 | * memory associated with each visited page as compared to
47 | * FragmentPagerAdapter at the cost of potentially more overhead when
48 | * switching between pages.
49 | *
When using FragmentPagerAdapter the host ViewPager must have a
50 | * valid ID set.
51 | *
Subclasses only need to implement {@link #getItem(int)}
52 | * and {@link #getCount()} to have a working adapter.
53 | *
54 | */
55 | public abstract class YFragmentStatePagerAdapter extends YPagerAdapter {
56 | private static final String TAG = "YFragmentStateAdapter";
57 | private static final boolean DEBUG = false;
58 |
59 | private final FragmentManager mFragmentManager;
60 | private FragmentTransaction mCurTransaction = null;
61 |
62 | private ArrayList mSavedState = new ArrayList();
63 | private ArrayList mFragments = new ArrayList();
64 | private Fragment mCurrentPrimaryItem = null;
65 |
66 | public YFragmentStatePagerAdapter(FragmentManager fm) {
67 | mFragmentManager = fm;
68 | }
69 |
70 | /**
71 | * Return the Fragment associated with a specified position.
72 | */
73 | public abstract Fragment getItem(int position);
74 |
75 | @Override
76 | public void startUpdate(ViewGroup container) {
77 | if (container.getId() == View.NO_ID) {
78 | throw new IllegalStateException("ViewPager with adapter " + this
79 | + " requires a view id");
80 | }
81 | }
82 |
83 | /**
84 | *
85 | * @param container The containing View in which the page will be shown.
86 | * @param position The page position to be instantiated.
87 | * @return
88 | */
89 | @Override
90 | public Object instantiateItem(ViewGroup container, int position) {
91 | // If we already have this item instantiated, there is nothing
92 | // to do. This can happen when we are restoring the entire pager
93 | // from its saved state, where the fragment manager has already
94 | // taken care of restoring the fragments we previously had instantiated.
95 | if (mFragments.size() > position) {
96 | Fragment f = mFragments.get(position);
97 | if (f != null) {
98 | return f;
99 | }
100 | }
101 |
102 | if (mCurTransaction == null) {
103 | mCurTransaction = mFragmentManager.beginTransaction();
104 | }
105 |
106 | Fragment fragment = getItem(position);
107 | if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
108 | if (mSavedState.size() > position) {
109 | Fragment.SavedState fss = mSavedState.get(position);
110 | if (fss != null) {
111 | fragment.setInitialSavedState(fss);
112 | }
113 | }
114 | while (mFragments.size() <= position) {
115 | mFragments.add(null);
116 | }
117 | fragment.setMenuVisibility(false);
118 | fragment.setUserVisibleHint(false);
119 | mFragments.set(position, fragment);
120 | mCurTransaction.add(container.getId(), fragment);
121 |
122 | return fragment;
123 | }
124 |
125 | @Override
126 | public void destroyItem(ViewGroup container, int position, Object object) {
127 | Fragment fragment = (Fragment) object;
128 |
129 | if (mCurTransaction == null) {
130 | mCurTransaction = mFragmentManager.beginTransaction();
131 | }
132 | if (DEBUG) Log.v(TAG, "Removing item #" + position + ": f=" + object
133 | + " v=" + ((Fragment) object).getView());
134 | while (mSavedState.size() <= position) {
135 | mSavedState.add(null);
136 | }
137 | mSavedState.set(position, fragment.isAdded()
138 | ? mFragmentManager.saveFragmentInstanceState(fragment) : null);
139 | mFragments.set(position, null);
140 |
141 | mCurTransaction.remove(fragment);
142 | }
143 |
144 | @Override
145 | public void setPrimaryItem(ViewGroup container, int position, Object object) {
146 | Fragment fragment = (Fragment) object;
147 | if (fragment != mCurrentPrimaryItem) {
148 | if (mCurrentPrimaryItem != null) {
149 | mCurrentPrimaryItem.setMenuVisibility(false);
150 | mCurrentPrimaryItem.setUserVisibleHint(false);
151 | }
152 | if (fragment != null) {
153 | fragment.setMenuVisibility(true);
154 | fragment.setUserVisibleHint(true);
155 | }
156 | mCurrentPrimaryItem = fragment;
157 | }
158 | }
159 |
160 | @Override
161 | public void finishUpdate(ViewGroup container) {
162 | if (mCurTransaction != null) {
163 | mCurTransaction.commitNowAllowingStateLoss();
164 | mCurTransaction = null;
165 | }
166 | }
167 |
168 | @Override
169 | public boolean isViewFromObject(View view, Object object) {
170 | return ((Fragment) object).getView() == view;
171 | }
172 |
173 | @Override
174 | public Parcelable saveState() {
175 | Bundle state = null;
176 | if (mSavedState.size() > 0) {
177 | state = new Bundle();
178 | Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()];
179 | mSavedState.toArray(fss);
180 | state.putParcelableArray("states", fss);
181 | }
182 | for (int i = 0; i < mFragments.size(); i++) {
183 | Fragment f = mFragments.get(i);
184 | if (f != null && f.isAdded()) {
185 | if (state == null) {
186 | state = new Bundle();
187 | }
188 | String key = "f" + i;
189 | mFragmentManager.putFragment(state, key, f);
190 | }
191 | }
192 | return state;
193 | }
194 |
195 | @Override
196 | public void restoreState(Parcelable state, ClassLoader loader) {
197 | if (state != null) {
198 | Bundle bundle = (Bundle) state;
199 | bundle.setClassLoader(loader);
200 | Parcelable[] fss = bundle.getParcelableArray("states");
201 | mSavedState.clear();
202 | mFragments.clear();
203 | if (fss != null) {
204 | for (int i = 0; i < fss.length; i++) {
205 | mSavedState.add((Fragment.SavedState) fss[i]);
206 | }
207 | }
208 | Iterable keys = bundle.keySet();
209 | for (String key : keys) {
210 | if (key.startsWith("f")) {
211 | int index = Integer.parseInt(key.substring(1));
212 | Fragment f = mFragmentManager.getFragment(bundle, key);
213 | if (f != null) {
214 | while (mFragments.size() <= index) {
215 | mFragments.add(null);
216 | }
217 | f.setMenuVisibility(false);
218 | mFragments.set(index, f);
219 | } else {
220 | Log.w(TAG, "Bad fragment at key " + key);
221 | }
222 | }
223 | }
224 | }
225 | }
226 | }
227 |
--------------------------------------------------------------------------------
/yviewpager/src/main/java/cn/youngkaaa/yviewpager/YPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpager;
2 |
3 | /*
4 | * Copyright (C) 2011 The Android Open Source Project
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.database.DataSetObservable;
20 | import android.database.DataSetObserver;
21 | import android.os.Parcelable;
22 | import android.view.View;
23 | import android.view.ViewGroup;
24 |
25 | /**
26 | * Base class providing the adapter to populate pages inside of
27 | * a ViewPager. You will most likely want to use a more
28 | * specific implementation of this, such as
29 | * FragmentPagerAdapter or
30 | * FragmentStatePagerAdapter.
31 | *
When you implement a PagerAdapter, you must override the following methods
32 | * at minimum:
33 | *
34 | *
{@link #instantiateItem(ViewGroup, int)}
35 | *
{@link #destroyItem(ViewGroup, int, Object)}
36 | *
{@link #getCount()}
37 | *
{@link #isViewFromObject(View, Object)}
38 | *
39 | *
PagerAdapter is more general than the adapters used for
40 | * {@link android.widget.AdapterView AdapterViews}. Instead of providing a
41 | * View recycling mechanism directly ViewPager uses callbacks to indicate the
42 | * steps taken during an update. A PagerAdapter may implement a form of View
43 | * recycling if desired or use a more sophisticated method of managing page
44 | * Views such as Fragment transactions where each page is represented by its
45 | * own Fragment.
46 | *
ViewPager associates each page with a key Object instead of working with
47 | * Views directly. This key is used to track and uniquely identify a given page
48 | * independent of its position in the adapter. A call to the PagerAdapter method
49 | * {@link #startUpdate(ViewGroup)} indicates that the contents of the ViewPager
50 | * are about to change. One or more calls to {@link #instantiateItem(ViewGroup, int)}
51 | * and/or {@link #destroyItem(ViewGroup, int, Object)} will follow, and the end
52 | * of an update will be signaled by a call to {@link #finishUpdate(ViewGroup)}.
53 | * By the time {@link #finishUpdate(ViewGroup) finishUpdate} returns the views
54 | * associated with the key objects returned by
55 | * {@link #instantiateItem(ViewGroup, int) instantiateItem} should be added to
56 | * the parent ViewGroup passed to these methods and the views associated with
57 | * the keys passed to {@link #destroyItem(ViewGroup, int, Object) destroyItem}
58 | * should be removed. The method {@link #isViewFromObject(View, Object)} identifies
59 | * whether a page View is associated with a given key object.
60 | *
A very simple PagerAdapter may choose to use the page Views themselves
61 | * as key objects, returning them from {@link #instantiateItem(ViewGroup, int)}
62 | * after creation and adding them to the parent ViewGroup. A matching
63 | * {@link #destroyItem(ViewGroup, int, Object)} implementation would remove the
64 | * View from the parent ViewGroup and {@link #isViewFromObject(View, Object)}
65 | * could be implemented as return view == object;.
66 | *
PagerAdapter supports data set changes. Data set changes must occur on the
67 | * main thread and must end with a call to {@link #notifyDataSetChanged()} similar
68 | * to AdapterView adapters derived from {@link android.widget.BaseAdapter}. A data
69 | * set change may involve pages being added, removed, or changing position. The
70 | * ViewPager will keep the current page active provided the adapter implements
71 | * the method {@link #getItemPosition(Object)}.
72 | */
73 | public abstract class YPagerAdapter{
74 | private final DataSetObservable mObservable = new DataSetObservable();
75 | private DataSetObserver mViewPagerObserver;
76 |
77 | public static final int POSITION_UNCHANGED = -1;
78 | public static final int POSITION_NONE = -2;
79 |
80 | /**
81 | * Return the number of views available.
82 | */
83 | public abstract int getCount();
84 |
85 | /**
86 | * Called when a change in the shown pages is going to start being made.
87 | *
88 | * @param container The containing View which is displaying this adapter's
89 | * page views.
90 | */
91 | public void startUpdate(ViewGroup container) {
92 | startUpdate((View) container);
93 | }
94 |
95 | /**
96 | * Create the page for the given position. The adapter is responsible
97 | * for adding the view to the container given here, although it only
98 | * must ensure this is done by the time it returns from
99 | * {@link #finishUpdate(ViewGroup)}.
100 | *
101 | * @param container The containing View in which the page will be shown.
102 | * @param position The page position to be instantiated.
103 | * @return Returns an Object representing the new page. This does not
104 | * need to be a View, but can be some other container of the page.
105 | */
106 | public Object instantiateItem(ViewGroup container, int position) {
107 | return instantiateItem((View) container, position);
108 | }
109 |
110 | /**
111 | * Remove a page for the given position. The adapter is responsible
112 | * for removing the view from its container, although it only must ensure
113 | * this is done by the time it returns from {@link #finishUpdate(ViewGroup)}.
114 | *
115 | * @param container The containing View from which the page will be removed.
116 | * @param position The page position to be removed.
117 | * @param object The same object that was returned by
118 | * {@link #instantiateItem(View, int)}.
119 | */
120 | public void destroyItem(ViewGroup container, int position, Object object) {
121 | destroyItem((View) container, position, object);
122 | }
123 |
124 | /**
125 | * Called to inform the adapter of which item is currently considered to
126 | * be the "primary", that is the one show to the user as the current page.
127 | *
128 | * @param container The containing View from which the page will be removed.
129 | * @param position The page position that is now the primary.
130 | * @param object The same object that was returned by
131 | * {@link #instantiateItem(View, int)}.
132 | */
133 | public void setPrimaryItem(ViewGroup container, int position, Object object) {
134 | setPrimaryItem((View) container, position, object);
135 | }
136 |
137 | /**
138 | * Called when the a change in the shown pages has been completed. At this
139 | * point you must ensure that all of the pages have actually been added or
140 | * removed from the container as appropriate.
141 | *
142 | * @param container The containing View which is displaying this adapter's
143 | * page views.
144 | */
145 | public void finishUpdate(ViewGroup container) {
146 | finishUpdate((View) container);
147 | }
148 |
149 | /**
150 | * Called when a change in the shown pages is going to start being made.
151 | *
152 | * @param container The containing View which is displaying this adapter's
153 | * page views.
154 | * @deprecated Use {@link #startUpdate(ViewGroup)}
155 | */
156 | @Deprecated
157 | public void startUpdate(View container) {
158 | }
159 |
160 | /**
161 | * Create the page for the given position. The adapter is responsible
162 | * for adding the view to the container given here, although it only
163 | * must ensure this is done by the time it returns from
164 | * {@link #finishUpdate(ViewGroup)}.
165 | *
166 | * @param container The containing View in which the page will be shown.
167 | * @param position The page position to be instantiated.
168 | * @return Returns an Object representing the new page. This does not
169 | * need to be a View, but can be some other container of the page.
170 | * @deprecated Use {@link #instantiateItem(ViewGroup, int)}
171 | */
172 | @Deprecated
173 | public Object instantiateItem(View container, int position) {
174 | throw new UnsupportedOperationException(
175 | "Required method instantiateItem was not overridden");
176 | }
177 |
178 | /**
179 | * Remove a page for the given position. The adapter is responsible
180 | * for removing the view from its container, although it only must ensure
181 | * this is done by the time it returns from {@link #finishUpdate(View)}.
182 | *
183 | * @param container The containing View from which the page will be removed.
184 | * @param position The page position to be removed.
185 | * @param object The same object that was returned by
186 | * {@link #instantiateItem(View, int)}.
187 | * @deprecated Use {@link #destroyItem(ViewGroup, int, Object)}
188 | */
189 | @Deprecated
190 | public void destroyItem(View container, int position, Object object) {
191 | throw new UnsupportedOperationException("Required method destroyItem was not overridden");
192 | }
193 |
194 | /**
195 | * Called to inform the adapter of which item is currently considered to
196 | * be the "primary", that is the one show to the user as the current page.
197 | *
198 | * @param container The containing View from which the page will be removed.
199 | * @param position The page position that is now the primary.
200 | * @param object The same object that was returned by
201 | * {@link #instantiateItem(View, int)}.
202 | * @deprecated Use {@link #setPrimaryItem(ViewGroup, int, Object)}
203 | */
204 | @Deprecated
205 | public void setPrimaryItem(View container, int position, Object object) {
206 | }
207 |
208 | /**
209 | * Called when the a change in the shown pages has been completed. At this
210 | * point you must ensure that all of the pages have actually been added or
211 | * removed from the container as appropriate.
212 | *
213 | * @param container The containing View which is displaying this adapter's
214 | * page views.
215 | * @deprecated Use {@link #finishUpdate(ViewGroup)}
216 | */
217 | @Deprecated
218 | public void finishUpdate(View container) {
219 | }
220 |
221 | /**
222 | * Determines whether a page View is associated with a specific key object
223 | * as returned by {@link #instantiateItem(ViewGroup, int)}. This method is
224 | * required for a PagerAdapter to function properly.
225 | *
226 | * @param view Page View to check for association with object
227 | * @param object Object to check for association with view
228 | * @return true if view is associated with the key object object
229 | */
230 | public abstract boolean isViewFromObject(View view, Object object);
231 |
232 | /**
233 | * Save any instance state associated with this adapter and its pages that should be
234 | * restored if the current UI state needs to be reconstructed.
235 | *
236 | * @return Saved state for this adapter
237 | */
238 | public Parcelable saveState() {
239 | return null;
240 | }
241 |
242 | /**
243 | * Restore any instance state associated with this adapter and its pages
244 | * that was previously saved by {@link #saveState()}.
245 | *
246 | * @param state State previously saved by a call to {@link #saveState()}
247 | * @param loader A ClassLoader that should be used to instantiate any restored objects
248 | */
249 | public void restoreState(Parcelable state, ClassLoader loader) {
250 | }
251 |
252 | /**
253 | * Called when the host view is attempting to determine if an item's position
254 | * has changed. Returns {@link #POSITION_UNCHANGED} if the position of the given
255 | * item has not changed or {@link #POSITION_NONE} if the item is no longer present
256 | * in the adapter.
257 | *
The default implementation assumes that items will never
258 | * change position and always returns {@link #POSITION_UNCHANGED}.
259 | *
260 | * @param object Object representing an item, previously returned by a call to
261 | * {@link #instantiateItem(View, int)}.
262 | * @return object's new position index from [0, {@link #getCount()}),
263 | * {@link #POSITION_UNCHANGED} if the object's position has not changed,
264 | * or {@link #POSITION_NONE} if the item is no longer present.
265 | */
266 | public int getItemPosition(Object object) {
267 | return POSITION_UNCHANGED;
268 | }
269 |
270 | /**
271 | * This method should be called by the application if the data backing this adapter has changed
272 | * and associated views should update.
273 | */
274 | public void notifyDataSetChanged() {
275 | synchronized (this) {
276 | if (mViewPagerObserver != null) {
277 | mViewPagerObserver.onChanged();
278 | }
279 | }
280 | mObservable.notifyChanged();
281 | }
282 |
283 | /**
284 | * Register an observer to receive callbacks related to the adapter's data changing.
285 | *
286 | * @param observer The {@link android.database.DataSetObserver} which will receive callbacks.
287 | */
288 | public void registerDataSetObserver(DataSetObserver observer) {
289 | mObservable.registerObserver(observer);
290 | }
291 |
292 | /**
293 | * Unregister an observer from callbacks related to the adapter's data changing.
294 | *
295 | * @param observer The {@link android.database.DataSetObserver} which will be unregistered.
296 | */
297 | public void unregisterDataSetObserver(DataSetObserver observer) {
298 | mObservable.unregisterObserver(observer);
299 | }
300 |
301 | public void setViewPagerObserver(DataSetObserver observer) {
302 | synchronized (this) {
303 | mViewPagerObserver = observer;
304 | }
305 | }
306 |
307 | /**
308 | * This method may be called by the ViewPager to obtain a title string
309 | * to describe the specified page. This method may return null
310 | * indicating no title for this page. The default implementation returns
311 | * null.
312 | *
313 | * @param position The position of the title requested
314 | * @return A title for the requested page
315 | */
316 | public CharSequence getPageTitle(int position) {
317 | return null;
318 | }
319 |
320 | /**
321 | * Returns the proportional width of a given page as a percentage of the
322 | * ViewPager's measured width from (0.f-1.f]
323 | *
324 | * @param position The position of the page requested
325 | * @return Proportional width for the given page position
326 | */
327 | public float getPageWidth(int position) {
328 | return 1.f;
329 | }
330 | }
331 |
--------------------------------------------------------------------------------
/yviewpager/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/yviewpager/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | YViewPager
3 |
4 |
--------------------------------------------------------------------------------
/yviewpager/src/test/java/cn/youngkaaa/yviewpager/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.youngkaaa.yviewpager;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------