@@ -287,6 +287,9 @@ public void onClick(View v) {
287
287
}
288
288
289
289
private void smoothScrollPagerTo (final int position ) {
290
+ if (pager .isFakeDragging ())
291
+ return ;
292
+
290
293
ValueAnimator animator = ValueAnimator .ofFloat (pager .getCurrentItem (), position );
291
294
animator .addListener (new AnimatorListenerAdapter () {
292
295
@ Override
@@ -329,11 +332,17 @@ else if (position < currentPosition && Math.ceil(position) != currentPosition &&
329
332
}
330
333
});
331
334
335
+ int distance = Math .abs (position - pager .getCurrentItem ());
336
+
332
337
animator .setInterpolator (pageScrollInterpolator );
333
- animator .setDuration (pageScrollDuration );
338
+ animator .setDuration (calculateScrollDuration ( distance ) );
334
339
animator .start ();
335
340
}
336
341
342
+ private long calculateScrollDuration (int distance ) {
343
+ return Math .round (pageScrollDuration * (distance + Math .sqrt (distance )) / 2 );
344
+ }
345
+
337
346
public void nextSlide () {
338
347
int currentItem = pager .getCurrentItem ();
339
348
if (currentItem > adapter .getCount () - 1 ) finishIfNeeded ();
@@ -343,16 +352,15 @@ public void nextSlide() {
343
352
}
344
353
else {
345
354
AnimUtils .applyShakeAnimation (this , buttonNext );
346
-
347
355
}
348
356
}
349
357
350
- private boolean nextSlideAuto () {
358
+ private int nextSlideAuto () {
351
359
int endPosition = pager .getCurrentItem ();
352
360
int count = getCount ();
353
361
354
362
if (count == 1 ) {
355
- return false ;
363
+ return 0 ;
356
364
}
357
365
else if (pager .getCurrentItem () >= count - 1 ) {
358
366
while (endPosition >= 0 && canGoBackward (endPosition , true )) {
@@ -365,12 +373,16 @@ else if (canGoForward(endPosition, true)) {
365
373
endPosition ++;
366
374
}
367
375
376
+ int distance = Math .abs (endPosition - pager .getCurrentItem ());
377
+
368
378
if (endPosition == pager .getCurrentItem ())
369
- return false ;
379
+ return 0 ;
370
380
371
381
smoothScrollPagerTo (endPosition );
372
382
373
- return autoplayCounter != 0 ;
383
+ if (autoplayCounter == 0 )
384
+ return 0 ;
385
+ return distance ;
374
386
375
387
}
376
388
@@ -793,8 +805,9 @@ public void run() {
793
805
cancelAutoplay ();
794
806
return ;
795
807
}
796
- if (nextSlideAuto ())
797
- autoplayHandler .postDelayed (autoplayCallback , autoplayDelay );
808
+ int distance = nextSlideAuto ();
809
+ if (distance != 0 )
810
+ autoplayHandler .postDelayed (autoplayCallback , autoplayDelay + calculateScrollDuration (distance ));
798
811
}
799
812
};
800
813
autoplayHandler .postDelayed (autoplayCallback , autoplayDelay );
0 commit comments