Add container velocity for all apps to be used by the caret

Change-Id: I03479d53eb7203ab4a0515e2bf68b917dfb81f23
This commit is contained in:
Hyunyoung Song
2016-08-02 13:31:22 -07:00
parent 1460475626
commit 5b6470679e
2 changed files with 31 additions and 26 deletions
@@ -93,10 +93,9 @@ public class VerticalPullDetector {
private float mDownX;
private float mDownY;
private float mDownMillis;
private float mLastY;
private float mLastMillis;
private long mCurrentMillis;
private float mVelocity;
private float mLastDisplacement;
@@ -153,7 +152,6 @@ public class VerticalPullDetector {
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mDownMillis = ev.getDownTime();
mDownX = ev.getX();
mDownY = ev.getY();
mLastDisplacement = 0;
@@ -167,7 +165,7 @@ public class VerticalPullDetector {
case MotionEvent.ACTION_MOVE:
mDisplacementX = ev.getX() - mDownX;
mDisplacementY = ev.getY() - mDownY;
mVelocity = computeVelocity(ev, mVelocity);
computeVelocity(ev);
// handle state and listener calls.
if (mState != ScrollState.DRAGGING && shouldScrollStart()) {
@@ -190,10 +188,7 @@ public class VerticalPullDetector {
}
// Do house keeping.
mLastDisplacement = mDisplacementY;
mLastY = ev.getY();
mLastMillis = ev.getEventTime();
return true;
}
@@ -245,21 +240,23 @@ public class VerticalPullDetector {
/**
* Computes the damped velocity using the two motion events and the previous velocity.
*/
private float computeVelocity(MotionEvent to, float previousVelocity) {
float delta = computeDelta(to);
float deltaTimeMillis = to.getEventTime() - mLastMillis;
float velocity = (deltaTimeMillis > 0) ? (delta / deltaTimeMillis) : 0;
if (Math.abs(previousVelocity) < 0.001f) {
return velocity;
}
float alpha = computeDampeningFactor(deltaTimeMillis);
return interpolate(previousVelocity, velocity, alpha);
private float computeVelocity(MotionEvent to) {
return computeVelocity(to.getY() - mLastY, to.getEventTime());
}
private float computeDelta(MotionEvent to) {
return to.getY() - mLastY;
public float computeVelocity(float delta, long currentMillis) {
long previousMillis = mCurrentMillis;
mCurrentMillis = currentMillis;
float deltaTimeMillis = mCurrentMillis - previousMillis;
float velocity = (deltaTimeMillis > 0) ? (delta / deltaTimeMillis) : 0;
if (Math.abs(mVelocity) < 0.001f) {
mVelocity = velocity;
} else {
float alpha = computeDampeningFactor(deltaTimeMillis);
mVelocity = interpolate(mVelocity, velocity, alpha);
}
return mVelocity;
}
/**