summaryrefslogtreecommitdiffstats
path: root/carousel/java
diff options
context:
space:
mode:
authorJim Shuma <jshuma@google.com>2010-12-01 15:12:28 -0800
committerJim Shuma <jshuma@google.com>2010-12-01 15:53:20 -0800
commitb2c785780ecbe79a5b7ba558b21985f956458c8c (patch)
tree24c2d39b65499b13b01cba96bbf149a68246a629 /carousel/java
parent9c019da0f3083c4b82552fb2fe5b052f90073cb9 (diff)
downloadandroid_frameworks_ex-b2c785780ecbe79a5b7ba558b21985f956458c8c.tar.gz
android_frameworks_ex-b2c785780ecbe79a5b7ba558b21985f956458c8c.tar.bz2
android_frameworks_ex-b2c785780ecbe79a5b7ba558b21985f956458c8c.zip
Tap to stop the carousel
When the carousel is moving faster than 15 degrees per second, a tap will stop the motion but not be interpreted as a selection. Slower than that, it will be considered a selection. This is an improvement on an earlier implementation because it lets through selections when the carousel is still moving slowly. Bug: 3179984 Change-Id: I27b55cf88e20d4ef1383ec0e4144f65a101f37fc
Diffstat (limited to 'carousel/java')
-rw-r--r--carousel/java/com/android/ex/carousel/carousel.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/carousel/java/com/android/ex/carousel/carousel.rs b/carousel/java/com/android/ex/carousel/carousel.rs
index 939cb85..1de38de 100644
--- a/carousel/java/com/android/ex/carousel/carousel.rs
+++ b/carousel/java/com/android/ex/carousel/carousel.rs
@@ -896,7 +896,8 @@ static int64_t lastTime = 0L; // keep track of how much time has passed between
static float lastAngle = 0.0f;
static float2 lastPosition;
static bool animating = false;
-static float velocityThreshold = 0.1f * M_PI / 180.0f;
+static float stopVelocity = 0.1f * M_PI / 180.0f; // slower than this: carousel stops
+static float selectionVelocity = 15.0f * M_PI / 180.0f; // faster than this: tap won't select
static float velocityTracker;
static int velocityTrackerCount;
static float mass = 5.0f; // kg
@@ -977,13 +978,13 @@ void doStart(float x, float y, long eventTime)
{
touchPosition = lastPosition = (float2) { x, y };
lastAngle = hitAngle(x,y, &lastAngle) ? lastAngle : 0.0f;
+ enableSelection = fabs(velocity) < selectionVelocity;
velocity = 0.0f;
velocityTracker = 0.0f;
velocityTrackerCount = 0;
touchTime = lastTime = eventTime;
touchBias = bias;
isDragging = true;
- enableSelection = true;
animatedSelection = doSelection(x, y); // used to provide visual feedback on touch
}
@@ -1013,7 +1014,7 @@ void doStop(float x, float y, long eventTime)
// TODO: move velocity tracking to Java
velocity = velocityTrackerCount > 0 ?
(velocityTracker / velocityTrackerCount) : 0.0f; // avg velocity
- if (fabs(velocity) > velocityThreshold) {
+ if (fabs(velocity) > stopVelocity) {
animating = true;
}
}
@@ -1305,7 +1306,7 @@ static bool doPhysics(float dt)
velocity = momentum / mass;
bias += velocity * dt;
}
- return fabs(velocity) > velocityThreshold;
+ return fabs(velocity) > stopVelocity;
}
static float easeOut(float x)