Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the logic: stop cycle when SliderLayout has only one SliderView #186

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -235,6 +238,11 @@ public void setCustomIndicator(PagerIndicator indicator){

public <T extends BaseSliderView> 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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion library/src/main/res/layout/slider_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
<com.daimajia.slider.library.Indicators.PagerIndicator
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<enum name="invisible" value="1"/>
</attr>

<attr name="shape" format="enum">
<attr name="daimajia_slider_shape" format="enum">
<enum value="0" name="oval"/>
<enum value="1" name="rect"/>
</attr>
Expand Down
6 changes: 3 additions & 3 deletions library/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<item name="android:background">@drawable/indicator_corner_bg</item>
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingRight">2dp</item>
<item name="shape">oval</item>
<item name="daimajia_slider_shape">oval</item>
<item name="padding_left">3dp</item>
<item name="padding_right">3dp</item>
<item name="padding_top">4dp</item>
Expand All @@ -27,7 +27,7 @@
<item name="android:gravity">center</item>
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingRight">2dp</item>
<item name="shape">rect</item>
<item name="daimajia_slider_shape">rect</item>
<item name="padding_left">3dp</item>
<item name="padding_right">3dp</item>
<item name="padding_top">4dp</item>
Expand All @@ -47,7 +47,7 @@
<item name="android:gravity">center</item>
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingRight">2dp</item>
<item name="shape">oval</item>
<item name="daimajia_slider_shape">oval</item>
<item name="padding_left">3dp</item>
<item name="padding_right">3dp</item>
<item name="padding_top">4dp</item>
Expand Down