@@ -281,22 +281,32 @@ public boolean onTouch(View v, MotionEvent event) {
281281 mHandleView .setPressed (false );
282282 mBar .onTrackingStopped (PanelView .this );
283283 trackMovement (event );
284- mVelocityTracker .computeCurrentVelocity (1000 );
285284
286- float yVel = mVelocityTracker . getYVelocity () ;
287- boolean negative = yVel < 0 ;
285+ float vel = 0 , yVel = 0 , xVel = 0 ;
286+ boolean negative = false ;
288287
289- float xVel = mVelocityTracker .getXVelocity ();
290- if (xVel < 0 ) {
291- xVel = -xVel ;
292- }
293- if (xVel > mFlingGestureMaxXVelocityPx ) {
294- xVel = mFlingGestureMaxXVelocityPx ; // limit how much we care about the x axis
295- }
288+ if (mVelocityTracker != null ) {
289+ // the velocitytracker might be null if we got a bad input stream
290+ mVelocityTracker .computeCurrentVelocity (1000 );
291+
292+ yVel = mVelocityTracker .getYVelocity ();
293+ negative = yVel < 0 ;
296294
297- float vel = (float )Math .hypot (yVel , xVel );
298- if (vel > mFlingGestureMaxOutputVelocityPx ) {
299- vel = mFlingGestureMaxOutputVelocityPx ;
295+ xVel = mVelocityTracker .getXVelocity ();
296+ if (xVel < 0 ) {
297+ xVel = -xVel ;
298+ }
299+ if (xVel > mFlingGestureMaxXVelocityPx ) {
300+ xVel = mFlingGestureMaxXVelocityPx ; // limit how much we care about the x axis
301+ }
302+
303+ vel = (float )Math .hypot (yVel , xVel );
304+ if (vel > mFlingGestureMaxOutputVelocityPx ) {
305+ vel = mFlingGestureMaxOutputVelocityPx ;
306+ }
307+
308+ mVelocityTracker .recycle ();
309+ mVelocityTracker = null ;
300310 }
301311
302312 // if you've barely moved your finger, we treat the velocity as 0
@@ -321,9 +331,6 @@ public boolean onTouch(View v, MotionEvent event) {
321331
322332 fling (vel , true );
323333
324- mVelocityTracker .recycle ();
325- mVelocityTracker = null ;
326-
327334 break ;
328335 }
329336 return true ;
0 commit comments