private double touches = 0;
private int lastX = 0;
private int lastY = 0;
- private double lastTime = 0;
private boolean snappedScrollEnabled = true;
private double deltaX = 0;
private double deltaY = 0;
private CustomTouchEvent latestTouchMoveEvent;
/** The timestamp of {@link #flickPageX1} and {@link #flickPageY1} */
- private double flickTimestamp = Double.MIN_VALUE;
+ private double flickStartTime = 0;
+
+ /** The timestamp of {@link #flickPageX2} and {@link #flickPageY2} */
+ private double flickTimestamp = 0;
/** The most recent flick touch reference Y */
private double flickPageY1 = -1;
* over here.
*/
private AnimationCallback mover = new AnimationCallback() {
+
@Override
public void execute(double timestamp) {
if (touches != 1) {
final int y = latestTouchMoveEvent.getPageY();
/*
- * Check if we need a new flick coordinate sample (more than
- * FLICK_POLL_FREQUENCY ms have passed since the last
- * sample)
+ * Check if we need a new flick coordinate sample ( more
+ * than FLICK_POLL_FREQUENCY ms have passed since the last
+ * sample )
*/
- if (timestamp - flickTimestamp > FLICK_POLL_FREQUENCY) {
- flickTimestamp = timestamp;
- flickPageY2 = flickPageY1;
- flickPageY1 = y;
+ if (System.currentTimeMillis() - flickTimestamp > FLICK_POLL_FREQUENCY) {
- flickPageX2 = flickPageX1;
- flickPageX1 = x;
+ flickTimestamp = System.currentTimeMillis();
+ // Set target coordinates
+ flickPageY2 = y;
+ flickPageX2 = x;
}
deltaX = x - lastX;
lastX = x;
lastY = y;
- /*
- * Instead of using the provided arbitrary timestamp, let's
- * use a known-format and reproducible timestamp.
- */
- lastTime = Duration.currentTimeMillis();
-
// snap the scroll to the major axes, at first.
if (snappedScrollEnabled) {
final double oldDeltaX = deltaX;
lastX = event.getPageX();
lastY = event.getPageY();
+ // Reset flick parameters
+ flickPageX1 = lastX;
+ flickPageX2 = -1;
+ flickPageY1 = lastY;
+ flickPageY2 = -1;
+ flickStartTime = System.currentTimeMillis();
+ flickTimestamp = 0;
+
snappedScrollEnabled = true;
}
final double finalPageY;
final double finalPageX;
- double deltaT = lastTime - flickTimestamp;
+ double deltaT = flickTimestamp - flickStartTime;
boolean onlyOneSample = flickPageX2 < 0 || flickPageY2 < 0;
- if (onlyOneSample || deltaT > FLICK_POLL_FREQUENCY / 3) {
- finalPageY = flickPageY1;
- finalPageX = flickPageX1;
+ if (onlyOneSample) {
+ finalPageX = latestTouchMoveEvent.getPageX();
+ finalPageY = latestTouchMoveEvent.getPageY();
} else {
- deltaT += FLICK_POLL_FREQUENCY;
finalPageY = flickPageY2;
finalPageX = flickPageX2;
}
- flickPageY1 = -1;
- flickPageY2 = -1;
- flickTimestamp = Double.MIN_VALUE;
-
- double deltaX = latestTouchMoveEvent.getPageX()
- - finalPageX;
- double deltaY = latestTouchMoveEvent.getPageY()
- - finalPageY;
+ double deltaX = finalPageX - flickPageX1;
+ double deltaY = finalPageY - flickPageY1;
escalator.scroller
.handleFlickScroll(deltaX, deltaY, deltaT);