summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com
diff options
context:
space:
mode:
authorJorim Jaggi <jjaggi@google.com>2014-05-21 23:24:30 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-21 23:24:31 +0000
commit8aacfb80995f88f8fe5f05562cca4963988945c4 (patch)
tree11b292851e02d1bf03b2cb634c715c41fb24071d /packages/SystemUI/src/com
parent05b7e2c671557a265778d2b55177c2d28ba8c78d (diff)
parentefbd7e3bb8244efae2561f0d9d7cedb36b1730bd (diff)
downloadframeworks_base-8aacfb80995f88f8fe5f05562cca4963988945c4.zip
frameworks_base-8aacfb80995f88f8fe5f05562cca4963988945c4.tar.gz
frameworks_base-8aacfb80995f88f8fe5f05562cca4963988945c4.tar.bz2
Merge "Improve logic when flinging up."
Diffstat (limited to 'packages/SystemUI/src/com')
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/FlingAnimationUtils.java31
1 files changed, 26 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/FlingAnimationUtils.java b/packages/SystemUI/src/com/android/systemui/statusbar/FlingAnimationUtils.java
index bb3a295..7d576cb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/FlingAnimationUtils.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/FlingAnimationUtils.java
@@ -28,33 +28,35 @@ import android.view.animation.PathInterpolator;
public class FlingAnimationUtils {
private static final float LINEAR_OUT_SLOW_IN_X2 = 0.35f;
- private static final float LINEAR_OUT_FASTER_IN_Y2 = 0.7f;
+ private static final float LINEAR_OUT_FASTER_IN_Y2_MIN = 0.7f;
+ private static final float LINEAR_OUT_FASTER_IN_Y2_MAX = 1f;
private static final float MIN_VELOCITY_DP_PER_SECOND = 250;
+ private static final float HIGH_VELOCITY_DP_PER_SECOND = 3000;
/**
* Crazy math. http://en.wikipedia.org/wiki/B%C3%A9zier_curve
*/
private static final float LINEAR_OUT_SLOW_IN_START_GRADIENT = 1.0f / LINEAR_OUT_SLOW_IN_X2;
- private static final float LINEAR_OUT_FASTER_IN_START_GRADIENT = LINEAR_OUT_FASTER_IN_Y2;
private Interpolator mLinearOutSlowIn;
private Interpolator mFastOutSlowIn;
private Interpolator mFastOutLinearIn;
- private Interpolator mLinearOutFasterIn;
private float mMinVelocityPxPerSecond;
private float mMaxLengthSeconds;
+ private float mHighVelocityPxPerSecond;
public FlingAnimationUtils(Context ctx, float maxLengthSeconds) {
mMaxLengthSeconds = maxLengthSeconds;
mLinearOutSlowIn = new PathInterpolator(0, 0, LINEAR_OUT_SLOW_IN_X2, 1);
- mLinearOutFasterIn = new PathInterpolator(0, 0, 1, LINEAR_OUT_FASTER_IN_Y2);
mFastOutSlowIn
= AnimationUtils.loadInterpolator(ctx, android.R.interpolator.fast_out_slow_in);
mFastOutLinearIn
= AnimationUtils.loadInterpolator(ctx, android.R.interpolator.fast_out_linear_in);
mMinVelocityPxPerSecond
= MIN_VELOCITY_DP_PER_SECOND * ctx.getResources().getDisplayMetrics().density;
+ mHighVelocityPxPerSecond
+ = HIGH_VELOCITY_DP_PER_SECOND * ctx.getResources().getDisplayMetrics().density;
}
/**
@@ -126,7 +128,12 @@ public class FlingAnimationUtils {
* Math.pow(Math.abs(endValue - currValue) / maxDistance, 0.5f));
float diff = Math.abs(endValue - currValue);
float velAbs = Math.abs(velocity);
- float durationSeconds = LINEAR_OUT_FASTER_IN_START_GRADIENT * diff / velAbs;
+ float y2 = calculateLinearOutFasterInY2(velAbs);
+
+ // The gradient at the start of the curve is just y2.
+ float startGradient = y2;
+ Interpolator mLinearOutFasterIn = new PathInterpolator(0, 0, 1, y2);
+ float durationSeconds = startGradient * diff / velAbs;
if (durationSeconds <= maxLengthSeconds) {
animator.setInterpolator(mLinearOutFasterIn);
} else if (velAbs >= mMinVelocityPxPerSecond) {
@@ -149,6 +156,20 @@ public class FlingAnimationUtils {
}
/**
+ * Calculates the y2 control point for a linear-out-faster-in path interpolator depending on the
+ * velocity. The faster the velocity, the more "linear" the interpolator gets.
+ *
+ * @param velocity the velocity of the gesture.
+ * @return the y2 control point for a cubic bezier path interpolator
+ */
+ private float calculateLinearOutFasterInY2(float velocity) {
+ float t = (velocity - mMinVelocityPxPerSecond)
+ / (mHighVelocityPxPerSecond - mMinVelocityPxPerSecond);
+ t = Math.max(0, Math.min(1, t));
+ return (1 - t) * LINEAR_OUT_FASTER_IN_Y2_MIN + t * LINEAR_OUT_FASTER_IN_Y2_MAX;
+ }
+
+ /**
* @return the minimum velocity a gesture needs to have to be considered a fling
*/
public float getMinVelocityPxPerSecond() {