├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── shiming │ │ └── cardviewpager │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── shiming │ │ │ └── cardviewpager │ │ │ ├── CardViewPager.java │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── text_layout.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── test.jpg │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── shiming │ └── cardviewpager │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.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/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | C:\Users\shiming\AppData\Roaming\Subversion 48 | 49 | 50 | 51 | 52 | 53 | 1.8 54 | 55 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CardViewPager 2 | 自定义ViewPager 3 | ##不逼逼,看效果!两边有点露出来的效果,比如腾讯视频App的上方的效果,都是轻量级的控件,请勿见怪,总体时间花费大约9个小时,其中找Bug找了3个小时,哈哈 4 | 5 | ![微信图片_20170904213432.jpg](http://upload-images.jianshu.io/upload_images/5363507-8ad5b63a07dad73f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 6 | 7 | - 第一个效果是正常的滑动情况 8 | ![xiao.gif](http://upload-images.jianshu.io/upload_images/5363507-ce7c0fa257533994.gif?imageMogr2/auto-orient/strip) 9 | - 第二个效果是禁止滑动情况,同时呢,有一个回弹的效果,四川话讲这个很巴适 10 | ![xiao.gif](http://upload-images.jianshu.io/upload_images/5363507-fd86e9fec575c1a4.gif?imageMogr2/auto-orient/strip) 11 | ##分享两个东西 12 | - 今天发现的一个Android UI 开发效率的 UI 库:https://github.com/QMUI/QMUI_Android 13 | - 这个我都不好意思分享,嘿嘿,周天就做这个,做完了发现根本没有什么东西可以分享,所以就写了现在这个博客,等我以后研究下hexo,才来更新 14 | https://shimingli.github.io/ 15 | 16 | 17 | ##写在前面的话:如果我手写慢一点,多看看一下api,我就不会把两个api写错了,由于手滑写错了,导致我这篇博客现在才来写,兴奋感都快磨完了。 18 | ![72F75ABC3304DD06A39EB5A18180F6CE.gif](http://upload-images.jianshu.io/upload_images/5363507-dfa1376367aa27eb.gif?imageMogr2/auto-orient/strip) 19 | - 这辈子我都不会忘记这个值了,getScaledTouchSlop()是一个距离,表示滑动的时候,手的移动要大于这个距离才开始移动控件。viewpager就是用这个距离来判断用户是否翻页,只不过呢 20 | ``` 21 | ViewConfiguration.get(mContext).getScaledTouchSlop() 22 | ``` 23 | --- 24 | 原理如下: mTouchSlop = configuration.getScaledPagingTouchSlop();就是这个值,但是你可能会说有毛的的关系啊,别急 25 | ![](http://upload-images.jianshu.io/upload_images/5363507-fa2d83618ec0929f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 26 | 往ViewConfiguration类看记住这个值 27 | ![](http://upload-images.jianshu.io/upload_images/5363507-55e3fe09f76552f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 28 | 29 | ![image.png](http://upload-images.jianshu.io/upload_images/5363507-3f0eed8d739c16fe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 30 | 看这个值mTouchSlop,对吧只不过在ViewPager判断是否需要移动的时候,这个距离是*2。 31 | 32 | ![image.png](http://upload-images.jianshu.io/upload_images/5363507-df28f20936b2d39c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 33 | 由于我这里需要更高的精度,所以获取了这个值getScaledTouchSlop() 34 | --- 35 | - 可千万不要拿到getScaledDoubleTapSlop()这个值了啊! 36 | ``` 37 | //第一次触摸和第二次触摸之间的距离,Distance in pixels between the first touch and second touch 38 | ViewConfiguration.get(mContext).getScaledDoubleTapSlop(); 39 | ``` 40 | ##继承ViewGroup,重写构造方法 41 | ``` 42 | public class CardViewPager extends ViewGroup{ 43 | 44 | public CardViewPager(Context context) { 45 | this(context,null); 46 | } 47 | 48 | public CardViewPager(Context context, AttributeSet attrs) { 49 | super(context, attrs); 50 | init(context); 51 | } 52 | } 53 | ``` 54 | ##初始化init 55 | ``` 56 | private void init(Context context) { 57 | mContext = context; 58 | //滑动的对象 59 | mScroller = new Scroller(mContext); 60 | //getScaledTouchSlop是一个距离,表示滑动的时候,手的移动要大于这个距离才开始移动控件。 61 | // 如果小于这个距离就不触发移动控件,如viewpager就是用这个距离来判断用户是否翻页 62 | // mScaledDoubleTapSlop = ViewConfiguration.get(mContext).getScaledTouchSlop(); 63 | mScaledDoubleTapSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop(); 64 | //第一次触摸和第二次触摸之间的距离,Distance in pixels between the first touch and second touch 65 | ViewConfiguration.get(mContext).getScaledDoubleTapSlop(); 66 | FIRST_width = dp2px(mContext, 10); 67 | TWO_GAP_WIDTH = FIRST_width * 2; 68 | THREE_GAP_WIDTH = FIRST_width * 3; 69 | FOUR_GAP_WIDTH = FIRST_width * 4; 70 | } 71 | ``` 72 | ##onMeasure,重写测量这里记住widthMeasureSpec、heightMeasureSpec是一个32位的int值,其中高两位是物理模式,低的30位才是控件的宽度和高度的信息。 73 | MeasureSpec.EXACTLY:父视图希望子视图的大小应该是specSize中指定的。 74 | MeasureSpec.AT_MOST:子视图的大小最多是specSize中指定的值,也就是说不建议子视图的大小超过specSize中给定的值。 75 | MeasureSpec.UNSPECIFIED:我们可以随意指定视图的大小。 76 | ``` 77 | @Override 78 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 79 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 80 | //这才是真正的宽度和高度 81 | int widthSize = MeasureSpec.getSize(widthMeasureSpec); 82 | int heighSize = MeasureSpec.getSize(heightMeasureSpec); 83 | //设置测量的大小 84 | setMeasuredDimension(widthSize,heighSize); 85 | //测量孩子的大小 86 | mChildCount = getChildCount(); 87 | for (int i=0;imScaledDoubleTapSlop){ 153 | return true; 154 | } 155 | break; 156 | } 157 | return super.onInterceptTouchEvent(ev); 158 | } 159 | 160 | ``` 161 | ##处理事件:在down的事件一定需要拦截,才能记录坐标 162 | 返回值为True,代表拦截这次事件,直接进入到ViewGroup的onTouchEvent中,就不会进入到View的onTouchEvent了 163 | 返回值为False,代表不拦截这次事件,不进入到ViewGroup的onTouchEvent中,直接进入到View的onTouchEvent中 164 | ``` 165 | public boolean onTouchEvent(MotionEvent event) { 166 | //如果没有孩子的话,不需要拦截 167 | if (getChildCount()==0){ 168 | return false; 169 | } 170 | //监听滑动的速度 171 | obtainTracker(event); 172 | switch (event.getAction()){ 173 | case MotionEvent.ACTION_DOWN: 174 | if (!mScroller.isFinished()){ 175 | //停止动画 176 | mScroller.abortAnimation(); 177 | } 178 | int x = (int) event.getX(); 179 | mLastMotionX=x; 180 | //不管怎么怎么样这个事件都必须拦截 181 | return true; 182 | 183 | case MotionEvent.ACTION_MOVE: 184 | x = (int) event.getX(); 185 | int desX = mLastMotionX - x; 186 | //这个距离大于了屏幕的10/1的话,就给他赋值10/1 187 | if (!isAllowScroll&&desX>getWidth()/10){ 188 | desX=getWidth()/10; 189 | //如果设置了不可以滑动的,这个flag需要到up事件单独处理 190 | mCanScrolled = true; 191 | } 192 | //只需计算x的距离 193 | mVelocityTracker.computeCurrentVelocity(1000,ViewConfiguration.getMaximumFlingVelocity()); 194 | mXVelocity = (int) mVelocityTracker.getXVelocity(); 195 | //如果说距离滑动太小,或者是只有一个屏幕的话,就不往下去做操作了 196 | if (Math.abs(desX)=0&& 197 | mCurScreen==mChildCount-1)||(desX<=0&&mCurScreen==0)){ 198 | break; 199 | } 200 | 201 | //能到这里来的话,就必须往手指方向慢慢滚动了 202 | scrollTo(getChildAt(mCurScreen).getLeft()+desX,0); 203 | break; 204 | case MotionEvent.ACTION_UP: 205 | //mXVelocity为正数的话,这个是往left滚 206 | if (isAllowScroll&&mXVelocity>MAX_VELOCITY_VALUE&&mCurScreen>0){ 207 | scrollScreen(mCurScreen-1); 208 | }else if (isAllowScroll&&mXVelocity<-MAX_VELOCITY_VALUE&&mCurScreenTesting 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("com.shiming.cardviewpager", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/shiming/cardviewpager/CardViewPager.java: -------------------------------------------------------------------------------- 1 | package com.shiming.cardviewpager; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.MotionEvent; 6 | import android.view.VelocityTracker; 7 | import android.view.View; 8 | import android.view.ViewConfiguration; 9 | import android.view.ViewGroup; 10 | import android.widget.Scroller; 11 | 12 | /** 13 | * 14 | * Created by shiming on 2017/9/3. 15 | * 一种类似于viewpager的滑动,有padding的卡片效果 16 | */ 17 | 18 | public class CardViewPager extends ViewGroup { 19 | 20 | private Context mContext; 21 | private Scroller mScroller; 22 | private int mScaledDoubleTapSlop; 23 | private int FIRST_width; 24 | private int TWO_GAP_WIDTH; 25 | private int THREE_GAP_WIDTH; 26 | private int FOUR_GAP_WIDTH; 27 | private int mChildCount; 28 | private int mLastMotionX; 29 | // 滑动速度 30 | private VelocityTracker mVelocityTracker; 31 | private final static int MAX_VELOCITY_VALUE = 2000; 32 | private boolean mCanScrolled=false; 33 | private int mXVelocity; 34 | // 当前屏 35 | private int mCurScreen = 0; 36 | 37 | // 是否允许滚动 38 | private boolean isAllowScroll = false; 39 | public CardViewPager(Context context) { 40 | this(context,null); 41 | } 42 | 43 | public CardViewPager(Context context, AttributeSet attrs) { 44 | super(context, attrs); 45 | init(context); 46 | } 47 | 48 | private void init(Context context) { 49 | mContext = context; 50 | //滑动的对象 51 | mScroller = new Scroller(mContext); 52 | //getScaledTouchSlop是一个距离,表示滑动的时候,手的移动要大于这个距离才开始移动控件。 53 | // 如果小于这个距离就不触发移动控件,如viewpager就是用这个距离来判断用户是否翻页 54 | mScaledDoubleTapSlop = ViewConfiguration.get(mContext).getScaledTouchSlop(); 55 | //第一次触摸和第二次触摸之间的距离,Distance in pixels between the first touch and second touch 56 | ViewConfiguration.get(mContext).getScaledDoubleTapSlop(); 57 | FIRST_width = dp2px(mContext, 10); 58 | TWO_GAP_WIDTH = FIRST_width * 2; 59 | THREE_GAP_WIDTH = FIRST_width * 3; 60 | FOUR_GAP_WIDTH = FIRST_width * 4; 61 | } 62 | 63 | /** 64 | * 65 | MeasureSpec.EXACTLY:父视图希望子视图的大小应该是specSize中指定的。 66 | MeasureSpec.AT_MOST:子视图的大小最多是specSize中指定的值,也就是说不建议子视图的大小超过specSize中给定的值。 67 | MeasureSpec.UNSPECIFIED:我们可以随意指定视图的大小。 68 | * @param widthMeasureSpec 是一个32位的int值,其中高两位是物理模式,低的30位才是控件的宽度和高度的信息 69 | * @param heightMeasureSpec 70 | */ 71 | @Override 72 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 73 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 74 | //这才是真正的宽度和高度 75 | int widthSize = MeasureSpec.getSize(widthMeasureSpec); 76 | int heighSize = MeasureSpec.getSize(heightMeasureSpec); 77 | //设置测量的大小 78 | setMeasuredDimension(widthSize,heighSize); 79 | //测量孩子的大小 80 | mChildCount = getChildCount(); 81 | for (int i=0;imScaledDoubleTapSlop){ 134 | return true; 135 | } 136 | break; 137 | } 138 | return super.onInterceptTouchEvent(ev); 139 | } 140 | 141 | /** 142 | * 处理事件 143 | * @param event 144 | * @return 145 | */ 146 | @Override 147 | public boolean onTouchEvent(MotionEvent event) { 148 | //如果没有孩子的话,不需要拦截 149 | if (getChildCount()==0){ 150 | return false; 151 | } 152 | //监听滑动的速度 153 | obtainTracker(event); 154 | switch (event.getAction()){ 155 | case MotionEvent.ACTION_DOWN: 156 | if (!mScroller.isFinished()){ 157 | //停止动画 158 | mScroller.abortAnimation(); 159 | } 160 | int x = (int) event.getX(); 161 | mLastMotionX=x; 162 | //不管怎么怎么样这个事件都必须拦截 163 | return true; 164 | 165 | case MotionEvent.ACTION_MOVE: 166 | x = (int) event.getX(); 167 | int desX = mLastMotionX - x; 168 | //这个距离大于了屏幕的10/1的话,就给他赋值10/1 169 | if (!isAllowScroll&&desX>getWidth()/10){ 170 | desX=getWidth()/10; 171 | //如果设置了不可以滑动的,这个flag需要到up事件单独处理 172 | mCanScrolled = true; 173 | } 174 | //只需计算x的距离 175 | mVelocityTracker.computeCurrentVelocity(1000,ViewConfiguration.getMaximumFlingVelocity()); 176 | mXVelocity = (int) mVelocityTracker.getXVelocity(); 177 | //如果说距离滑动太小,或者是只有一个屏幕的话,就不往下去做操作了 178 | if (Math.abs(desX)=0&& 179 | mCurScreen==mChildCount-1)||(desX<=0&&mCurScreen==0)){ 180 | break; 181 | } 182 | 183 | //能到这里来的话,就必须往手指方向慢慢滚动了 184 | scrollTo(getChildAt(mCurScreen).getLeft()+desX,0); 185 | break; 186 | case MotionEvent.ACTION_UP: 187 | //mXVelocity为正数的话,这个是往left滚 188 | if (isAllowScroll&&mXVelocity>MAX_VELOCITY_VALUE&&mCurScreen>0){ 189 | scrollScreen(mCurScreen-1); 190 | }else if (isAllowScroll&&mXVelocity<-MAX_VELOCITY_VALUE&&mCurScreen viewSparseArray = new ArrayList<>(); 25 | for (int i = 0; i < 5; i++) { 26 | View inflate = LayoutInflater.from(this).inflate(R.layout.text_layout, null); 27 | viewSparseArray.add(inflate); 28 | mCardViewPager.addView(inflate); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/text_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-xxhdpi/test.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CardViewPager 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/shiming/cardviewpager/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.shiming.cardviewpager; 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.3.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /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/Shimingli/CardViewPager/883ddb69261dac9b447d50ef6532d23ed211820d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Sep 03 17:46:12 CST 2017 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-3.3-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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------