private void stopDrag ( MotionEvent ev ) { mTouchMode = TOUCH_MODE_IDLE ; // Up and not canceled, also checks the switch has not been disabled // during the drag boolean commitChange = ev . getAction ( ) == MotionEvent . ACTION_UP && isEnabled ( ) ; cancelSuperTouch ( ev ) ; if ( commitChange ) { boolean newState ; mVelocityTracker . computeCurrentVelocity ( 1000 ) ; float xvel = mVelocityTracker . getXVelocity ( ) ; if ( Math . abs ( xvel ) > mMinFlingVelocity ) { // newState = isLayoutRtl() ? (xvel < 0) : (xvel > 0); newState = xvel > 0 ; } else { newState = getTargetCheckedState ( ) ; } animateThumbToCheckedState ( newState ) ; } else { animateThumbToCheckedState ( isChecked ( ) ) ; } }
Called from onTouchEvent to end a drag operation .