diff options
| author | Grace Kloba <klobag@google.com> | 2010-05-17 19:19:06 -0700 |
|---|---|---|
| committer | Grace Kloba <klobag@google.com> | 2010-05-17 20:34:08 -0700 |
| commit | 3c19d99042ee6ebbfda23cdfb65e3cc7fda72031 (patch) | |
| tree | abf50dccd0e93b6b6050507206fb19b96dd00d8a /core/java | |
| parent | e0e9cb54346c182cd89314a07677b361227ce699 (diff) | |
If the new fling is much slower (less than 1/5 of
the previous fling), don't accelerate it.
Fix http://b/issue?id=2672074
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/webkit/WebView.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index b01022edb90c..4764722e9160 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -398,6 +398,10 @@ public class WebView extends AbsoluteLayout private float mLastVelX; private float mLastVelY; + // only trigger accelerated fling if the new velocity is at least + // MINIMUM_VELOCITY_RATIO_FOR_ACCELERATION times of the previous velocity + private static final float MINIMUM_VELOCITY_RATIO_FOR_ACCELERATION = 0.2f; + /** * Touch mode */ @@ -5512,13 +5516,16 @@ public class WebView extends AbsoluteLayout return; } float currentVelocity = mScroller.getCurrVelocity(); - if (mLastVelocity > 0 && currentVelocity > 0) { + float velocity = (float) Math.hypot(vx, vy); + if (mLastVelocity > 0 && currentVelocity > 0 && velocity + > mLastVelocity * MINIMUM_VELOCITY_RATIO_FOR_ACCELERATION) { float deltaR = (float) (Math.abs(Math.atan2(mLastVelY, mLastVelX) - Math.atan2(vy, vx))); final float circle = (float) (Math.PI) * 2.0f; if (deltaR > circle * 0.9f || deltaR < circle * 0.1f) { vx += currentVelocity * mLastVelX / mLastVelocity; vy += currentVelocity * mLastVelY / mLastVelocity; + velocity = (float) Math.hypot(vx, vy); if (DebugFlags.WEB_VIEW) { Log.v(LOGTAG, "doFling vx= " + vx + " vy=" + vy); } @@ -5534,7 +5541,7 @@ public class WebView extends AbsoluteLayout } mLastVelX = vx; mLastVelY = vy; - mLastVelocity = (float) Math.hypot(vx, vy); + mLastVelocity = velocity; mScroller.fling(mScrollX, mScrollY, -vx, -vy, 0, maxX, 0, maxY); // TODO: duration is calculated based on velocity, if the range is |
