Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class AutoScrollViewPager extends ViewPager {
/** scroll factor for swipe scroll animation, default is 1.0 **/
private double swipeScrollFactor = 1.0;

/** first scroll delay time */
private long delayTimeInMills;

private Handler handler;
private boolean isAutoScroll = false;
private boolean isStopByTouch = false;
Expand Down Expand Up @@ -91,7 +94,7 @@ private void init() {
*/
public void startAutoScroll() {
isAutoScroll = true;
sendScrollMessage((long)(interval + scroller.getDuration() / autoScrollFactor * swipeScrollFactor));
this.delayTimeInMills = (long)(interval + scroller.getDuration() / autoScrollFactor * swipeScrollFactor);
}

/**
Expand All @@ -101,15 +104,40 @@ public void startAutoScroll() {
*/
public void startAutoScroll(int delayTimeInMills) {
isAutoScroll = true;
sendScrollMessage(delayTimeInMills);
this.delayTimeInMills = delayTimeInMills;
}

/**
* start scroll when view attached
*/
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if(isAutoScroll){
sendScrollMessage(delayTimeInMills);
}
}

/**
* stop scroll when view detached
*/
@Override
protected void onDetachedFromWindow() {
if(isAutoScroll){
handler.removeMessages(SCROLL_WHAT);
}
super.onDetachedFromWindow();
}


/**
* stop auto scroll
*/
public void stopAutoScroll() {
isAutoScroll = false;
handler.removeMessages(SCROLL_WHAT);
if(isAutoScroll){
isAutoScroll = false;
handler.removeMessages(SCROLL_WHAT);
}
}

/**
Expand Down