Bug 716673 - Encapsulate the velocity, locked, and disableSnap variables in Axis. r=pcwalton

This commit is contained in:
Kartikaya Gupta 2012-01-10 10:06:01 -05:00
parent 507223b40b
commit 9b28ae4a9f

View File

@ -236,7 +236,8 @@ public class PanZoomController
// anything special. // anything special.
switch (mState) { switch (mState) {
case FLING: case FLING:
mX.velocity = mY.velocity = 0.0f; mX.stopFling();
mY.stopFling();
mState = PanZoomState.NOTHING; mState = PanZoomState.NOTHING;
// fall through // fall through
case ANIMATED_ZOOM: case ANIMATED_ZOOM:
@ -392,18 +393,18 @@ public class PanZoomController
angle = Math.abs(angle); // range [0, pi] angle = Math.abs(angle); // range [0, pi]
if (angle < AXIS_LOCK_ANGLE || angle > (Math.PI - AXIS_LOCK_ANGLE)) { if (angle < AXIS_LOCK_ANGLE || angle > (Math.PI - AXIS_LOCK_ANGLE)) {
// lock to x-axis // lock to x-axis
mX.locked = false; mX.setLocked(false);
mY.locked = true; mY.setLocked(true);
} else if (Math.abs(angle - (Math.PI / 2)) < AXIS_LOCK_ANGLE) { } else if (Math.abs(angle - (Math.PI / 2)) < AXIS_LOCK_ANGLE) {
// lock to y-axis // lock to y-axis
mX.locked = true; mX.setLocked(true);
mY.locked = false; mY.setLocked(false);
} else { } else {
// break axis lock but log the angle so we can fine-tune this when people complain // break axis lock but log the angle so we can fine-tune this when people complain
mState = PanZoomState.PANNING; mState = PanZoomState.PANNING;
mX.locked = mY.locked = false; mX.setLocked(false);
mY.setLocked(false);
angle = Math.abs(angle - (Math.PI / 2)); // range [0, pi/2] angle = Math.abs(angle - (Math.PI / 2)); // range [0, pi/2]
Log.i(LOGTAG, "Breaking axis lock at " + (angle * 180.0 / Math.PI) + " degrees");
} }
} }
@ -440,16 +441,14 @@ public class PanZoomController
} }
private void fling() { private void fling() {
mX.disableSnap = mY.disableSnap = mOverridePanning;
mX.displace(mOverridePanning); mY.displace(mOverridePanning); mX.displace(mOverridePanning); mY.displace(mOverridePanning);
updatePosition(); updatePosition();
stopAnimationTimer(); stopAnimationTimer();
boolean stopped = stopped(); boolean stopped = stopped();
mX.startFling(stopped); mX.startFling(stopped, mOverridePanning);
mY.startFling(stopped); mY.startFling(stopped, mOverridePanning);
startAnimationTimer(new FlingRunnable()); startAnimationTimer(new FlingRunnable());
} }
@ -706,9 +705,9 @@ public class PanZoomController
private float firstTouchPos; /* Position of the first touch event on the current drag. */ private float firstTouchPos; /* Position of the first touch event on the current drag. */
private float touchPos; /* Position of the most recent touch event on the current drag. */ private float touchPos; /* Position of the most recent touch event on the current drag. */
private float lastTouchPos; /* Position of the touch event before touchPos. */ private float lastTouchPos; /* Position of the touch event before touchPos. */
public float velocity; /* Velocity in this direction. */ private float velocity; /* Velocity in this direction. */
public boolean locked; /* Whether movement on this axis is locked. */ private boolean locked; /* Whether movement on this axis is locked. */
public boolean disableSnap; /* Whether overscroll snapping is disabled. */ private boolean disableSnap; /* Whether overscroll snapping is disabled. */
private FlingStates mFlingState; /* The fling state we're in on this axis. */ private FlingStates mFlingState; /* The fling state we're in on this axis. */
@ -738,6 +737,10 @@ public class PanZoomController
return currentPos - firstTouchPos; return currentPos - firstTouchPos;
} }
void setLocked(boolean locked) {
this.locked = locked;
}
void saveTouchPos() { void saveTouchPos() {
lastTouchPos = touchPos; lastTouchPos = touchPos;
} }
@ -810,7 +813,9 @@ public class PanZoomController
return locked ? 0.0f : velocity; return locked ? 0.0f : velocity;
} }
public void startFling(boolean stopped) { public void startFling(boolean stopped, boolean panningOverridden) {
disableSnap = panningOverridden;
if (stopped) { if (stopped) {
setFlingState(FlingStates.STOPPED); setFlingState(FlingStates.STOPPED);
} else { } else {