From 53d431ed9810ef5af7d35ec41b29ff628aecb61e Mon Sep 17 00:00:00 2001 From: nieyinyin Date: Wed, 20 Jan 2016 14:51:21 +0800 Subject: [PATCH 1/4] fix the logic: stop cycle when SliderLayout has only one SliderView --- .../java/com/daimajia/slider/library/SliderLayout.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/src/main/java/com/daimajia/slider/library/SliderLayout.java b/library/src/main/java/com/daimajia/slider/library/SliderLayout.java index ba36e5e..9cb431a 100644 --- a/library/src/main/java/com/daimajia/slider/library/SliderLayout.java +++ b/library/src/main/java/com/daimajia/slider/library/SliderLayout.java @@ -193,6 +193,9 @@ public SliderLayout(Context context, AttributeSet attrs, int defStyle) { mViewPager.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { + if(mSliderAdapter.getCount() < 2){ + return true; + } int action = event.getAction(); switch (action) { case MotionEvent.ACTION_UP: @@ -235,6 +238,11 @@ public void setCustomIndicator(PagerIndicator indicator){ public void addSlider(T imageContent){ mSliderAdapter.addSlider(imageContent); + if(mSliderAdapter.getCount() < 2){ + stopAutoCycle(); + }else{ + if(mAutoCycle) recoverCycle(); + } } private android.os.Handler mh = new android.os.Handler(){ From 58d8ab222ff866f2745dcc6258862cec80458538 Mon Sep 17 00:00:00 2001 From: nieyinyin Date: Fri, 29 Jan 2016 17:07:24 +0800 Subject: [PATCH 2/4] modify attr "shape" to "daimajia_slider_shape" --- demo/src/main/res/layout/activity_main.xml | 2 +- .../daimajia/slider/library/Indicators/PagerIndicator.java | 2 +- library/src/main/res/layout/slider_layout.xml | 2 +- library/src/main/res/values/attrs.xml | 2 +- library/src/main/res/values/styles.xml | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml index 9e1f049..14e8a0b 100644 --- a/demo/src/main/res/layout/activity_main.xml +++ b/demo/src/main/res/layout/activity_main.xml @@ -22,7 +22,7 @@ custom:selected_color="#0095BF" custom:unselected_color="#55333333" custom:selected_drawable="@drawable/bird" - custom:shape="oval" + custom:daimajia_slider_shape="oval" custom:selected_padding_left="5dp" custom:selected_padding_right="5dp" custom:unselected_padding_left="5dp" diff --git a/library/src/main/java/com/daimajia/slider/library/Indicators/PagerIndicator.java b/library/src/main/java/com/daimajia/slider/library/Indicators/PagerIndicator.java index b10abee..98e6acc 100644 --- a/library/src/main/java/com/daimajia/slider/library/Indicators/PagerIndicator.java +++ b/library/src/main/java/com/daimajia/slider/library/Indicators/PagerIndicator.java @@ -127,7 +127,7 @@ public PagerIndicator(Context context, AttributeSet attrs) { } } - int shape = attributes.getInt(R.styleable.PagerIndicator_shape, Shape.Oval.ordinal()); + int shape = attributes.getInt(R.styleable.PagerIndicator_daimajia_slider_shape, Shape.Oval.ordinal()); for(Shape s: Shape.values()){ if(s.ordinal() == shape){ mIndicatorShape = s; diff --git a/library/src/main/res/layout/slider_layout.xml b/library/src/main/res/layout/slider_layout.xml index 01fcf0d..868fb2d 100644 --- a/library/src/main/res/layout/slider_layout.xml +++ b/library/src/main/res/layout/slider_layout.xml @@ -14,7 +14,7 @@ android:layout_centerHorizontal="true" android:paddingBottom="10dp" android:gravity="center" - custom:shape="oval" + custom:daimajia_slider_shape="oval" android:layout_width="wrap_content" android:layout_height="wrap_content"/> - + diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml index f8d0ad2..1c74ee4 100644 --- a/library/src/main/res/values/styles.xml +++ b/library/src/main/res/values/styles.xml @@ -7,7 +7,7 @@ @drawable/indicator_corner_bg 2dp 2dp - oval + oval 3dp 3dp 4dp @@ -27,7 +27,7 @@ center 2dp 2dp - rect + rect 3dp 3dp 4dp @@ -47,7 +47,7 @@ center 2dp 2dp - oval + oval 3dp 3dp 4dp From 6f2f29972732676f07cc56a0abf8a84684b829b1 Mon Sep 17 00:00:00 2001 From: nieyinyin Date: Sun, 31 Jan 2016 11:04:17 +0800 Subject: [PATCH 3/4] optimize the logic: stop cycle when SliderLayout has only one SliderView --- .../main/java/com/daimajia/slider/library/SliderLayout.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/src/main/java/com/daimajia/slider/library/SliderLayout.java b/library/src/main/java/com/daimajia/slider/library/SliderLayout.java index 9cb431a..106911c 100644 --- a/library/src/main/java/com/daimajia/slider/library/SliderLayout.java +++ b/library/src/main/java/com/daimajia/slider/library/SliderLayout.java @@ -358,6 +358,9 @@ public void run() { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { + if(mSliderAdapter.getCount() < 2){ + return true; + } int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: From 66285f721ff64fe0aa743f9ad9f6ad1c3784dfbb Mon Sep 17 00:00:00 2001 From: nieyinyin Date: Tue, 2 Feb 2016 15:32:40 +0800 Subject: [PATCH 4/4] optimize the logic again: stop cycle when SliderLayout has only one SliderView --- .../com/daimajia/slider/library/SliderLayout.java | 3 --- .../slider/library/Tricks/InfiniteViewPager.java | 11 +++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/daimajia/slider/library/SliderLayout.java b/library/src/main/java/com/daimajia/slider/library/SliderLayout.java index 106911c..9cb431a 100644 --- a/library/src/main/java/com/daimajia/slider/library/SliderLayout.java +++ b/library/src/main/java/com/daimajia/slider/library/SliderLayout.java @@ -358,9 +358,6 @@ public void run() { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if(mSliderAdapter.getCount() < 2){ - return true; - } int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: diff --git a/library/src/main/java/com/daimajia/slider/library/Tricks/InfiniteViewPager.java b/library/src/main/java/com/daimajia/slider/library/Tricks/InfiniteViewPager.java index 5bcc457..38bbd66 100644 --- a/library/src/main/java/com/daimajia/slider/library/Tricks/InfiniteViewPager.java +++ b/library/src/main/java/com/daimajia/slider/library/Tricks/InfiniteViewPager.java @@ -4,6 +4,7 @@ import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.util.AttributeSet; +import android.view.MotionEvent; /** * A {@link ViewPager} that allows pseudo-infinite paging with a wrap-around effect. Should be used with an {@link @@ -24,4 +25,14 @@ public void setAdapter(PagerAdapter adapter) { super.setAdapter(adapter); } + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + if(getAdapter() != null && getAdapter() instanceof InfinitePagerAdapter){ + InfinitePagerAdapter adapter = (InfinitePagerAdapter)getAdapter(); + if(adapter.getRealCount() == 1){ + return false; + } + } + return super.onInterceptTouchEvent(ev); + } } \ No newline at end of file