Merge "Round up time calculations in LinearSmoothScroller" into lmp-preview-dev
diff --git a/v7/recyclerview/src/android/support/v7/widget/LinearSmoothScroller.java b/v7/recyclerview/src/android/support/v7/widget/LinearSmoothScroller.java
index 295aac7..8036a0c 100644
--- a/v7/recyclerview/src/android/support/v7/widget/LinearSmoothScroller.java
+++ b/v7/recyclerview/src/android/support/v7/widget/LinearSmoothScroller.java
@@ -168,7 +168,7 @@
// area under curve (1-(1-x)^2) can be calculated as (1 - x/3) * x * x
// which gives 0.100028 when x = .3356
// this is why we divide linear scrolling time with .3356
- return (int) (calculateTimeForScrolling(dx) / .3356);
+ return (int) Math.ceil(calculateTimeForScrolling(dx) / .3356);
}
/**
@@ -179,7 +179,10 @@
* @see #calculateSpeedPerPixel(android.util.DisplayMetrics)
*/
protected int calculateTimeForScrolling(int dx) {
- return Math.round(Math.abs(dx) * MILLISECONDS_PER_PX);
+ // In a case where dx is very small, rounding may return 0 although dx > 0.
+ // To avoid that issue, ceil the result so that if dx > 0, we'll always return positive
+ // time.
+ return (int) Math.ceil(Math.abs(dx) * MILLISECONDS_PER_PX);
}
/**