diff options
author | Tony Wickham <twickham@google.com> | 2015-09-16 15:38:16 -0700 |
---|---|---|
committer | Tony Wickham <twickham@google.com> | 2015-09-16 16:28:43 -0700 |
commit | ab946a19d41f245e27580281c3904e6c6636bcdd (patch) | |
tree | 5082de325b4bc41e478bd37ce41bbbd21ba6b513 /src/com/android/launcher3/util | |
parent | 6d1bbe350f0e37e99ec31b4ab480cc83f0b0c5dc (diff) | |
download | android_packages_apps_Trebuchet-ab946a19d41f245e27580281c3904e6c6636bcdd.tar.gz android_packages_apps_Trebuchet-ab946a19d41f245e27580281c3904e6c6636bcdd.tar.bz2 android_packages_apps_Trebuchet-ab946a19d41f245e27580281c3904e6c6636bcdd.zip |
Flinging to the left deletes when in vertical bar layout mode.
This mode has the remove icon on the left side, so flinging to the
left makes more sense. But flinging up still works in either case.
Change-Id: I7ab40776b67659026f03f81efd43fae3375b5ba0
Diffstat (limited to 'src/com/android/launcher3/util')
-rw-r--r-- | src/com/android/launcher3/util/FlingAnimation.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/com/android/launcher3/util/FlingAnimation.java b/src/com/android/launcher3/util/FlingAnimation.java index f82038bf2..da8bae712 100644 --- a/src/com/android/launcher3/util/FlingAnimation.java +++ b/src/com/android/launcher3/util/FlingAnimation.java @@ -51,7 +51,7 @@ public class FlingAnimation implements AnimatorUpdateListener { mFrom.top += yOffset; mFrom.bottom -= yOffset; - mDuration = initDuration(); + mDuration = Math.abs(vel.y) > Math.abs(vel.x) ? initFlingUpDuration() : initFlingLeftDuration(); mAnimationTimeFraction = ((float) mDuration) / (mDuration + DRAG_END_DELAY); } @@ -62,7 +62,7 @@ public class FlingAnimation implements AnimatorUpdateListener { * - Calculate a constant acceleration in x direction such that the object reaches * {@link #mIconRect} in the given time. */ - protected int initDuration() { + protected int initFlingUpDuration() { float sY = -mFrom.bottom; float d = mUY * mUY + 2 * sY * MAX_ACCELERATION; @@ -83,6 +83,34 @@ public class FlingAnimation implements AnimatorUpdateListener { return (int) Math.round(t); } + /** + * The fling animation is based on the following system + * - Apply a constant force in the x direction to causing the fling to decelerate. + * - The animation runs for the time taken by the object to go out of the screen. + * - Calculate a constant acceleration in y direction such that the object reaches + * {@link #mIconRect} in the given time. + */ + protected int initFlingLeftDuration() { + float sX = -mFrom.right; + + float d = mUX * mUX + 2 * sX * MAX_ACCELERATION; + if (d >= 0) { + // sX can be reached under the MAX_ACCELERATION. Use MAX_ACCELERATION for x direction. + mAX = MAX_ACCELERATION; + } else { + // sX is not reachable, decrease the acceleration so that sX is almost reached. + d = 0; + mAX = mUX * mUX / (2 * -sX); + } + double t = (-mUX - Math.sqrt(d)) / mAX; + + float sY = -mFrom.exactCenterY() + mIconRect.exactCenterY(); + + // Find vertical acceleration such that: u*t + a*t*t/2 = s + mAY = (float) ((sY - t * mUY) * 2 / (t * t)); + return (int) Math.round(t); + } + public final int getDuration() { return mDuration + DRAG_END_DELAY; } |